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());
}
Aggregations