use of com.walmartlabs.concord.sdk.MockContext in project concord by walmartlabs.
the class SlackTaskTest method testJsonMessage.
@Test
@SuppressWarnings("unchecked")
public void testJsonMessage() {
Map<String, Object> m = new HashMap<>();
Map<String, Object> slackCfg = new HashMap<>();
slackCfg.put("authToken", TestParams.TEST_API_TOKEN);
slackCfg.put("proxyAddress", TestParams.TEST_PROXY_ADDRESS);
slackCfg.put("proxyPort", TestParams.TEST_PROXY_PORT);
m.put("slackCfg", slackCfg);
String json = "{\n" + " \"channel\": \"@SLACK_CHANNEL@\",\n" + " \"attachments\": [\n" + " {\n" + " \"mrkdwn_in\": [\n" + " \"text\"\n" + " ],\n" + " \"color\": \"#36a64f\",\n" + " \"author_name\": \"Jason van Zyl\",\n" + " \"author_link\": \"https://github.com/jvanzyl\",\n" + " \"author_icon\": \"https://github.com/jvanzyl.png\",\n" + " \"title\": \"#1234 Add JSON support for Slack messages\",\n" + " \"title_link\": \"https://github.com/jvanzyl/test/commit/44921371d769d85e7ad7665c36a802c2db47aee1\",\n" + " \"text\": \"Modify all the dodos to make JSON slack messages work.\",\n" + " \"fields\": [\n" + " {\n" + " \"title\": \":white_check_mark: *Unit Tests*\"\n" + " },\n" + " {\n" + " \"title\": \":white_check_mark: *Integration Tests*\"\n" + " }\n" + " ],\n" + " \"footer\": \"walmartlabs/concord\",\n" + " \"footer_icon\": \"https://github.com/github.png\",\n" + " \"ts\": \"now\"\n" + " }\n" + " ]\n" + "}";
json = json.replace("@SLACK_CHANNEL@", TestParams.TEST_CHANNEL);
m.put("json", json);
MockContext ctx = new MockContext(m);
SlackTask t = new SlackTask();
t.execute(ctx);
Map<String, Object> result = (Map<String, Object>) ctx.getVariable("result");
assert (boolean) result.get("ok");
}
use of com.walmartlabs.concord.sdk.MockContext in project concord by walmartlabs.
the class SlackTaskTest method testMessageInvalidProxyIgnoreErrors.
@Test
public void testMessageInvalidProxyIgnoreErrors() {
Map<String, Object> m = new HashMap<>();
Map<String, Object> slackCfg = new HashMap<>();
slackCfg.put("authToken", TestParams.TEST_API_TOKEN);
slackCfg.put("proxyAddress", TestParams.TEST_PROXY_ADDRESS);
slackCfg.put("proxyPort", TestParams.TEST_PROXY_PORT);
m.put("slackCfg", slackCfg);
m.put("channelId", TestParams.TEST_CHANNEL);
m.put("text", "test");
m.put("ignoreErrors", true);
MockContext ctx = new MockContext(m);
SlackTask t = new SlackTask();
t.execute(ctx);
}
use of com.walmartlabs.concord.sdk.MockContext in project concord by walmartlabs.
the class SmtpTaskTest method testVariables.
@Test
public void testVariables() throws Exception {
SmtpServer server = mail.getSmtp();
Map<String, Object> smtpParams = new HashMap<>();
smtpParams.put("host", "localhost");
smtpParams.put("port", server.getPort());
Map<String, Object> mailParams = new HashMap<>();
mailParams.put("from", "my@mail.com");
mailParams.put("to", "their@mail.com");
mailParams.put("template", new File(ClassLoader.getSystemResource("test.mustache").toURI()).toString());
Map<String, Object> m = new HashMap<>();
m.put("name", "Concord");
m.put("workDir", "/");
m.put("smtp", smtpParams);
m.put("mail", mailParams);
Context ctx = new MockContext(m);
SmtpTask t = new SmtpTask();
t.execute(ctx);
MimeMessage[] messages = mail.getReceivedMessages();
assertEquals("Hello, Concord!\r\n", messages[0].getContent());
mail.reset();
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class JenkinsTaskTest method testBuildWithParams.
@Test
public void testBuildWithParams() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put("stringParam", "iddqd");
params.put("booleanParam", true);
params.put("choiceParam", "one");
params.put("mlineParam", "multi-line");
params.put("file.txt", "@/tmp/jenkins-file-1");
Map<String, Object> cfg = buildCfg();
cfg.put(Constants.JOB_NAME_KEY, "test-with-params");
cfg.put(Constants.PARAMETERS_KEY, params);
MockContext ctx = new MockContext(cfg);
JenkinsTask task = new JenkinsTask();
task.execute(ctx);
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class JenkinsTaskTest method testSimple.
@Test
public void testSimple() throws Exception {
Map<String, Object> cfg = buildCfg();
cfg.put(Constants.JOB_NAME_KEY, "test");
MockContext ctx = new MockContext(cfg);
JenkinsTask task = new JenkinsTask();
task.execute(ctx);
}
Aggregations