Search in sources :

Example 1 with MDSDataProvider

use of org.motechproject.mds.tasks.MDSDataProvider in project motech by motech.

the class MdsDataProviderTest method setUp.

@Before
public void setUp() {
    when(entityService.getEntityByClassName(Record.class.getName())).thenReturn(entity);
    when(entity.getId()).thenReturn(ENTITY_ID);
    FieldDto fieldDto = FieldTestHelper.fieldDto(1L, "field", String.class.getName(), "disp", null);
    when(entityService.getEntityFields(ENTITY_ID)).thenReturn(asList(fieldDto));
    LookupFieldDto lookupField = FieldTestHelper.lookupFieldDto(1L, "field");
    LookupDto singleLookup = new LookupDto("singleLookup", true, false, asList(lookupField), false);
    LookupDto multiLookup = new LookupDto("multiLookup", false, false, asList(lookupField), false);
    lookupField = FieldTestHelper.lookupFieldDto(2L, "related");
    lookupField.setRelatedName("stringVar");
    LookupDto relatedLookup = new LookupDto("relatedLookup", false, false, asList(lookupField), false);
    when(entityService.getLookupByName(ENTITY_ID, "singleLookup")).thenReturn(singleLookup);
    when(entityService.getLookupByName(ENTITY_ID, "multiLookup")).thenReturn(multiLookup);
    when(entityService.getLookupByName(ENTITY_ID, "relatedLookup")).thenReturn(relatedLookup);
    Map<String, FieldDto> mapping = new HashMap<>();
    mapping.put("field", fieldDto);
    when(entityService.getLookupFieldsMapping(ENTITY_ID, "singleLookup")).thenReturn(mapping);
    when(entityService.getLookupFieldsMapping(ENTITY_ID, "multiLookup")).thenReturn(mapping);
    mapping = new HashMap<>();
    mapping.put("related.stringVar", fieldDto);
    when(entityService.getLookupFieldsMapping(ENTITY_ID, "relatedLookup")).thenReturn(mapping);
    when(bundleContext.getServiceReference(LookupService.class.getName())).thenReturn(serviceReference);
    when(bundleContext.getService(serviceReference)).thenReturn(new LookupService());
    dataProvider = new MDSDataProvider(resourceLoader);
    dataProvider.setEntityService(entityService);
    dataProvider.setBundleContext(bundleContext);
    MotechClassPool.registerServiceInterface(Record.class.getName(), LookupService.class.getName());
}
Also used : HashMap(java.util.HashMap) LookupDto(org.motechproject.mds.dto.LookupDto) MDSDataProvider(org.motechproject.mds.tasks.MDSDataProvider) Record(org.motechproject.mds.testutil.records.Record) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Before(org.junit.Before)

Aggregations

HashMap (java.util.HashMap)1 Before (org.junit.Before)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 LookupDto (org.motechproject.mds.dto.LookupDto)1 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)1 MDSDataProvider (org.motechproject.mds.tasks.MDSDataProvider)1 Record (org.motechproject.mds.testutil.records.Record)1