Search in sources :

Example 1 with Payload

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;
}
Also used : Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 2 with Payload

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();
}
Also used : INSTANT(com.redhat.cloud.notifications.models.EmailSubscriptionType.INSTANT) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) EmailSubscriptionProperties(com.redhat.cloud.notifications.models.EmailSubscriptionProperties) HttpRequest(org.mockserver.model.HttpRequest) Endpoint(com.redhat.cloud.notifications.models.Endpoint) ITUserResponse(com.redhat.cloud.notifications.recipients.itservice.pojo.response.ITUserResponse) LocalDateTime(java.time.LocalDateTime) Disabled(org.junit.jupiter.api.Disabled) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) MockServerLifecycleManager(com.redhat.cloud.notifications.MockServerLifecycleManager) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) InjectSpy(io.quarkus.test.junit.mockito.InjectSpy) ITUserRequest(com.redhat.cloud.notifications.recipients.itservice.pojo.request.ITUserRequest) Event(com.redhat.cloud.notifications.models.Event) JsonObject(io.vertx.core.json.JsonObject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Payload(com.redhat.cloud.notifications.ingress.Payload) Context(com.redhat.cloud.notifications.ingress.Context) InjectMock(io.quarkus.test.junit.mockito.InjectMock) RestClient(org.eclipse.microprofile.rest.client.inject.RestClient) Transactional(javax.transaction.Transactional) ExpectationResponseCallback(org.mockserver.mock.action.ExpectationResponseCallback) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) ITUserService(com.redhat.cloud.notifications.recipients.itservice.ITUserService) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) Mockito(org.mockito.Mockito) List(java.util.List) Authentication(com.redhat.cloud.notifications.recipients.itservice.pojo.response.Authentication) EndpointType(com.redhat.cloud.notifications.models.EndpointType) StatelessSessionFactory(com.redhat.cloud.notifications.db.StatelessSessionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccountRelationship(com.redhat.cloud.notifications.recipients.itservice.pojo.response.AccountRelationship) TestHelpers(com.redhat.cloud.notifications.TestHelpers) Metadata(com.redhat.cloud.notifications.ingress.Metadata) Action(com.redhat.cloud.notifications.ingress.Action) Comparator(java.util.Comparator) HttpResponse.response(org.mockserver.model.HttpResponse.response) PersonalInformation(com.redhat.cloud.notifications.recipients.itservice.pojo.response.PersonalInformation) HttpRequest(org.mockserver.model.HttpRequest) Action(com.redhat.cloud.notifications.ingress.Action) ExpectationResponseCallback(org.mockserver.mock.action.ExpectationResponseCallback) EmailSubscriptionProperties(com.redhat.cloud.notifications.models.EmailSubscriptionProperties) ArrayList(java.util.ArrayList) Endpoint(com.redhat.cloud.notifications.models.Endpoint) NotificationHistory(com.redhat.cloud.notifications.models.NotificationHistory) Event(com.redhat.cloud.notifications.models.Event) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with Payload

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;
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 4 with Payload

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;
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Example 5 with Payload

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;
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Action(com.redhat.cloud.notifications.ingress.Action) Event(com.redhat.cloud.notifications.ingress.Event) JsonObject(io.vertx.core.json.JsonObject) Payload(com.redhat.cloud.notifications.ingress.Payload) EmailAggregation(com.redhat.cloud.notifications.models.EmailAggregation)

Aggregations

Payload (com.redhat.cloud.notifications.ingress.Payload)12 Action (com.redhat.cloud.notifications.ingress.Action)11 JsonObject (io.vertx.core.json.JsonObject)10 Event (com.redhat.cloud.notifications.ingress.Event)8 EmailAggregation (com.redhat.cloud.notifications.models.EmailAggregation)8 Context (com.redhat.cloud.notifications.ingress.Context)6 Event (com.redhat.cloud.notifications.models.Event)3 MockServerLifecycleManager (com.redhat.cloud.notifications.MockServerLifecycleManager)2 Metadata (com.redhat.cloud.notifications.ingress.Metadata)2 Endpoint (com.redhat.cloud.notifications.models.Endpoint)2 EndpointType (com.redhat.cloud.notifications.models.EndpointType)2 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 JsonArray (io.vertx.core.json.JsonArray)2 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Inject (javax.inject.Inject)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2