Created
March 9, 2009 10:37
-
-
Save p3t0r/76207 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.finalist.eip.examples; | |
import java.util.Arrays; | |
import java.util.List; | |
import javax.jms.ConnectionFactory; | |
import org.apache.activemq.ActiveMQConnectionFactory; | |
import org.apache.camel.CamelContext; | |
import org.apache.camel.EndpointInject; | |
import org.apache.camel.Exchange; | |
import org.apache.camel.Produce; | |
import org.apache.camel.ProducerTemplate; | |
import org.apache.camel.builder.RouteBuilder; | |
import org.apache.camel.component.mock.MockEndpoint; | |
import org.apache.camel.test.CamelTestSupport; | |
import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge; | |
/** | |
* @author Peter Maas | |
*/ | |
public class SimpleSplitterRouteTest extends CamelTestSupport { | |
private static final long ONE_SECOND = 1000L; | |
@EndpointInject(uri = "mock:result") | |
protected MockEndpoint resultEndpoint; | |
@Produce(uri = "direct:subscriptionBatchInput") | |
protected ProducerTemplate template; | |
private static final String[] VALID_ARPU_VALUES = new String[]{"low","medium","high"}; | |
static { | |
Arrays.sort(VALID_ARPU_VALUES); | |
} | |
public void testShouldPublishAllSubscriptionsAndExtractAttributes() throws InterruptedException{ | |
resultEndpoint.setExpectedMessageCount(5); | |
final String body = "<?xml version=\"1.0\"?>" + | |
"<subscriptions>" + | |
" <subscription arpu=\"high\" subscriptionId=\"1203\">high arpu 1</subscription>" + | |
" <subscription arpu=\"high\" subscriptionId=\"1205\">high arpu 2</subscription>" + | |
" <subscription arpu=\"low\" subscriptionId=\"1208\">low arpu 1</subscription>" + | |
" <subscription arpu=\"high\" subscriptionId=\"1213\">high arpu 3</subscription>" + | |
" <subscription arpu=\"medium\" subscriptionId=\"1217\">medium arpu 1</subscription>" + | |
"</subscriptions>"; | |
template.sendBody(body); | |
resultEndpoint.assertIsSatisfied(ONE_SECOND); | |
final List<Exchange> exchanges = resultEndpoint.getExchanges(); | |
assertAllMessagesValid(exchanges); | |
} | |
private void assertAllMessagesValid(final List<Exchange> exchanges) { | |
for(final Exchange exchange : exchanges){ | |
assertNotNull(exchange.getIn().getHeader("id")); | |
final String arpuHeader = (String)exchange.getIn().getHeader("arpu"); | |
assertValidArpuHeader(arpuHeader); | |
} | |
} | |
private void assertValidArpuHeader(final String arpuHeader) { | |
assertTrue(Arrays.binarySearch(VALID_ARPU_VALUES, arpuHeader) >= 0); | |
} | |
@Override | |
protected CamelContext createCamelContext() throws Exception { | |
final CamelContext camelContext = super.createCamelContext(); | |
final ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); | |
camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory)); | |
return camelContext; | |
} | |
@Override | |
protected RouteBuilder[] createRouteBuilders() throws Exception { | |
final RouteBuilder[] builders = new RouteBuilder[]{ | |
new GatewayService(), | |
new RouteBuilder(){ | |
@Override | |
public void configure() throws Exception { | |
from("activemq:topic:incomingSubscription").to("mock:result"); | |
} | |
} | |
}; | |
return builders; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment