Skip to content

Commit

Permalink
Tweak unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Feb 12, 2021
1 parent d902f86 commit 22f36e7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
22 changes: 10 additions & 12 deletions slack-api-client/src/test/java/test_locally/api/audit/ApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
@Slf4j
public class ApiTest {

public static final String ValidToken = "xoxb-this-is-valid";
public static final String InvalidToken = "xoxb-this-is-INVALID";
public static final String ValidToken = "xoxb-this-is-valid-audit-logs";

private static final FileReader reader = new FileReader("../json-logs/samples/audit/v1/");

Expand All @@ -50,11 +49,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
" \"url\": \"https://java-slack-sdk-test.slack.com/\",\n" +
" \"team\": \"java-slack-sdk-test\",\n" +
" \"user\": \"test_user\",\n" +
" \"team_id\": \"T1234567\",\n" +
" \"user_id\": \"U1234567\",\n" +
" \"bot_id\": \"B12345678\",\n" +
" \"team_id\": \"E12345678\",\n" +
" \"enterprise_id\": \"E12345678\",\n" +
" \"error\": \"\"\n" +
" \"is_enterprise_install\": true,\n" +
" \"user_id\": \"U1234567\"\n" +
"}";
resp.setStatus(200);
resp.getWriter().write(body);
Expand Down Expand Up @@ -112,14 +110,14 @@ public void getLogs() throws Exception {
config.setAuditConfig(new AuditConfig());
config.getAuditConfig().setExecutorName("getLogs" + System.currentTimeMillis());
MetricsDatastore datastore = config.getAuditConfig().getMetricsDatastore();
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("logs"), is(nullValue()));

AuditClient audit = Slack.getInstance(config).audit(ValidToken);
LogsResponse response = audit.getLogs(r -> r.action("something"));
assertThat(response.isOk(), is(true));

stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("logs"), is(1L));
}

Expand All @@ -132,13 +130,13 @@ public void getSchemas() throws Exception {
config.setAuditConfig(new AuditConfig());
config.getAuditConfig().setExecutorName("getSchemas" + System.currentTimeMillis());
MetricsDatastore datastore = config.getAuditConfig().getMetricsDatastore();
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("schemas"), is(nullValue()));

AuditClient audit = Slack.getInstance(config).audit(ValidToken);
assertThat(audit.getSchemas().isOk(), is(true));

stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("schemas"), is(1L));
}

Expand All @@ -151,13 +149,13 @@ public void getActions() throws Exception {
config.setAuditConfig(new AuditConfig());
config.getAuditConfig().setExecutorName("getActions" + System.currentTimeMillis());
MetricsDatastore datastore = config.getAuditConfig().getMetricsDatastore();
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("actions"), is(nullValue()));

AuditClient audit = Slack.getInstance(config).audit(ValidToken);
assertThat(audit.getActions().isOk(), is(true));

stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("actions"), is(1L));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
@Slf4j
public class AsyncApiTest {

public static final String ValidToken = "xoxb-this-is-valid";
public static final String InvalidToken = "xoxb-this-is-INVALID";
public static final String ValidToken = "xoxb-this-is-valid-audit-logs";

private static final FileReader reader = new FileReader("../json-logs/samples/audit/v1/");

Expand All @@ -50,11 +49,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
" \"url\": \"https://java-slack-sdk-test.slack.com/\",\n" +
" \"team\": \"java-slack-sdk-test\",\n" +
" \"user\": \"test_user\",\n" +
" \"team_id\": \"T1234567\",\n" +
" \"user_id\": \"U1234567\",\n" +
" \"bot_id\": \"B12345678\",\n" +
" \"team_id\": \"E12345678\",\n" +
" \"enterprise_id\": \"E12345678\",\n" +
" \"error\": \"\"\n" +
" \"is_enterprise_install\": true,\n" +
" \"user_id\": \"U1234567\"\n" +
"}";
resp.setStatus(200);
resp.getWriter().write(body);
Expand Down Expand Up @@ -112,14 +110,14 @@ public void getLogs() throws Exception {
config.setAuditConfig(new AuditConfig());
config.getAuditConfig().setExecutorName("getActions" + System.currentTimeMillis());
MetricsDatastore datastore = config.getAuditConfig().getMetricsDatastore();
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("logs"), is(nullValue()));

AsyncAuditClient audit = Slack.getInstance(config).auditAsync(ValidToken);
LogsResponse response = audit.getLogs(r -> r.action("something")).get();
assertThat(response.isOk(), is(true));

stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("logs"), is(1L));
}

Expand All @@ -132,13 +130,13 @@ public void getSchemas() throws Exception {
config.setAuditConfig(new AuditConfig());
config.getAuditConfig().setExecutorName("getActions" + System.currentTimeMillis());
MetricsDatastore datastore = config.getAuditConfig().getMetricsDatastore();
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("schemas"), is(nullValue()));

AsyncAuditClient audit = Slack.getInstance(config).auditAsync(ValidToken);
assertThat(audit.getSchemas().get().isOk(), is(true));

stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("schemas"), is(1L));
}

Expand All @@ -151,13 +149,13 @@ public void getActions() throws Exception {
config.setAuditConfig(new AuditConfig());
config.getAuditConfig().setExecutorName("getActions" + System.currentTimeMillis());
MetricsDatastore datastore = config.getAuditConfig().getMetricsDatastore();
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
RequestStats stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("actions"), is(nullValue()));

AsyncAuditClient audit = Slack.getInstance(config).auditAsync(ValidToken);
assertThat(audit.getActions().get().isOk(), is(true));

stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "T1234567");
stats = datastore.getStats(config.getAuditConfig().getExecutorName(), "E12345678");
assertThat(stats.getAllCompletedCalls().get("actions"), is(1L));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@

public class ApiTest {

public static final String ValidToken = "xoxb-this-is-valid";
public static final String InvalidToken = "xoxb-this-is-INVALID";
public static final String ValidToken = "xoxb-this-is-valid-scim";

private static final FileReader reader = new FileReader("../json-logs/samples/scim/v1/");

Expand Down Expand Up @@ -68,10 +67,9 @@ private void handle(HttpServletRequest req, HttpServletResponse resp) throws IOE
" \"team\": \"java-slack-sdk-test\",\n" +
" \"user\": \"test_user\",\n" +
" \"team_id\": \"E12345678\",\n" +
" \"user_id\": \"U1234567\",\n" +
" \"bot_id\": \"B12345678\",\n" +
" \"enterprise_id\": \"E12345678\",\n" +
" \"error\": \"\"\n" +
" \"is_enterprise_install\": true,\n" +
" \"user_id\": \"U1234567\"\n" +
"}";
resp.setStatus(200);
resp.getWriter().write(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@

public class AsyncApiTest {

public static final String ValidToken = "xoxb-this-is-valid";
public static final String InvalidToken = "xoxb-this-is-INVALID";
public static final String ValidToken = "xoxb-this-is-valid-scim";

private static final FileReader reader = new FileReader("../json-logs/samples/scim/v1/");

Expand Down Expand Up @@ -69,10 +68,9 @@ private void handle(HttpServletRequest req, HttpServletResponse resp) throws IOE
" \"team\": \"java-slack-sdk-test\",\n" +
" \"user\": \"test_user\",\n" +
" \"team_id\": \"E12345678\",\n" +
" \"user_id\": \"U1234567\",\n" +
" \"bot_id\": \"B12345678\",\n" +
" \"enterprise_id\": \"E12345678\",\n" +
" \"error\": \"\"\n" +
" \"is_enterprise_install\": true,\n" +
" \"user_id\": \"U1234567\"\n" +
"}";
resp.setStatus(200);
resp.getWriter().write(body);
Expand Down

0 comments on commit 22f36e7

Please sign in to comment.