Search in sources :

Example 11 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WebhookActionInvokerBuilderTest method testInvoker.

@Test
void testInvoker() {
    ProcessorDTO processor = createProcessor();
    ActionInvoker actionInvoker = builder.build(processor, processor.getDefinition().getResolvedAction());
    assertThat(actionInvoker).isNotNull().isInstanceOf(WebhookActionInvoker.class);
    WebhookActionInvoker webhookActionInvoker = (WebhookActionInvoker) actionInvoker;
    assertThat(webhookActionInvoker.getEndpoint()).isEqualTo(TEST_ENDPOINT);
    assertThat(webhookActionInvoker.getWebClient()).isNotNull();
    assertThat(webhookActionInvoker.getOidcClient()).isNull();
    assertThat(webhookActionInvoker.getBasicAuthUsername()).isNull();
    assertThat(webhookActionInvoker.getBasicAuthPassword()).isNull();
}
Also used : ActionInvoker(com.redhat.service.smartevents.processor.actions.ActionInvoker) ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 12 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ManagerSyncServiceTest method testProcessorsAreDeletedWhenNotDeployed.

@Test
public void testProcessorsAreDeletedWhenNotDeployed() throws JsonProcessingException, InterruptedException {
    ProcessorDTO processor = TestSupport.newRequestedProcessorDTO();
    processor.setStatus(ManagedResourceStatus.DEPROVISION);
    stubProcessorsToDeployOrDelete(List.of(processor));
    stubProcessorUpdate();
    String expectedJsonUpdateRequestForDeprovisioning = String.format("{\"id\": \"%s\", \"name\": \"%s\", \"bridgeId\": \"%s\", \"customerId\": \"%s\", \"status\": \"deleting\"}", processor.getId(), processor.getName(), processor.getBridgeId(), processor.getCustomerId());
    String expectedJsonUpdateRequest = String.format("{\"id\": \"%s\", \"name\": \"%s\", \"bridgeId\": \"%s\", \"customerId\": \"%s\", \"status\": \"deleted\"}", processor.getId(), processor.getName(), processor.getBridgeId(), processor.getCustomerId());
    // The BridgeExecutorController does not need to execute if the CRD is not deployed
    CountDownLatch latch = new CountDownLatch(1);
    addProcessorUpdateRequestListener(latch);
    managerSyncService.doProcessors().await().atMost(Duration.ofSeconds(5));
    assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
    assertJsonRequest(expectedJsonUpdateRequestForDeprovisioning, APIConstants.SHARD_API_BASE_PATH + "processors");
    assertJsonRequest(expectedJsonUpdateRequest, APIConstants.SHARD_API_BASE_PATH + "processors");
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) CountDownLatch(java.util.concurrent.CountDownLatch) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 13 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutorServiceTest method testBridgeExecutorCreation.

@Test
public void testBridgeExecutorCreation() {
    // Given
    ProcessorDTO dto = TestSupport.newRequestedProcessorDTO();
    // When
    bridgeExecutorService.createBridgeExecutor(dto);
    // Then
    BridgeExecutor bridgeExecutor = kubernetesClient.resources(BridgeExecutor.class).inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeExecutor.resolveResourceName(dto.getId())).get();
    assertThat(bridgeExecutor).isNotNull();
    assertThat(bridgeExecutor.getSpec().getOwner()).isEqualTo(dto.getOwner());
    Secret secret = fetchBridgeExecutorSecret(dto);
    assertThat(secret).isNotNull();
    assertThat(secret.getMetadata().getName()).isEqualTo(bridgeExecutor.getMetadata().getName());
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_BOOTSTRAP_SERVERS_ENV_VAR)).isNotEmpty();
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_CLIENT_ID_ENV_VAR)).isNotEmpty();
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_CLIENT_SECRET_ENV_VAR)).isNotEmpty();
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_SECURITY_PROTOCOL_ENV_VAR)).isNotEmpty();
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_TOPIC_ENV_VAR)).isNotEmpty();
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_ERROR_STRATEGY_ENV_VAR)).isNotEmpty();
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_ERROR_TOPIC_ENV_VAR)).isNotEmpty();
    assertThat(secret.getData().get(GlobalConfigurationsConstants.KAFKA_GROUP_ID_ENV_VAR)).isNotEmpty();
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) BridgeExecutor(com.redhat.service.smartevents.shard.operator.resources.BridgeExecutor) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 14 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutorServiceTest method testFetchOrCreateBridgeExecutorDeploymentRedeployment.

@Test
public void testFetchOrCreateBridgeExecutorDeploymentRedeployment() {
    // Given
    ProcessorDTO dto = TestSupport.newRequestedProcessorDTO();
    String patchedImage = TestSupport.EXECUTOR_IMAGE + "-patched";
    // When
    bridgeExecutorService.createBridgeExecutor(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 = fetchBridgeExecutorDeployment(dto);
        assertThat(deployment).isNotNull();
    });
    // Patch the deployment and replace
    Deployment deployment = fetchBridgeExecutorDeployment(dto);
    deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(patchedImage);
    kubernetesClient.apps().deployments().inNamespace(deployment.getMetadata().getNamespace()).createOrReplace(deployment);
    // Then
    deployment = bridgeExecutorService.fetchOrCreateBridgeExecutorDeployment(fetchBridgeIngress(dto), fetchBridgeExecutorSecret(dto));
    assertThat(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage()).isEqualTo(TestSupport.EXECUTOR_IMAGE);
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 15 with ProcessorDTO

use of com.redhat.service.smartevents.infra.models.dto.ProcessorDTO in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutorServiceTest method testBridgeExecutorCreationTriggersController.

@Test
public void testBridgeExecutorCreationTriggersController() {
    // Given
    ProcessorDTO dto = TestSupport.newRequestedProcessorDTO();
    // When
    bridgeExecutorService.createBridgeExecutor(dto);
    // Then
    Awaitility.await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        // The deployment is deployed by the controller
        Deployment deployment = kubernetesClient.apps().deployments().inNamespace(customerNamespaceProvider.resolveName(dto.getCustomerId())).withName(BridgeExecutor.resolveResourceName(dto.getId())).get();
        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(Constants.CUSTOMER_ID_CONFIG_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_EXECUTOR_PROCESSOR_DEFINITION_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_EXECUTOR_WEBHOOK_SSO_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_EXECUTOR_WEBHOOK_CLIENT_ID_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
        assertThat(environmentVariables.stream().filter(x -> x.getName().equals(Constants.BRIDGE_EXECUTOR_WEBHOOK_CLIENT_SECRET_ENV_VAR)).findFirst().get().getValue().length()).isGreaterThan(0);
    });
}
Also used : ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) 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)

Aggregations

ProcessorDTO (com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)33 Test (org.junit.jupiter.api.Test)24 QuarkusTest (io.quarkus.test.junit.QuarkusTest)22 BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)5 TestSecurity (io.quarkus.test.security.TestSecurity)5 KafkaConnectionDTO (com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO)4 Action (com.redhat.service.smartevents.infra.models.gateways.Action)4 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)4 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)4 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)4 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)4 ActionInvoker (com.redhat.service.smartevents.processor.actions.ActionInvoker)4 TypeRef (io.restassured.common.mapper.TypeRef)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)3 StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)3 HashMap (java.util.HashMap)3 ItemNotFoundException (com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException)2