Search in sources :

Example 46 with EventListener

use of won.bot.framework.eventbot.listener.EventListener in project webofneeds by researchstudio-sat.

the class AclTests method testGroupChat.

@Test(timeout = 60 * 1000)
public void testGroupChat() throws Exception {
    runTest(ctx -> {
        EventBus bus = ctx.getEventBus();
        final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
        final URI atomUri1 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final URI atomUri2 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final URI atomUri3 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final URI atomUri4 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final URI atom1GroupSocket = URI.create(atomUri1.toString() + "#groupSocket");
        final BotBehaviour bbCreateAtom1 = new BotBehaviour(ctx, "bbCreateAtom1") {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri1.toString();
                AtomContent atomContent = AtomContent.builder(atomUri1).addTitle("Group Chat Atom (1/4)").addSocket(Socket.builder(atom1GroupSocket).setSocketDefinition(WXGROUP.GroupSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                Authorization autoConnectGroupSocket = Authorization.builder().setGranteeGranteeWildcard(GranteeWildcard.ANYONE).addGrant(b -> b.addSocket(s -> s.addSocketType(WXGROUP.GroupSocket.asURI()).addOperationsSimpleOperationExpression(OP_AUTO_CONNECT))).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri1).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayConnectAuth())).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayReadAnything())).content().aclGraph(won.auth.model.RdfOutput.toGraph(autoConnectGroupSocket)).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri1);
                EventListener successCallback = event -> {
                    logger.debug("group chat atom created");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Create group chat atom");
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        final BotBehaviour bbCreateAtom2 = new BotBehaviour(ctx, "bbCreateAtom2") {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri2.toString();
                AtomContent atomContent = AtomContent.builder(atomUri2).addTitle("member atom A (2/4)").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri2).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayConnectAuth())).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayReadAnything())).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri2);
                EventListener successCallback = event -> {
                    logger.debug("member atom A created");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Create member atom A");
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        final BotBehaviour bbCreateAtom3 = new BotBehaviour(ctx, "bbCreateAtom3") {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri3.toString();
                AtomContent atomContent = AtomContent.builder(atomUri3).addTitle("member atom B (3/4)").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri3).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayConnectAuth())).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayReadAnything())).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri3);
                EventListener successCallback = event -> {
                    logger.debug("member atom B created");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Creating member atom B");
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        final BotBehaviour bbCreateAtom4 = new BotBehaviour(ctx, "bbCreateAtom4") {

            @Override
            protected void onActivate(Optional<Object> message) {
                final String atomUriString = atomUri4.toString();
                AtomContent atomContent = AtomContent.builder(atomUri4).addTitle("member atom C (4/4)").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
                WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri4).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayConnectAuth())).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayReadAnything())).build();
                createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
                ctx.getBotContextWrapper().rememberAtomUri(atomUri4);
                EventListener successCallback = event -> {
                    logger.debug("member atom C created");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Creating member atom C");
                EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(createMessage);
            }
        };
        BotBehaviour bbSendConnect21 = new BotBehaviour(ctx, "bbSendConnect21") {

            @Override
            protected void onActivate(Optional<Object> message) {
                WonMessage connectMessage = WonMessageBuilder.connect().sockets().sender(URI.create(atomUri2.toString() + "#chatSocket")).recipient(atom1GroupSocket).direction().fromOwner().build();
                connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
                EventListener successCallback = event -> {
                    logger.debug("member A -> group connection requested");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Requesting connection member A -> group");
                EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(connectMessage);
            }
        };
        BotBehaviour bbSendConnect31 = new BotBehaviour(ctx, "bbSendConnect31") {

            @Override
            protected void onActivate(Optional<Object> message) {
                WonMessage connectMessage = WonMessageBuilder.connect().sockets().sender(URI.create(atomUri3.toString() + "#chatSocket")).recipient(atom1GroupSocket).direction().fromOwner().build();
                connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
                EventListener successCallback = event -> {
                    logger.debug("member B -> group connection requested");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Requesting connection member B -> group");
                EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(connectMessage);
            }
        };
        BotBehaviour bbSendConnect41 = new BotBehaviour(ctx, "bbSendConnect41") {

            @Override
            protected void onActivate(Optional<Object> message) {
                WonMessage connectMessage = WonMessageBuilder.connect().sockets().sender(URI.create(atomUri4.toString() + "#chatSocket")).recipient(atom1GroupSocket).direction().fromOwner().build();
                connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
                EventListener successCallback = event -> {
                    logger.debug("member C -> group connection requested");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Requesting connection member C -> group");
                EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(connectMessage);
            }
        };
        BotBehaviour bbWaitForAutoConnect = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                bus.subscribe(ConnectFromOtherAtomEvent.class, new ActionOnceAfterNEventsListener(ctx, new EventFilter() {

                    @Override
                    public boolean accept(Event event) {
                        boolean waitingForThis = ((ConnectFromOtherAtomEvent) event).getSenderSocket().equals(atom1GroupSocket);
                        return waitingForThis;
                    }
                }, 3, new EventBotAction() {

                    @Override
                    public Runnable getActionTask(Event event, EventListener eventListener) {
                        return () -> deactivate();
                    }
                }));
            }
        };
        BotBehaviour bbSendMsg41 = new BotBehaviour(ctx, "bbSendMsg41") {

            @Override
            protected void onActivate(Optional<Object> message) {
                WonMessage connectMessage = WonMessageBuilder.connectionMessage().sockets().sender(URI.create(atomUri4.toString() + "#chatSocket")).recipient(URI.create(atomUri1.toString() + "#groupSocket")).direction().fromOwner().content().text("Hello, world!").build();
                connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
                EventListener successCallback = event -> {
                    logger.debug("member C -> send message to group");
                    deactivate();
                };
                EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "sending message member C -> group");
                EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
                ctx.getWonMessageSender().sendMessage(connectMessage);
            }
        };
        BotBehaviour bbWaitForGroupMessage = new BotBehaviour(ctx) {

            @Override
            protected void onActivate(Optional<Object> message) {
                bus.subscribe(MessageFromOtherAtomEvent.class, new ActionOnceAfterNEventsListener(ctx, new EventFilter() {

                    @Override
                    public boolean accept(Event event) {
                        boolean interestedInThis = ((MessageFromOtherAtomEvent) event).getWonMessage().getSenderSocketURIRequired().equals(atom1GroupSocket);
                        return interestedInThis;
                    }
                }, 2, new EventBotAction() {

                    @Override
                    public Runnable getActionTask(Event event, EventListener eventListener) {
                        return () -> passTest(bus);
                    }
                }));
            }
        };
        BehaviourBarrier barrier = new BehaviourBarrier(ctx);
        barrier.waitFor(bbCreateAtom1, bbCreateAtom2, bbCreateAtom3, bbCreateAtom4);
        barrier.thenStart(bbSendConnect21, bbSendConnect31, bbSendConnect41);
        barrier.activate();
        bbWaitForAutoConnect.onDeactivateActivate(bbSendMsg41);
        bbWaitForGroupMessage.activate();
        bbWaitForAutoConnect.activate();
        bbCreateAtom1.activate();
        bbCreateAtom2.activate();
        bbCreateAtom3.activate();
        bbCreateAtom4.activate();
    });
}
Also used : EventBotAction(won.bot.framework.eventbot.action.EventBotAction) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) EventBus(won.bot.framework.eventbot.bus.EventBus) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) ContentUtils(won.utils.content.ContentUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) WonMessage(won.protocol.message.WonMessage) HashSet(java.util.HashSet) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Individuals(won.auth.model.Individuals) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) Socket(won.utils.content.model.Socket) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) MethodHandles(java.lang.invoke.MethodHandles) RdfOutput(won.utils.content.model.RdfOutput) Set(java.util.Set) Test(org.junit.Test) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) AtomContent(won.utils.content.model.AtomContent) AuthEnabledLinkedDataSource(won.auth.linkeddata.AuthEnabledLinkedDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) Event(won.bot.framework.eventbot.event.Event) won.protocol.vocabulary(won.protocol.vocabulary) Optional(java.util.Optional) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventListener(won.bot.framework.eventbot.listener.EventListener) Assert(org.junit.Assert) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) Optional(java.util.Optional) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) EventBus(won.bot.framework.eventbot.bus.EventBus) URI(java.net.URI) EventFilter(won.bot.framework.eventbot.filter.EventFilter) WonMessage(won.protocol.message.WonMessage) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) Event(won.bot.framework.eventbot.event.Event) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomContent(won.utils.content.model.AtomContent) EventBotAction(won.bot.framework.eventbot.action.EventBotAction) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) Test(org.junit.Test)

