Search in sources :

Example 1 with DecisionModelResource

use of org.kie.kogito.decision.DecisionModelResource 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 DecisionModelResource

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

the class SpringBootModelEventEmitterTest method makeModel.

private DecisionModelResource makeModel() {
    final DecisionModelResource model = mock(DecisionModelResource.class);
    when(model.getGav()).thenReturn(new KogitoGAV("groupId", "artifactId", "version"));
    when(model.getModelName()).thenReturn("name");
    when(model.getNamespace()).thenReturn("namespace");
    when(model.getModelMetadata()).thenReturn(new DecisionModelMetadata("http://www.omg.org/spec/DMN/20151101/dmn.xsd"));
    when(model.get()).thenReturn("model");
    return model;
}
Also used : DecisionModelMetadata(org.kie.kogito.decision.DecisionModelMetadata) DecisionModelResource(org.kie.kogito.decision.DecisionModelResource) KogitoGAV(org.kie.kogito.KogitoGAV)

Example 3 with DecisionModelResource

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

the class DefaultDecisionModelResourceTest method testGetters.

@Test
public void testGetters() {
    final DecisionModelResource resource = new DefaultDecisionModelResource(GAV, "namespace", "name", new DecisionModelMetadata("http://www.omg.org/spec/DMN/20151101/dmn.xsd"), new InputStreamReader(new ByteArrayInputStream(CONTENT.getBytes())));
    assertEquals(GAV, resource.getGav());
    assertEquals("name", resource.getModelName());
    assertEquals("namespace", resource.getNamespace());
    assertEquals(ModelDomain.DECISION, resource.getModelMetadata().getModelDomain());
    assertEquals("http://www.omg.org/spec/DMN/20151101/dmn.xsd", resource.getModelMetadata().getSpecVersion());
}
Also used : DecisionModelMetadata(org.kie.kogito.decision.DecisionModelMetadata) DecisionModelResource(org.kie.kogito.decision.DecisionModelResource) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.jupiter.api.Test)

Example 4 with DecisionModelResource

use of org.kie.kogito.decision.DecisionModelResource 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)

Example 5 with DecisionModelResource

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

the class DefaultDecisionModelResourceTest method testLoad.

@Test
public void testLoad() {
    final DecisionModelResource resource = new DefaultDecisionModelResource(GAV, "namespace", "name", new DecisionModelMetadata("http://www.omg.org/spec/DMN/20151101/dmn.xsd"), new InputStreamReader(new ByteArrayInputStream(CONTENT.getBytes())));
    assertEquals(CONTENT, resource.get().trim());
}
Also used : DecisionModelMetadata(org.kie.kogito.decision.DecisionModelMetadata) DecisionModelResource(org.kie.kogito.decision.DecisionModelResource) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

DecisionModelResource (org.kie.kogito.decision.DecisionModelResource)6 Test (org.junit.jupiter.api.Test)4 DecisionModelMetadata (org.kie.kogito.decision.DecisionModelMetadata)4 CloudEvent (io.cloudevents.CloudEvent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 KogitoGAV (org.kie.kogito.KogitoGAV)2 DecisionModelResourcesProvider (org.kie.kogito.decision.DecisionModelResourcesProvider)2