Skip to content

Commit ac2a010

Browse files
committed
Fix code format and tests
1 parent b8c0cee commit ac2a010

5 files changed

Lines changed: 108 additions & 39 deletions

File tree

json-logs/samples/api/chat.postMessage.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,51 @@
141141
"image_bytes": 12345
142142
}
143143
],
144+
"call_id": "R00000000",
145+
"api_decoration_available": false,
146+
"call": {
147+
"v1": {
148+
"id": "R00000000",
149+
"app_id": "A00000000",
150+
"app_icon_urls": {
151+
"image_32": "https://www.example.com/",
152+
"image_36": "https://www.example.com/",
153+
"image_48": "https://www.example.com/",
154+
"image_64": "https://www.example.com/",
155+
"image_72": "https://www.example.com/",
156+
"image_96": "https://www.example.com/",
157+
"image_128": "https://www.example.com/",
158+
"image_192": "https://www.example.com/",
159+
"image_512": "https://www.example.com/",
160+
"image_1024": "https://www.example.com/",
161+
"image_original": "https://www.example.com/"
162+
},
163+
"date_start": 12345,
164+
"active_participants": [
165+
{
166+
"slack_id": "U00000000"
167+
}
168+
],
169+
"all_participants": [
170+
{
171+
"slack_id": "U00000000"
172+
}
173+
],
174+
"display_id": "",
175+
"join_url": "https://www.example.com/",
176+
"name": "",
177+
"created_by": "U00000000",
178+
"date_end": 12345,
179+
"channels": [
180+
"C00000000"
181+
],
182+
"is_dm_call": false,
183+
"was_rejected": false,
184+
"was_missed": false,
185+
"was_accepted": false,
186+
"has_ended": false
187+
}
188+
},
144189
"fallback": "",
145190
"image_url": "",
146191
"image_width": 12345,