Example 47 with EventListener

use of won.bot.framework.eventbot.listener.EventListener in project webofneeds by researchstudio-sat.

the class AclTests method testCreateAtomWithEmptyACLButSocketAuths_isNotPubliclyReadable.

@Test(timeout = 60 * 1000)
public void testCreateAtomWithEmptyACLButSocketAuths_isNotPubliclyReadable() throws Exception {
    runTest(ctx -> {
        EventBus bus = ctx.getEventBus();
        final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
        final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final String atomUriString = atomUri.toString();
        final AtomContent atomContent = new AtomContent(atomUriString);
        atomContent.addTitle("Unit Test Atom ACL Test 1");
        final Socket holderSocket = new Socket(atomUriString + "#holderSocket");
        holderSocket.setSocketDefinition(WXHOLD.HolderSocket.asURI());
        final Socket buddySocket = new Socket(atomUriString + "#buddySocket");
        buddySocket.setSocketDefinition(WXBUDDY.BuddySocket.asURI());
        atomContent.addSocket(holderSocket);
        atomContent.addSocket(buddySocket);
        atomContent.addType(URI.create(WON.Atom.getURI()));
        WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(// add an empty acl graph
        GraphFactory.createGraphMem()).build();
        createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
        ctx.getBotContextWrapper().rememberAtomUri(atomUri);
        final String action = "Create Atom action";
        EventListener successCallback = event -> {
            ((CachingLinkedDataSource) ctx.getLinkedDataSource()).clear();
            boolean passed = true;
            passed = passed && testLinkedDataRequestOk(ctx, bus, "withWebid", atomUri, atomUri);
            passed = passed && testLinkedDataRequestFailsNoWebId(ctx, bus, "withoutWebId", LinkedDataFetchingException.Forbidden.class);
            if (passed) {
                passTest(bus);
            }
        };
        EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
        EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
        ctx.getWonMessageSender().sendMessage(createMessage);
    });
}
Also used : EventBotAction(won.bot.framework.eventbot.action.EventBotAction) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) EventBus(won.bot.framework.eventbot.bus.EventBus) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) ContentUtils(won.utils.content.ContentUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) WonMessage(won.protocol.message.WonMessage) HashSet(java.util.HashSet) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Individuals(won.auth.model.Individuals) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) Socket(won.utils.content.model.Socket) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) MethodHandles(java.lang.invoke.MethodHandles) RdfOutput(won.utils.content.model.RdfOutput) Set(java.util.Set) Test(org.junit.Test) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) AtomContent(won.utils.content.model.AtomContent) AuthEnabledLinkedDataSource(won.auth.linkeddata.AuthEnabledLinkedDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) Event(won.bot.framework.eventbot.event.Event) won.protocol.vocabulary(won.protocol.vocabulary) Optional(java.util.Optional) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventListener(won.bot.framework.eventbot.listener.EventListener) Assert(org.junit.Assert) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) WonMessage(won.protocol.message.WonMessage) EventBus(won.bot.framework.eventbot.bus.EventBus) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomContent(won.utils.content.model.AtomContent) URI(java.net.URI) Socket(won.utils.content.model.Socket) Test(org.junit.Test)

