Search in sources :

Example 6 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorTest method testOnEventWithNullTemplate.

@Test
public void testOnEventWithNullTemplate() throws JsonProcessingException {
    Set<BaseFilter> filters = new HashSet<>();
    filters.add(new StringEquals("data.key", "value"));
    BaseAction action = new BaseAction();
    action.setType(KafkaTopicAction.TYPE);
    ProcessorDTO processorDTO = createProcessor(new ProcessorDefinition(filters, null, action));
    Executor executor = new Executor(processorDTO, filterEvaluatorFactory, transformationEvaluatorFactory, actionProviderFactoryMock, meterRegistry);
    CloudEvent cloudEvent = createCloudEvent();
    executor.onEvent(cloudEvent);
    verify(actionProviderFactoryMock).getInvokableActionProvider(KafkaTopicAction.TYPE);
    verify(actionInvokerMock).onEvent(any());
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) CloudEvent(io.cloudevents.CloudEvent) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 7 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method toResponse.

@Test
public void toResponse() {
    Bridge b = Fixtures.createBridge();
    Processor p = Fixtures.createProcessor(b, "foo", ManagedResourceStatus.READY);
    BaseAction action = Fixtures.createKafkaAction();
    ProcessorDefinition definition = new ProcessorDefinition(Collections.emptySet(), "", action);
    p.setDefinition(definitionToJsonNode(definition));
    ProcessorResponse r = processorService.toResponse(p);
    assertThat(r).isNotNull();
    assertThat(r.getHref()).isEqualTo(APIConstants.USER_API_BASE_PATH + b.getId() + "/processors/" + p.getId());
    assertThat(r.getName()).isEqualTo(p.getName());
    assertThat(r.getStatus()).isEqualTo(p.getStatus());
    assertThat(r.getId()).isEqualTo(p.getId());
    assertThat(r.getSubmittedAt()).isEqualTo(p.getSubmittedAt());
    assertThat(r.getPublishedAt()).isEqualTo(p.getPublishedAt());
    assertThat(r.getKind()).isEqualTo("Processor");
    assertThat(r.getTransformationTemplate()).isEmpty();
    assertThat(r.getAction().getType()).isEqualTo(KafkaTopicAction.TYPE);
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorResponse(com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Bridge(com.redhat.service.bridge.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 8 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method createProcessor.

@Test
public void createProcessor() {
    Bridge b = createPersistBridge(ManagedResourceStatus.READY);
    ProcessorRequest r = new ProcessorRequest("My Processor", null, "{}", createKafkaAction());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), r);
    await().atMost(5, SECONDS).untilAsserted(() -> {
        Processor p = processorDAO.findById(processor.getId());
        assertThat(p).isNotNull();
        assertThat(p.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
    });
    assertThat(processor.getBridge().getId()).isEqualTo(b.getId());
    assertThat(processor.getName()).isEqualTo(r.getName());
    assertThat(processor.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
    assertThat(processor.getSubmittedAt()).isNotNull();
    assertThat(processor.getDefinition()).isNotNull();
    ProcessorDefinition definition = jsonNodeToDefinition(processor.getDefinition());
    assertThat(definition.getTransformationTemplate()).isEqualTo("{}");
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) Bridge(com.redhat.service.bridge.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 9 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method toDTO.

@Override
public ProcessorDTO toDTO(Processor processor) {
    ProcessorDefinition definition = processor.getDefinition() != null ? jsonNodeToDefinition(processor.getDefinition()) : null;
    KafkaConnectionDTO kafkaConnectionDTO = new KafkaConnectionDTO(internalKafkaConfigurationProvider.getBootstrapServers(), internalKafkaConfigurationProvider.getClientId(), internalKafkaConfigurationProvider.getClientSecret(), internalKafkaConfigurationProvider.getSecurityProtocol(), bridgesService.getBridgeTopicName(processor.getBridge()));
    return new ProcessorDTO(processor.getId(), processor.getName(), definition, processor.getBridge().getId(), processor.getBridge().getCustomerId(), processor.getStatus(), kafkaConnectionDTO);
}
Also used : KafkaConnectionDTO(com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)

Example 10 with ProcessorDefinition

use of com.redhat.service.bridge.infra.models.processors.ProcessorDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAOTest method createProcessor.

private Processor createProcessor(Bridge bridge, String name) {
    Processor p = new Processor();
    p.setBridge(bridge);
    p.setName(name);
    p.setStatus(ManagedResourceStatus.ACCEPTED);
    p.setSubmittedAt(ZonedDateTime.now());
    p.setPublishedAt(ZonedDateTime.now());
    p.setShardId(TestConstants.SHARD_ID);
    BaseAction a = new BaseAction();
    a.setType(KafkaTopicAction.TYPE);
    Map<String, String> params = new HashMap<>();
    params.put(KafkaTopicAction.TOPIC_PARAM, TestConstants.DEFAULT_KAFKA_TOPIC);
    a.setParameters(params);
    ProcessorDefinition definition = new ProcessorDefinition(Collections.emptySet(), null, a);
    p.setDefinition(mapper.valueToTree(definition));
    processorDAO.persist(p);
    return p;
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) HashMap(java.util.HashMap) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction)

Aggregations

ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)16 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)13 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)10 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)7 Test (org.junit.jupiter.api.Test)7 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Processor (com.redhat.service.bridge.manager.models.Processor)5 CloudEvent (io.cloudevents.CloudEvent)5 Bridge (com.redhat.service.bridge.manager.models.Bridge)3 ProcessorResponse (com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 ActionProvider (com.redhat.service.bridge.actions.ActionProvider)1 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)1 KafkaConnectionDTO (com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO)1 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)1