Search in sources :

Example 46 with Endpoint

use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.

the class BehaviorGroupRepositoryTest method updateAndCheckBehaviorGroupActions.

@Transactional
void updateAndCheckBehaviorGroupActions(String accountId, UUID bundleId, UUID behaviorGroupId, Status expectedResult, UUID... endpointIds) {
    Status status = behaviorGroupRepository.updateBehaviorGroupActions(accountId, behaviorGroupId, Arrays.asList(endpointIds));
    // Is the update result the one we expected?
    assertEquals(expectedResult, status);
    if (expectedResult == Status.OK) {
        // We need to clear the session L1 cache before checking the update result.
        entityManager.clear();
        // If we expected a success, the behavior group actions should match exactly the given endpoint IDs.
        List<BehaviorGroupAction> actions = findBehaviorGroupActions(accountId, bundleId, behaviorGroupId);
        assertEquals(endpointIds.length, actions.size());
        for (int i = 0; i < endpointIds.length; i++) {
            assertEquals(endpointIds[i], actions.get(i).getEndpoint().getId());
        }
    }
}
Also used : Status(javax.ws.rs.core.Response.Status) BehaviorGroupAction(com.redhat.cloud.notifications.models.BehaviorGroupAction) Endpoint(com.redhat.cloud.notifications.models.Endpoint) Transactional(javax.transaction.Transactional)

Example 47 with Endpoint

use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.

the class EndpointRepository method deleteEndpoint.

@Transactional
public boolean deleteEndpoint(String tenant, UUID id) {
    String query = "DELETE FROM Endpoint WHERE accountId = :accountId AND id = :id";
    int rowCount = entityManager.createQuery(query).setParameter("id", id).setParameter("accountId", tenant).executeUpdate();
    return rowCount > 0;
// Actually, the endpoint targeting this should be repeatable
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) Transactional(javax.transaction.Transactional)

Example 48 with Endpoint

use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.

the class EndpointRepository method modifyEndpointStatus.

@Transactional
boolean modifyEndpointStatus(String tenant, UUID id, boolean enabled) {
    String query = "UPDATE Endpoint SET enabled = :enabled WHERE accountId = :accountId AND id = :id";
    int rowCount = entityManager.createQuery(query).setParameter("id", id).setParameter("accountId", tenant).setParameter("enabled", enabled).executeUpdate();
    return rowCount > 0;
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) Transactional(javax.transaction.Transactional)

Example 49 with Endpoint

use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.

the class EndpointRepository method updateEndpoint.

@Transactional
public boolean updateEndpoint(Endpoint endpoint) {
    // TODO Update could fail because the item did not exist, throw 404 in that case?
    // TODO Fix transaction so that we don't end up with half the updates applied
    String endpointQuery = "UPDATE Endpoint SET name = :name, description = :description, enabled = :enabled " + "WHERE accountId = :accountId AND id = :id";
    String webhookQuery = "UPDATE WebhookProperties SET url = :url, method = :method, " + "disableSslVerification = :disableSslVerification, secretToken = :secretToken WHERE endpoint.id = :endpointId";
    String camelQuery = "UPDATE CamelProperties SET url = :url, extras = :extras, " + "basicAuthentication = :basicAuthentication, " + "disableSslVerification = :disableSslVerification, secretToken = :secretToken WHERE endpoint.id = :endpointId";
    if (endpoint.getType() == EndpointType.EMAIL_SUBSCRIPTION) {
        throw new RuntimeException("Unable to update an endpoint of type EMAIL_SUBSCRIPTION");
    }
    int endpointRowCount = entityManager.createQuery(endpointQuery).setParameter("name", endpoint.getName()).setParameter("description", endpoint.getDescription()).setParameter("enabled", endpoint.isEnabled()).setParameter("accountId", endpoint.getAccountId()).setParameter("id", endpoint.getId()).executeUpdate();
    if (endpointRowCount == 0) {
        return false;
    } else if (endpoint.getProperties() == null) {
        return true;
    } else {
        switch(endpoint.getType()) {
            case WEBHOOK:
                WebhookProperties properties = endpoint.getProperties(WebhookProperties.class);
                return entityManager.createQuery(webhookQuery).setParameter("url", properties.getUrl()).setParameter("method", properties.getMethod()).setParameter("disableSslVerification", properties.getDisableSslVerification()).setParameter("secretToken", properties.getSecretToken()).setParameter("endpointId", endpoint.getId()).executeUpdate() > 0;
            case CAMEL:
                CamelProperties cAttr = (CamelProperties) endpoint.getProperties();
                return entityManager.createQuery(camelQuery).setParameter("url", cAttr.getUrl()).setParameter("disableSslVerification", cAttr.getDisableSslVerification()).setParameter("secretToken", cAttr.getSecretToken()).setParameter("endpointId", endpoint.getId()).setParameter("extras", cAttr.getExtras()).setParameter("basicAuthentication", cAttr.getBasicAuthentication()).executeUpdate() > 0;
            default:
                return true;
        }
    }
}
Also used : WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties) CamelProperties(com.redhat.cloud.notifications.models.CamelProperties) Endpoint(com.redhat.cloud.notifications.models.Endpoint) Transactional(javax.transaction.Transactional)

Example 50 with Endpoint

use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.

the class LifecycleITest method addDefaultBehaviorGroupAction.

private void addDefaultBehaviorGroupAction(BehaviorGroup behaviorGroup) {
    EmailSubscriptionProperties properties = new EmailSubscriptionProperties();
    properties.setOnlyAdmins(true);
    Endpoint endpoint = createEndpoint(null, EMAIL_SUBSCRIPTION, "Email endpoint", "System email endpoint", properties);
    addBehaviorGroupAction(behaviorGroup.getId(), endpoint.getId());
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) EmailSubscriptionProperties(com.redhat.cloud.notifications.models.EmailSubscriptionProperties)

Aggregations

Endpoint (com.redhat.cloud.notifications.models.Endpoint)57 Test (org.junit.jupiter.api.Test)23 JsonObject (io.vertx.core.json.JsonObject)22 QuarkusTest (io.quarkus.test.junit.QuarkusTest)20 WebhookProperties (com.redhat.cloud.notifications.models.WebhookProperties)18 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)15 CamelProperties (com.redhat.cloud.notifications.models.CamelProperties)14 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)14 Header (io.restassured.http.Header)13 List (java.util.List)13 Transactional (javax.transaction.Transactional)13 Inject (javax.inject.Inject)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 EndpointType (com.redhat.cloud.notifications.models.EndpointType)10 Collectors (java.util.stream.Collectors)10 EmailSubscriptionProperties (com.redhat.cloud.notifications.models.EmailSubscriptionProperties)9 Event (com.redhat.cloud.notifications.models.Event)9 Response (io.restassured.response.Response)9 Map (java.util.Map)9 UUID (java.util.UUID)9