|
| 1 | +package com.redhat.cloud.notifications.routers.internal.cleanup; |
| 2 | + |
| 3 | +import com.redhat.cloud.notifications.Constants; |
| 4 | +import com.redhat.cloud.notifications.TestHelpers; |
| 5 | +import com.redhat.cloud.notifications.TestLifecycleManager; |
| 6 | +import com.redhat.cloud.notifications.db.DbIsolatedTest; |
| 7 | +import com.redhat.cloud.notifications.db.ResourceHelpers; |
| 8 | +import com.redhat.cloud.notifications.models.Endpoint; |
| 9 | +import com.redhat.cloud.notifications.models.EndpointType; |
| 10 | +import io.quarkus.test.common.QuarkusTestResource; |
| 11 | +import io.quarkus.test.junit.QuarkusTest; |
| 12 | +import jakarta.inject.Inject; |
| 13 | +import jakarta.persistence.EntityManager; |
| 14 | +import org.eclipse.microprofile.config.inject.ConfigProperty; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +import static io.restassured.RestAssured.given; |
| 19 | +import static io.restassured.http.ContentType.JSON; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 21 | + |
| 22 | +@QuarkusTest |
| 23 | +@QuarkusTestResource(TestLifecycleManager.class) |
| 24 | +class DrawerIntegrationCleanUpResourceTest extends DbIsolatedTest { |
| 25 | + |
| 26 | + @ConfigProperty(name = "internal.admin-role") |
| 27 | + String adminRole; |
| 28 | + |
| 29 | + @Inject |
| 30 | + ResourceHelpers resourceHelpers; |
| 31 | + |
| 32 | + @Inject |
| 33 | + EntityManager entityManager; |
| 34 | + |
| 35 | + @Test |
| 36 | + void testDrawerIntegrationDelete() { |
| 37 | + |
| 38 | + for (int i = 0; i < 15; i++) { |
| 39 | + resourceHelpers.createEndpoint("123456", "123456", EndpointType.DRAWER); |
| 40 | + } |
| 41 | + String query = "SELECT e FROM Endpoint e WHERE e.orgId = :orgId"; |
| 42 | + List<Endpoint> endpoints = entityManager.createQuery(query, Endpoint.class) |
| 43 | + .setParameter("orgId", 123456) |
| 44 | + .getResultList(); |
| 45 | + |
| 46 | + assertEquals(15, endpoints.size()); |
| 47 | + |
| 48 | + given() |
| 49 | + .basePath(Constants.API_INTERNAL) |
| 50 | + .header(TestHelpers.createTurnpikeIdentityHeader("user", this.adminRole)) |
| 51 | + .when() |
| 52 | + .contentType(JSON) |
| 53 | + .body(10) |
| 54 | + .post("/drawer_cleanup") |
| 55 | + .then() |
| 56 | + .statusCode(200); |
| 57 | + |
| 58 | + endpoints = entityManager.createQuery(query, Endpoint.class) |
| 59 | + .setParameter("orgId", 123456) |
| 60 | + .getResultList(); |
| 61 | + assertEquals(5, endpoints.size()); |
| 62 | + |
| 63 | + given() |
| 64 | + .basePath(Constants.API_INTERNAL) |
| 65 | + .header(TestHelpers.createTurnpikeIdentityHeader("user", this.adminRole)) |
| 66 | + .when() |
| 67 | + .contentType(JSON) |
| 68 | + .body(10) |
| 69 | + .post("/drawer_cleanup") |
| 70 | + .then() |
| 71 | + .statusCode(200); |
| 72 | + |
| 73 | + endpoints = entityManager.createQuery(query, Endpoint.class) |
| 74 | + .setParameter("orgId", 123456) |
| 75 | + .getResultList(); |
| 76 | + assertEquals(0, endpoints.size()); |
| 77 | + } |
| 78 | +} |
0 commit comments