json-logs/samples/api/rtm.start.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@
668668
"team": "",
669669
"user": "",
670670
"username": "",
671+
"parent_user_id": "",
671672
"text": "",
672673
"topic": "",
673674
"root": {
@@ -713,6 +714,19 @@
713714
"display_as_bot": false,
714715
"bot_id": "",
715716
"bot_link": "",
717+
"bot_profile": {
718+
"id": "",
719+
"deleted": false,
720+
"name": "",
721+
"updated": 123,
722+
"app_id": "",
723+
"icons": {
724+
"image_36": "",
725+
"image_48": "",
726+
"image_72": ""
727+
},
728+
"team_id": ""
729+
},
716730
"thread_ts": "",
717731
"ts": "",
718732
"icons": {
@@ -815,6 +829,7 @@
815829
"team": "",
816830
"user": "",
817831
"username": "",
832+
"parent_user_id": "",
818833
"text": "",
819834
"topic": "",
820835
"root": {
@@ -860,6 +875,19 @@
860875
"display_as_bot": false,
861876
"bot_id": "",
862877
"bot_link": "",
878+
"bot_profile": {
879+
"id": "",
880+
"deleted": false,
881+
"name": "",
882+
"updated": 123,
883+
"app_id": "",
884+
"icons": {
885+
"image_36": "",
886+
"image_48": "",
887+
"image_72": ""
888+
},
889+
"team_id": ""
890+
},
863891
"thread_ts": "",
864892
"ts": "",
865893
"icons": {

slack-api-client/src/main/java/com/slack/api/rtm/message/PingMessage.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77

88
import java.time.Instant;
99

10+
/**
11+
* https://api.slack.com/rtm#ping_and_pong
12+
*/
1013
@Data
1114
@Builder
1215
@NoArgsConstructor
1316
@AllArgsConstructor
1417
public class PingMessage implements RTMMessage {
1518

16-
public static final String TYPE_NAME = "ping";
19+
public static final String TYPE_NAME = "ping";
1720

18-
private Long id;
19-
private final String type = TYPE_NAME;
20-
private Instant time;
21+
private Long id;
22+
private final String type = TYPE_NAME;
23+
private Instant time;
2124
}

slack-api-client/src/test/java/test_with_remote_apis/methods/rtm_Test.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,8 @@
1313
import com.slack.api.model.event.MessageBotEvent;
1414
import com.slack.api.model.event.PongEvent;
1515
import com.slack.api.model.event.UserTypingEvent;
16-
import com.slack.api.rtm.RTMClient;
17-
import com.slack.api.rtm.RTMEventHandler;
18-
import com.slack.api.rtm.RTMEventsDispatcher;
19-
import com.slack.api.rtm.RTMEventsDispatcherFactory;
20-
import com.slack.api.rtm.RTMMessageHandler;
21-
import com.slack.api.rtm.message.Message;
22-
import com.slack.api.rtm.message.PingMessage;
23-
import com.slack.api.rtm.message.PresenceQuery;
24-
import com.slack.api.rtm.message.PresenceSub;
25-
import com.slack.api.rtm.message.Typing;
16+
import com.slack.api.rtm.*;
17+
import com.slack.api.rtm.message.*;
2618
import config.Constants;
2719
import config.SlackTestConfig;
2820
import lombok.extern.slf4j.Slf4j;
@@ -41,10 +33,7 @@
4133
import java.util.Objects;
4234
import java.util.concurrent.atomic.AtomicInteger;
4335

44-
import static org.hamcrest.CoreMatchers.equalTo;
45-
import static org.hamcrest.CoreMatchers.is;
46-
import static org.hamcrest.CoreMatchers.notNullValue;
47-
import static org.hamcrest.CoreMatchers.nullValue;
36+
import static org.hamcrest.CoreMatchers.*;
4837
import static org.hamcrest.MatcherAssert.assertThat;
4938
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
5039

@@ -314,7 +303,7 @@ public void handle(String message) {
314303

315304

316305
@Test
317-
public void givenRTMClient_whenPing_ensureReceivesPong() throws Exception {
306+
public void ping_pong() throws Exception {
318307

319308
// given
320309
SlackConfig config = new SlackConfig();
@@ -325,36 +314,41 @@ public void givenRTMClient_whenPing_ensureReceivesPong() throws Exception {
325314
final Instant now = Instant.now();
326315
final long pingId = now.toEpochMilli();
327316

328-
class PongReceived { PongEvent event = null; }
317+
class PongReceived {
318+
PongEvent event = null;
319+
}
329320
final PongReceived pongReceived = new PongReceived();
330321

331322
RTMEventsDispatcher dispatcher = RTMEventsDispatcherFactory.getInstance();
332323
dispatcher.register(new RTMEventHandler<PongEvent>() {
333-
@Override public void handle(PongEvent event) {
324+
@Override
325+
public void handle(PongEvent event) {
334326
if (Objects.equals(event.getReplyTo(), pingId)) {
335-
synchronized(pongReceived) {
336-
pongReceived.event = event;
337-
pongReceived.notifyAll();
338-
}
327+
pongReceived.event = event;
328+
pongReceived.notifyAll();
339329
}
340330
}
341331
});
342332

343333
try (RTMClient rtm = slack.rtmStart(classicAppBotToken)) {
344-
rtm.connect();
345334
rtm.addMessageHandler(dispatcher.toMessageHandler());
335+
rtm.connect();
336+
337+
Thread.sleep(3000);
346338

347339
// when
348340
rtm.sendMessage(PingMessage.builder().id(pingId).time(now).build().toJSONString());
349341

350342
// ensure
351-
synchronized(pongReceived) {
352-
pongReceived.wait(5000L);
343+
long millis = 0L;
344+
while (pongReceived.event == null && millis < 30_000L) {
345+
Thread.sleep(1000L);
346+
millis += 1000;
353347
}
354-
assertThat(pongReceived.event, notNullValue());
355-
assertThat(pongReceived.event.getReplyTo(), equalTo(pingId));
356-
assertThat(pongReceived.event.getTime(), equalTo(now));
357348
}
349+
assertThat(pongReceived.event, notNullValue());
350+
assertThat(pongReceived.event.getReplyTo(), equalTo(pingId));
351+
assertThat(pongReceived.event.getTime(), equalTo(now));
358352

359353
}
360354
}

slack-api-model/src/main/java/com/slack/api/model/event/PongEvent.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
* The pong event is sent in response to a 'ping' message previously sent. The id and
99
* other fields will match that of the ping message.
1010
* <p>
11-
* https://api.slack.com/rtm
11+
* https://api.slack.com/rtm#ping_and_pong
1212
*/
1313
@Data
14-
public class PongEvent implements Event
15-
{
16-
public static final String TYPE_NAME = "pong";
17-
private final String type = TYPE_NAME;
14+
public class PongEvent implements Event {
15+
public static final String TYPE_NAME = "pong";
16+
private final String type = TYPE_NAME;
1817

19-
private Long replyTo;
20-
private Instant time;
21-
}
18+
private Long replyTo;
19+
private Instant time;
20+
}

0 commit comments

Comments
 (0)