Search in sources :

Example 1 with Application

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();
}
Also used : ProcessInstances(org.kie.kogito.process.ProcessInstances) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) Process(org.kie.kogito.process.Process) ProcessInstance(org.kie.kogito.process.ProcessInstance) ProcessService(org.kie.kogito.process.ProcessService) Application(org.kie.kogito.Application) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Application

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);
}
Also used : Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 3 with Application

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")));
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) PersonsUnit(org.kie.kogito.codegen.unit.PersonsUnit) AdultUnit(org.kie.kogito.codegen.unit.AdultUnit) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Application

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);
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) AdultUnit(org.kie.kogito.codegen.unit.AdultUnit) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Application

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)));
}
Also used : RuleUnits(org.kie.kogito.rules.RuleUnits) AdultUnit(org.kie.kogito.codegen.unit.AdultUnit) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Application (org.kie.kogito.Application)146 Processes (org.kie.kogito.process.Processes)122 Model (org.kie.kogito.Model)112 Test (org.junit.jupiter.api.Test)109 HashMap (java.util.HashMap)105 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ArrayList (java.util.ArrayList)34 List (java.util.List)34 Person (org.kie.kogito.codegen.data.Person)33 WorkItem (org.kie.kogito.process.WorkItem)26 ProcessConfig (org.kie.kogito.process.ProcessConfig)19 ValueSource (org.junit.jupiter.params.provider.ValueSource)14 UnitOfWork (org.kie.kogito.uow.UnitOfWork)14 Arrays.asList (java.util.Arrays.asList)13 RuleUnits (org.kie.kogito.rules.RuleUnits)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)12 HumanTaskTransition (org.jbpm.process.instance.impl.humantask.HumanTaskTransition)11 AdultUnit (org.kie.kogito.codegen.unit.AdultUnit)11 DataEvent (org.kie.kogito.event.DataEvent)11 ProcessInstanceDataEvent (org.kie.kogito.services.event.ProcessInstanceDataEvent)11