use of com.redhat.cloud.notifications.ingress.Payload in project notifications-backend by RedHatInsights.
the class TestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String policyId, String inventory_id) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
aggregation.setAccountId(tenant);
Action emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType(eventType);
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventory_id).withAdditionalProperty("system_check_in", "2020-08-03T15:22:42.199046").withAdditionalProperty("display_name", "My test machine").withAdditionalProperty("tags", List.of()).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("policy_id", policyId).withAdditionalProperty("policy_name", "not-tested-name").withAdditionalProperty("policy_description", "not-used-desc").withAdditionalProperty("policy_condition", "not-used-condition").build()).build()));
emailActionMessage.setAccountId(tenant);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
use of com.redhat.cloud.notifications.ingress.Payload in project notifications-backend by RedHatInsights.
the class RhosakEmailAggregatorTest method createUpgradeEmailAggregation.
private static EmailAggregation createUpgradeEmailAggregation(String kafkaName, String kafkaVersion) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(APPLICATION_SERVICES);
aggregation.setApplicationName(RHOSAK);
aggregation.setAccountId(ACCOUNT_ID);
Action emailActionMessage = new Action();
emailActionMessage.setBundle(APPLICATION_SERVICES);
emailActionMessage.setApplication(RHOSAK);
emailActionMessage.setTimestamp(NOW);
emailActionMessage.setEventType(SCHEDULED_UPGRADE);
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("kafka_version", kafkaVersion).withAdditionalProperty("upgrade_time", LocalDateTime.now().toString()).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("id", kafkaName).withAdditionalProperty("name", kafkaName).build()).build()));
emailActionMessage.setAccountId(ACCOUNT_ID);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
use of com.redhat.cloud.notifications.ingress.Payload in project notifications-backend by RedHatInsights.
the class WebhookTest method buildWebhookAction.
private static Action buildWebhookAction() {
Action webhookActionMessage = new Action();
webhookActionMessage.setBundle("mybundle");
webhookActionMessage.setApplication("WebhookTest");
webhookActionMessage.setTimestamp(LocalDateTime.of(2020, 10, 3, 15, 22, 13, 25));
webhookActionMessage.setEventType("testWebhook");
webhookActionMessage.setAccountId("tenant");
Payload payload1 = new Payload.PayloadBuilder().withAdditionalProperty("any", "thing").withAdditionalProperty("we", 1).withAdditionalProperty("want", "here").build();
Context context = new Context.ContextBuilder().withAdditionalProperty("free", "more").withAdditionalProperty("format", 1).withAdditionalProperty("here", "stuff").build();
webhookActionMessage.setEvents(List.of(new com.redhat.cloud.notifications.ingress.Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(payload1).build(), new com.redhat.cloud.notifications.ingress.Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().build()).build()));
webhookActionMessage.setContext(context);
return webhookActionMessage;
}
use of com.redhat.cloud.notifications.ingress.Payload in project notifications-backend by RedHatInsights.
the class WebhookTest method testWebhook.
@Test
void testWebhook() {
String url = getMockServerUrl() + "/foobar";
final List<String> bodyRequests = new ArrayList<>();
ExpectationResponseCallback verifyEmptyRequest = req -> {
bodyRequests.add(req.getBodyAsString());
return response().withStatusCode(200);
};
HttpRequest postReq = getMockHttpRequest(verifyEmptyRequest);
Action webhookActionMessage = buildWebhookAction();
Event event = new Event();
event.setAction(webhookActionMessage);
Endpoint ep = buildWebhookEndpoint(url);
try {
List<NotificationHistory> process = webhookTypeProcessor.process(event, List.of(ep));
NotificationHistory history = process.get(0);
assertTrue(history.isInvocationResult());
} catch (Exception e) {
e.printStackTrace();
fail(e);
} finally {
// Remove expectations
MockServerLifecycleManager.getClient().clear(postReq);
}
assertEquals(1, bodyRequests.size());
JsonObject webhookInput = new JsonObject(bodyRequests.get(0));
assertEquals("mybundle", webhookInput.getString("bundle"));
assertEquals("WebhookTest", webhookInput.getString("application"));
assertEquals("testWebhook", webhookInput.getString("event_type"));
assertEquals("tenant", webhookInput.getString("account_id"));
JsonObject webhookInputContext = webhookInput.getJsonObject("context");
assertEquals("more", webhookInputContext.getString("free"));
assertEquals(1, webhookInputContext.getInteger("format"));
assertEquals("stuff", webhookInputContext.getString("here"));
JsonArray webhookInputEvents = webhookInput.getJsonArray("events");
assertEquals(2, webhookInputEvents.size());
JsonObject webhookInputPayload1 = webhookInputEvents.getJsonObject(0).getJsonObject("payload");
assertEquals("thing", webhookInputPayload1.getString("any"));
assertEquals(1, webhookInputPayload1.getInteger("we"));
assertEquals("here", webhookInputPayload1.getString("want"));
}
use of com.redhat.cloud.notifications.ingress.Payload in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method testActionPayloadExtension.
@Test
void testActionPayloadExtension() {
Template template = createTemplate("action-payload-template", "{payload.foo} {payload.bar.baz}");
Payload payload = new Payload.PayloadBuilder().withAdditionalProperty("foo", "im foo").withAdditionalProperty("bar", Map.of("baz", "im baz")).build();
TemplateInstance templateInstance = templateService.compileTemplate(template.getData(), template.getName());
assertEquals("im foo im baz", templateInstance.data("payload", payload).render());
}
Aggregations