Example 48 with EventListener

use of won.bot.framework.eventbot.listener.EventListener in project webofneeds by researchstudio-sat.

the class AclTests method testCreateAtomWithACL_isNotPubliclyReadable.

@Test(timeout = 60 * 1000)
public void testCreateAtomWithACL_isNotPubliclyReadable() throws Exception {
    runTest(ctx -> {
        EventBus bus = ctx.getEventBus();
        final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
        final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final String atomUriString = atomUri.toString();
        final AtomContent atomContent = AtomContent.builder(atomUri).addTitle("Unit Test Atom ACL Test 3 (with acl)").addSocket(Socket.builder(atomUriString + "#holderSocket").setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).addSocket(Socket.builder(atomUriString + "#buddySocket").setSocketDefinition(WXBUDDY.BuddySocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
        // create an acl allowing only the atom itself to read everything
        Authorization auth = Authorization.builder().addGrant(ase -> ase.addOperationsSimpleOperationExpression(OP_READ)).addGranteesAtomExpression(ae -> ae.addAtomsURI(URI.create("https://example.com/nobody"))).build();
        WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(// add the acl graph
        won.auth.model.RdfOutput.toGraph(auth)).build();
        createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
        ctx.getBotContextWrapper().rememberAtomUri(atomUri);
        final String action = "Create Atom action";
        EventListener successCallback = event -> {
            URI connContainerUri = uriService.createConnectionContainerURIForAtom(atomUri);
            URI createMessageUri = ((SuccessResponseEvent) event).getOriginalMessageURI();
            boolean passed = true;
            passed = passed && testLinkedDataRequestOk(ctx, bus, "test1.", atomUri, atomUri, createMessageUri);
            passed = passed && testLinkedDataRequestOk_emptyDataset(ctx, bus, "test2.", atomUri, connContainerUri);
            passed = passed && testLinkedDataRequestFailsNoWebId(ctx, bus, "test3.", LinkedDataFetchingException.class, atomUri, connContainerUri, createMessageUri);
            if (passed) {
                passTest(bus);
            }
        };
        EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
        EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
        ctx.getWonMessageSender().sendMessage(createMessage);
    });
}
Also used : EventBotAction(won.bot.framework.eventbot.action.EventBotAction) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) EventBus(won.bot.framework.eventbot.bus.EventBus) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) ContentUtils(won.utils.content.ContentUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) WonMessage(won.protocol.message.WonMessage) HashSet(java.util.HashSet) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Individuals(won.auth.model.Individuals) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) Socket(won.utils.content.model.Socket) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) MethodHandles(java.lang.invoke.MethodHandles) RdfOutput(won.utils.content.model.RdfOutput) Set(java.util.Set) Test(org.junit.Test) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) AtomContent(won.utils.content.model.AtomContent) AuthEnabledLinkedDataSource(won.auth.linkeddata.AuthEnabledLinkedDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) Event(won.bot.framework.eventbot.event.Event) won.protocol.vocabulary(won.protocol.vocabulary) Optional(java.util.Optional) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventListener(won.bot.framework.eventbot.listener.EventListener) Assert(org.junit.Assert) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) WonMessage(won.protocol.message.WonMessage) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) EventBus(won.bot.framework.eventbot.bus.EventBus) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomContent(won.utils.content.model.AtomContent) URI(java.net.URI) Test(org.junit.Test)

