Search in sources :

Example 16 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class QueryParamsBuilderTest method shouldBuildDefaultQueryParams.

@Test
public void shouldBuildDefaultQueryParams() {
    when(gridSettings.getPage()).thenReturn(null);
    when(gridSettings.getRows()).thenReturn(null);
    QueryParams queryParams = QueryParamsBuilder.buildQueryParams(gridSettings);
    assertNotNull(queryParams);
    assertPagination(queryParams, QueryParamsBuilder.DEFAULT_PAGE, QueryParamsBuilder.DEFAULT_PAGE_SIZE);
    assertEquals(1, queryParams.getOrderList().size());
    assertDefaultIdOrder(queryParams, 0);
}
Also used : QueryParams(org.motechproject.mds.query.QueryParams) Test(org.junit.Test)

Example 17 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class QueryParamsBuilderTest method shouldNotAddIdOrderingIfItsPresent.

@Test
public void shouldNotAddIdOrderingIfItsPresent() {
    when(gridSettings.getSortColumn()).thenReturn(Constants.Util.ID_FIELD_NAME);
    when(gridSettings.getSortDirection()).thenReturn("descending");
    QueryParams queryParams = QueryParamsBuilder.buildQueryParams(gridSettings);
    assertNotNull(queryParams);
    assertEquals(1, queryParams.getOrderList().size());
    assertOrderPresent(queryParams, 0, Constants.Util.ID_FIELD_NAME, Order.Direction.DESC);
}
Also used : QueryParams(org.motechproject.mds.query.QueryParams) Test(org.junit.Test)

Example 18 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class MdsRestFacadeTest method shouldExecuteLookupWithoutBlobField.

@Test
public void shouldExecuteLookupWithoutBlobField() {
    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, false);
    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));
    assertNull(result.getData().get(0).get(BLOB_FIELD));
    verify(dataService).supportedLookup(null, 44, queryParams);
}
Also used : QueryParams(org.motechproject.mds.query.QueryParams) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class MdsRestFacadeTest method shouldGetByQueryParamsWithBlobField.

@Test
public void shouldGetByQueryParamsWithBlobField() {
    setUpCrudAccess(false, true, false, false);
    QueryParams queryParams = new QueryParams(5, 20, new Order("value", Order.Direction.DESC));
    RestResponse result = mdsRestFacade.get(queryParams, true);
    verify(dataService).retrieveAll(queryParams);
    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(encodedBlobField, (byte[]) result.getData().get(0).get(BLOB_FIELD));
}
Also used : Order(org.motechproject.mds.util.Order) QueryParams(org.motechproject.mds.query.QueryParams) Test(org.junit.Test)

Example 20 with QueryParams

use of org.motechproject.mds.query.QueryParams in project motech by motech.

the class MdsRestFacadeTest method shouldGetByQueryParamsWithoutBlobField.

// regular verifications
@Test
public void shouldGetByQueryParamsWithoutBlobField() {
    setUpCrudAccess(false, true, false, false);
    QueryParams queryParams = new QueryParams(5, 20, new Order("value", Order.Direction.DESC));
    RestResponse result = mdsRestFacade.get(queryParams, false);
    verify(dataService).retrieveAll(queryParams);
    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));
    assertNull(result.getData().get(0).get(BLOB_FIELD));
}
Also used : Order(org.motechproject.mds.util.Order) QueryParams(org.motechproject.mds.query.QueryParams) Test(org.junit.Test)

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