use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class ConfigurationTest method setup.
@Before
public void setup() {
Map<String, Object> cfg = new HashMap<>();
cfg.put(Constants.Keys.DATABASE_URL_KEY, "https://example.com");
cfg.put(Constants.Keys.API_TOKEN_KEY, "23w4der5f6tg7yh8uj9iko");
cfg.put("txId", "cd729813-e93f-4e0a-9856-dc8e65bdd9df");
cfg.put("workDir", System.getProperty("user.dir"));
ctx = new MockContext(cfg);
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testSelfSignedCertWithPath.
@Test
public void testSelfSignedCertWithPath() throws Exception {
MockContext ctx = new MockContext(buildDbQueryConfig());
UtilsTest.injectVariable(task, "action", "pql");
ctx.setVariable("queryString", "inventory[certname]{ limit 10 }");
ctx.setVariable(Constants.Keys.DATABASE_URL_KEY, httpsRule.baseUrl());
// Self-signed cert will fail unless we provide a cert to trust
try {
task.execute(ctx);
throw new Exception("Task should fail when self-signed cert is used without a provided certificate to trust.");
} catch (SSLHandshakeException expected) {
// that's fine
log.info("hit expected ssl exception. Not a problem");
} catch (Exception e) {
log.error(e.getMessage());
throw e;
}
Map<String, Object> certificate = new HashMap<>();
certificate.put("path", getWiremockCertFile().toString());
ctx.setVariable("certificate", certificate);
// now it should work
task.execute(ctx);
Map result = (Map) ctx.getVariable("result");
assertNotNull(result);
assertTrue((boolean) result.get("ok"));
List data = (List) result.get("data");
assertEquals(10, data.size());
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method test404.
@Test
public void test404() {
stubFor404();
MockContext ctx = new MockContext(buildDbQueryConfig());
UtilsTest.injectVariable(task, "action", "pql");
ctx.setVariable("queryString", "inventory[certname]{ limit 10 }");
try {
task.execute(ctx);
throw new Exception("No exception was thrown in task.");
} catch (ApiException expected) {
assertEquals(404, expected.getCode());
} catch (Exception e) {
fail("404 error should cause API exception");
}
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testMissingAction.
@Test
public void testMissingAction() {
MockContext ctx = new MockContext(buildDbQueryConfig());
try {
UtilsTest.injectVariable(task, "action", null);
task.execute(ctx);
fail("Missing action value should cause exception");
} catch (MissingParameterException expected) {
// ok
assertTrue(expected.getMessage().contains("action"));
} catch (Exception e) {
fail("Unexpected exception: " + e.getMessage());
}
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testIgnoreErrors.
@Test
public void testIgnoreErrors() throws Exception {
MockContext ctx = new MockContext(buildDbQueryConfig());
// Set ignoreErrors = true
UtilsTest.injectVariable(task, "action", "bad_action");
UtilsTest.injectVariable(task, "ignoreErrors", true);
// Normally, this should throw an exception
task.execute(ctx);
// Make sure it failed gracefully and has an error message
Map result = (Map) ctx.getVariable("result");
assertNotNull(result);
assertFalse((Boolean) result.get("ok"));
String error = (String) result.get("error");
assertTrue(error.contains("Not a supported action"));
}
Aggregations