Search in sources :

Example 1 with ContextPublishedWaitCondition

use of org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition in project motech by motech.

the class EmailChannelBundleIT method testEmailSentOnSendEmailEvent.

@Test
public void testEmailSentOnSendEmailEvent() throws MessagingException, IOException, InterruptedException {
    SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(this));
    new Wait(new ContextPublishedWaitCondition(bundleContext, "org.motechproject.motech-platform-event"), 5000).start();
    new Wait(new ContextPublishedWaitCondition(bundleContext), 5000).start();
    try {
        smtpServer.setPort(8099);
        smtpServer.start();
        String messageText = "test message";
        String from = "testfromaddress";
        String to = "testtoaddress";
        String subject = "test subject";
        Map<String, Object> values = new HashMap<>();
        values.put("fromAddress", from);
        values.put("toAddress", to);
        values.put("message", messageText);
        values.put("subject", subject);
        eventRelay.sendEventMessage(new MotechEvent(SendEmailConstants.SEND_EMAIL_SUBJECT, values));
        new Wait(lock, this, 100, 60000).start();
        assertTrue("Message not received", messageReceived);
        assertNotNull(receivedMessageText);
        assertEquals(messageText, receivedMessageText.trim());
    } finally {
        smtpServer.stop();
    }
}
Also used : ContextPublishedWaitCondition(org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition) HashMap(java.util.HashMap) SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter) Wait(org.motechproject.testing.osgi.wait.Wait) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 2 with ContextPublishedWaitCondition

use of org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition in project motech by motech.

the class EventRelayClassLoaderBundleIT method testThatEventHandlerClassLoaderIsInvokedWithCurrentClassLoaderSetAsEventRelaysClassLoader.

@Test
public void testThatEventHandlerClassLoaderIsInvokedWithCurrentClassLoaderSetAsEventRelaysClassLoader() throws InterruptedException {
    assertNotNull(eventListenerRegistry);
    assertNotNull(eventRelay);
    new Wait(new ContextPublishedWaitCondition(bundleContext, "org.motechproject.motech-platform-event"), 5000).start();
    eventRelay.sendEventMessage(new MotechEvent(TestHandler.SUBJECT_READ));
    final Properties properties = TestHandler.PROPERTIES;
    new Wait(new WaitCondition() {

        @Override
        public boolean needsToWait() {
            return properties.isEmpty();
        }
    }, 2000).start();
    assertTrue(properties.containsKey("message"));
    assertEquals("hello world", properties.get("message"));
}
Also used : WaitCondition(org.motechproject.testing.osgi.wait.WaitCondition) ContextPublishedWaitCondition(org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition) ContextPublishedWaitCondition(org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition) Wait(org.motechproject.testing.osgi.wait.Wait) Properties(java.util.Properties) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 3 with ContextPublishedWaitCondition

use of org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition in project motech by motech.

the class BundleContextWrapperBundleIT method testThatBundleContextWrapperReturnsCorrectApplicationContext.

@Test
public void testThatBundleContextWrapperReturnsCorrectApplicationContext() throws InterruptedException {
    BundleContextWrapper bundleContextWrapper = new BundleContextWrapper(bundleContext);
    Bundle bundle = bundleContext.getBundle();
    assertEquals(bundle.getSymbolicName(), bundleContextWrapper.getCurrentBundleSymbolicName());
    new Wait(new ContextPublishedWaitCondition(bundleContext), 5000).start();
    ApplicationContext applicationContextForCurrentBundle = bundleContextWrapper.getBundleApplicationContext();
    assertNotNull(applicationContextForCurrentBundle);
    Object testBundleContextWrapper = applicationContextForCurrentBundle.getBean("testBundleContextWrapper");
    assertNotNull(testBundleContextWrapper);
}
Also used : BundleContextWrapper(org.motechproject.osgi.web.BundleContextWrapper) ContextPublishedWaitCondition(org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition) ApplicationContext(org.springframework.context.ApplicationContext) Bundle(org.osgi.framework.Bundle) Wait(org.motechproject.testing.osgi.wait.Wait) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ContextPublishedWaitCondition (org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition)3 Wait (org.motechproject.testing.osgi.wait.Wait)3 MotechEvent (org.motechproject.event.MotechEvent)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 BundleContextWrapper (org.motechproject.osgi.web.BundleContextWrapper)1 WaitCondition (org.motechproject.testing.osgi.wait.WaitCondition)1 Bundle (org.osgi.framework.Bundle)1 ApplicationContext (org.springframework.context.ApplicationContext)1 SimpleMessageListenerAdapter (org.subethamail.smtp.helper.SimpleMessageListenerAdapter)1 SMTPServer (org.subethamail.smtp.server.SMTPServer)1