use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldUseCorrectClassLoaderWhenCreatingInstances.
@Test
public void shouldUseCorrectClassLoaderWhenCreatingInstances() throws ClassNotFoundException {
mockSampleFields();
mockEntity();
mockDataService();
Bundle ddeBundle = mock(Bundle.class);
Bundle entitiesBundle = mock(Bundle.class);
when(bundleContext.getBundles()).thenReturn(new Bundle[] { ddeBundle, entitiesBundle });
when(entity.getBundleSymbolicName()).thenReturn("org.motechproject.test");
when(entitiesBundle.getSymbolicName()).thenReturn(Constants.BundleNames.MDS_ENTITIES_SYMBOLIC_NAME);
when(ddeBundle.getSymbolicName()).thenReturn("org.motechproject.test");
Class testClass = TestSample.class;
when(entitiesBundle.loadClass(testClass.getName())).thenReturn(testClass);
when(ddeBundle.loadClass(testClass.getName())).thenReturn(testClass);
EntityRecord entityRecord = new EntityRecord(null, ENTITY_ID, Collections.<FieldRecord>emptyList());
when(entity.isDDE()).thenReturn(true);
instanceService.saveInstance(entityRecord);
verify(ddeBundle).loadClass(TestSample.class.getName());
when(entity.isDDE()).thenReturn(false);
instanceService.saveInstance(entityRecord);
verify(entitiesBundle).loadClass(TestSample.class.getName());
verify(motechDataService, times(2)).create(any(TestSample.class));
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceController method newInstance.
@RequestMapping(value = "/instances/{entityId}/new")
@ResponseBody
public EntityRecord newInstance(@PathVariable Long entityId) {
EntityRecord entityRecord = instanceService.newInstance(entityId);
processFieldsForUI(entityRecord);
return entityRecord;
}
Aggregations