Search in sources :

Example 1 with V4Event

use of com.symphony.api.model.V4Event in project spring-bot by finos.

the class AgentIT method testStreamsV4.

@ParameterizedTest
@MethodSource("setupConfigurations")
public void testStreamsV4(TestClientStrategy s) throws Exception {
    DatafeedApi dfApi = s.getAgentApi(DatafeedApi.class);
    MessagesApi messageAPi = s.getAgentApi(MessagesApi.class);
    Datafeed datafeed = dfApi.v4DatafeedCreatePost(null, null);
    System.out.println("Datafeed ID: " + datafeed.getId());
    Supplier<List<V4Event>> supplier = () -> dfApi.v4DatafeedIdReadGet(datafeed.getId(), null, null, 100);
    final int[] count = { 0 };
    final Worker<V4Event> w = Streams.createWorker(supplier, e -> e.printStackTrace());
    Thread t = new Thread(() -> {
        w.stream().forEach(e -> count[0]++);
    });
    t.setDaemon(true);
    t.start();
    String toSend = "Trigger Listener." + new Random().nextInt();
    messageAPi.v4StreamSidMessageCreatePost(null, ROOM, "<messageML>" + toSend + "</messageML>", null, null, null, null, null);
    // wait for roundtrip
    while (count[0] == 0) {
        Thread.yield();
    }
}
Also used : MessagesApi(com.symphony.api.agent.MessagesApi) Random(java.util.Random) DatafeedApi(com.symphony.api.agent.DatafeedApi) V5EventList(com.symphony.api.model.V5EventList) List(java.util.List) V4Event(com.symphony.api.model.V4Event) V5Datafeed(com.symphony.api.model.V5Datafeed) Datafeed(com.symphony.api.model.Datafeed) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with V4Event

use of com.symphony.api.model.V4Event in project spring-bot by finos.

the class AgentIT method testStreamsV5.

@ParameterizedTest
@MethodSource("setupConfigurations")
public void testStreamsV5(TestClientStrategy s) throws Exception {
    DatafeedApi dfApi = s.getAgentApi(DatafeedApi.class);
    MessagesApi messageAPi = s.getAgentApi(MessagesApi.class);
    // ensure a clean slate
    dfApi.listDatafeed(null, null, "testy").stream().forEach(df -> dfApi.deleteDatafeed(df.getId(), null, null));
    // create the new datafeed
    V5DatafeedCreateBody body = new V5DatafeedCreateBody();
    body.setTag("testy");
    V5Datafeed datafeed = dfApi.createDatafeed(null, null, body);
    System.out.println("Datafeed ID: " + datafeed.getId());
    // should be able to list
    List<V5Datafeed> foundFeeds = dfApi.listDatafeed(null, null, "testy");
    Assertions.assertEquals(1, foundFeeds.size());
    Assertions.assertEquals(datafeed.getId(), foundFeeds.get(0).getId());
    V5Supplier supplier = new V5Supplier(dfApi, datafeed);
    final int[] count = { 0 };
    final Worker<V4Event> w = Streams.createWorker(supplier, e -> e.printStackTrace());
    Thread t = new Thread(() -> {
        w.stream().forEach(e -> count[0]++);
    });
    t.setDaemon(true);
    t.start();
    Thread.sleep(10000);
    String toSend = "Trigger Listener." + new Random().nextInt();
    messageAPi.v4StreamSidMessageCreatePost(null, ROOM, "<messageML>" + toSend + "</messageML>", null, null, null, null, null);
    System.out.println("Wrote message");
    // wait for roundtrip
    while (count[0] == 0) {
        messageAPi.v4StreamSidMessageCreatePost(null, ROOM, "<messageML>" + toSend + "</messageML>", null, null, null, null, null);
        Thread.yield();
    }
    supplier.datafeed = null;
    // try deleting the datafeed
    V2Error error = dfApi.deleteDatafeed(datafeed.getId(), null, null);
    Assertions.assertNull(error);
    // should be able to list
    foundFeeds = dfApi.listDatafeed(null, null, "testy");
    Assertions.assertEquals(0, foundFeeds.size());
}
Also used : V2Error(com.symphony.api.model.V2Error) MessagesApi(com.symphony.api.agent.MessagesApi) DatafeedApi(com.symphony.api.agent.DatafeedApi) V4Event(com.symphony.api.model.V4Event) Random(java.util.Random) V5DatafeedCreateBody(com.symphony.api.model.V5DatafeedCreateBody) V5Datafeed(com.symphony.api.model.V5Datafeed) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with V4Event

use of com.symphony.api.model.V4Event in project spring-bot by finos.

the class RoomWelcomeEventConsumerIT method testUserAdded.

