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"));
}
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)));
}
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);
}
}
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);
}
}
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;
}
Aggregations