Search in sources :

Example 11 with StringEquals

use of com.redhat.service.smartevents.infra.models.filters.StringEquals in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorAPITest method updateProcessorWithFilter.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void updateProcessorWithFilter() {
    Bridge bridge = Fixtures.createBridge();
    bridgeDAO.persist(bridge);
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("key", "value"));
    Response createResponse = TestUtils.addProcessorToBridge(bridge.getId(), new ProcessorRequest("myProcessor", filters, null, TestUtils.createKafkaAction()));
    ProcessorResponse processor = TestUtils.getProcessor(bridge.getId(), createResponse.as(ProcessorResponse.class).getId()).as(ProcessorResponse.class);
    setProcessorAsReady(processor.getId());
    Set<BaseFilter> updatedFilters = Set.of(new StringEquals("key1", "value1"), new StringEquals("key2", "value2"));
    Response response = TestUtils.updateProcessor(bridge.getId(), processor.getId(), new ProcessorRequest(processor.getName(), updatedFilters, processor.getTransformationTemplate(), processor.getAction()));
    assertThat(response.getStatusCode()).isEqualTo(202);
    ProcessorResponse updated = TestUtils.getProcessor(bridge.getId(), createResponse.as(ProcessorResponse.class).getId()).as(ProcessorResponse.class);
    assertThat(updated.getName()).isEqualTo("myProcessor");
    assertThat(updated.getFilters().size()).isEqualTo(2);
    assertThat(updated.getFilters().stream().filter(f -> f.getKey().equals("key1") && f.getValue().equals("value1")).count()).isEqualTo(1);
    assertThat(updated.getFilters().stream().filter(f -> f.getKey().equals("key2") && f.getValue().equals("value2")).count()).isEqualTo(1);
    assertThat(updated.getTransformationTemplate()).isNull();
    assertRequestedAction(updated);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) 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) BeforeEach(org.junit.jupiter.api.BeforeEach) Action(com.redhat.service.smartevents.infra.models.gateways.Action) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BridgeDAO(com.redhat.service.smartevents.manager.dao.BridgeDAO) DatabaseManagerUtils(com.redhat.service.smartevents.manager.utils.DatabaseManagerUtils) SOURCE(com.redhat.service.smartevents.infra.models.processors.ProcessorType.SOURCE) TestUtils(com.redhat.service.smartevents.manager.utils.TestUtils) DEFAULT_USER_NAME(com.redhat.service.smartevents.manager.TestConstants.DEFAULT_USER_NAME) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) Map(java.util.Map) TypeRef(io.restassured.common.mapper.TypeRef) Awaitility.await(org.awaitility.Awaitility.await) Transactional(javax.transaction.Transactional) TestProfile(io.quarkus.test.junit.TestProfile) Set(java.util.Set) Test(org.junit.jupiter.api.Test) APIConstants(com.redhat.service.smartevents.infra.api.APIConstants) List(java.util.List) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) Fixtures(com.redhat.service.smartevents.manager.utils.Fixtures) StringIn(com.redhat.service.smartevents.infra.models.filters.StringIn) ACCEPTED(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus.ACCEPTED) TestSecurity(io.quarkus.test.security.TestSecurity) ProcessorDAO(com.redhat.service.smartevents.manager.dao.ProcessorDAO) READY(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus.READY) TestConstants(com.redhat.service.smartevents.manager.TestConstants) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) HashMap(java.util.HashMap) ProcessorListResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse) ArrayList(java.util.ArrayList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) Processor(com.redhat.service.smartevents.manager.models.Processor) SlackAction(com.redhat.service.smartevents.processor.actions.slack.SlackAction) USER_NAME_ATTRIBUTE_CLAIM(com.redhat.service.smartevents.infra.api.APIConstants.USER_NAME_ATTRIBUTE_CLAIM) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) InjectMock(io.quarkus.test.junit.mockito.InjectMock) Mockito.when(org.mockito.Mockito.when) WorkerSchedulerProfile(com.redhat.service.smartevents.manager.WorkerSchedulerProfile) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Response(io.restassured.response.Response) JsonWebToken(org.eclipse.microprofile.jwt.JsonWebToken) RhoasService(com.redhat.service.smartevents.manager.RhoasService) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) SendToBridgeAction(com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.smartevents.manager.models.Bridge) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 12 with StringEquals

