use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class BackendManagerTest method setUp.
@Before
public void setUp() throws Exception {
Path tmpDir = Paths.get("/tmp/concord");
if (!Files.exists(tmpDir)) {
Files.createDirectories(tmpDir);
}
dstDir = Files.createTempDirectory(tmpDir, "test");
Context ctx = new MockContext(Collections.singletonMap("workDir", dstDir.toAbsolutePath().toString()));
LockService lockService = mock(LockService.class);
ObjectStorage objectStorage = TerraformTaskTest.createObjectStorage(wireMockRule);
backendManager = new BackendFactoryV1(ctx, lockService, objectStorage);
}
use of com.walmartlabs.concord.sdk.MockContext in project concord by walmartlabs.
the class SmtpTaskTest method testAttachments.
@Test
public void testAttachments() 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());
mailParams.put("attachments", Collections.singletonList(new File(ClassLoader.getSystemResource("attahcment.txt").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(1, messages.length);
MimeMessage msg = messages[0];
assertNotNull(msg.getContent());
assertTrue(msg.getContent() instanceof MimeMultipart);
MimeMultipart mp = (MimeMultipart) msg.getContent();
assertEquals(2, mp.getCount());
assertEquals("Hello, Concord!", mp.getBodyPart(0).getContent());
assertEquals("test-attachment", mp.getBodyPart(1).getContent());
mail.reset();
}
use of com.walmartlabs.concord.sdk.MockContext in project concord by walmartlabs.
the class SlackTaskTest method testMessage.
@Test
@SuppressWarnings("unchecked")
public void testMessage() {
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");
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 testMessageInvalidProxyThrowErrors.
@Test
public void testMessageInvalidProxyThrowErrors() {
Map<String, Object> m = new HashMap<>();
Map<String, Object> slackCfg = new HashMap<>();
slackCfg.put("authToken", TestParams.TEST_API_TOKEN);
slackCfg.put("proxyAddress", TestParams.TEST_INVALID_PROXY_ADDRESS);
slackCfg.put("proxyPort", TestParams.TEST_PROXY_PORT);
m.put("slackCfg", slackCfg);
m.put("channelId", TestParams.TEST_CHANNEL);
m.put("text", "test");
MockContext ctx = new MockContext(m);
SlackTask t = new SlackTask();
try {
t.execute(ctx);
fail("should fail");
} catch (Exception e) {
// expected
}
}
use of com.walmartlabs.concord.sdk.MockContext in project concord by walmartlabs.
the class CustomTaskTest method test.
@Test
public void test() throws Exception {
Map<String, Object> args = new HashMap<>();
args.put("url", "https://jsonplaceholder.typicode.com/todos/1");
MockContext ctx = new MockContext(args);
CustomTask task = new CustomTask();
task.execute(ctx);
Map<String, Object> result = ContextUtils.getMap(ctx, "result", Collections.emptyMap());
assertEquals(true, result.get("ok"));
System.out.println(result.get("data"));
}
Aggregations