Example 49 with EventListener

use of won.bot.framework.eventbot.listener.EventListener in project webofneeds by researchstudio-sat.

the class AclTests method testCreateAtomWithEmptyACL_isPubliclyReadable.

@Test(timeout = 60 * 1000)
public void testCreateAtomWithEmptyACL_isPubliclyReadable() throws Exception {
    runTest(ctx -> {
        EventBus bus = ctx.getEventBus();
        final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
        final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final String atomUriString = atomUri.toString();
        final AtomContent atomContent = new AtomContent(atomUriString);
        atomContent.addTitle("Unit Test Atom ACL Test 1");
        atomContent.addType(URI.create(WON.Atom.getURI()));
        atomContent.addSocket(Socket.builder(atomUri.toString() + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build());
        WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(// add an empty acl graph
        GraphFactory.createGraphMem()).build();
        createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
        ctx.getBotContextWrapper().rememberAtomUri(atomUri);
        final String action = "Create Atom action";
        EventListener successCallback = event -> {
            ((CachingLinkedDataSource) ctx.getLinkedDataSource()).clear();
            boolean passed = true;
            passed = passed && testLinkedDataRequestOk(ctx, bus, "withWebid", atomUri, atomUri);
            passed = passed && testLinkedDataRequestOkNoWebId(ctx, bus, "withoutWebId", atomUri);
            if (passed) {
                passTest(bus);
            }
        };
        EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
        EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
        ctx.getWonMessageSender().sendMessage(createMessage);
    });
}
Also used : EventBotAction(won.bot.framework.eventbot.action.EventBotAction) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) EventBus(won.bot.framework.eventbot.bus.EventBus) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) ContentUtils(won.utils.content.ContentUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) WonMessage(won.protocol.message.WonMessage) HashSet(java.util.HashSet) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Individuals(won.auth.model.Individuals) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) Socket(won.utils.content.model.Socket) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) MethodHandles(java.lang.invoke.MethodHandles) RdfOutput(won.utils.content.model.RdfOutput) Set(java.util.Set) Test(org.junit.Test) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) AtomContent(won.utils.content.model.AtomContent) AuthEnabledLinkedDataSource(won.auth.linkeddata.AuthEnabledLinkedDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) Event(won.bot.framework.eventbot.event.Event) won.protocol.vocabulary(won.protocol.vocabulary) Optional(java.util.Optional) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventListener(won.bot.framework.eventbot.listener.EventListener) Assert(org.junit.Assert) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) WonMessage(won.protocol.message.WonMessage) EventBus(won.bot.framework.eventbot.bus.EventBus) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomContent(won.utils.content.model.AtomContent) URI(java.net.URI) Test(org.junit.Test)

Example 50 with EventListener

