Search in sources :

Example 1 with RegexMetadataFilter

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()));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneProducer(com.adaptris.core.StandaloneProducer) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 2 with RegexMetadataFilter

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);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) HttpURLConnection(java.net.HttpURLConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) URL(java.net.URL) Test(org.junit.Test)

Example 3 with RegexMetadataFilter

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);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) HttpURLConnection(java.net.HttpURLConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) URL(java.net.URL) Test(org.junit.Test)

Example 4 with RegexMetadataFilter

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);
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) NoOpMetadataFilter(com.adaptris.core.metadata.NoOpMetadataFilter) Test(org.junit.Test)

Example 5 with 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);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

RegexMetadataFilter (com.adaptris.core.metadata.RegexMetadataFilter)33 Test (org.junit.Test)25 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)19 Channel (com.adaptris.core.Channel)8 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 Session (javax.jms.Session)5 StandaloneProducer (com.adaptris.core.StandaloneProducer)4 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)4 Message (javax.jms.Message)4 MetadataElement (com.adaptris.core.MetadataElement)3 MessageTypeTranslatorImp (com.adaptris.core.jms.MessageTypeTranslatorImp)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 ServiceList (com.adaptris.core.ServiceList)2 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)2 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)2 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)2 KeyValuePair (com.adaptris.util.KeyValuePair)2 CoreException (com.adaptris.core.CoreException)1