Search in sources :

Example 1 with RelatedClass

use of org.motechproject.mds.testutil.records.RelatedClass in project motech by motech.

the class CsvImporterExporterTest method setUp.

@Before
public void setUp() {
    MotechClassPool.registerServiceInterface(ENTITY_CLASSNAME, DATA_SERVICE_CLASSNAME);
    when(bundleContext.getServiceReference(DATA_SERVICE_CLASSNAME)).thenReturn(serviceRef);
    when(bundleContext.getService(serviceRef)).thenReturn(motechDataService);
    when(motechDataService.getClassType()).thenReturn(Record2.class);
    MotechClassPool.registerServiceInterface(RELATED_CLASSNAME, RELATED_SERVICE_CLASSNAME);
    when(bundleContext.getServiceReference(RELATED_SERVICE_CLASSNAME)).thenReturn(relatedServiceRef);
    when(bundleContext.getService(relatedServiceRef)).thenReturn(relatedDataService);
    when(relatedDataService.getClassType()).thenReturn(RelatedClass.class);
    when(relatedDataService.findById(0L)).thenReturn(new RelatedClass(0L));
    when(relatedDataService.findById(1L)).thenReturn(new RelatedClass(1L));
    when(entityInfoReader.getEntityInfo(ENTITY_CLASSNAME)).thenReturn(entityInfo);
    when(entityInfoReader.getEntityInfo(ENTITY_ID)).thenReturn(entityInfo);
    when(entityInfo.getEntity()).thenReturn(entityDto);
    when(entityDto.getClassName()).thenReturn(ENTITY_CLASSNAME);
    when(entityDto.getName()).thenReturn(ENTITY_NAME);
    when(entityDto.getModule()).thenReturn(ENTITY_MODULE);
    when(entityDto.getNamespace()).thenReturn(ENTITY_NAMESPACE);
    when(csvExportCustomizer.columnOrderComparator(any(BrowsingSettingsDto.class))).thenReturn(new UIDisplayFieldComparator(new ArrayList<Number>()));
    when(csvExportCustomizer.exportDisplayName(any(FieldDto.class))).thenCallRealMethod();
    CsvTestHelper.mockRecord2Fields(entityInfo, advancedSettingsDto, browsingSettingsDto);
}
Also used : BrowsingSettingsDto(org.motechproject.mds.dto.BrowsingSettingsDto) ArrayList(java.util.ArrayList) RelatedClass(org.motechproject.mds.testutil.records.RelatedClass) UIDisplayFieldComparator(org.motechproject.mds.dto.UIDisplayFieldComparator) FieldDto(org.motechproject.mds.dto.FieldDto) Before(org.junit.Before)

Example 2 with RelatedClass

use of org.motechproject.mds.testutil.records.RelatedClass in project motech by motech.

the class CsvImporterExporterTest method testInstances.

private List<Record2> testInstances(IdMode idMode) {
    List<Record2> instances = new ArrayList<>();
    for (int i = 0; i < INSTANCE_COUNT; i++) {
        Record2 record = new Record2();
        if (idMode == IdMode.INCLUDE_ID) {
            record.setId((long) i);
        }
        record.setCreator("the creator " + i);
        record.setOwner("the owner " + i);
        record.setModifiedBy("username" + i);
        record.setCreationDate(NOW.plusMinutes(i));
        record.setModificationDate(NOW.plusHours(i));
        record.setValue("value " + i);
        record.setDate(NOW.plusSeconds(i).toDate());
        record.setDateIgnoredByRest(NOW.minusHours(i).toDate());
        record.setEnumField(enumValue(i));
        record.setEnumListField(Arrays.asList(enumValue(i + 1), enumValue(i + 2)));
        record.setSingleRelationship(new RelatedClass(relatedId(i)));
        record.setMultiRelationship(new ArrayList<>((Arrays.asList(new RelatedClass(relatedId(i + 1)), new RelatedClass(relatedId(i + 2))))));
        instances.add(record);
    }
    return instances;
}
Also used : ArrayList(java.util.ArrayList) RelatedClass(org.motechproject.mds.testutil.records.RelatedClass) Record2(org.motechproject.mds.testutil.records.Record2)

Aggregations

ArrayList (java.util.ArrayList)2 RelatedClass (org.motechproject.mds.testutil.records.RelatedClass)2 Before (org.junit.Before)1 BrowsingSettingsDto (org.motechproject.mds.dto.BrowsingSettingsDto)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 UIDisplayFieldComparator (org.motechproject.mds.dto.UIDisplayFieldComparator)1 Record2 (org.motechproject.mds.testutil.records.Record2)1