Search in sources :

Example 1 with SpongeEngine

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();
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) SpringSpongeEngine(org.openksavi.sponge.spring.SpringSpongeEngine) Test(org.junit.Test)

Example 2 with SpongeEngine

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();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with SpongeEngine

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();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 4 with SpongeEngine

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();
    }
}
Also used : SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 5 with SpongeEngine

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();
    }
}
Also used : StandaloneEngineMain(org.openksavi.sponge.standalone.StandaloneEngineMain) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Aggregations

SpongeEngine (org.openksavi.sponge.engine.SpongeEngine)91 DefaultSpongeEngine (org.openksavi.sponge.core.engine.DefaultSpongeEngine)55 Test (org.junit.Test)49 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 StandaloneEngineMain (org.openksavi.sponge.standalone.StandaloneEngineMain)6 SpringSpongeEngine (org.openksavi.sponge.spring.SpringSpongeEngine)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 CamelContext (org.apache.camel.CamelContext)4 SpongeException (org.openksavi.sponge.SpongeException)4 CorrelationEventsLog (org.openksavi.sponge.test.util.CorrelationEventsLog)4 LinkedHashMap (java.util.LinkedHashMap)3 ProducerTemplate (org.apache.camel.ProducerTemplate)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 BigInteger (java.math.BigInteger)1 List (java.util.List)1