Search in sources :

Example 11 with BridgeDTO

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

the class ManagerSyncServiceTest method testNotifyBridgeStatusChange.

@Test
public void testNotifyBridgeStatusChange() throws InterruptedException {
    BridgeDTO dto = new BridgeDTO("myId-1", "myName-1", "myEndpoint", "myCustomerId", ManagedResourceStatus.PROVISIONING, TestSupport.KAFKA_CONNECTION_DTO);
    stubBridgeUpdate();
    String expectedJsonUpdate = "{\"id\": \"myId-1\", \"name\": \"myName-1\", \"endpoint\": \"myEndpoint\", \"customerId\": \"myCustomerId\", \"status\": \"provisioning\"}";
    // One update to the manager is expected
    CountDownLatch latch = new CountDownLatch(1);
    addBridgeUpdateRequestListener(latch);
    managerSyncService.notifyBridgeStatusChange(dto).await().atMost(Duration.ofSeconds(5));
    assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
    wireMockServer.verify(putRequestedFor(urlEqualTo(APIConstants.SHARD_API_BASE_PATH)).withRequestBody(equalToJson(expectedJsonUpdate, true, true)).withHeader("Content-Type", equalTo("application/json")));
}
Also used : BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) CountDownLatch(java.util.concurrent.CountDownLatch) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 12 with BridgeDTO

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

the class BridgeIngressServiceTest method testBridgeIngressRedeployment.

@Test
public void testBridgeIngressRedeployment() {
    // Given
    BridgeDTO dto = TestSupport.newProvisioningBridgeDTO();
    String patchedCustomerId = TestSupport.CUSTOMER_ID + "-patched";
    // When
    bridgeIngressService.createBridgeIngress(dto);
    dto.setCustomerId(patchedCustomerId);
    bridgeIngressService.createBridgeIngress(dto);
    // Then
    BridgeIngress bridgeIngress = fetchBridgeIngress(dto);
    assertThat(bridgeIngress).isNotNull();
    assertThat(bridgeIngress.getSpec().getCustomerId()).isEqualTo(patchedCustomerId);
    Secret secret = fetchBridgeIngressSecret(dto);
    assertThat(secret).isNotNull();
    assertThat(secret.getMetadata().getName()).isEqualTo(bridgeIngress.getMetadata().getName());
}
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 13 with BridgeDTO

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

the class BridgeIngressServiceTest method testBridgeIngressDeletionRemovesAllLinkedResource.

@Test
@Disabled("Delete loop in BridgeIngressController does not get called. Bug in the SDK? https://issues.redhat.com/browse/MGDOBR-128")
public void testBridgeIngressDeletionRemovesAllLinkedResource() {
    // Given
    BridgeDTO dto = TestSupport.newProvisioningBridgeDTO();
    // When
    bridgeIngressService.createBridgeIngress(dto);
    Awaitility.await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        Deployment deployment = fetchBridgeIngressDeployment(dto);
        assertThat(deployment).isNotNull();
    });
    bridgeIngressService.deleteBridgeIngress(dto);
    // Then
    Awaitility.await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(5)).untilAsserted(() -> {
        Deployment deployment = fetchBridgeIngressDeployment(dto);
        assertThat(deployment).isNull();
    });
}
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) Disabled(org.junit.jupiter.api.Disabled)

Example 14 with BridgeDTO

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

the class ShardBridgesSyncAPITest method getProcessorsWithSendToBridgeAction.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void getProcessorsWithSendToBridgeAction() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    String bridgeId = bridgeResponse.getId();
    BridgeDTO bridge = new BridgeDTO(bridgeId, bridgeResponse.getName(), TEST_BRIDGE_ENDPOINT, TestConstants.DEFAULT_CUSTOMER_ID, ManagedResourceStatus.READY, new KafkaConnectionDTO());
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    BaseAction action = TestUtils.createSendToBridgeAction(bridgeId);
    TestUtils.updateBridge(bridge);
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(TestConstants.DEFAULT_PROCESSOR_NAME, filters, null, action));
    List<ProcessorDTO> processors = TestUtils.getProcessorsToDeployOrDelete().as(new TypeRef<List<ProcessorDTO>>() {
    });
    assertThat(processors.size()).isEqualTo(1);
    ProcessorDTO processor = processors.get(0);
    assertThat(processor.getName()).isEqualTo(TestConstants.DEFAULT_PROCESSOR_NAME);
    assertThat(processor.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
    assertThat(processor.getDefinition().getFilters().size()).isEqualTo(1);
    assertThat(processor.getDefinition().getRequestedAction()).isNotNull();
    assertThat(processor.getDefinition().getRequestedAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
    assertThat(processor.getDefinition().getRequestedAction().getParameters()).containsEntry(SendToBridgeAction.BRIDGE_ID_PARAM, bridgeId);
    assertThat(processor.getDefinition().getResolvedAction()).isNotNull();
    assertThat(processor.getDefinition().getResolvedAction().getType()).isEqualTo(WebhookAction.TYPE);
    assertThat(processor.getDefinition().getResolvedAction().getParameters()).containsEntry(WebhookAction.ENDPOINT_PARAM, TEST_BRIDGE_WEBHOOK);
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) BridgeRequest(com.redhat.service.bridge.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) KafkaConnectionDTO(com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) List(java.util.List) BridgeResponse(com.redhat.service.bridge.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 15 with BridgeDTO

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

the class ShardBridgesSyncAPITest method testUnouthorizedRole.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void testUnouthorizedRole() {
    reset(jwt);
    when(jwt.getClaim(APIConstants.SUBJECT_ATTRIBUTE_CLAIM)).thenReturn("hacker");
    TestUtils.getBridgesToDeployOrDelete().then().statusCode(403);
    TestUtils.getProcessorsToDeployOrDelete().then().statusCode(403);
    TestUtils.updateBridge(new BridgeDTO()).then().statusCode(403);
    TestUtils.updateProcessor(new ProcessorDTO()).then().statusCode(403);
}
Also used : BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) TestSecurity(io.quarkus.test.security.TestSecurity) 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