Search in sources :

Example 1 with TestMdsEntity

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EventListener(org.motechproject.event.listener.EventListener) MotechEvent(org.motechproject.event.MotechEvent) TestMdsEntity(org.motechproject.mds.test.domain.TestMdsEntity) Test(org.junit.Test)

Example 2 with TestMdsEntity

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()));
}
Also used : DateTime(org.joda.time.DateTime) TestMdsEntity(org.motechproject.mds.test.domain.TestMdsEntity)

Example 3 with TestMdsEntity

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());
}
Also used : SubclassB(org.motechproject.mds.test.domain.instancelifecyclelistener.SubclassB) SubclassA(org.motechproject.mds.test.domain.instancelifecyclelistener.SubclassA) TestMdsEntity(org.motechproject.mds.test.domain.TestMdsEntity) Test(org.junit.Test)

Aggregations

TestMdsEntity (org.motechproject.mds.test.domain.TestMdsEntity)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 MotechEvent (org.motechproject.event.MotechEvent)1 EventListener (org.motechproject.event.listener.EventListener)1 SubclassA (org.motechproject.mds.test.domain.instancelifecyclelistener.SubclassA)1 SubclassB (org.motechproject.mds.test.domain.instancelifecyclelistener.SubclassB)1