Search in sources :

Example 21 with BridgeDTO

use of com.redhat.service.bridge.infra.models.dto.BridgeDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressServiceTest method testFetchOrCreateBridgeIngressDeploymentRedeployment.

@Test
public void testFetchOrCreateBridgeIngressDeploymentRedeployment() {
    // Given
    BridgeDTO dto = TestSupport.newProvisioningBridgeDTO();
    String patchedImage = TestSupport.INGRESS_IMAGE + "-patched";
    // When
    bridgeIngressService.createBridgeIngress(dto);
    // Wait until deployment is created by the controller.
    Awaitility.await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        // The deployment is deployed by the controller
        Deployment deployment = fetchBridgeIngressDeployment(dto);
        assertThat(deployment).isNotNull();
    });
    // Patch the deployment and replace
    Deployment deployment = fetchBridgeIngressDeployment(dto);
    deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(patchedImage);
    kubernetesClient.apps().deployments().inNamespace(deployment.getMetadata().getNamespace()).createOrReplace(deployment);
    // Then
    deployment = bridgeIngressService.fetchOrCreateBridgeIngressDeployment(fetchBridgeIngress(dto), fetchBridgeIngressSecret(dto));
    assertThat(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage()).isEqualTo(TestSupport.INGRESS_IMAGE);
}
Also used : BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 22 with BridgeDTO

use of com.redhat.service.bridge.infra.models.dto.BridgeDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressServiceTest method testBridgeIngressCreationTriggersController.

@Test
public void testBridgeIngressCreationTriggersController() {
    // Given
    BridgeDTO dto = TestSupport.newProvisioningBridgeDTO();
    // When
    bridgeIngressService.createBridgeIngress(dto);
    // Then
    Awaitility.await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        // The deployment is deployed by the controller
        Deployment deployment = fetchBridgeIngressDeployment(dto);
        assertThat(deployment).isNotNull();
        assertThat(deployment.getSpec().getProgressDeadlineSeconds()).isEqualTo(60);
        List<EnvVar> environmentVariables = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(GlobalConfigurationsConstants.SSO_URL_CONFIG_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(GlobalConfigurationsConstants.SSO_CLIENT_ID_CONFIG_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_INGRESS_CUSTOMER_ID_CONFIG_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_INGRESS_WEBHOOK_TECHNICAL_ACCOUNT_ID)).findFirst().get().getValue().length()).isGreaterThan(0);
    });
}
Also used : BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 23 with BridgeDTO

use of com.redhat.service.bridge.infra.models.dto.BridgeDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressServiceTest method testBridgeIngressDeletion.

@Test
public void testBridgeIngressDeletion() {
    // Given
    BridgeDTO dto = TestSupport.newProvisioningBridgeDTO();
    // When
    bridgeIngressService.createBridgeIngress(dto);
    bridgeIngressService.deleteBridgeIngress(dto);
    // Then
    BridgeIngress bridgeIngress = fetchBridgeIngress(dto);
    assertThat(bridgeIngress).isNull();
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 24 with BridgeDTO

use of com.redhat.service.bridge.infra.models.dto.BridgeDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressServiceTest method testBridgeIngressCreation.

@Test
public void testBridgeIngressCreation() {
    // Given
    BridgeDTO dto = TestSupport.newProvisioningBridgeDTO();
    // When
    bridgeIngressService.createBridgeIngress(dto);
    // Then
    BridgeIngress bridgeIngress = fetchBridgeIngress(dto);
    assertThat(bridgeIngress).isNotNull();
    Secret secret = fetchBridgeIngressSecret(dto);
    assertThat(secret).isNotNull();
    assertThat(secret.getMetadata().getName()).isEqualTo(bridgeIngress.getMetadata().getName());
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_BOOTSTRAP_SERVERS_ENV_VAR).length()).isGreaterThan(0);
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_CLIENT_ID_ENV_VAR).length()).isGreaterThan(0);
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_CLIENT_SECRET_ENV_VAR).length()).isGreaterThan(0);
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_SECURITY_PROTOCOL_ENV_VAR).length()).isGreaterThan(0);
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_TOPIC_ENV_VAR).length()).isGreaterThan(0);
}
Also used : BridgeIngress(com.redhat.service.bridge.shard.operator.resources.BridgeIngress) Secret(io.fabric8.kubernetes.api.model.Secret) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 25 with BridgeDTO

use of com.redhat.service.bridge.infra.models.dto.BridgeDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ManagerSyncServiceTest method testBridgesAreDeleted.

@Test
public void testBridgesAreDeleted() throws JsonProcessingException, InterruptedException {
    List<BridgeDTO> bridgeDTOS = new ArrayList<>();
    bridgeDTOS.add(new BridgeDTO("myId-1", "myName-1", "myEndpoint", "myCustomerId", ManagedResourceStatus.DEPROVISION, TestSupport.KAFKA_CONNECTION_DTO));
    bridgeDTOS.add(new BridgeDTO("myId-2", "myName-2", "myEndpoint", "myCustomerId", ManagedResourceStatus.DEPROVISION, TestSupport.KAFKA_CONNECTION_DTO));
    stubBridgesToDeployOrDelete(bridgeDTOS);
    stubBridgeUpdate();
    String expectedJsonUpdateRequest = "{\"id\": \"myId-1\", \"name\": \"myName-1\", \"endpoint\": \"myEndpoint\", \"customerId\": \"myCustomerId\", \"status\": \"deleting\"}";
    // Two updates to the manager are expected
    CountDownLatch latch = new CountDownLatch(2);
    addBridgeUpdateRequestListener(latch);
    managerSyncService.fetchAndProcessBridgesToDeployOrDelete().await().atMost(Duration.ofSeconds(5));
    assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
    wireMockServer.verify(putRequestedFor(urlEqualTo(APIConstants.SHARD_API_BASE_PATH)).withRequestBody(equalToJson(expectedJsonUpdateRequest, true, true)).withHeader("Content-Type", equalTo("application/json")));
}
Also used : BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

BridgeDTO (com.redhat.service.bridge.infra.models.dto.BridgeDTO)29 Test (org.junit.jupiter.api.Test)24 QuarkusTest (io.quarkus.test.junit.QuarkusTest)23 TestSecurity (io.quarkus.test.security.TestSecurity)11 BridgeRequest (com.redhat.service.bridge.manager.api.models.requests.BridgeRequest)10 BridgeResponse (com.redhat.service.bridge.manager.api.models.responses.BridgeResponse)10 KafkaConnectionDTO (com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO)9 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)9 List (java.util.List)9 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)8 BridgeIngress (com.redhat.service.bridge.shard.operator.resources.BridgeIngress)6 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)5 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)5 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)4 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 TypeRef (io.restassured.common.mapper.TypeRef)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 KafkaTopicAction (com.redhat.service.bridge.actions.kafkatopic.KafkaTopicAction)3 WebhookAction (com.redhat.service.bridge.actions.webhook.WebhookAction)3