Search in sources :

Example 11 with MockContext

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");
}
Also used : MockContext(com.walmartlabs.concord.sdk.MockContext) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 12 with MockContext

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);
}
Also used : MockContext(com.walmartlabs.concord.sdk.MockContext) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 13 with MockContext

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();
}
Also used : MockContext(com.walmartlabs.concord.sdk.MockContext) Context(com.walmartlabs.concord.sdk.Context) MockContext(com.walmartlabs.concord.sdk.MockContext) SmtpServer(com.icegreen.greenmail.smtp.SmtpServer) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) File(java.io.File) Test(org.junit.jupiter.api.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 14 with MockContext

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);
}
Also used : MockContext(com.walmartlabs.concord.sdk.MockContext) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with MockContext

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);
}
Also used : MockContext(com.walmartlabs.concord.sdk.MockContext) Test(org.junit.Test)

Aggregations

MockContext (com.walmartlabs.concord.sdk.MockContext)25 HashMap (java.util.HashMap)18 Test (org.junit.Test)17 Map (java.util.Map)11 ApiException (com.walmartlabs.concord.plugins.puppet.model.exception.ApiException)8 MissingParameterException (com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException)8 CertificateException (java.security.cert.CertificateException)8 Test (org.junit.jupiter.api.Test)6 List (java.util.List)5 Context (com.walmartlabs.concord.sdk.Context)3 SmtpServer (com.icegreen.greenmail.smtp.SmtpServer)2 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)2 File (java.io.File)2 Path (java.nio.file.Path)2 MimeMessage (javax.mail.internet.MimeMessage)2 Before (org.junit.Before)2 RbacCfg (com.walmartlabs.concord.plugins.puppet.model.cfg.RbacCfg)1 TokenPayload (com.walmartlabs.concord.plugins.puppet.model.token.TokenPayload)1 LockService (com.walmartlabs.concord.sdk.LockService)1 ObjectStorage (com.walmartlabs.concord.sdk.ObjectStorage)1