use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceControllerTest method shouldExportInstancesWithAllRecordsAsCsv.
@Test
public void shouldExportInstancesWithAllRecordsAsCsv() throws Exception {
when(response.getWriter()).thenReturn(writer);
ArgumentCaptor<QueryParams> captor = ArgumentCaptor.forClass(QueryParams.class);
GridSettings gridSettings = new GridSettings();
gridSettings.setLookup("lookup");
instanceController.exportEntityInstances(1L, gridSettings, "all", "csv", response);
verify(instanceService).verifyEntityAccess(1L);
verify(csvImportExportService).exportCsv(eq(1L), eq(writer), eq("lookup"), captor.capture(), any(List.class), any(Map.class));
verify(response).setContentType("text/csv");
verify(response).setHeader("Content-Disposition", "attachment; filename=Entity_1_instances.csv");
assertNull(captor.getValue().getPageSize());
assertTrue(captor.getValue().isOrderSet());
assertEquals(1, captor.getValue().getOrderList().size());
assertEquals(Constants.Util.ID_FIELD_NAME, captor.getValue().getOrderList().get(0).getField());
assertEquals(Order.Direction.ASC, captor.getValue().getOrderList().get(0).getDirection());
}
use of org.motechproject.mds.query.QueryParams 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.query.QueryParams in project motech by motech.
the class MdsRestFacadeTest method shouldExecuteLookupWithBlobField.
@Test
public void shouldExecuteLookupWithBlobField() {
Map<String, String> lookupMap = asLookupMap(null, "44");
QueryParams queryParams = mock(QueryParams.class);
when(dataService.supportedLookup(null, 44, queryParams)).thenReturn(asList(recordOne));
RestResponse result = (RestResponse) mdsRestFacade.executeLookup(SUPPORTED_LOOKUP_NAME, lookupMap, queryParams, true);
assertEquals(1, result.getData().size());
assertEquals(3, result.getData().get(0).size());
assertEquals(recordOne.getValue(), result.getData().get(0).get(VALUE_FIELD));
assertEquals(recordOne.getDate(), result.getData().get(0).get(DATE_FIELD));
assertArrayEquals((byte[]) result.getData().get(0).get(BLOB_FIELD), encodedBlobField);
verify(dataService).supportedLookup(null, 44, queryParams);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class MdsRestFacadeTest method shouldThrowExceptionForUnsupportedRead.
@Test(expected = RestOperationNotSupportedException.class)
public void shouldThrowExceptionForUnsupportedRead() {
setUpCrudAccess(true, false, true, true);
mdsRestFacade.get(new QueryParams(1, 10), false);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class MdsRestFacadeTest method shouldThrowExceptionForEmptyResult.
@Test(expected = RestNoLookupResultException.class)
public void shouldThrowExceptionForEmptyResult() {
Map<String, String> lookupMap = asLookupMap(null, "44");
QueryParams queryParams = mock(QueryParams.class);
when(dataService.supportedLookup(null, 44, queryParams)).thenReturn(null);
mdsRestFacade.executeLookup(SUPPORTED_LOOKUP_NAME, lookupMap, queryParams, false);
}
Aggregations