use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceServiceTest method shouldReturnInstancesFromTrash.
@Test
public void shouldReturnInstancesFromTrash() {
mockDataService();
mockSampleFields();
mockEntity();
QueryParams queryParams = new QueryParams(1, 10);
when(trashService.getInstancesFromTrash(anyString(), eq(queryParams))).thenReturn(sampleCollection());
List<BasicEntityRecord> records = instanceService.getTrashRecords(ENTITY_ID, queryParams);
verify(trashService).getInstancesFromTrash(anyString(), eq(queryParams));
assertNotNull(records);
assertEquals(records.size(), 1);
// Make sure all fields that were in the instance are still available
assertEquals(records.get(0).getFields().size(), 5);
// should not perform update when username is null or blank
verify(userPreferencesService, never()).updateGridSize(anyLong(), anyString(), anyInt());
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceServiceTest method shouldReturnRelatedInstances.
@Test
public void shouldReturnRelatedInstances() {
mockDataService();
mockAnotherEntity();
mockEntity();
mockSampleFields();
mockAnotherEntityFields();
mockTestClassEntity();
mockTestClassService();
mockTestClassFields();
when(serviceForAnotherSample.findById(INSTANCE_ID)).thenReturn(sampleForRelationshipTesting());
QueryParams queryParams = new QueryParams(1, 2, new Order(Constants.Util.ID_FIELD_NAME, Order.Direction.ASC));
Records<BasicEntityRecord> records = instanceService.getRelatedFieldValue(ANOTHER_ENTITY_ID, INSTANCE_ID, "testClasses", new RelationshipsUpdate(), queryParams);
assertNotNull(records);
// page 1
assertEquals(Integer.valueOf(1), records.getPage());
// 2 pages total
assertEquals(Integer.valueOf(2), records.getTotal());
// 3 records total
assertEquals(Integer.valueOf(3), records.getRecords());
assertEquals(asList(1L, 2L), extract(records.getRows(), on(BasicEntityRecord.class).getFieldByName("id").getValue()));
RelationshipsUpdate filter = new RelationshipsUpdate();
filter.setRemovedIds(Arrays.asList(1L, 2L));
filter.setAddedIds(Arrays.asList(50L));
when(testClassMotechDataService.findByIds(filter.getAddedIds())).thenReturn(Arrays.asList(new TestClass(50)));
records = instanceService.getRelatedFieldValue(ANOTHER_ENTITY_ID, INSTANCE_ID, "testClasses", filter, queryParams);
assertNotNull(records);
// page 1
assertEquals(Integer.valueOf(1), records.getPage());
// 1 page total
assertEquals(Integer.valueOf(1), records.getTotal());
// 2 records total
assertEquals(Integer.valueOf(2), records.getRecords());
// 1L and 2L removed, 50L added
assertEquals(asList(3L, 50L), extract(records.getRows(), on(BasicEntityRecord.class).getFieldByName("id").getValue()));
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class InstanceServiceTest method shouldUpdateGridSize.
@Test
public void shouldUpdateGridSize() {
setUpSecurityContext();
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<>());
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).updateGridSize(ENTITY_ID + 1, "motech", 100);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class QueryParamsBuilderTest method shouldBuildQueryParamsFromGridSettings.
@Test
public void shouldBuildQueryParamsFromGridSettings() {
when(gridSettings.getPage()).thenReturn(3);
when(gridSettings.getRows()).thenReturn(50);
when(gridSettings.getSortColumn()).thenReturn("field");
when(gridSettings.getSortDirection()).thenReturn("desc");
QueryParams queryParams = QueryParamsBuilder.buildQueryParams(gridSettings);
assertNotNull(queryParams);
assertPagination(queryParams, 3, 50);
assertEquals(2, queryParams.getOrderList().size());
assertOrderPresent(queryParams, 0, "field", Order.Direction.DESC);
assertDefaultIdOrder(queryParams, 1);
}
use of org.motechproject.mds.query.QueryParams in project motech by motech.
the class QueryParamsBuilderTest method shouldBuildQueryParamsForLookups.
@Test
public void shouldBuildQueryParamsForLookups() {
when(gridSettings.getPage()).thenReturn(7);
when(gridSettings.getRows()).thenReturn(80);
// the values are not important
Map<String, Object> lookupMap = new LinkedHashMap<>();
lookupMap.put("field1", null);
lookupMap.put("field2", null);
lookupMap.put("field3", null);
QueryParams queryParams = QueryParamsBuilder.buildQueryParams(gridSettings, lookupMap);
assertNotNull(queryParams);
assertPagination(queryParams, 7, 80);
assertEquals(4, queryParams.getOrderList().size());
assertOrderPresent(queryParams, 0, "field1", Order.Direction.ASC);
assertOrderPresent(queryParams, 1, "field2", Order.Direction.ASC);
assertOrderPresent(queryParams, 2, "field3", Order.Direction.ASC);
assertDefaultIdOrder(queryParams, 3);
}
Aggregations