Search in sources :

Example 1 with GridSettings

use of org.motechproject.mds.web.domain.GridSettings in project motech by motech.

the class InstanceControllerTest method shouldExportInstancesWithAdditionalOptionsAsCsv.

@Test
public void shouldExportInstancesWithAdditionalOptionsAsCsv() throws Exception {
    when(response.getWriter()).thenReturn(writer);
    ArgumentCaptor<QueryParams> queryParamsCaptor = ArgumentCaptor.forClass(QueryParams.class);
    ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
    GridSettings gridSettings = new GridSettings();
    gridSettings.setSortColumn("sortColumn");
    gridSettings.setSortDirection("asc");
    gridSettings.setSelectedFields(asList("id", "date"));
    gridSettings.setLookup("lookup");
    instanceController.exportEntityInstances(1L, gridSettings, "50", "csv", response);
    verify(instanceService).verifyEntityAccess(1L);
    verify(csvImportExportService).exportCsv(eq(1L), eq(writer), eq("lookup"), queryParamsCaptor.capture(), listCaptor.capture(), any(Map.class));
    verify(response).setContentType("text/csv");
    verify(response).setHeader("Content-Disposition", "attachment; filename=Entity_1_instances.csv");
    QueryParams captorValue = queryParamsCaptor.getValue();
    assertEquals(Order.Direction.ASC, captorValue.getOrderList().get(0).getDirection());
    assertEquals("sortColumn", captorValue.getOrderList().get(0).getField());
    assertEquals(Integer.valueOf(1), captorValue.getPage());
    assertEquals(Integer.valueOf(50), captorValue.getPageSize());
    assertEquals(2, listCaptor.getValue().size());
    assertTrue(listCaptor.getValue().contains("id"));
    assertTrue(listCaptor.getValue().contains("date"));
}
Also used : QueryParams(org.motechproject.mds.query.QueryParams) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) GridSettings(org.motechproject.mds.web.domain.GridSettings) Map(java.util.Map) Test(org.junit.Test)

Example 2 with GridSettings

use of org.motechproject.mds.web.domain.GridSettings 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());
}
Also used : QueryParams(org.motechproject.mds.query.QueryParams) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) GridSettings(org.motechproject.mds.web.domain.GridSettings) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Map (java.util.Map)2 Test (org.junit.Test)2 QueryParams (org.motechproject.mds.query.QueryParams)2 GridSettings (org.motechproject.mds.web.domain.GridSettings)2