This is the method to try: (how to generate mock data for UriInfo)
public EntityCollection getEntitySet(UriInfo uriInfo) {
logger.info("getEntitySet()");
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
EntityCollection entityCollection = getData(edmEntitySet);
return entityCollection;
}
Right now I have this, but it fails in "(UriResourceEntitySet) resourcePaths.get (0) because it is null"
this is my code:
private DataViewController dataView = new DataViewController();
@Mock
private EntityProvider service = new GenericEntityProvider();
@Mock
private UriInfo uriInfo;
private MockMvc mockMvc;
@Before
public void setUp(){
this.mockMvc = MockMvcBuilders.standaloneSetup(dataView).build();
}
/**
* Get Entity test.
*/
@Test
public void getEntity() throws Exception {
EntityCollection entityCollection = new EntityCollection();
EntityProvider provider = new GenericEntityProvider();
Mockito.when(provider.getEntitySet(uriInfo)).thenReturn(entityCollection);
mockMvc.perform(get("http://localhost:8081/itaca/odata/PER_BANK")).andExpect(status().isNotFound());
}