From ac2a0107f1a2ac20db20704ac298a44aa4d35a28 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Fri, 22 May 2020 00:46:13 +0900 Subject: [PATCH] Fix code format and tests --- json-logs/samples/api/chat.postMessage.json | 45 +++++++++++++++++ json-logs/samples/api/rtm.start.json | 28 +++++++++++ .../slack/api/rtm/message/PingMessage.java | 11 +++-- .../methods/rtm_Test.java | 48 ++++++++----------- .../com/slack/api/model/event/PongEvent.java | 15 +++--- 5 files changed, 108 insertions(+), 39 deletions(-) diff --git a/json-logs/samples/api/chat.postMessage.json b/json-logs/samples/api/chat.postMessage.json index d9fe3d826..e6a21cd7f 100644 --- a/json-logs/samples/api/chat.postMessage.json +++ b/json-logs/samples/api/chat.postMessage.json @@ -141,6 +141,51 @@ "image_bytes": 12345 } ], + "call_id": "R00000000", + "api_decoration_available": false, + "call": { + "v1": { + "id": "R00000000", + "app_id": "A00000000", + "app_icon_urls": { + "image_32": "https://www.example.com/", + "image_36": "https://www.example.com/", + "image_48": "https://www.example.com/", + "image_64": "https://www.example.com/", + "image_72": "https://www.example.com/", + "image_96": "https://www.example.com/", + "image_128": "https://www.example.com/", + "image_192": "https://www.example.com/", + "image_512": "https://www.example.com/", + "image_1024": "https://www.example.com/", + "image_original": "https://www.example.com/" + }, + "date_start": 12345, + "active_participants": [ + { + "slack_id": "U00000000" + } + ], + "all_participants": [ + { + "slack_id": "U00000000" + } + ], + "display_id": "", + "join_url": "https://www.example.com/", + "name": "", + "created_by": "U00000000", + "date_end": 12345, + "channels": [ + "C00000000" + ], + "is_dm_call": false, + "was_rejected": false, + "was_missed": false, + "was_accepted": false, + "has_ended": false + } + }, "fallback": "", "image_url": "", "image_width": 12345, diff --git a/json-logs/samples/api/rtm.start.json b/json-logs/samples/api/rtm.start.json index 2130ee8bf..271252041 100644 --- a/json-logs/samples/api/rtm.start.json +++ b/json-logs/samples/api/rtm.start.json @@ -668,6 +668,7 @@ "team": "", "user": "", "username": "", + "parent_user_id": "", "text": "", "topic": "", "root": { @@ -713,6 +714,19 @@ "display_as_bot": false, "bot_id": "", "bot_link": "", + "bot_profile": { + "id": "", + "deleted": false, + "name": "", + "updated": 123, + "app_id": "", + "icons": { + "image_36": "", + "image_48": "", + "image_72": "" + }, + "team_id": "" + }, "thread_ts": "", "ts": "", "icons": { @@ -815,6 +829,7 @@ "team": "", "user": "", "username": "", + "parent_user_id": "", "text": "", "topic": "", "root": { @@ -860,6 +875,19 @@ "display_as_bot": false, "bot_id": "", "bot_link": "", + "bot_profile": { + "id": "", + "deleted": false, + "name": "", + "updated": 123, + "app_id": "", + "icons": { + "image_36": "", + "image_48": "", + "image_72": "" + }, + "team_id": "" + }, "thread_ts": "", "ts": "", "icons": { diff --git a/slack-api-client/src/main/java/com/slack/api/rtm/message/PingMessage.java b/slack-api-client/src/main/java/com/slack/api/rtm/message/PingMessage.java index bc5a571f6..c0e2c3c08 100644 --- a/slack-api-client/src/main/java/com/slack/api/rtm/message/PingMessage.java +++ b/slack-api-client/src/main/java/com/slack/api/rtm/message/PingMessage.java @@ -7,15 +7,18 @@ import java.time.Instant; +/** + * https://api.slack.com/rtm#ping_and_pong + */ @Data @Builder @NoArgsConstructor @AllArgsConstructor public class PingMessage implements RTMMessage { - public static final String TYPE_NAME = "ping"; + public static final String TYPE_NAME = "ping"; - private Long id; - private final String type = TYPE_NAME; - private Instant time; + private Long id; + private final String type = TYPE_NAME; + private Instant time; } diff --git a/slack-api-client/src/test/java/test_with_remote_apis/methods/rtm_Test.java b/slack-api-client/src/test/java/test_with_remote_apis/methods/rtm_Test.java index 96ffe7d0a..51d81a4b5 100644 --- a/slack-api-client/src/test/java/test_with_remote_apis/methods/rtm_Test.java +++ b/slack-api-client/src/test/java/test_with_remote_apis/methods/rtm_Test.java @@ -13,16 +13,8 @@ import com.slack.api.model.event.MessageBotEvent; import com.slack.api.model.event.PongEvent; import com.slack.api.model.event.UserTypingEvent; -import com.slack.api.rtm.RTMClient; -import com.slack.api.rtm.RTMEventHandler; -import com.slack.api.rtm.RTMEventsDispatcher; -import com.slack.api.rtm.RTMEventsDispatcherFactory; -import com.slack.api.rtm.RTMMessageHandler; -import com.slack.api.rtm.message.Message; -import com.slack.api.rtm.message.PingMessage; -import com.slack.api.rtm.message.PresenceQuery; -import com.slack.api.rtm.message.PresenceSub; -import com.slack.api.rtm.message.Typing; +import com.slack.api.rtm.*; +import com.slack.api.rtm.message.*; import config.Constants; import config.SlackTestConfig; import lombok.extern.slf4j.Slf4j; @@ -41,10 +33,7 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -314,7 +303,7 @@ public void handle(String message) { @Test - public void givenRTMClient_whenPing_ensureReceivesPong() throws Exception { + public void ping_pong() throws Exception { // given SlackConfig config = new SlackConfig(); @@ -325,36 +314,41 @@ public void givenRTMClient_whenPing_ensureReceivesPong() throws Exception { final Instant now = Instant.now(); final long pingId = now.toEpochMilli(); - class PongReceived { PongEvent event = null; } + class PongReceived { + PongEvent event = null; + } final PongReceived pongReceived = new PongReceived(); RTMEventsDispatcher dispatcher = RTMEventsDispatcherFactory.getInstance(); dispatcher.register(new RTMEventHandler() { - @Override public void handle(PongEvent event) { + @Override + public void handle(PongEvent event) { if (Objects.equals(event.getReplyTo(), pingId)) { - synchronized(pongReceived) { - pongReceived.event = event; - pongReceived.notifyAll(); - } + pongReceived.event = event; + pongReceived.notifyAll(); } } }); try (RTMClient rtm = slack.rtmStart(classicAppBotToken)) { - rtm.connect(); rtm.addMessageHandler(dispatcher.toMessageHandler()); + rtm.connect(); + + Thread.sleep(3000); // when rtm.sendMessage(PingMessage.builder().id(pingId).time(now).build().toJSONString()); // ensure - synchronized(pongReceived) { - pongReceived.wait(5000L); + long millis = 0L; + while (pongReceived.event == null && millis < 30_000L) { + Thread.sleep(1000L); + millis += 1000; } - assertThat(pongReceived.event, notNullValue()); - assertThat(pongReceived.event.getReplyTo(), equalTo(pingId)); - assertThat(pongReceived.event.getTime(), equalTo(now)); } + assertThat(pongReceived.event, notNullValue()); + assertThat(pongReceived.event.getReplyTo(), equalTo(pingId)); + assertThat(pongReceived.event.getTime(), equalTo(now)); } } diff --git a/slack-api-model/src/main/java/com/slack/api/model/event/PongEvent.java b/slack-api-model/src/main/java/com/slack/api/model/event/PongEvent.java index dd2d3048f..ed06000a3 100644 --- a/slack-api-model/src/main/java/com/slack/api/model/event/PongEvent.java +++ b/slack-api-model/src/main/java/com/slack/api/model/event/PongEvent.java @@ -8,14 +8,13 @@ * The pong event is sent in response to a 'ping' message previously sent. The id and * other fields will match that of the ping message. *

- * https://api.slack.com/rtm + * https://api.slack.com/rtm#ping_and_pong */ @Data -public class PongEvent implements Event -{ - public static final String TYPE_NAME = "pong"; - private final String type = TYPE_NAME; +public class PongEvent implements Event { + public static final String TYPE_NAME = "pong"; + private final String type = TYPE_NAME; - private Long replyTo; - private Instant time; -} + private Long replyTo; + private Instant time; +} \ No newline at end of file