Search in sources :

Example 6 with BridgeRequest

use of com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method getProcessorsWithSendToBridgeAction.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void getProcessorsWithSendToBridgeAction() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    String bridgeId = bridgeResponse.getId();
    // Emulate the Shard having deployed the Bridge
    BridgeDTO bridge = new BridgeDTO(bridgeId, bridgeResponse.getName(), TEST_BRIDGE_ENDPOINT, DEFAULT_CUSTOMER_ID, DEFAULT_USER_NAME, READY, new KafkaConnectionDTO());
    TestUtils.updateBridge(bridge);
    // Create a Processor for the Bridge
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    Action action = TestUtils.createSendToBridgeAction(bridgeId);
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(DEFAULT_PROCESSOR_NAME, filters, null, action));
    final List<ProcessorDTO> processors = new ArrayList<>();
    await().atMost(5, SECONDS).untilAsserted(() -> {
        processors.clear();
        processors.addAll(TestUtils.getProcessorsToDeployOrDelete().as(new TypeRef<List<ProcessorDTO>>() {
        }));
        assertThat(processors.size()).isEqualTo(1);
    });
    ProcessorDTO processor = processors.get(0);
    assertThat(processor.getName()).isEqualTo(DEFAULT_PROCESSOR_NAME);
    assertThat(processor.getStatus()).isEqualTo(PREPARING);
    assertThat(processor.getDefinition().getFilters().size()).isEqualTo(1);
    assertThat(processor.getDefinition().getRequestedAction()).isNotNull();
    assertThat(processor.getDefinition().getRequestedAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
    assertThat(processor.getDefinition().getRequestedAction().getParameter(SendToBridgeAction.BRIDGE_ID_PARAM)).isEqualTo(bridgeId);
    assertThat(processor.getDefinition().getResolvedAction()).isNotNull();
    assertThat(processor.getDefinition().getResolvedAction().getType()).isEqualTo(WebhookAction.TYPE);
    assertThat(processor.getDefinition().getResolvedAction().getParameter(WebhookAction.ENDPOINT_PARAM)).isEqualTo(TEST_BRIDGE_WEBHOOK);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) Action(com.redhat.service.smartevents.infra.models.gateways.Action) WebhookAction(com.redhat.service.smartevents.processor.actions.webhook.WebhookAction) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) SendToBridgeAction(com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction) KafkaConnectionDTO(com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO) TypeRef(io.restassured.common.mapper.TypeRef) ArrayList(java.util.ArrayList) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 7 with BridgeRequest

use of com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method metricsAreProduced.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void metricsAreProduced() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    BridgeDTO bridge = new BridgeDTO(bridgeResponse.getId(), bridgeResponse.getName(), TEST_BRIDGE_ENDPOINT, DEFAULT_CUSTOMER_ID, DEFAULT_USER_NAME, READY, new KafkaConnectionDTO());
    TestUtils.updateBridge(bridge);
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(DEFAULT_PROCESSOR_NAME, TestUtils.createKafkaAction()));
    final List<ProcessorDTO> processors = new ArrayList<>();
    await().atMost(5, SECONDS).untilAsserted(() -> {
        processors.clear();
        processors.addAll(TestUtils.getProcessorsToDeployOrDelete().as(new TypeRef<List<ProcessorDTO>>() {
        }));
        assertThat(processors.size()).isEqualTo(1);
    });
    ProcessorDTO processor = processors.get(0);
    processor.setStatus(READY);
    TestUtils.updateProcessor(processor);
    String metrics = given().filter(new ResponseLoggingFilter()).contentType(ContentType.JSON).when().get("/q/metrics").then().extract().body().asString();
    metricsService.getMetricNames().forEach(metric -> assertThat(metrics).contains(metric));
}
Also used : BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) KafkaConnectionDTO(com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO) ProcessorDTO(com.redhat.service.smartevents.infra.models.dto.ProcessorDTO) TypeRef(io.restassured.common.mapper.TypeRef) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) ArrayList(java.util.ArrayList) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 8 with BridgeRequest

use of com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncSegmentationAPITest method testShardSegmentation.

/**
 * This test needs to be in a separated class since for the current implementation the ShardService fetches
 * the authorized shards at startup. We inject a mock for this scenario.
 */
@Test
@TestSecurity(user = "knative")
public void testShardSegmentation() {
    // the bridge gets assigned to the default shard
    mockJwt(TestConstants.SHARD_ID);
    TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME));
    final List<BridgeDTO> bridgesToDeployForDefaultShard = new ArrayList<>();
    await().atMost(5, SECONDS).untilAsserted(() -> {
        bridgesToDeployForDefaultShard.clear();
        bridgesToDeployForDefaultShard.addAll(TestUtils.getBridgesToDeployOrDelete().as(new TypeRef<List<BridgeDTO>>() {
        }));
        assertThat(bridgesToDeployForDefaultShard.size()).isEqualTo(1);
    });
    mockJwt("knative");
    // No bridges are assigned to the 'knative' shard
    List<BridgeDTO> bridgesToDeployForOtherShard = new ArrayList<>();
    await().atMost(5, SECONDS).untilAsserted(() -> {
        bridgesToDeployForOtherShard.clear();
        bridgesToDeployForOtherShard.addAll(TestUtils.getBridgesToDeployOrDelete().as(new TypeRef<List<BridgeDTO>>() {
        }));
        assertThat(bridgesToDeployForOtherShard.size()).isEqualTo(0);
    });
}
Also used : BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) TypeRef(io.restassured.common.mapper.TypeRef) ArrayList(java.util.ArrayList) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 9 with BridgeRequest

use of com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesAPITest method getBridgeWithErrorHandler.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void getBridgeWithErrorHandler() {
    Action errorHandler = createWebhookAction();
    Response bridgeCreateResponse = TestUtils.createBridge(new BridgeRequest(DEFAULT_BRIDGE_NAME, errorHandler));
    bridgeCreateResponse.then().statusCode(202);
    BridgeResponse bridge = bridgeCreateResponse.as(BridgeResponse.class);
    BridgeResponse retrievedBridge = TestUtils.getBridge(bridge.getId()).as(BridgeResponse.class);
    assertThat(retrievedBridge).isNotNull();
    assertThat(retrievedBridge.getId()).isEqualTo(bridge.getId());
    assertThat(retrievedBridge.getName()).isEqualTo(bridge.getName());
    assertThat(retrievedBridge.getEndpoint()).isEqualTo(bridge.getEndpoint());
    assertThat(retrievedBridge.getErrorHandler()).isNotNull();
    assertThat(retrievedBridge.getErrorHandler()).isEqualTo(errorHandler);
}
Also used : ErrorResponse(com.redhat.service.smartevents.infra.api.models.responses.ErrorResponse) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) BridgeListResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeListResponse) Response(io.restassured.response.Response) BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) Action(com.redhat.service.smartevents.infra.models.gateways.Action) TestUtils.createWebhookAction(com.redhat.service.smartevents.manager.utils.TestUtils.createWebhookAction) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 10 with BridgeRequest

use of com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesAPITest method testDeleteBridgeWithActiveProcessors.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void testDeleteBridgeWithActiveProcessors() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    TestUtils.updateBridge(new BridgeDTO(bridgeResponse.getId(), bridgeResponse.getName(), bridgeResponse.getEndpoint(), DEFAULT_CUSTOMER_ID, DEFAULT_USER_NAME, READY, new KafkaConnectionDTO()));
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(DEFAULT_PROCESSOR_NAME, TestUtils.createKafkaAction())).then().statusCode(202);
    TestUtils.deleteBridge(bridgeResponse.getId()).then().statusCode(400);
}
Also used : BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) KafkaConnectionDTO(com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)22 QuarkusTest (io.quarkus.test.junit.QuarkusTest)21 Test (org.junit.jupiter.api.Test)21 TestSecurity (io.quarkus.test.security.TestSecurity)14 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)13 BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)10 TypeRef (io.restassured.common.mapper.TypeRef)9 ArrayList (java.util.ArrayList)9 KafkaConnectionDTO (com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO)8 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)8 ProcessorDTO (com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)7 Bridge (com.redhat.service.smartevents.manager.models.Bridge)7 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)5 StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)5 Action (com.redhat.service.smartevents.infra.models.gateways.Action)5 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)4 SendToBridgeAction (com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction)4 WebhookAction (com.redhat.service.smartevents.processor.actions.webhook.WebhookAction)4 ACCOUNT_ID_SERVICE_ACCOUNT_ATTRIBUTE_CLAIM (com.redhat.service.smartevents.infra.api.APIConstants.ACCOUNT_ID_SERVICE_ACCOUNT_ATTRIBUTE_CLAIM)3 ORG_ID_SERVICE_ACCOUNT_ATTRIBUTE_CLAIM (com.redhat.service.smartevents.infra.api.APIConstants.ORG_ID_SERVICE_ACCOUNT_ATTRIBUTE_CLAIM)3