use of org.apache.camel.model.WhenDefinition in project camel by apache.
the class BacklogTracerIdOnAllNodesTest method testBacklogTracerEventMessage.
@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessage() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
assertEquals("Should be 1000", 1000, size.intValue());
// enable it
mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:end").expectedMessageCount(2);
template.sendBody("direct:start", "Hello Camel");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
List<Exchange> fooExchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
List<Exchange> camelExchanges = getMockEndpoint("mock:camel").getReceivedExchanges();
RouteDefinition route = context.getRouteDefinitions().get(0);
assertNotNull(route);
ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
assertEquals("choice1", choice.getId());
WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
assertEquals("when1", when.getId());
LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
assertEquals("log1", log1.getId());
ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
assertEquals("camel", to1.getId());
OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
assertEquals("otherwise1", other.getId());
LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
assertEquals("log2", log2.getId());
ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
assertEquals("to1", to2.getId());
ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
assertEquals("foo", to3.getId());
ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
assertEquals("end", to4.getId());
List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "to1" }, new String[] { "java.lang.String" });
assertNotNull(events);
assertEquals(1, events.size());
BacklogTracerEventMessage event1 = events.get(0);
assertEquals("to1", event1.getToNode());
assertEquals(" <message exchangeId=\"" + fooExchanges.get(0).getExchangeId() + "\">\n" + " <body type=\"java.lang.String\">Hello World</body>\n" + " </message>", event1.getMessageAsXml());
events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "camel" }, new String[] { "java.lang.String" });
assertNotNull(events);
assertEquals(1, events.size());
event1 = events.get(0);
assertEquals("camel", event1.getToNode());
assertEquals(" <message exchangeId=\"" + camelExchanges.get(0).getExchangeId() + "\">\n" + " <body type=\"java.lang.String\">Hello Camel</body>\n" + " </message>", event1.getMessageAsXml());
}
use of org.apache.camel.model.WhenDefinition in project camel by apache.
the class CustomIdIssuesTest method testCustomId.
public void testCustomId() {
RouteDefinition route = context.getRouteDefinition("myRoute");
assertNotNull(route);
assertTrue(route.hasCustomIdAssigned());
FromDefinition from = route.getInputs().get(0);
assertEquals("fromFile", from.getId());
assertTrue(from.hasCustomIdAssigned());
ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
assertEquals("myChoice", choice.getId());
assertTrue(choice.hasCustomIdAssigned());
WhenDefinition when = choice.getWhenClauses().get(0);
assertTrue(when.hasCustomIdAssigned());
assertEquals("UK", when.getId());
LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
assertFalse(log.hasCustomIdAssigned());
}
use of org.apache.camel.model.WhenDefinition in project camel by apache.
the class CustomIdIssuesTest method testCustomId.
@Test
public void testCustomId() {
RouteDefinition route = context.getRouteDefinition("myRoute");
assertNotNull(route);
assertTrue(route.hasCustomIdAssigned());
FromDefinition from = route.getInputs().get(0);
assertEquals("fromFile", from.getId());
assertTrue(from.hasCustomIdAssigned());
ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
assertEquals("myChoice", choice.getId());
assertTrue(choice.hasCustomIdAssigned());
WhenDefinition when = choice.getWhenClauses().get(0);
assertTrue(when.hasCustomIdAssigned());
assertEquals("UK", when.getId());
LogDefinition log = (LogDefinition) choice.getOtherwise().getOutputs().get(0);
assertFalse(log.hasCustomIdAssigned());
}
use of org.apache.camel.model.WhenDefinition in project camel by apache.
the class ManagedChoice method choiceStatistics.
@Override
public TabularData choiceStatistics() {
try {
TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.choiceTabularType());
List<WhenDefinition> whens = getDefinition().getWhenClauses();
List<FilterProcessor> filters = processor.getFilters();
for (int i = 0; i < filters.size(); i++) {
WhenDefinition when = whens.get(i);
FilterProcessor filter = filters.get(i);
CompositeType ct = CamelOpenMBeanTypes.choiceCompositeType();
String predicate = when.getExpression().getExpression();
String language = when.getExpression().getLanguage();
Long matches = filter.getFilteredCount();
CompositeData data = new CompositeDataSupport(ct, new String[] { "predicate", "language", "matches" }, new Object[] { predicate, language, matches });
answer.put(data);
}
if (getDefinition().getOtherwise() != null) {
CompositeType ct = CamelOpenMBeanTypes.choiceCompositeType();
String predicate = "otherwise";
String language = "";
Long matches = processor.getNotFilteredCount();
CompositeData data = new CompositeDataSupport(ct, new String[] { "predicate", "language", "matches" }, new Object[] { predicate, language, matches });
answer.put(data);
}
return answer;
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
use of org.apache.camel.model.WhenDefinition in project camel by apache.
the class TraceInitIdOnAllNodesTest method testInitIdsOnAllNodes.
public void testInitIdsOnAllNodes() throws Exception {
getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:end").expectedMessageCount(2);
template.sendBody("direct:start", "Hello Camel");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
RouteDefinition route = context.getRouteDefinitions().get(0);
assertNotNull(route);
ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
assertEquals("choice1", choice.getId());
WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
assertEquals("when1", when.getId());
LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
assertEquals("log1", log1.getId());
ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
assertEquals("camel", to1.getId());
OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
assertEquals("otherwise1", other.getId());
LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
assertEquals("log2", log2.getId());
ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
assertEquals("to1", to2.getId());
ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
assertEquals("foo", to3.getId());
ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
assertEquals("end", to4.getId());
}
Aggregations