use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class SimpleCamelConsumerTest method testCamelConsumer.
@Test
public void testCamelConsumer() throws Exception {
// Starting Spring context.
try (GenericApplicationContext context = new AnnotationConfigApplicationContext(ExampleConfiguration.class)) {
context.start();
SpongeEngine engine = context.getBean(SpongeEngine.class);
engine.getOperations().event("spongeEvent").set("message", "Send me to Camel").send();
await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").get());
assertFalse(engine.isError());
context.stop();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class SimpleCamelNoSpringTest method testCamelConsumer.
@Test
public void testCamelConsumer() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_consumer.py").build();
registry.put("spongeEngine", engine);
CamelContext camel = new DefaultCamelContext(registry);
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() {
// @formatter:off
from("sponge:spongeEngine").routeId("spongeConsumer").log("${body}").process(exchange -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").set(true)).to("stream:out");
// @formatter:on
}
});
camel.start();
try {
engine.getOperations().event("spongeEvent").set("message", "Send me to Camel").send();
await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").get());
assertFalse(engine.isError());
} finally {
camel.stop();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class CamelProducerOverriddenActionTest method testCamelProducerOverridenAction.
@Test
public void testCamelProducerOverridenAction() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
SpongeEngine engine = DefaultSpongeEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer_overridden_action.py").build();
registry.put("spongeEngine", engine);
CamelContext camel = new DefaultCamelContext(registry);
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() {
// @formatter:off
from("direct:start").routeId("spongeProducer").to("sponge:spongeEngine");
// @formatter:on
}
});
camel.start();
try {
ProducerTemplate producerTemplate = camel.createProducerTemplate();
producerTemplate.sendBody("direct:start", "Send me to the Sponge");
await().pollDelay(2, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_camelEvent").get());
assertFalse(engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_spongeProducer").get());
assertFalse(engine.isError());
} finally {
camel.stop();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class NewsTest method testNews.
@Test
public void testNews() throws InterruptedException {
NewsExampleMain example = new NewsExampleMain();
try {
example.startup();
SpongeEngine engine = example.getEngine();
await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "alarmSounded").get());
TimeUnit.SECONDS.sleep(2);
if (engine.isError()) {
Assert.fail(engine.getError().toString());
}
} finally {
example.shutdown();
}
}
use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.
the class StandaloneCamelXmlTest method testCamelRouteXml.
@Test
public void testCamelRouteXml() {
StandaloneEngineMain engineMain = new StandaloneEngineMain(true);
try {
engineMain.startup("-c", "config/config.xml");
SpongeEngine engine = engineMain.getEngine();
await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable("message") != null && engine.getOperations().getVariable(Boolean.class, "sent"));
assertTrue(engine.getOperations().getVariable(String.class, "message").contains("Send me to Camel"));
} finally {
engineMain.shutdown();
}
}
Aggregations