use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class StandardHttpProducerTest method testProduce_MetadataRequestHeaders.
@Test
public void testProduce_MetadataRequestHeaders() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
Channel c = HttpHelper.createAndStartChannel(mock);
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
stdHttp.setRequestHeaderProvider(new MetadataRequestHeaders(new RegexMetadataFilter()));
StandaloneProducer producer = new StandaloneProducer(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata(getName(), getName());
try {
c.requestStart();
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(producer);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertTrue(m2.headersContainsKey(getName()));
assertEquals(getName(), m2.getMetadataValue(getName()));
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class MetadataRequestHeadersTest method testAddHeaders.
@Test
public void testAddHeaders() throws Exception {
Channel c = null;
HttpURLConnection urlC = null;
try {
c = HttpHelper.createAndStartChannel();
URL url = new URL(HttpHelper.createProduceDestination(c));
urlC = (HttpURLConnection) url.openConnection();
MetadataRequestHeaders headers = new MetadataRequestHeaders();
headers.setFilter(new RegexMetadataFilter());
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
String name = testName.getMethodName();
msg.addMetadata(name, name);
urlC = headers.addHeaders(msg, urlC);
assertTrue(contains(urlC, name, name));
} finally {
HttpHelper.stopChannelAndRelease(c);
}
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class MetadataRequestHeadersTest method testAddHeaders_Flatten.
@Test
public void testAddHeaders_Flatten() throws Exception {
Channel c = null;
HttpURLConnection urlC = null;
try {
c = HttpHelper.createAndStartChannel();
URL url = new URL(HttpHelper.createProduceDestination(c));
urlC = (HttpURLConnection) url.openConnection();
MetadataRequestHeaders headers = new MetadataRequestHeaders();
headers.setUnfold(true);
headers.setFilter(new RegexMetadataFilter());
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
String name = testName.getMethodName();
msg.addMetadata(name, name + "\r\n " + name);
urlC = headers.addHeaders(msg, urlC);
assertTrue(contains(urlC, name, name + " " + name));
} finally {
HttpHelper.stopChannelAndRelease(c);
}
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class MetadataConverterCase method testMetadataFilter.
@Test
public void testMetadataFilter() throws Exception {
MetadataConverter mc = createConverter();
assertTrue(mc.getMetadataFilter() instanceof NoOpMetadataFilter);
mc.setMetadataFilter(new RegexMetadataFilter());
assertTrue(mc.getMetadataFilter() instanceof RegexMetadataFilter);
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class TextMessageTranslatorTest method testAdaptrisMessageToTextMessageWithMetadataFilter.
@Test
public void testAdaptrisMessageToTextMessageWithMetadataFilter() throws Exception {
TextMessageTranslator trans = new TextMessageTranslator();
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addExcludePattern(INTEGER_METADATA);
trans.setMetadataFilter(filter);
try {
Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
start(trans, session);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
addMetadata(msg);
Message jmsMsg = trans.translate(msg);
assertTrue("jmsMsg instanceof TextMessage", jmsMsg instanceof TextMessage);
assertEquals(TEXT, ((TextMessage) jmsMsg).getText());
assertEquals(STRING_VALUE, jmsMsg.getStringProperty(STRING_METADATA));
assertEquals(BOOLEAN_VALUE, jmsMsg.getStringProperty(BOOLEAN_METADATA));
assertEquals(Boolean.valueOf(BOOLEAN_VALUE).booleanValue(), // default
jmsMsg.getBooleanProperty(BOOLEAN_METADATA));
// We should not of copied the integer value according to the filter.
assertNull(jmsMsg.getStringProperty(INTEGER_METADATA));
} finally {
stop(trans);
}
}
Aggregations