use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class MdsRestControllerTest method testRead.
private void testRead(String entityName, String moduleName, String namespace) throws Exception {
final RestProjection record1 = new RestProjection();
record1.put(NAME_FIELD, "T1");
record1.put(VAL_FIELD, 5);
final RestProjection record2 = new RestProjection();
record1.put(NAME_FIELD, "T2");
record1.put(VAL_FIELD, 5);
final List<RestProjection> records = asList(record1, record2);
final RestResponse response = new RestResponse(entityName, CLASSNAME, moduleName, namespace, 2l, new QueryParams(1, 20), records);
final RestResponse response2 = new RestResponse(entityName, CLASSNAME, moduleName, namespace, 1l, new QueryParams(1, 1), asList(record1));
when(restFacadeRetriever.getRestFacade(entityName, moduleName, namespace)).thenReturn(restFacade);
when(restFacade.get(any(QueryParams.class), anyBoolean())).thenReturn(response);
when(restFacade.get(1l, true)).thenReturn(response2);
mockMvc.perform(get(buildUrl(entityName, moduleName, namespace) + "?" + PAGINATION_STR)).andExpect(status().isOk()).andExpect(content().string(objectMapper.writeValueAsString(response)));
mockMvc.perform(get(buildUrl(entityName, moduleName, namespace) + "?id=1")).andExpect(status().isOk()).andExpect(content().string(objectMapper.writeValueAsString(response2)));
ArgumentCaptor<QueryParams> captor = ArgumentCaptor.forClass(QueryParams.class);
verify(restFacade).get(captor.capture(), anyBoolean());
ArgumentCaptor<Long> longCaptor = ArgumentCaptor.forClass(Long.class);
verify(restFacade).get(longCaptor.capture(), anyBoolean());
verifyQueryParams(captor.getValue());
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceServiceTest method shouldNotUpdateGridSizeWhenUsernameIsBlank.
@Test
public void shouldNotUpdateGridSizeWhenUsernameIsBlank() {
EntityDto entityDto = new EntityDto();
entityDto.setReadOnlySecurityMode(null);
entityDto.setSecurityMode(null);
entityDto.setClassName(TestSample.class.getName());
EntityRecord entityRecord = new EntityRecord(ENTITY_ID + 1, null, new ArrayList<FieldRecord>());
when(entityService.getEntity(ENTITY_ID + 1)).thenReturn(entityDto);
mockDataService();
instanceService.getEntityRecords(entityRecord.getId(), new QueryParams(1, 100));
verify(entityService).getEntityFieldsForUI(ENTITY_ID + 1);
verify(userPreferencesService, never()).updateGridSize(anyLong(), anyString(), anyInt());
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceController method getRelatedValues.
@RequestMapping(value = "/instances/{entityId}/instance/new/{fieldName}", method = RequestMethod.POST)
@ResponseBody
public Records<BasicEntityRecord> getRelatedValues(@PathVariable Long entityId, @PathVariable String fieldName, String filters, GridSettings settings) {
RelationshipsUpdate filter = parseRelatedInstancesFilter(filters);
QueryParams queryParams = QueryParamsBuilder.buildQueryParams(settings);
Records<BasicEntityRecord> records = instanceService.getRelatedFieldValue(entityId, null, fieldName, filter, queryParams);
processFieldsForUI(records);
return records;
}
Aggregations