Search in sources :

Example 1 with DecisionModelResourcesProvider

use of org.kie.kogito.decision.DecisionModelResourcesProvider in project kogito-runtimes by kiegroup.

the class QuarkusModelEventEmitterTest method testEmitEvent.

@Test
public void testEmitEvent() {
    final AssertSubscriber<String> subscriber = AssertSubscriber.create(2);
    final List<DecisionModelResource> models = Arrays.asList(makeModel(), makeModel());
    final DecisionModelResourcesProvider mockedDecisionModelResourcesProvider = () -> models;
    final QuarkusModelEventEmitter eventEmitter = new QuarkusModelEventEmitter(mockedDecisionModelResourcesProvider);
    eventEmitter.getEventPublisher().subscribe(subscriber);
    eventEmitter.publishDecisionModels();
    subscriber.assertNotTerminated();
    List<String> items = subscriber.getItems();
    assertEquals(2, items.size());
    final String rawCloudEvent1 = items.get(0);
    final String rawCloudEvent2 = items.get(1);
    final CloudEvent cloudEvent1 = CloudEventUtils.decode(rawCloudEvent1).orElseThrow(IllegalStateException::new);
    final CloudEvent cloudEvent2 = CloudEventUtils.decode(rawCloudEvent2).orElseThrow(IllegalStateException::new);
    assertEquals("id", cloudEvent1.getId());
    assertEquals("id", cloudEvent2.getId());
}
Also used : DecisionModelResource(org.kie.kogito.decision.DecisionModelResource) DecisionModelResourcesProvider(org.kie.kogito.decision.DecisionModelResourcesProvider) CloudEvent(io.cloudevents.CloudEvent) Test(org.junit.jupiter.api.Test)

Example 2 with DecisionModelResourcesProvider

use of org.kie.kogito.decision.DecisionModelResourcesProvider in project kogito-runtimes by kiegroup.

the class SpringBootModelEventEmitterTest method testEmitEvent.

@Test
public void testEmitEvent() throws JsonProcessingException {
    @SuppressWarnings("unchecked") final KafkaTemplate<String, String> mockedKarkaTemplate = mock(KafkaTemplate.class);
    final List<DecisionModelResource> models = Arrays.asList(makeModel(), makeModel());
    final DecisionModelResourcesProvider mockedDecisionModelResourcesProvider = () -> models;
    final SpringBootModelEventEmitter eventEmitter = new SpringBootModelEventEmitter(mockedDecisionModelResourcesProvider, mockedKarkaTemplate, TEST_TOPIC);
    eventEmitter.publishDecisionModels();
    final ArgumentCaptor<String> topicCaptor = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
    verify(mockedKarkaTemplate, times(2)).send(topicCaptor.capture(), payloadCaptor.capture());
    topicCaptor.getAllValues().forEach(v -> assertEquals(TEST_TOPIC, v));
    final String rawCloudEvent1 = payloadCaptor.getAllValues().get(0);
    final String rawCloudEvent2 = payloadCaptor.getAllValues().get(1);
    final CloudEvent cloudEvent1 = OBJECT_MAPPER.readValue(rawCloudEvent1, CloudEvent.class);
    final CloudEvent cloudEvent2 = OBJECT_MAPPER.readValue(rawCloudEvent2, CloudEvent.class);
    assertEquals("id", cloudEvent1.getId());
    assertEquals("id", cloudEvent2.getId());
}
Also used : DecisionModelResource(org.kie.kogito.decision.DecisionModelResource) DecisionModelResourcesProvider(org.kie.kogito.decision.DecisionModelResourcesProvider) CloudEvent(io.cloudevents.CloudEvent) Test(org.junit.jupiter.api.Test)

Aggregations

CloudEvent (io.cloudevents.CloudEvent)2 Test (org.junit.jupiter.api.Test)2 DecisionModelResource (org.kie.kogito.decision.DecisionModelResource)2 DecisionModelResourcesProvider (org.kie.kogito.decision.DecisionModelResourcesProvider)2