Search in sources :

Example 1 with MessageClient

use of org.structr.messaging.engine.entities.MessageClient in project structr by structr.

the class SimpleMessagingTest method test01.

@Test
public void test01() {
    try (final Tx tx = app.tx()) {
        MessageClient client1 = app.create(MessageClient.class, "client1");
        MessageSubscriber sub = app.create(MessageSubscriber.class, "sub");
        List<MessageSubscriber> subList = new ArrayList<>();
        subList.add(sub);
        client1.setProperty(StructrApp.key(MessageClient.class, "subscribers"), subList);
        sub.setProperty(StructrApp.key(MessageSubscriber.class, "topic"), "test");
        sub.setProperty(StructrApp.key(MessageSubscriber.class, "callback"), "set(this, 'name', retrieve('message'))");
        Scripting.replaceVariables(new ActionContext(securityContext, null), client1, "${{Structr.log('Sending message'); Structr.get('this').sendMessage('test','testmessage');}}");
        assertEquals("testmessage", sub.getName());
        tx.success();
    } catch (FrameworkException ex) {
        fail("Exception during test: " + ex.getMessage());
    }
}
Also used : MessageSubscriber(org.structr.messaging.engine.entities.MessageSubscriber) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ArrayList(java.util.ArrayList) ActionContext(org.structr.schema.action.ActionContext) MessageClient(org.structr.messaging.engine.entities.MessageClient) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 FrameworkException (org.structr.common.error.FrameworkException)1 Tx (org.structr.core.graph.Tx)1 MessageClient (org.structr.messaging.engine.entities.MessageClient)1 MessageSubscriber (org.structr.messaging.engine.entities.MessageSubscriber)1 ActionContext (org.structr.schema.action.ActionContext)1