Search in sources :

Example 11 with KeyValuePairList

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

the class AddExtendedLoggingContextTest method testLoggingContextFromMetadata.

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

Example 12 with KeyValuePairList

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

the class IdentityBuilderTest method testMappedMetadataIdentityBuilder_RoundTrip.

@Test
public void testMappedMetadataIdentityBuilder_RoundTrip() throws Exception {
    MappedMetadataIdentityBuilder builder = new MappedMetadataIdentityBuilder(MetadataSource.Standard, new KeyValuePairList(Arrays.asList(new KeyValuePair[] { new KeyValuePair(MAPPED_USER, USER), new KeyValuePair(MAPPED_PASSWORD, PASSWORD), new KeyValuePair(MAPPED_ROLE, ROLE) })));
    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 13 with KeyValuePairList

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

the class IdentityBuilderTest method testCompositeIdentityBuilder.

@Test
public void testCompositeIdentityBuilder() 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(ROLE, role);
    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)));
    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 14 with KeyValuePairList

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

the class LoggingContextInterceptorTest method testInterceptor_KVP.

@Test
public void testInterceptor_KVP() throws Exception {
    KeyValuePairList kvp = new KeyValuePairList();
    kvp.add(new KeyValuePair("key1", "value1"));
    kvp.add(new KeyValuePair("key2", "value2"));
    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();
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        assertTrue(metadata.containsKey("key1"));
        assertEquals("value1", metadata.get("key1"));
    } 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 15 with KeyValuePairList

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

the class MetadataBranchingServiceTest method createService.

private static MetadataValueBranchingService createService() {
    MetadataValueBranchingService service = new MetadataValueBranchingService();
    service.addMetadataKey(KEY1);
    service.addMetadataKey(KEY2);
    KeyValuePairList mappings = new KeyValuePairList();
    mappings.addKeyValuePair(new KeyValuePair(VAL1VAL2, NEXT_SERVICE_ID));
    service.setMetadataToServiceIdMappings(mappings);
    service.setValueMatcher(new EqualsValueMatcher());
    return service;
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) KeyValuePairList(com.adaptris.util.KeyValuePairList)

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