use of org.motechproject.mds.testutil.records.Record in project motech by motech.
the class MdsRestFacadeTest method setUp.
@Before
public void setUp() {
when(dataService.getClassType()).thenReturn(Record.class);
when(entityInfoReader.getEntityInfo(Record.class.getName())).thenReturn(entity);
when(entity.getName()).thenReturn(ENTITY_NAME);
when(entity.getModule()).thenReturn(TEST_MODULE);
when(entity.getClassName()).thenReturn(Record.class.getName());
when(entity.getNamespace()).thenReturn(NAMESPACE);
when(entity.getAdvancedSettings()).thenReturn(advancedSettingsDto);
when(advancedSettingsDto.getRestOptions()).thenReturn(restOptions);
// set up rest fields
FieldDto valueField = FieldTestHelper.fieldDto(3L, VALUE_FIELD, String.class.getName(), VALUE_FIELD, null);
FieldDto dateField = FieldTestHelper.fieldDto(4L, DATE_FIELD, Date.class.getName(), DATE_FIELD, null);
FieldDto blobField = FieldTestHelper.fieldDto(5L, BLOB_FIELD, Byte[].class.getName(), BLOB_FIELD, null);
blobField.setType(new TypeDto("mds.field.blob", StringUtils.EMPTY, BLOB_FIELD, Byte[].class.getName()));
when(restOptions.getFieldNames()).thenReturn(Arrays.asList(VALUE_FIELD, DATE_FIELD, BLOB_FIELD));
// set up lookups
FieldDto strField = FieldTestHelper.fieldDto(1L, STR_FIELD, String.class.getName(), STR_FIELD, null);
FieldDto intField = FieldTestHelper.fieldDto(2L, INT_FIELD, Integer.class.getName(), INT_FIELD, null);
when(entity.getFieldDtos()).thenReturn(asList(intField, strField, valueField, dateField, blobField));
when(entity.getField(STR_FIELD)).thenReturn(FieldTestHelper.fieldInfo(STR_FIELD, String.class, false, true));
when(entity.getField(INT_FIELD)).thenReturn(FieldTestHelper.fieldInfo(INT_FIELD, Integer.class, false, true));
LookupDto forbiddenLookup = new LookupDto(FORBIDDEN_LOOKUP_NAME, true, false, asList(FieldTestHelper.lookupFieldDto(1L, STR_FIELD), FieldTestHelper.lookupFieldDto(2L, INT_FIELD)), true);
LookupDto supportedLookup = new LookupDto(SUPPORTED_LOOKUP_NAME, false, true, asList(FieldTestHelper.lookupFieldDto(1L, STR_FIELD), FieldTestHelper.lookupFieldDto(2L, INT_FIELD)), true);
when(entity.getLookups()).thenReturn(asList(forbiddenLookup, supportedLookup));
// set up record
recordOne = testRecord();
// set up data service
when(dataService.retrieveAll(any(QueryParams.class))).thenReturn(asList(recordOne));
when(dataService.retrieveAll()).thenReturn(asList(recordOne));
when(dataService.findById(1l)).thenReturn(recordOne);
when(dataService.create(recordOne)).thenReturn(recordOne);
when(dataService.getDetachedField(recordOne, BLOB_FIELD)).thenReturn(blobFieldValue);
// do the initialization, normally called by Spring as @PostConstruct
mdsRestFacade.init();
}
use of org.motechproject.mds.testutil.records.Record in project motech by motech.
the class MdsLookupServiceTest method shouldExecuteSingleReturnLookups.
@Test
public void shouldExecuteSingleReturnLookups() {
Map<String, Object> lookupMap = lookupMap();
Record recordByClass = mdsLookupService.findOne(Record.class, FIRST_LOOKUP_NAME, lookupMap);
Record recordByClassName = mdsLookupService.findOne(Record.class.getName(), FIRST_LOOKUP_NAME, lookupMap);
assertNotNull(recordByClass);
assertEquals(SINGLE_LOOKUP_VAL, recordByClass.getValue());
assertNotNull(recordByClassName);
assertEquals(SINGLE_LOOKUP_VAL, recordByClassName.getValue());
}
use of org.motechproject.mds.testutil.records.Record in project motech by motech.
the class RestProjectionTest method buildRecord.
private Record buildRecord(Long id, String creator, String owner, String modifiedBy, DateTime creationDate, DateTime modificationDate, String value, Date date, Byte[] blob) {
Record record = new Record();
record.setId(id);
record.setCreator(creator);
record.setOwner(owner);
record.setModifiedBy(modifiedBy);
record.setCreationDate(creationDate);
record.setModificationDate(modificationDate);
record.setValue(value);
record.setDate(date);
record.setBlob(blob);
return record;
}
use of org.motechproject.mds.testutil.records.Record in project motech by motech.
the class InMemoryQueryFilterTest method shouldApplyQueryParams.
@Test
public void shouldApplyQueryParams() {
QueryParams queryParams = new QueryParams(2, 3, new Order("value", Order.Direction.DESC));
List<Record> result = InMemoryQueryFilter.filter(testCollection, queryParams);
assertListByValues(result, asList("nullRecord", "hmm", "hmm"));
assertListByIds(result, asList(null, 5L, 6L));
}
use of org.motechproject.mds.testutil.records.Record in project motech by motech.
the class InMemoryQueryFilterTest method shouldPaginate.
@Test
public void shouldPaginate() {
Order order = new Order("value", Order.Direction.ASC);
QueryParams queryParams = new QueryParams(1, 3, order);
List<Record> result = InMemoryQueryFilter.filter(testCollection, queryParams);
assertListByValues(result, asList("aaa", "hmm", "hmm"));
assertListByIds(result, asList(4L, 5L, 6L));
queryParams = new QueryParams(2, 3, order);
result = InMemoryQueryFilter.filter(testCollection, queryParams);
assertListByValues(result, asList("nullRecord", "something", "test"));
assertListByIds(result, asList(null, 3L, 2L));
}
Aggregations