Search in sources :

Example 1 with KeyValuePairList

use of com.adaptris.util.KeyValuePairList in project interlok by adaptris.

the class LoggingContextInterceptorTest method testInterceptor_KVP_Expression.

@Test
public void testInterceptor_KVP_Expression() throws Exception {
    KeyValuePairList kvp = new KeyValuePairList();
    kvp.add(new KeyValuePair("key1", "%message{mk1}"));
    kvp.add(new KeyValuePair("key2", "%message{mk2}"));
    LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
    interceptor.setValuesToSet(kvp);
    StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new LoggingContextToMetadata());
    MockChannel c = new MockChannel();
    c.setUniqueId("channelName");
    c.getWorkflowList().add(wf);
    try {
        BaseCase.start(c);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        msg.addMetadata("mk1", "mv1");
        msg.addMetadata("mk2", "mv2");
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        assertTrue(metadata.containsKey("key1"));
        assertEquals("mv1", metadata.get("key1"));
        assertTrue(metadata.containsKey("key2"));
        assertEquals("mv2", metadata.get("key2"));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) KeyValuePair(com.adaptris.util.KeyValuePair) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) KeyValuePairList(com.adaptris.util.KeyValuePairList) Test(org.junit.Test)

Example 2 with KeyValuePairList

use of com.adaptris.util.KeyValuePairList in project interlok by adaptris.

the class IdentityBuilderTest method testCompositeMetadataIdentityBuilder_RoundTrip.

@Test
public void testCompositeMetadataIdentityBuilder_RoundTrip() throws Exception {
    MappedMetadataIdentityBuilder mapped = new MappedMetadataIdentityBuilder(new KeyValuePairList(Arrays.asList(new KeyValuePair[] { new KeyValuePair(MAPPED_USER, USER), new KeyValuePair(MAPPED_PASSWORD, PASSWORD) })));
    MetadataIdentityBuilder metadata = new MetadataIdentityBuilder(Arrays.asList(USER, PASSWORD, ROLE));
    // Due to order, we should get the mapped-user becoming the "user" etc.
    CompositeIdentityBuilder builder = new CompositeIdentityBuilder(new ArrayList<IdentityBuilder>(Arrays.asList(metadata, mapped)));
    AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller();
    assertRoundtripEquality(builder, m.unmarshal(m.marshal(builder)));
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) AdaptrisMarshaller(com.adaptris.core.AdaptrisMarshaller) KeyValuePairList(com.adaptris.util.KeyValuePairList) Test(org.junit.Test)

Example 3 with KeyValuePairList

use of com.adaptris.util.KeyValuePairList in project interlok by adaptris.

the class IdentityBuilderTest method testMappedMetadataIdentityBuilder_ObjectMetadata.

@Test
public void testMappedMetadataIdentityBuilder_ObjectMetadata() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    String username = getName() + ThreadLocalRandom.current().nextInt();
    String password = getName() + ThreadLocalRandom.current().nextInt();
    String role = getName() + +ThreadLocalRandom.current().nextInt();
    msg.getObjectHeaders().put(MAPPED_USER, username);
    msg.getObjectHeaders().put(MAPPED_PASSWORD, password);
    msg.getObjectHeaders().put(MAPPED_ROLE, role);
    MappedMetadataIdentityBuilder builder = new MappedMetadataIdentityBuilder(MetadataSource.Object, new KeyValuePairList(Arrays.asList(new KeyValuePair[] { new KeyValuePair(MAPPED_USER, USER), new KeyValuePair(MAPPED_PASSWORD, PASSWORD), new KeyValuePair(MAPPED_ROLE, ROLE) })));
    try {
        BaseCase.start(builder);
        Map<String, Object> identityMap = builder.build(msg);
        assertTrue(identityMap.containsKey(ROLE));
        assertTrue(identityMap.containsKey(USER));
        assertTrue(identityMap.containsKey(PASSWORD));
        assertEquals(username, identityMap.get(USER));
        assertEquals(password, identityMap.get(PASSWORD));
        assertEquals(role, identityMap.get(ROLE));
    } finally {
        BaseCase.stop(builder);
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) KeyValuePairList(com.adaptris.util.KeyValuePairList) Test(org.junit.Test)

Example 4 with KeyValuePairList

use of com.adaptris.util.KeyValuePairList in project interlok by adaptris.

the class IdentityBuilderTest method testMappedMetadataIdentityBuilder.

@Test
public void testMappedMetadataIdentityBuilder() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    String username = getName() + ThreadLocalRandom.current().nextInt();
    String password = getName() + ThreadLocalRandom.current().nextInt();
    String role = getName() + +ThreadLocalRandom.current().nextInt();
    msg.addMetadata(MAPPED_USER, username);
    msg.addMetadata(MAPPED_PASSWORD, password);
    msg.addMetadata(MAPPED_ROLE, role);
    MappedMetadataIdentityBuilder builder = new MappedMetadataIdentityBuilder(new KeyValuePairList(Arrays.asList(new KeyValuePair[] { new KeyValuePair(MAPPED_USER, USER), new KeyValuePair(MAPPED_PASSWORD, PASSWORD), new KeyValuePair(MAPPED_ROLE, ROLE) })));
    try {
        BaseCase.start(builder);
        Map<String, Object> identityMap = builder.build(msg);
        assertTrue(identityMap.containsKey(ROLE));
        assertTrue(identityMap.containsKey(USER));
        assertTrue(identityMap.containsKey(PASSWORD));
        assertEquals(username, identityMap.get(USER));
        assertEquals(password, identityMap.get(PASSWORD));
        assertEquals(role, identityMap.get(ROLE));
    } finally {
        BaseCase.stop(builder);
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) KeyValuePairList(com.adaptris.util.KeyValuePairList) Test(org.junit.Test)

Example 5 with KeyValuePairList

use of com.adaptris.util.KeyValuePairList in project interlok by adaptris.

the class AddExtendedLoggingContextTest method testDefaultLoggingContext.

@Test
public void testDefaultLoggingContext() throws Exception {
    AddExtendedLoggingContext srv = new AddExtendedLoggingContext().withValuesToSet(new KeyValuePairList(Collections.singletonMap("contextKey", "contextValue"))).withUseDefaultKeys(false);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    execute(srv, msg);
    assertEquals("contextValue", MDC.get("contextKey"));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) KeyValuePairList(com.adaptris.util.KeyValuePairList) Test(org.junit.Test)

Aggregations

KeyValuePairList (com.adaptris.util.KeyValuePairList)15 KeyValuePair (com.adaptris.util.KeyValuePair)12 Test (org.junit.Test)12 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)9 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)2 StandardWorkflow (com.adaptris.core.StandardWorkflow)2 MockChannel (com.adaptris.core.stubs.MockChannel)2 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)2 MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)1 Before (org.junit.Before)1