I am using Spring 3.2.11.RELEASE and JUnit 4.11. I am using the Springs org.springframework.test.web.servlet.MockMvcFramework to test the controller method. In one test, I have a model that is populated with the following object:
public class MyObjectForm
{
private List<MyObject> myobjects;
public List<MyObject> getMyObjects() {
return myobjects;
}
public void setMyObjects(List<MyObject> myobjects) {
this.myobjects = myobjects;
}
}
The object "MyObject", in turn, has the following field ...
public class MyObject
{
…
private Boolean myProperty;
Using the MockMvc framework, how can I verify that the first item in the "myobjects" list has the attribute "myProperty" equal to true? As long as I know this is happening like this ...
mockMvc.perform(get("/my-path/get-page")
.param("param1", ids))
.andExpect(status().isOk())
.andExpect(model().attribute("MyObjectForm", hasProperty("myobjects[0].myProperty", Matchers.equalTo(true))))
.andExpect(view().name("assessment/upload"));
but i don't know how to check attribute attribute value?
source
share