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();
}
}
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());
}
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);
}
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")));
}
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")));
}
Aggregations