use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class EventConsumerTest method testUnknownEventTypeWithoutMessageId.
@Test
void testUnknownEventTypeWithoutMessageId() {
mockGetUnknownEventType();
Action action = buildValidAction();
String payload = serializeAction(action);
inMemoryConnector.source(INGRESS_CHANNEL).send(payload);
micrometerAssertionHelper.awaitAndAssertTimerIncrement(CONSUMED_TIMER_NAME, 1);
assertEquals(1L, registry.timer(CONSUMED_TIMER_NAME, "bundle", action.getBundle(), "application", action.getApplication()).count());
micrometerAssertionHelper.assertCounterIncrement(MESSAGE_ID_MISSING_COUNTER_NAME, 1);
micrometerAssertionHelper.assertCounterIncrement(REJECTED_COUNTER_NAME, 1);
micrometerAssertionHelper.assertCounterIncrement(PROCESSING_EXCEPTION_COUNTER_NAME, 1);
assertNoCounterIncrement(PROCESSING_ERROR_COUNTER_NAME, DUPLICATE_COUNTER_NAME, MESSAGE_ID_VALID_COUNTER_NAME, MESSAGE_ID_INVALID_COUNTER_NAME);
verify(endpointProcessor, never()).process(any(Event.class));
verify(kafkaMessageDeduplicator, times(1)).registerMessageId(null);
}
use of com.redhat.cloud.notifications.ingress.Action in project notifications-backend by RedHatInsights.
the class LifecycleITest method emitMockedIngressAction.
private void emitMockedIngressAction() throws IOException {
Action action = new Action();
action.setAccountId("tenant");
action.setOrgId("org-id");
action.setVersion("v1.0.0");
action.setBundle(BUNDLE_NAME);
action.setApplication(APP_NAME);
action.setEventType(EVENT_TYPE_NAME);
action.setTimestamp(LocalDateTime.now());
action.setContext(new Context.ContextBuilder().build());
action.setRecipients(List.of());
action.setEvents(List.of(new Event.EventBuilder().withMetadata(new Metadata.MetadataBuilder().build()).withPayload(new Payload.PayloadBuilder().build()).build()));
String serializedAction = serializeAction(action);
inMemoryConnector.source("ingress").send(serializedAction);
}
use of com.redhat.cloud.notifications.ingress.Action 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.Action in project notifications-backend by RedHatInsights.
the class EmailTest method testEmailSubscriptionInstant.
@Test
@Disabled
void testEmailSubscriptionInstant() {
mockGetUsers(8);
final String tenant = "instant-email-tenant";
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 = TestHelpers.createPoliciesAction(tenant, bundle, application, "My test machine");
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));
});
NotificationHistory history = historyEntries.get(0);
assertTrue(history.isInvocationResult());
assertEquals(3, bodyRequests.size());
List<JsonObject> emailRequests = emailRequestIsOK(bodyRequests, usernames);
for (int i = 0; i < usernames.length; ++i) {
JsonObject body = emailRequests.get(i);
JsonArray emails = body.getJsonArray("emails");
assertNotNull(emails);
assertEquals(1, emails.size());
JsonObject firstEmail = emails.getJsonObject(0);
JsonArray recipients = firstEmail.getJsonArray("recipients");
assertEquals(1, recipients.size());
assertEquals(usernames[i], recipients.getString(0));
JsonArray bccList = firstEmail.getJsonArray("bccList");
assertEquals(0, bccList.size());
String bodyRequest = body.toString();
assertTrue(bodyRequest.contains(TestHelpers.policyId1), "Body should contain policy id" + TestHelpers.policyId1);
assertTrue(bodyRequest.contains(TestHelpers.policyName1), "Body should contain policy name" + TestHelpers.policyName1);
assertTrue(bodyRequest.contains(TestHelpers.policyId2), "Body should contain policy id" + TestHelpers.policyId2);
assertTrue(bodyRequest.contains(TestHelpers.policyName2), "Body should contain policy name" + TestHelpers.policyName2);
// Display name
assertTrue(bodyRequest.contains("My test machine"), "Body should contain the display_name");
// Formatted date
assertTrue(bodyRequest.contains("03 Aug 2020 15:22 UTC"));
}
} catch (Exception e) {
e.printStackTrace();
fail(e);
} finally {
// Remove expectations
MockServerLifecycleManager.getClient().clear(postReq);
}
clearSubscriptions();
}
use of com.redhat.cloud.notifications.ingress.Action 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;
}
Aggregations