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());
}
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;
}
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());
}
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());
}
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());
}
Aggregations