use of org.motechproject.mds.web.domain.BasicEntityRecord in project motech by motech.
the class InstanceControllerTest method shouldRetrieveRelatedFieldValues.
@Test
public void shouldRetrieveRelatedFieldValues() throws Exception {
Records<BasicEntityRecord> records = new Records<>(2, 5, 7, recordsList());
when(instanceService.getRelatedFieldValue(eq(1L), eq(6L), eq("relField"), any(RelationshipsUpdate.class), any(QueryParams.class))).thenReturn(records);
controller.perform(post("/instances/1/instance/6/relField?rows=5&page=2&sortColumn=age&sortDirection=desc")).andExpect(status().isOk()).andExpect(content().type(RestTestUtil.JSON_UTF8)).andExpect(content().string(new ObjectMapper().writeValueAsString(records)));
ArgumentCaptor<QueryParams> captor = ArgumentCaptor.forClass(QueryParams.class);
verify(instanceService).getRelatedFieldValue(eq(1L), eq(6L), eq("relField"), any(RelationshipsUpdate.class), captor.capture());
QueryParams queryParams = captor.getValue();
// check query params
assertNotNull(queryParams);
assertEquals(Integer.valueOf(5), queryParams.getPageSize());
assertEquals(Integer.valueOf(2), queryParams.getPage());
assertNotNull(queryParams.getOrderList());
assertEquals(2, queryParams.getOrderList().size());
assertEquals("age", queryParams.getOrderList().get(0).getField());
assertEquals(Order.Direction.DESC, queryParams.getOrderList().get(0).getDirection());
assertEquals(Constants.Util.ID_FIELD_NAME, queryParams.getOrderList().get(1).getField());
assertEquals(Order.Direction.ASC, queryParams.getOrderList().get(1).getDirection());
}
use of org.motechproject.mds.web.domain.BasicEntityRecord in project motech by motech.
the class InstanceServiceTest method shouldHandleNullParamsForLookups.
@Test
public void shouldHandleNullParamsForLookups() {
mockSampleFields();
mockEntity();
mockLookups();
mockLookupService();
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("dtField", null);
List<BasicEntityRecord> result = instanceService.getEntityRecordsFromLookup(ENTITY_ID, TestDataService.NULL_EXPECTING_LOOKUP_NAME, lookupMap, queryParams());
assertNotNull(result);
assertEquals(2, result.size());
BasicEntityRecord entityRecord = result.get(0);
List<? extends BasicFieldRecord> fieldRecords = entityRecord.getFields();
assertCommonBasicFieldRecordFields(fieldRecords);
assertEquals(asList("three", 3, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
entityRecord = result.get(1);
fieldRecords = entityRecord.getFields();
assertCommonBasicFieldRecordFields(fieldRecords);
assertEquals(asList("four", 4, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
use of org.motechproject.mds.web.domain.BasicEntityRecord in project motech by motech.
the class InstanceServiceTest method shouldRetrieveInstancesBasedOnASingleReturnLookup.
@Test
public void shouldRetrieveInstancesBasedOnASingleReturnLookup() {
mockSampleFields();
mockEntity();
mockLookups();
mockLookupService();
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("strField", TestDataService.LOOKUP_1_EXPECTED_PARAM);
List<BasicEntityRecord> result = instanceService.getEntityRecordsFromLookup(ENTITY_ID, TestDataService.LOOKUP_1_NAME, lookupMap, queryParams());
assertNotNull(result);
assertEquals(1, result.size());
BasicEntityRecord entityRecord = result.get(0);
List<? extends BasicFieldRecord> fieldRecords = entityRecord.getFields();
assertCommonBasicFieldRecordFields(fieldRecords);
assertEquals(asList("strField", 6, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
use of org.motechproject.mds.web.domain.BasicEntityRecord in project motech by motech.
the class InstanceServiceTest method shouldRetrieveInstancesBasedOnAMultiReturnLookup.
@Test
public void shouldRetrieveInstancesBasedOnAMultiReturnLookup() {
mockSampleFields();
mockEntity();
mockLookups();
mockLookupService();
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("strField", TestDataService.LOOKUP_2_EXPECTED_PARAM);
List<BasicEntityRecord> result = instanceService.getEntityRecordsFromLookup(ENTITY_ID, TestDataService.LOOKUP_2_NAME, lookupMap, queryParams());
assertNotNull(result);
assertEquals(2, result.size());
BasicEntityRecord entityRecord = result.get(0);
List<? extends BasicFieldRecord> fieldRecords = entityRecord.getFields();
assertCommonBasicFieldRecordFields(fieldRecords);
assertEquals(asList("one", 1, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
entityRecord = result.get(1);
fieldRecords = entityRecord.getFields();
assertCommonBasicFieldRecordFields(fieldRecords);
assertEquals(asList("two", 2, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
use of org.motechproject.mds.web.domain.BasicEntityRecord 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