Search in sources :

Example 46 with QueryParams

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());
}
Also used : RestProjection(org.motechproject.mds.rest.RestProjection) RestResponse(org.motechproject.mds.rest.RestResponse) QueryParams(org.motechproject.mds.query.QueryParams)

Example 47 with QueryParams

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());
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) EntityDto(org.motechproject.mds.dto.EntityDto) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) QueryParams(org.motechproject.mds.query.QueryParams) Test(org.junit.Test)

Example 48 with QueryParams

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;
}
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

QueryParams (org.motechproject.mds.query.QueryParams)48 Test (org.junit.Test)27 Order (org.motechproject.mds.util.Order)14 ArrayList (java.util.ArrayList)8 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 DateTime (org.joda.time.DateTime)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Arrays.asList (java.util.Arrays.asList)5 List (java.util.List)5 Map (java.util.Map)4 Records (org.motechproject.mds.web.domain.Records)4 TaskActivityType (org.motechproject.tasks.domain.enums.TaskActivityType)4 HashSet (java.util.HashSet)3 Matchers.anyString (org.mockito.Matchers.anyString)3 EntityDto (org.motechproject.mds.dto.EntityDto)3 RestResponse (org.motechproject.mds.rest.RestResponse)3 TaskActivity (org.motechproject.tasks.domain.mds.task.TaskActivity)3 TaskActivityDto (org.motechproject.tasks.dto.TaskActivityDto)3 JsonObject (com.google.gson.JsonObject)2