use of com.redhat.service.smartevents.infra.models.filters.StringEquals in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorAPITest method addProcessorToBridge_noActionSpecified.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void addProcessorToBridge_noActionSpecified() {
    BridgeResponse bridgeResponse = createAndDeployBridge();
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    Response response = TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest("myProcessor", filters, null, null));
    assertThat(response.getStatusCode()).isEqualTo(400);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) 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) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 13 with StringEquals

use of com.redhat.service.smartevents.infra.models.filters.StringEquals in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorAPITest method addProcessorToBridgeAndRetrieve.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void addProcessorToBridgeAndRetrieve() {
    BridgeResponse bridgeResponse = createAndDeployBridge();
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    Response response = TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest("myProcessor", filters, null, TestUtils.createKafkaAction()));
    assertThat(response.getStatusCode()).isEqualTo(202);
    ProcessorResponse retrieved = TestUtils.getProcessor(bridgeResponse.getId(), response.as(ProcessorResponse.class).getId()).as(ProcessorResponse.class);
    assertThat(retrieved.getName()).isEqualTo("myProcessor");
    assertThat(retrieved.getFilters().size()).isEqualTo(1);
    assertThat(retrieved.getTransformationTemplate()).isNull();
    assertRequestedAction(retrieved);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) 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) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 14 with StringEquals

use of com.redhat.service.smartevents.infra.models.filters.StringEquals in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method testUpdateProcessorWithNoChange.

@ParameterizedTest
@MethodSource("updateProcessorParams")
void testUpdateProcessorWithNoChange(ProcessorRequest request) {
    Set<BaseFilter> filters = Set.of(new StringBeginsWith("source", List.of("Storage")), new StringContains("source", List.of("StorageService")), new StringEquals("source", "StorageService"), new StringIn("source", List.of("StorageService")));
    request.setFilters(filters);
    Processor existingProcessor = createReadyProcessorFromRequest(request);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(existingProcessor);
    Processor updatedProcessor = processorService.updateProcessor(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID, request);
    assertThat(updatedProcessor.getStatus()).isEqualTo(READY);
    assertThat(updatedProcessor).isEqualTo(existingProcessor);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) Processor(com.redhat.service.smartevents.manager.models.Processor) StringBeginsWith(com.redhat.service.smartevents.infra.models.filters.StringBeginsWith) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) StringIn(com.redhat.service.smartevents.infra.models.filters.StringIn) StringContains(com.redhat.service.smartevents.infra.models.filters.StringContains) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with StringEquals

use of com.redhat.service.smartevents.infra.models.filters.StringEquals in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method getProcessorsWithKafkaAction.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void getProcessorsWithKafkaAction() {
    BridgeResponse bridgeResponse = TestUtils.createBridge(new BridgeRequest(DEFAULT_BRIDGE_NAME)).as(BridgeResponse.class);
    // Emulate the Shard having deployed the Bridge
    BridgeDTO bridge = new BridgeDTO(bridgeResponse.getId(), 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"));
    TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest(DEFAULT_PROCESSOR_NAME, filters, null, 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);
    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(KafkaTopicAction.TYPE);
    assertThat(processor.getDefinition().getRequestedAction().getParameter(KafkaTopicAction.TOPIC_PARAM)).isEqualTo(TestConstants.DEFAULT_KAFKA_TOPIC);
    assertThat(processor.getDefinition().getResolvedAction()).isNotNull();
    assertThat(processor.getDefinition().getResolvedAction().getType()).isEqualTo(KafkaTopicAction.TYPE);
    assertThat(processor.getDefinition().getResolvedAction().getParameter(KafkaTopicAction.TOPIC_PARAM)).isEqualTo(TestConstants.DEFAULT_KAFKA_TOPIC);
}
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) 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) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)15 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)14 Test (org.junit.jupiter.api.Test)12 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)11 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)11 QuarkusTest (io.quarkus.test.junit.QuarkusTest)11 TestSecurity (io.quarkus.test.security.TestSecurity)11 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)10 ProcessorListResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse)9 Response (io.restassured.response.Response)9 Action (com.redhat.service.smartevents.infra.models.gateways.Action)5 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)5 Bridge (com.redhat.service.smartevents.manager.models.Bridge)4 BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)3 ProcessorDTO (com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)3 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)3 Processor (com.redhat.service.smartevents.manager.models.Processor)3 SendToBridgeAction (com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction)3 TypeRef (io.restassured.common.mapper.TypeRef)3 ArrayList (java.util.ArrayList)3