Search in sources :

Example 11 with Record

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();
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) Record(org.motechproject.mds.testutil.records.Record) TypeDto(org.motechproject.mds.dto.TypeDto) QueryParams(org.motechproject.mds.query.QueryParams) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) FieldDto(org.motechproject.mds.dto.FieldDto) Before(org.junit.Before)

Example 12 with Record

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());
}
Also used : Record(org.motechproject.mds.testutil.records.Record) Test(org.junit.Test)

Example 13 with Record

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;
}
Also used : Record(org.motechproject.mds.testutil.records.Record)

Example 14 with 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));
}
Also used : Order(org.motechproject.mds.util.Order) Record(org.motechproject.mds.testutil.records.Record) Test(org.junit.Test)

Example 15 with Record

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));
}
Also used : Order(org.motechproject.mds.util.Order) Record(org.motechproject.mds.testutil.records.Record) Test(org.junit.Test)

Aggregations

Record (org.motechproject.mds.testutil.records.Record)20 Test (org.junit.Test)16 HashMap (java.util.HashMap)4 Order (org.motechproject.mds.util.Order)4 Date (java.util.Date)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Entity (org.motechproject.mds.domain.Entity)2 Field (org.motechproject.mds.domain.Field)2 Type (org.motechproject.mds.domain.Type)2 Record__Trash (org.motechproject.mds.testutil.records.history.Record__Trash)2 Set (java.util.Set)1 Before (org.junit.Before)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 LookupDto (org.motechproject.mds.dto.LookupDto)1 TypeDto (org.motechproject.mds.dto.TypeDto)1 QueryParams (org.motechproject.mds.query.QueryParams)1