Repository navigation
Expand file tree
/
Copy pathChatPostMessageTest.java
More file actions
51 lines (41 loc) · 1.61 KB
/
Copy pathChatPostMessageTest.java
File metadata and controls
51 lines (41 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package chat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.slack.api.Slack;
import com.slack.api.SlackConfig;
import com.slack.api.methods.response.chat.ChatPostMessageResponse;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class ChatPostMessageTest {
MockWebServer server;
Slack slack;
@BeforeEach
public void setup() throws Exception {
server = new MockWebServer();
server.start();
SlackConfig config = new SlackConfig();
config.setMethodsEndpointUrlPrefix(server.url("/api/").toString());
slack = Slack.getInstance(config);
}
@AfterEach
public void tearDown() throws Exception {
server.shutdown();
}
@Test
public void sends() throws Exception {
server.enqueue(new MockResponse().setBody("{\"ok\":true}"));
ChatPostMessageResponse response = ChatPostMessage.example01(slack);
assertTrue(response.isOk());
RecordedRequest request = server.takeRequest();
assertEquals("/api/chat.postMessage", request.getPath());
String body = URLDecoder.decode(request.getBody().readUtf8(), StandardCharsets.UTF_8);
assertTrue(body.contains("channel=C123ABC456"));
assertTrue(body.contains("text=Here's a message for you"));
}
}