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