Search in sources :

Example 1 with ProcessorDTO

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

the class KafkaTopicActionTest method createProcessorWithActionForTopic.

private ProcessorDTO createProcessorWithActionForTopic(String topicName) {
    BaseAction b = new BaseAction();
    b.setType(KafkaTopicAction.TYPE);
    Map<String, String> params = new HashMap<>();
    params.put(KafkaTopicAction.TOPIC_PARAM, topicName);
    b.setParameters(params);
    ProcessorDTO p = new ProcessorDTO();
    p.setId("myProcessor");
    p.setDefinition(new ProcessorDefinition(null, null, b));
    p.setBridgeId("myBridge");
    return p;
}
Also used : HashMap(java.util.HashMap) 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)

Example 2 with ProcessorDTO

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

the class KafkaTopicActionValidatorTest method isValid.

@Test
public void isValid() {
    ProcessorDTO processor = createProcessorWithActionForTopic("myTopic");
    assertThat(validator.isValid(processor.getDefinition().getResolvedAction()).isValid()).isTrue();
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 3 with ProcessorDTO

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

the class KafkaTopicActionValidatorTest method isValid_noTopicIsNotValid.

@Test
public void isValid_noTopicIsNotValid() {
    ProcessorDTO processor = createProcessorWithActionForTopic("myTopic");
    processor.getDefinition().getResolvedAction().getParameters().remove(KafkaTopicAction.TOPIC_PARAM);
    ValidationResult validationResult = validator.isValid(processor.getDefinition().getResolvedAction());
    assertThat(validationResult.isValid()).isFalse();
    assertThat(validationResult.getMessage()).isEqualTo(KafkaTopicActionValidator.INVALID_TOPIC_PARAM_MESSAGE);
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ValidationResult(com.redhat.service.bridge.actions.ValidationResult) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 4 with ProcessorDTO

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

the class KafkaTopicInvokerTest method onEvent.

@Test
public void onEvent() {
    ArgumentCaptor<Message<String>> captor = ArgumentCaptor.forClass(Message.class);
    Emitter<String> emitter = mock(Emitter.class);
    String event = "{\"key\": \"value\"}";
    String topic = "myTestTopic";
    ProcessorDTO processor = createProcessor();
    KafkaTopicInvoker invoker = new KafkaTopicInvoker(emitter, processor, topic);
    invoker.onEvent(event);
    verify(emitter).send(captor.capture());
    Message<String> sent = captor.getValue();
    assertThat(sent.getPayload()).isEqualTo(event);
    Metadata metadata = sent.getMetadata();
    OutgoingKafkaRecordMetadata recordMetadata = metadata.get(OutgoingKafkaRecordMetadata.class).get();
    assertThat(recordMetadata.getTopic()).isEqualTo(topic);
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) OutgoingKafkaRecordMetadata(io.smallrye.reactive.messaging.kafka.api.OutgoingKafkaRecordMetadata) Metadata(org.eclipse.microprofile.reactive.messaging.Metadata) OutgoingKafkaRecordMetadata(io.smallrye.reactive.messaging.kafka.api.OutgoingKafkaRecordMetadata) Test(org.junit.jupiter.api.Test)

Example 5 with ProcessorDTO

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

the class WebhookActionTest method testInvokerOk.

@Test
void testInvokerOk() {
    ProcessorDTO processor = createProcessorWithActionForEndpoint("http://www.example.com/webhook");
    ActionInvoker actionInvoker = webhookAction.getActionInvoker(processor, processor.getDefinition().getResolvedAction());
    assertThat(actionInvoker).isNotNull().isInstanceOf(WebhookInvoker.class);
}
Also used : ActionInvoker(com.redhat.service.bridge.actions.ActionInvoker) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)39 Test (org.junit.jupiter.api.Test)28 QuarkusTest (io.quarkus.test.junit.QuarkusTest)21 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)11 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)10 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)8 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)8 BridgeDTO (com.redhat.service.bridge.infra.models.dto.BridgeDTO)6 HashSet (java.util.HashSet)6 KafkaConnectionDTO (com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO)5 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)5 CloudEvent (io.cloudevents.CloudEvent)5 TestSecurity (io.quarkus.test.security.TestSecurity)5 BridgeRequest (com.redhat.service.bridge.manager.api.models.requests.BridgeRequest)4 BridgeResponse (com.redhat.service.bridge.manager.api.models.responses.BridgeResponse)4 HashMap (java.util.HashMap)4 List (java.util.List)4 ActionInvoker (com.redhat.service.bridge.actions.ActionInvoker)2 ValidationResult (com.redhat.service.bridge.actions.ValidationResult)2 ActionProviderException (com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException)2