Search in sources :

Example 26 with EntityRecord

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));
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) Bundle(org.osgi.framework.Bundle) Test(org.junit.Test)

Example 27 with EntityRecord

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;
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)27 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)27 Test (org.junit.Test)16 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)15 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)15 EntityDto (org.motechproject.mds.dto.EntityDto)11 ArrayList (java.util.ArrayList)5 FieldDto (org.motechproject.mds.dto.FieldDto)5 Matchers.anyString (org.mockito.Matchers.anyString)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 List (java.util.List)3 MotechDataService (org.motechproject.mds.service.MotechDataService)3 RelationshipsUpdate (org.motechproject.mds.web.domain.RelationshipsUpdate)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Collection (java.util.Collection)2 Predicate (java.util.function.Predicate)2 CannotCompileException (javassist.CannotCompileException)2 FieldNotFoundException (org.motechproject.mds.exception.field.FieldNotFoundException)2 ObjectNotFoundException (org.motechproject.mds.exception.object.ObjectNotFoundException)2