Search in sources :

Example 71 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class RetryFromJettyTest method testExecuteQuietly.

@Test
public void testExecuteQuietly() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    NullService s1 = new NullService();
    ThrowExceptionService s2 = new ThrowExceptionService(new ConfiguredException("failure"));
    try {
        start(s1, s2);
        RetryFromJetty.executeQuietly(s1, msg);
        RetryFromJetty.executeQuietly(s2, msg);
    } finally {
        stop(s1, s2);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) NullService(com.adaptris.core.NullService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Example 72 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class RetryStoreListTest method testService_Exception.

@Test(expected = ServiceException.class)
public void testService_Exception() throws Exception {
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("hello");
    RetryStoreListService service = new RetryStoreListService().withRetryStore(new FilesystemRetryStore().withBaseUrl(INVALID_URL));
    execute(service, msg);
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 73 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class GetAndCacheOauthTokenTest method testService_WithError.

@Test(expected = ServiceException.class)
public void testService_WithError() throws Exception {
    ExpiringMapCache cache = new ExpiringMapCache().withExpiration(new TimeInterval(5L, TimeUnit.SECONDS));
    AccessToken t = new AccessToken(getName());
    GetAndCacheOauthToken service = new GetAndCacheOauthToken().withCacheKey("OauthToken").withConnection(new CacheConnection(cache)).withAccessTokenBuilder(new DummyAccessTokenBuilder(t, true));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    execute(service, msg);
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 74 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class GetOauthTokenTest method testService.

@Test
@SuppressWarnings("deprecation")
public void testService() throws Exception {
    long now = System.currentTimeMillis();
    String expiryDate = DateFormatUtil.format(new Date(now));
    AccessToken t = new AccessToken(getName(), now);
    GetOauthToken service = new GetOauthToken().withAccessTokenWriter(new MetadataAccessTokenWriter().withTokenKey("Authorization"));
    service.setAccessTokenBuilder(new DummyAccessTokenBuilder(t));
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    try {
        execute(service, msg);
        assertTrue(msg.headersContainsKey("Authorization"));
        assertEquals("Bearer " + getName(), msg.getMetadataValue("Authorization"));
    } finally {
    }
    assertTrue(msg.headersContainsKey("Authorization"));
    assertEquals("Bearer " + getName(), msg.getMetadataValue("Authorization"));
    assertFalse(msg.headersContainsKey("expiry"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Date(java.util.Date) Test(org.junit.Test)

Example 75 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class MetadataTokenWriterTest method testApply.

@Test
public void testApply() throws Exception {
    AccessToken token = new AccessToken("Bearer", "token").withRefreshToken("refresh").withExpiry(DateFormatUtil.format(new Date(System.currentTimeMillis() + 2000)));
    MetadataAccessTokenWriter writer = new MetadataAccessTokenWriter().withTokenKey("access_token").withTokenExpiryKey("expiry_token").withRefreshTokenKey("refresh_token");
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    try {
        LifecycleHelper.initAndStart(writer);
        writer.apply(token, msg);
        assertTrue(msg.headersContainsKey("access_token"));
        assertEquals("Bearer token", msg.getMetadataValue("access_token"));
        assertTrue(msg.headersContainsKey("expiry_token"));
        assertTrue(msg.headersContainsKey("refresh_token"));
    } finally {
        LifecycleHelper.stopAndClose(writer);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Date(java.util.Date) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1495 Test (org.junit.Test)1362 ServiceException (com.adaptris.core.ServiceException)171 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)158 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)156 StandaloneProducer (com.adaptris.core.StandaloneProducer)125 Channel (com.adaptris.core.Channel)122 MetadataElement (com.adaptris.core.MetadataElement)94 File (java.io.File)89 TimeInterval (com.adaptris.util.TimeInterval)77 CoreException (com.adaptris.core.CoreException)67 Session (javax.jms.Session)62 StandardWorkflow (com.adaptris.core.StandardWorkflow)57 GuidGenerator (com.adaptris.util.GuidGenerator)56 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)49 Message (javax.jms.Message)47 XPath (com.adaptris.util.text.xml.XPath)45 ServiceList (com.adaptris.core.ServiceList)43 Document (org.w3c.dom.Document)40