Search in sources :

Example 1 with Processes

use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.

the class ProcessInstanceManagementResourceTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@BeforeEach
public void setup() {
    responseBuilder = mock(ResponseBuilder.class);
    Response response = mock(Response.class);
    when((runtimeDelegate).createResponseBuilder()).thenReturn(responseBuilder);
    lenient().when((responseBuilder).status(any(StatusType.class))).thenReturn(responseBuilder);
    lenient().when((responseBuilder).entity(any())).thenReturn(responseBuilder);
    lenient().when((responseBuilder).build()).thenReturn(response);
    application = mock(Application.class);
    processes = mock(Processes.class);
    AbstractProcess process = mock(AbstractProcess.class);
    ProcessInstances instances = mock(ProcessInstances.class);
    processInstance = mock(ProcessInstance.class);
    error = mock(ProcessError.class);
    lenient().when(processes.processById(anyString())).thenReturn(process);
    lenient().when(process.instances()).thenReturn(instances);
    lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance));
    lenient().when(processInstance.error()).thenReturn(Optional.of(error));
    lenient().when(processInstance.id()).thenReturn("abc-def");
    lenient().when(processInstance.status()).thenReturn(KogitoProcessInstance.STATE_ACTIVE);
    lenient().when(error.failedNodeId()).thenReturn("xxxxx");
    lenient().when(error.errorMessage()).thenReturn("Test error message");
    lenient().when(process.get()).thenReturn(mock(KogitoWorkflowProcess.class));
    lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    resource = spy(new ProcessInstanceManagementResource(processes, application));
}
Also used : AbstractProcess(org.kie.kogito.process.impl.AbstractProcess) Processes(org.kie.kogito.process.Processes) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) Response(javax.ws.rs.core.Response) ProcessInstances(org.kie.kogito.process.ProcessInstances) ProcessError(org.kie.kogito.process.ProcessError) StatusType(javax.ws.rs.core.Response.StatusType) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Application(org.kie.kogito.Application) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Processes

use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.

the class BusinessRuleUnitIT method testBasicBusinessRuleUnitWithAgendaListener.

@ParameterizedTest
@MethodSource("processes")
public void testBasicBusinessRuleUnitWithAgendaListener(String bpmnPath) throws Exception {
    Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList(bpmnPath));
    resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("org/kie/kogito/codegen/tests/BusinessRuleUnit.drl"));
    Application app = generateCode(resourcesTypeMap);
    assertThat(app).isNotNull();
    final AtomicInteger counter = new AtomicInteger();
    app.config().get(RuleConfig.class).ruleEventListeners().agendaListeners().add(new DefaultAgendaEventListener() {

        @Override
        public void afterMatchFired(AfterMatchFiredEvent event) {
            counter.incrementAndGet();
        }
    });
    Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleUnit");
    Model m = p.createModel();
    m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKey("person");
    assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
    assertThat(counter.get()).isEqualTo(1);
}
Also used : HashMap(java.util.HashMap) DefaultAgendaEventListener(org.drools.core.event.DefaultAgendaEventListener) Processes(org.kie.kogito.process.Processes) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Model(org.kie.kogito.Model) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) RuleConfig(org.kie.kogito.rules.RuleConfig) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with Processes

use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.

the class BusinessRuleUnitIT method testBasicBusinessRuleUnitControlledByUnitOfWork.

@ParameterizedTest
@MethodSource("processes")
public void testBasicBusinessRuleUnitControlledByUnitOfWork(String bpmnPath) throws Exception {
    Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList(bpmnPath));
    resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("org/kie/kogito/codegen/tests/BusinessRuleUnit.drl"));
    Application app = generateCode(resourcesTypeMap);
    assertThat(app).isNotNull();
    final List<String> startedProcesses = new ArrayList<>();
    // add custom event listener that collects data
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            startedProcesses.add(((KogitoProcessInstance) event.getProcessInstance()).getStringId());
        }
    });
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleUnit");
    Model m = p.createModel();
    m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKey("person");
    assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
    // since the unit of work has not been finished yet not listeners where invoked
    assertThat(startedProcesses).hasSize(0);
    uow.end();
    // after unit of work has been ended listeners are invoked
    assertThat(startedProcesses).hasSize(1);
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) ProcessConfig(org.kie.kogito.process.ProcessConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) Processes(org.kie.kogito.process.Processes) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) Model(org.kie.kogito.Model) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with Processes

use of org.kie.kogito.process.Processes in project kogito-runtimes by kiegroup.

the class BusinessRuleUnitIT method testBasicBusinessRuleUnit.

@ParameterizedTest
@MethodSource("processes")
public void testBasicBusinessRuleUnit(String bpmnPath) throws Exception {
    Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList(bpmnPath));
    resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("org/kie/kogito/codegen/tests/BusinessRuleUnit.drl"));
    Application app = generateCode(resourcesTypeMap);
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleUnit");
    Model m = p.createModel();
    m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKey("person");
    assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
}
Also used : HashMap(java.util.HashMap) Model(org.kie.kogito.Model) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Application (org.kie.kogito.Application)4 Processes (org.kie.kogito.process.Processes)4 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 Model (org.kie.kogito.Model)3 Person (org.kie.kogito.codegen.data.Person)3 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 StatusType (javax.ws.rs.core.Response.StatusType)1 DefaultAgendaEventListener (org.drools.core.event.DefaultAgendaEventListener)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)1 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)1 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)1