use of won.bot.framework.eventbot.listener.EventListener in project webofneeds by researchstudio-sat.

the class AclTests method testAtomWithoutACL_fallbackToLegacyImpl.

@Test(timeout = 60 * 1000)
public void testAtomWithoutACL_fallbackToLegacyImpl() throws Exception {
    runTest(ctx -> {
        EventBus bus = ctx.getEventBus();
        final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
        final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
        final String atomUriString = atomUri.toString();
        final AtomContent atomContent = AtomContent.builder(atomUri).addTitle("Unit Test Atom ACL Test 2").addSocket(Socket.builder(atomUri.toString() + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
        WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).build();
        createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
        ctx.getBotContextWrapper().rememberAtomUri(atomUri);
        final String action = "Create Atom action";
        EventListener successCallback = event -> {
            ((CachingLinkedDataSource) ctx.getLinkedDataSource()).clear();
            URI connContainerUri = uriService.createConnectionContainerURIForAtom(atomUri);
            URI createMessageUri = ((SuccessResponseEvent) event).getOriginalMessageURI();
            boolean passed = true;
            passed = passed && testLinkedDataRequestOk(ctx, bus, "test1.", atomUri, atomUri, createMessageUri);
            passed = passed && testLinkedDataRequestOk_emptyDataset(ctx, bus, "test2.", atomUri, connContainerUri);
            passed = passed && testLinkedDataRequestOkNoWebId(ctx, bus, "test3.", atomUri);
            passed = passed && testLinkedDataRequestOkNoWebId_emptyDataset(ctx, bus, "test4.", connContainerUri);
            passed = passed && testLinkedDataRequestFailsNoWebId(ctx, bus, "test5.", LinkedDataFetchingException.class, createMessageUri);
            if (passed) {
                passTest(bus);
            }
        };
        EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
        EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
        ctx.getWonMessageSender().sendMessage(createMessage);
    });
}
Also used : EventBotAction(won.bot.framework.eventbot.action.EventBotAction) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) LoggerFactory(org.slf4j.LoggerFactory) won.auth.model(won.auth.model) EventBus(won.bot.framework.eventbot.bus.EventBus) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) BehaviourBarrier(won.bot.framework.eventbot.behaviour.BehaviourBarrier) ContentUtils(won.utils.content.ContentUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) WonMessage(won.protocol.message.WonMessage) HashSet(java.util.HashSet) WonMessageBuilder(won.protocol.message.builder.WonMessageBuilder) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Individuals(won.auth.model.Individuals) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) Socket(won.utils.content.model.Socket) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) MethodHandles(java.lang.invoke.MethodHandles) RdfOutput(won.utils.content.model.RdfOutput) Set(java.util.Set) Test(org.junit.Test) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) EventBotActionUtils(won.bot.framework.eventbot.action.EventBotActionUtils) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) AtomContent(won.utils.content.model.AtomContent) AuthEnabledLinkedDataSource(won.auth.linkeddata.AuthEnabledLinkedDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) Event(won.bot.framework.eventbot.event.Event) won.protocol.vocabulary(won.protocol.vocabulary) Optional(java.util.Optional) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventListener(won.bot.framework.eventbot.listener.EventListener) Assert(org.junit.Assert) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) WonMessage(won.protocol.message.WonMessage) LinkedDataFetchingException(won.protocol.rest.LinkedDataFetchingException) EventBus(won.bot.framework.eventbot.bus.EventBus) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomContent(won.utils.content.model.AtomContent) URI(java.net.URI) Test(org.junit.Test)

Aggregations

EventListener (won.bot.framework.eventbot.listener.EventListener)57 Event (won.bot.framework.eventbot.event.Event)54 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)41 URI (java.net.URI)37 EventBus (won.bot.framework.eventbot.bus.EventBus)36 Dataset (org.apache.jena.query.Dataset)31 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)31 WonMessage (won.protocol.message.WonMessage)30 ActionOnceAfterNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener)24 MethodHandles (java.lang.invoke.MethodHandles)23 Logger (org.slf4j.Logger)23 LoggerFactory (org.slf4j.LoggerFactory)23 EventBotActionUtils (won.bot.framework.eventbot.action.EventBotActionUtils)22 WonMessageBuilder (won.protocol.message.builder.WonMessageBuilder)20 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)19 BotBehaviour (won.bot.framework.eventbot.behaviour.BotBehaviour)18 SuccessResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent)18 Optional (java.util.Optional)17 Test (org.junit.Test)17 EventBotAction (won.bot.framework.eventbot.action.EventBotAction)17