AddressTypeController extends BaseController implements PagedController<AddressTypeResource, AddressTypeResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(method = RequestMethod.GET) @ApiOperation(value = "Get All Address Types") public PagedResultResource<AddressTypeResource> getPagedResource(final PagedRequest<AddressTypeResource> request) { LOG.info("Getting PagedResultResource for Address Tyoe with offset: {}, limit: {}", request.getOffset(), request.getLimit()); return facade.getResources(request); }  @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(method = RequestMethod.GET) @ApiOperation(value = "Get All Address Types") PagedResultResource<AddressTypeResource> getPagedResource(final PagedRequest<AddressTypeResource> request); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Address Types by id") AddressTypeResource getResource(@PathVariable("id") final Long id);  }
@Test public void testOrderBy() throws Exception { int offset = 0; int limit = 20; long count = 1; String abbrName = "abbr name"; String name = "name"; AddressTypeResource resource = new AddressTypeResource(); resource.setAbbrName(abbrName); resource.setName(name); List<AddressTypeResource> entities = Arrays.asList(resource); PagedResultResource<AddressTypeResource> expected = new PagedResultResource<>( "/addresstypes"); expected.setResources(entities); expected.setCount(count); expected.setLimit(limit); expected.setOffset(offset); OrderBy orderBy1 = new OrderBy("abbrName", OrderByType.ASC); OrderBy orderBy2 = new OrderBy("name", OrderByType.DESC); List<OrderBy> orders = Arrays.asList(orderBy1, orderBy2); PagedRequest<AddressTypeResource> request = new PagedRequest<AddressTypeResource>(); request.setOffset(offset); request.setLimit(limit); request.setOrders(orders); when(facade.getResources(Matchers.<PagedRequest<AddressTypeResource>> any())).thenReturn(expected); String response = getJson(expected, false); PagedResultResource<AddressTypeResource> actual = unit.getPagedResource(request); mockMvc.perform(get("/addresstypes")) .andExpect(status().isOk()) .andExpect(content().string(response)); assertEquals(expected, actual); }