@Test
public void testUserAdded() {
    RoomWelcomeEventConsumer rwec = new RoomWelcomeEventConsumer(messages, users, bot, WELCOME_MESSAGE);
    V4Event event = new V4Event().payload(new V4Payload().userJoinedRoom(new V4UserJoinedRoom().affectedUser(new V4User().displayName("Gordon Bennett")).stream(new V4Stream().streamId(NEW_ROOM_STREAM_ID))));
    rwec.accept(event);
    Mockito.verify(messages, Mockito.times(1)).v4StreamSidMessageCreatePost(Mockito.isNull(), Mockito.matches(Pattern.quote(NEW_ROOM_STREAM_ID)), Mockito.matches(Pattern.quote(WELCOME_MESSAGE)), Mockito.isNotNull(), Mockito.isNull(), Mockito.isNull(), Mockito.isNull(), Mockito.isNull());
    Mockito.clearInvocations(messages);
}
Also used : V4Event(com.symphony.api.model.V4Event) V4UserJoinedRoom(com.symphony.api.model.V4UserJoinedRoom) V4User(com.symphony.api.model.V4User) V4Stream(com.symphony.api.model.V4Stream) V4Payload(com.symphony.api.model.V4Payload) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with V4Event

use of com.symphony.api.model.V4Event in project spring-bot by finos.

the class BotIT method testPressButton.

/**
 * When the user presses a button, we return a response.
 */
@Test
public void testPressButton() {
    V4Event in = new V4Event().initiator(new V4Initiator().user(new V4User().email("rob@example.com").displayName("Rob Example").userId(2438923l))).payload(new V4Payload().symphonyElementsAction(new V4SymphonyElementsAction().formId("koreai-choice").formValues(Collections.singletonMap("action", "some button")).stream(new V4Stream().streamId("ABC123"))));
    getPublicBot().sendToConsumer(in);
    littleSleep();
    wireMockRule.verify(1, WireMock.postRequestedFor(urlPathMatching("/agent/v4/stream/ABC123/message/create")));
}
Also used : V4SymphonyElementsAction(com.symphony.api.model.V4SymphonyElementsAction) V4Initiator(com.symphony.api.model.V4Initiator) V4Event(com.symphony.api.model.V4Event) V4User(com.symphony.api.model.V4User) V4Stream(com.symphony.api.model.V4Stream) V4Payload(com.symphony.api.model.V4Payload) Test(org.junit.jupiter.api.Test)

Example 5 with V4Event

use of com.symphony.api.model.V4Event in project spring-bot by finos.

the class BotIT method testSendMessageRoomWithMention.

@Test
public void testSendMessageRoomWithMention() throws JsonProcessingException {
    Mention m = new Mention();
    m.setId(new ArrayList<>());
    m.getId().add(new UserId("1234"));
    EntityJson ej = new EntityJson();
    ej.put("m1", m);
    String data = symphonyObjectMapper.writeValueAsString(ej);
    V4Event in = new V4Event().initiator(new V4Initiator().user(new V4User().email("rob@example.com").displayName("Rob Example").userId(2438923l))).payload(new V4Payload().messageSent(new V4MessageSent().message(new V4Message().message("<div>hello</div>").stream(new V4Stream().streamId("ABC123").streamType("ROOM")).data(data))));
    getPublicBot().sendToConsumer(in);
    littleSleep();
    wireMockRule.verify(1, WireMock.postRequestedFor(urlPathMatching("/agent/v4/stream/ABC123/message/create")));
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) V4Message(com.symphony.api.model.V4Message) UserId(com.symphony.user.UserId) Mention(com.symphony.user.Mention) V4Initiator(com.symphony.api.model.V4Initiator) V4MessageSent(com.symphony.api.model.V4MessageSent) V4Event(com.symphony.api.model.V4Event) V4User(com.symphony.api.model.V4User) V4Stream(com.symphony.api.model.V4Stream) V4Payload(com.symphony.api.model.V4Payload) Test(org.junit.jupiter.api.Test)

Aggregations

V4Event (com.symphony.api.model.V4Event)12 V4Payload (com.symphony.api.model.V4Payload)9 V4Stream (com.symphony.api.model.V4Stream)9 Test (org.junit.jupiter.api.Test)9 V4User (com.symphony.api.model.V4User)8 V4Initiator (com.symphony.api.model.V4Initiator)7 V4Message (com.symphony.api.model.V4Message)6 V4MessageSent (com.symphony.api.model.V4MessageSent)6 DatafeedApi (com.symphony.api.agent.DatafeedApi)3 MessagesApi (com.symphony.api.agent.MessagesApi)3 V5Datafeed (com.symphony.api.model.V5Datafeed)3 Random (java.util.Random)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 Datafeed (com.symphony.api.model.Datafeed)2 V5EventList (com.symphony.api.model.V5EventList)2 List (java.util.List)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 V2Error (com.symphony.api.model.V2Error)1 V4RoomCreated (com.symphony.api.model.V4RoomCreated)1