Created
July 19, 2013 09:01
-
-
Save stibi/6037772 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
import com.tieto.etb.esb.api.aggregating.StringListAggregator; | |
import org.apache.activemq.camel.component.ActiveMQComponent; | |
import org.apache.camel.LoggingLevel; | |
import org.apache.camel.builder.RouteBuilder; | |
import org.apache.camel.component.mock.MockEndpoint; | |
import org.apache.camel.test.junit4.CamelTestSupport; | |
import org.apache.camel.util.jndi.JndiContext; | |
import org.junit.Test; | |
import javax.naming.Context; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* @author stibomar | |
* @since 19/07/13 10:38 | |
*/ | |
public class AggregationStringResponseFromJmsTests extends CamelTestSupport { | |
private String getUriToJmsEndpoint() { | |
return "jms:queue:testing?transferExchange=true&exchangePattern=InOut"; | |
} | |
private List<String> getTestingListOfStrings() { | |
List<String> testingData = new ArrayList<String>(); | |
testingData.add("Testing item 1"); | |
testingData.add("Testing item 2"); | |
testingData.add("Testing item 3"); | |
testingData.add("Testing item 4"); | |
return testingData; | |
} | |
@Test | |
public void listOfStringsTransformedInJmsRouteAndResponsesAggregated() throws InterruptedException { | |
MockEndpoint mock = getMockEndpoint("mock:result"); | |
mock.expectedBodiesReceived(""); | |
mock.expectedMessageCount(1); | |
template.sendBody("direct:start", getTestingListOfStrings()); | |
assertMockEndpointsSatisfied(); | |
} | |
@Override | |
protected RouteBuilder createRouteBuilder() { | |
return new RouteBuilder() { | |
@Override | |
public void configure() throws Exception { | |
from(getUriToJmsEndpoint()) | |
.log(LoggingLevel.INFO, "In: ${body}") | |
.transform().simple("${body} transformed!") | |
.log(LoggingLevel.INFO, "Out: ${body}"); | |
from("direct:start") | |
.split().body().aggregationStrategy(new StringListAggregator()) | |
.to(getUriToJmsEndpoint()) | |
.end() | |
.to("mock:result"); | |
} | |
}; | |
} | |
@Override | |
protected Context createJndiContext() throws Exception { | |
JndiContext jndiContext = new JndiContext(); | |
ActiveMQComponent amq = ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"); | |
amq.setCamelContext(context); | |
jndiContext.bind("jms", amq); | |
return jndiContext; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment