Search in sources :

Example 11 with ProcessorResponse

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

the class ProcessorServiceTest method testUpdateProcessorWithFilter.

@ParameterizedTest
@MethodSource("updateProcessorParams")
void testUpdateProcessorWithFilter(ProcessorRequest request) {
    Processor existingProcessor = createReadyProcessorFromRequest(request);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(existingProcessor);
    Set<BaseFilter> updatedFilters = Collections.singleton(new StringEquals("key", "value"));
    request.setFilters(updatedFilters);
    Processor updatedProcessor = processorService.updateProcessor(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID, request);
    ProcessorResponse updatedResponse = processorService.toResponse(updatedProcessor);
    assertThat(updatedResponse.getStatus()).isEqualTo(ACCEPTED);
    assertThat(updatedResponse.getFilters()).hasSize(1);
    BaseFilter updatedFilter = updatedResponse.getFilters().iterator().next();
    assertThat(updatedFilter.getKey()).isEqualTo("key");
    assertThat(updatedFilter.getValue()).isEqualTo("value");
    assertThat(updatedResponse.getTransformationTemplate()).isNull();
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with ProcessorResponse

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

the class ProcessorAPITest method getProcessorWithSendToBridgeAction.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void getProcessorWithSendToBridgeAction() {
    BridgeResponse bridgeResponse = createAndDeployBridge();
    String bridgeId = bridgeResponse.getId();
    Response response = TestUtils.addProcessorToBridge(bridgeId, new ProcessorRequest("myProcessor", TestUtils.createSendToBridgeAction(bridgeId)));
    assertThat(response.getStatusCode()).isEqualTo(202);
    ProcessorResponse pr = response.as(ProcessorResponse.class);
    assertThat(pr.getAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
    assertThat(pr.getAction().getParameter(SendToBridgeAction.BRIDGE_ID_PARAM)).isEqualTo(bridgeId);
    ProcessorResponse found = TestUtils.getProcessor(bridgeId, pr.getId()).as(ProcessorResponse.class);
    assertThat(found.getId()).isEqualTo(pr.getId());
    assertThat(found.getAction().getType()).isEqualTo(SendToBridgeAction.TYPE);
    assertThat(found.getAction().getParameter(SendToBridgeAction.BRIDGE_ID_PARAM)).isEqualTo(bridgeId);
}
Also used : ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ProcessorListResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) Response(io.restassured.response.Response) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) 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 13 with ProcessorResponse

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

the class ProcessorSteps method updateProcessorOfTheBridgeWithBody.

@When("^update the Processor \"([^\"]*)\" of the Bridge \"([^\"]*)\" with body:$")
public void updateProcessorOfTheBridgeWithBody(String processorName, String testBridgeName, String processorRequestJson) {
    BridgeContext bridgeContext = context.getBridge(testBridgeName);
    processorRequestJson = ContextResolver.resolveWithScenarioContext(context, processorRequestJson);
    ProcessorContext processorContext = bridgeContext.getProcessor(processorName);
    JsonObject json = new JsonObject(processorRequestJson);
    String newProcessorName = json.getString("name");
    ProcessorResponse response;
    try (InputStream resourceStream = new ByteArrayInputStream(processorRequestJson.getBytes(StandardCharsets.UTF_8))) {
        response = ProcessorResource.updateProcessor(context.getManagerToken(), bridgeContext.getId(), processorContext.getId(), resourceStream);
    } catch (IOException e) {
        throw new RuntimeException("Error opening inputstream", e);
    }
    bridgeContext.removeProcessor(processorName);
    bridgeContext.newProcessor(newProcessorName, response.getId());
    assertThat(response.getName()).isEqualTo(processorName);
    assertThat(response.getKind()).isEqualTo("Processor");
    assertThat(response.getHref()).isNotNull();
    assertThat(response.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
}
Also used : ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BridgeContext(com.redhat.service.smartevents.integration.tests.context.BridgeContext) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) ProcessorContext(com.redhat.service.smartevents.integration.tests.context.ProcessorContext) When(io.cucumber.java.en.When)

Example 14 with ProcessorResponse

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

the class ProcessorSteps method addProcessorToBridgeWithBody.

@When("^add a Processor to the Bridge \"([^\"]*)\" with body:$")
public void addProcessorToBridgeWithBody(String testBridgeName, String processorRequestJson) {
    BridgeContext bridgeContext = context.getBridge(testBridgeName);
    processorRequestJson = ContextResolver.resolveWithScenarioContext(context, processorRequestJson);
    JsonObject json = new JsonObject(processorRequestJson);
    String processorName = json.getString("name");
    ProcessorResponse response;
    try (InputStream resourceStream = new ByteArrayInputStream(processorRequestJson.getBytes(StandardCharsets.UTF_8))) {
        response = ProcessorResource.createProcessor(context.getManagerToken(), bridgeContext.getId(), resourceStream);
    } catch (IOException e) {
        throw new RuntimeException("Error with inputstream", e);
    }
    bridgeContext.newProcessor(processorName, response.getId());
    assertThat(response.getName()).isEqualTo(processorName);
    assertThat(response.getKind()).isEqualTo("Processor");
    assertThat(response.getHref()).isNotNull();
    assertThat(response.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
}
Also used : ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BridgeContext(com.redhat.service.smartevents.integration.tests.context.BridgeContext) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) When(io.cucumber.java.en.When)

Example 15 with ProcessorResponse

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

the class ProcessorServiceImpl method toResponse.

@Override
public ProcessorResponse toResponse(Processor processor) {
    ProcessorResponse processorResponse = new ProcessorResponse();
    processorResponse.setType(processor.getType());
    processorResponse.setId(processor.getId());
    processorResponse.setName(processor.getName());
    processorResponse.setStatus(processor.getStatus());
    processorResponse.setPublishedAt(processor.getPublishedAt());
    processorResponse.setSubmittedAt(processor.getSubmittedAt());
    processorResponse.setOwner(processor.getOwner());
    if (processor.getDefinition() != null) {
        ProcessorDefinition definition = processor.getDefinition();
        processorResponse.setFilters(definition.getFilters());
        processorResponse.setTransformationTemplate(definition.getTransformationTemplate());
        processorResponse.setAction(definition.getRequestedAction());
        processorResponse.setSource(definition.getRequestedSource());
    }
    if (processor.getBridge() != null) {
        processorResponse.setHref(APIConstants.USER_API_BASE_PATH + processor.getBridge().getId() + "/processors/" + processor.getId());
    }
    return processorResponse;
}
Also used : ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)

Aggregations

ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)27 QuarkusTest (io.quarkus.test.junit.QuarkusTest)22 Test (org.junit.jupiter.api.Test)22 TestSecurity (io.quarkus.test.security.TestSecurity)21 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)20 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)20 ProcessorListResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse)20 Response (io.restassured.response.Response)11 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)7 StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)7 Bridge (com.redhat.service.smartevents.manager.models.Bridge)7 Processor (com.redhat.service.smartevents.manager.models.Processor)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Action (com.redhat.service.smartevents.infra.models.gateways.Action)2 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)2 BridgeContext (com.redhat.service.smartevents.integration.tests.context.BridgeContext)2 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)2 When (io.cucumber.java.en.When)2 JsonObject (io.vertx.core.json.JsonObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2