use of com.redhat.cloud.notifications.ingress.Payload in project notifications-backend by RedHatInsights.
the class TestHelpers method createEmailAggregation.
static EmailAggregation createEmailAggregation(String tenant, String orgId, String bundle, String application, String policyId, String inventoryId) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
aggregation.setAccountId(tenant);
aggregation.setOrgId(orgId);
aggregation.setCreated(LocalDateTime.now(UTC).minusHours(5L));
Action emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType("testEmailSubscriptionInstant");
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventoryId).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 EmailTest method testEmailSubscriptionInstantWrongPayload.
@Test
@Disabled
void testEmailSubscriptionInstantWrongPayload() {
mockGetUsers(8);
final String tenant = "instant-email-tenant-wrong-payload";
final String[] usernames = { "username-1", "username-2", "username-4" };
String bundle = "rhel";
String application = "policies";
for (String username : usernames) {
subscribe(tenant, username, bundle, application);
}
final List<String> bodyRequests = new ArrayList<>();
ExpectationResponseCallback verifyEmptyRequest = req -> {
assertEquals(BOP_TOKEN, req.getHeader(EmailSender.BOP_APITOKEN_HEADER).get(0));
assertEquals(BOP_CLIENT_ID, req.getHeader(EmailSender.BOP_CLIENT_ID_HEADER).get(0));
assertEquals(BOP_ENV, req.getHeader(EmailSender.BOP_ENV_HEADER).get(0));
bodyRequests.add(req.getBodyAsString());
return response().withStatusCode(200);
};
HttpRequest postReq = getMockHttpRequest(verifyEmptyRequest);
Action emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.of(2020, 10, 3, 15, 22, 13, 25));
emailActionMessage.setEventType(TestHelpers.eventType);
emailActionMessage.setRecipients(List.of());
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id-wrong", "host-01").withAdditionalProperty("system_check_in-wrong", "2020-08-03T15:22:42.199046").withAdditionalProperty("display_name-wrong", "My test machine").withAdditionalProperty("tags-what?", List.of()).build());
emailActionMessage.setEvents(List.of(new com.redhat.cloud.notifications.ingress.Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty("foo", "bar").build()).build()));
emailActionMessage.setAccountId(tenant);
Event event = new Event();
event.setAction(emailActionMessage);
EmailSubscriptionProperties properties = new EmailSubscriptionProperties();
Endpoint ep = new Endpoint();
ep.setType(EndpointType.EMAIL_SUBSCRIPTION);
ep.setName("positive feeling");
ep.setDescription("needle in the haystack");
ep.setEnabled(true);
ep.setProperties(properties);
try {
List<NotificationHistory> historyEntries = statelessSessionFactory.withSession(statelessSession -> {
return emailProcessor.process(event, List.of(ep));
});
// The processor returns a null history value but Multi does not support null values so the resulting Multi is empty.
assertTrue(historyEntries.isEmpty());
// No email, invalid payload
assertEquals(0, bodyRequests.size());
} catch (Exception e) {
e.printStackTrace();
fail(e);
} finally {
// Remove expectations
MockServerLifecycleManager.getClient().clear(postReq);
}
clearSubscriptions();
}
use of com.redhat.cloud.notifications.ingress.Payload in project notifications-backend by RedHatInsights.
the class RhosakEmailAggregatorTest method createDisruptionEmailAggregation.
private static EmailAggregation createDisruptionEmailAggregation(String kafkaName, String impactedArea) {
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(DISRUPTION);
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("impacted_area", impactedArea).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 PatchTestHelpers method createEmailAggregation.
public static EmailAggregation createEmailAggregation(String tenant, String bundle, String application, String advisoryName, String advisoryType, 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("new-advisories");
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", inventory_id).build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, advisoryName).withAdditionalProperty(ADVISORY_TYPE, advisoryType).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 PatchTestHelpers method createEmailAggregationMultipleEvents.
public static EmailAggregation createEmailAggregationMultipleEvents(String tenant, String bundle, String application) {
EmailAggregation aggregation = new EmailAggregation();
aggregation.setBundleName(bundle);
aggregation.setApplicationName(application);
aggregation.setAccountId(tenant);
Action emailActionMessage = new Action();
emailActionMessage = new Action();
emailActionMessage.setBundle(bundle);
emailActionMessage.setApplication(application);
emailActionMessage.setTimestamp(LocalDateTime.now());
emailActionMessage.setEventType("new-advisories");
emailActionMessage.setContext(new Context.ContextBuilder().withAdditionalProperty("inventory_id", "inventory_id").build());
emailActionMessage.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, "RH-1").withAdditionalProperty(ADVISORY_TYPE, "ENHANCEMENT").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, "RH-2").withAdditionalProperty(ADVISORY_TYPE, "BUGFIX").build()).build(), new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().withAdditionalProperty(ADVISORY_NAME, "RH-3").withAdditionalProperty(ADVISORY_TYPE, "UNKNOWN").build()).build()));
emailActionMessage.setAccountId(tenant);
JsonObject payload = baseTransformer.transform(emailActionMessage);
aggregation.setPayload(payload);
return aggregation;
}
Aggregations