Search in sources :

Example 46 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class SimpleCamelProducerTest method testCamelProducer.

@Test
public void testCamelProducer() throws Exception {
    // Starting Spring context.
    try (GenericApplicationContext context = new AnnotationConfigApplicationContext(ExampleConfiguration.class)) {
        context.start();
        // Sending Camel message.
        CamelContext camel = context.getBean(CamelContext.class);
        ProducerTemplate producerTemplate = camel.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "Send me to the Sponge");
        // Waiting for the engine to process an event.
        SpongeEngine engine = context.getBean(SpongeEngine.class);
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());
        assertFalse(engine.isError());
        context.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) 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 47 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class CamelRssNewsTest method testCamelRssNews.

@Test
public void testCamelRssNews() throws InterruptedException {
    CamelRssNewsExampleMain example = new CamelRssNewsExampleMain();
    try {
        example.startup();
        SpongeEngine engine = example.getEngine();
        await().atMost(60, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "alarmSounded").get() && engine.getOperations().getVariable(AtomicBoolean.class, "alarmForwarded").get() && engine.getOperations().getVariable(AtomicBoolean.class, "sourceRoutesStopped").get());
        if (engine.isError()) {
            Assert.fail(engine.getError().toString());
        }
    } finally {
        example.shutdown();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 48 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class StandaloneCamelGroovyTest 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)

Example 49 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class ConfigurationKnowledgeBaseFileTest method testKnowledgeBaseFileOptionalNonExisting.

@Test
public void testKnowledgeBaseFileOptionalNonExisting() {
    SpongeEngine engine = DefaultSpongeEngine.builder().config(DIR + "configuration_kb_file_optional_non_existing.xml").build();
    engine.startup();
    try {
        assertFalse(engine.getOperations().existsVariable("loaded"));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine) Test(org.junit.Test)

Example 50 with SpongeEngine

use of org.openksavi.sponge.engine.SpongeEngine in project sponge by softelnet.

the class ConfigurationTest method testRelativeFiles.

@Test
public void testRelativeFiles() throws InterruptedException {
    SpongeEngine engine = DefaultSpongeEngine.builder().config("examples/core/configuration/relative_files.xml").build();
    engine.startup();
    try {
        assertTrue(engine.getOperations().getVariable(Boolean.class, "loaded"));
        assertFalse(engine.isError());
    } finally {
        engine.shutdown();
    }
}
Also used : DefaultSpongeEngine(org.openksavi.sponge.core.engine.DefaultSpongeEngine) 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