use of org.motechproject.mds.test.domain.TestMdsEntity in project motech by motech.
the class MdsDdeBundleIT method testMdsCrudEvents.
@Test
public void testMdsCrudEvents() throws Exception {
getLogger().info("Test MDS CRUD Events");
final ArrayList<String> receivedEvents = new ArrayList<>();
final Map<String, Object> params = new HashMap<>();
String moduleName = "MOTECH Platform Data Services Test Bundle";
String simplifiedModuleName = simplifiedModuleName(moduleName);
String entityName = "TestMdsEntity";
final String subject = createSubject(moduleName, null, entityName, CrudEventType.CREATE);
registry.registerListener(new EventListener() {
@Override
public void handle(MotechEvent event) {
receivedEvents.add(event.getSubject());
params.putAll(event.getParameters());
synchronized (waitLock) {
waitLock.notify();
}
}
@Override
public String getIdentifier() {
return subject;
}
}, subject);
wait2s();
testMdsEntityService.create(new TestMdsEntity("string"));
wait2s();
assertEquals(1, receivedEvents.size());
assertEquals(subject, receivedEvents.get(0));
assertEquals(simplifiedModuleName, params.get(MODULE_NAME));
assertEquals(entityName, params.get(ENTITY_NAME));
assertEquals(TestMdsEntity.class.getName(), params.get(ENTITY_CLASS));
testMdsEntityService.deleteAll();
}
use of org.motechproject.mds.test.domain.TestMdsEntity in project motech by motech.
the class MdsDdeBundleIT method verifyDDE.
private void verifyDDE() {
getLogger().info("Verify DDE");
TestMdsEntity expected = new TestMdsEntity("name");
testMdsEntityService.create(expected);
List<TestMdsEntity> testMdsEntities = testMdsEntityService.detachedCopyAll(testMdsEntityService.retrieveAll());
assertEquals(asList(expected), testMdsEntities);
TestMdsEntity actual = testMdsEntities.get(0);
assertEquals(actual.getModifiedBy(), "motech");
assertEquals(actual.getCreator(), "motech");
assertEquals(actual.getOwner(), "motech");
assertNotNull(actual.getId());
actual.setSomeString("newName");
actual.setOwner("newOwner");
DateTime modificationDate = actual.getModificationDate();
testMdsEntityService.update(actual);
testMdsEntities = testMdsEntityService.retrieveAll();
assertEquals(asList(actual), testMdsEntities);
assertEquals(testMdsEntities.get(0).getOwner(), "newOwner");
// Actual modificationDate of instance should be after previous one
assertTrue(modificationDate.isBefore(testMdsEntities.get(0).getModificationDate()));
}
use of org.motechproject.mds.test.domain.TestMdsEntity in project motech by motech.
the class MdsDdeBundleIT method testJdoListeners.
@Test
public void testJdoListeners() throws Exception {
getLogger().info("Test JdoListeners");
testMdsEntityService.create(new TestMdsEntity("TestChangeName"));
List<TestMdsEntity> entities = testMdsEntityService.retrieveAll();
assertEquals(1, entities.size());
assertEquals("NameWasChanged", entities.get(0).getSomeString());
subclassADataService.create(new SubclassA());
subclassBDataService.create(new SubclassB());
List<SubclassA> subclassesA = subclassADataService.retrieveAll();
List<SubclassB> subclassesB = subclassBDataService.retrieveAll();
assertEquals(1, subclassesA.size());
assertEquals(1, subclassesB.size());
assertEquals("StringWasChanged", subclassesA.get(0).getSuperClassString());
assertEquals("StringWasChanged", subclassesB.get(0).getSuperClassString());
}
Aggregations