Search in sources :

Example 11 with BasicEntityRecord

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());
}
Also used : RelationshipsUpdate(org.motechproject.mds.web.domain.RelationshipsUpdate) QueryParams(org.motechproject.mds.query.QueryParams) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) Records(org.motechproject.mds.web.domain.Records) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 12 with BasicEntityRecord

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()));
}
Also used : HashMap(java.util.HashMap) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Matchers.anyString(org.mockito.Matchers.anyString) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) Test(org.junit.Test)

Example 13 with BasicEntityRecord

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()));
}
Also used : HashMap(java.util.HashMap) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Matchers.anyString(org.mockito.Matchers.anyString) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) Test(org.junit.Test)

Example 14 with BasicEntityRecord

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()));
}
Also used : HashMap(java.util.HashMap) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Matchers.anyString(org.mockito.Matchers.anyString) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) Test(org.junit.Test)

Example 15 with BasicEntityRecord

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;
}
Also used : RelationshipsUpdate(org.motechproject.mds.web.domain.RelationshipsUpdate) QueryParams(org.motechproject.mds.query.QueryParams) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)15 Test (org.junit.Test)6 QueryParams (org.motechproject.mds.query.QueryParams)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)5 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)5 FieldDto (org.motechproject.mds.dto.FieldDto)4 Records (org.motechproject.mds.web.domain.Records)4 HashMap (java.util.HashMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 RelationshipsUpdate (org.motechproject.mds.web.domain.RelationshipsUpdate)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CannotCompileException (javassist.CannotCompileException)2 EntityDto (org.motechproject.mds.dto.EntityDto)2 FieldNotFoundException (org.motechproject.mds.exception.field.FieldNotFoundException)2 LookupExecutionException (org.motechproject.mds.exception.lookup.LookupExecutionException)2 LookupExecutorException (org.motechproject.mds.exception.lookup.LookupExecutorException)2