use of org.kie.kogito.Application in project kogito-runtimes by kiegroup.
the class EventImplTest method setup.
@BeforeEach
void setup() {
application = mock(Application.class);
when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
process = mock(Process.class);
processInstances = mock(ProcessInstances.class);
processInstance = mock(ProcessInstance.class);
when(process.instances()).thenReturn(processInstances);
when(processInstances.findById(Mockito.anyString())).thenReturn(Optional.of(processInstance));
when(process.createInstance(Mockito.any(DummyModel.class))).thenReturn(processInstance);
processService = mock(ProcessService.class);
executor = Executors.newSingleThreadExecutor();
}
use of org.kie.kogito.Application in project kogito-runtimes by kiegroup.
the class LightProcessRuntimeTest method testInstantiation.
@Test
void testInstantiation() {
LightProcessRuntimeServiceProvider services = new LightProcessRuntimeServiceProvider();
MyProcess myProcess = new MyProcess();
LightProcessRuntimeContext rtc = new LightProcessRuntimeContext(Collections.singletonList(myProcess.process));
Application application = mock(Application.class);
when(application.get(Processes.class)).thenReturn(mock(Processes.class));
LightProcessRuntime rt = new LightProcessRuntime(rtc, services, application);
rt.startProcess(myProcess.process.getId());
assertEquals("Hello!", myProcess.result);
}
use of org.kie.kogito.Application in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method testRuleUnitExecutor.
@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitExecutor(SessionType sessionType) throws Exception {
Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/RuleUnit.drl", "org/kie/kogito/codegen/unit/PersonsUnit.drl");
DataStore<Person> persons = DataSource.createStore();
persons.add(new Person("Mario", 45));
persons.add(new Person("Marilena", 17));
persons.add(new Person("Sofia", 7));
RuleUnit<AdultUnit> adultUnit = application.get(RuleUnits.class).create(AdultUnit.class);
AdultUnit adultData18 = new AdultUnit(persons, 18);
RuleUnitInstance<AdultUnit> adultUnitInstance18 = adultUnit.createInstance(adultData18, "adult18");
AdultUnit adultData21 = new AdultUnit(persons, 21);
RuleUnitInstance<AdultUnit> adultUnitInstance21 = adultUnit.createInstance(adultData21, "adult21");
RuleUnit<PersonsUnit> personsUnit = application.get(RuleUnits.class).create(PersonsUnit.class);
personsUnit.createInstance(new PersonsUnit(persons)).fire();
assertEquals(2, adultData18.getResults().getResults().size());
assertTrue(adultData18.getResults().getResults().containsAll(asList("Mario", "Marilena")));
assertEquals(1, adultData21.getResults().getResults().size());
assertTrue(adultData21.getResults().getResults().containsAll(asList("Mario")));
}
use of org.kie.kogito.Application in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method testRuleUnitQueryWithNoRules.
@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitQueryWithNoRules(SessionType sessionType) throws Exception {
Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/RuleUnitQueryNoRules.drl");
AdultUnit adults = new AdultUnit();
adults.getPersons().add(new Person("Mario", 45).setAdult(true));
adults.getPersons().add(new Person("Marilena", 47).setAdult(true));
adults.getPersons().add(new Person("Sofia", 7).setAdult(true));
RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
List<Integer> results = instance.executeQuery("FindAdultsAge").stream().map(m -> m.get("$sum")).map(Integer.class::cast).collect(toList());
assertEquals(1, results.size());
assertThat(results).containsExactlyInAnyOrder(99);
}
use of org.kie.kogito.Application in project kogito-runtimes by kiegroup.
the class RuleUnitCompilerIT method testRuleUnitQueryOnPrimitive.
@ParameterizedTest
@EnumSource(SessionType.class)
public void testRuleUnitQueryOnPrimitive(SessionType sessionType) throws Exception {
Application application = createApplication(sessionType, "org/kie/kogito/codegen/unit/RuleUnitQuery.drl");
AdultUnit adults = new AdultUnit();
adults.getPersons().add(new Person("Mario", 45));
adults.getPersons().add(new Person("Marilena", 47));
adults.getPersons().add(new Person("Sofia", 7));
RuleUnit<AdultUnit> unit = application.get(RuleUnits.class).create(AdultUnit.class);
RuleUnitInstance<AdultUnit> instance = unit.createInstance(adults);
List<Integer> results = instance.executeQuery("FindAdultsAge").stream().map(m -> m.get("$age")).map(Integer.class::cast).collect(toList());
assertEquals(2, results.size());
assertTrue(results.containsAll(asList(45, 47)));
}
Aggregations