Search in sources :

Example 1 with CollectingUnitOfWorkFactory

use of org.kie.kogito.services.uow.CollectingUnitOfWorkFactory 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 CollectingUnitOfWorkFactory

use of org.kie.kogito.services.uow.CollectingUnitOfWorkFactory in project kogito-runtimes by kiegroup.

the class PredictionAwareHumanTaskLifeCycleTest method configure.

@BeforeEach
public void configure() {
    predictNow = new AtomicBoolean(false);
    trainedTasks = new ArrayList<>();
    predictionService = new PredictionService() {

        @Override
        public void train(org.kie.api.runtime.process.WorkItem task, Map<String, Object> inputData, Map<String, Object> outputData) {
            trainedTasks.add(((InternalKogitoWorkItem) task).getStringId());
        }

        @Override
        public PredictionOutcome predict(org.kie.api.runtime.process.WorkItem task, Map<String, Object> inputData) {
            if (predictNow.get()) {
                return new PredictionOutcome(95, 75, Collections.singletonMap("output", "predicted value"));
            }
            return new PredictionOutcome();
        }

        @Override
        public String getIdentifier() {
            return "test";
        }
    };
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    wiConfig.register("Human Task", new HumanTaskWorkItemHandler(new PredictionAwareHumanTaskLifeCycle(predictionService)));
    config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
}
Also used : InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) HumanTaskWorkItemHandler(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CachedWorkItemHandlerConfig(org.kie.kogito.process.impl.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(org.kie.kogito.process.impl.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CollectingUnitOfWorkFactory

use of org.kie.kogito.services.uow.CollectingUnitOfWorkFactory in project kogito-runtimes by kiegroup.

the class SmileRandomForestPredictionTest method configure.

@BeforeEach
public void configure() {
    final RandomForestConfiguration configuration = new RandomForestConfiguration();
    final Map<String, AttributeType> inputFeatures = new HashMap<>();
    inputFeatures.put("ActorId", AttributeType.NOMINAL);
    configuration.setInputFeatures(inputFeatures);
    configuration.setOutcomeName("output");
    configuration.setOutcomeType(AttributeType.NOMINAL);
    configuration.setConfidenceThreshold(0.7);
    configuration.setNumTrees(1);
    predictionService = new SmileRandomForest(configuration);
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    wiConfig.register("Human Task", new HumanTaskWorkItemHandler(new PredictionAwareHumanTaskLifeCycle(predictionService)));
    config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
    for (int i = 0; i < 10; i++) {
        predictionService.train(null, Collections.singletonMap("ActorId", "john"), Collections.singletonMap("output", "predicted value"));
    }
    for (int i = 0; i < 8; i++) {
        predictionService.train(null, Collections.singletonMap("ActorId", "mary"), Collections.singletonMap("output", "value"));
    }
}
Also used : HumanTaskWorkItemHandler(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler) PredictionAwareHumanTaskLifeCycle(org.kie.kogito.prediction.api.PredictionAwareHumanTaskLifeCycle) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) HashMap(java.util.HashMap) CachedWorkItemHandlerConfig(org.kie.kogito.process.impl.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(org.kie.kogito.process.impl.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CollectingUnitOfWorkFactory

use of org.kie.kogito.services.uow.CollectingUnitOfWorkFactory in project kogito-runtimes by kiegroup.

the class BaseProcessInstanceManagementResourceTest method setUp.

@BeforeEach
void setUp() {
    lenient().when(node.getId()).thenReturn(1l);
    lenient().when(node.getName()).thenReturn("node");
    lenient().when(node.getUniqueId()).thenReturn(NODE_ID);
    lenient().when(node.getMetaData()).thenReturn(singletonMap(UNIQUE_ID, NODE_UNIQUE_ID));
    lenient().when(wp.getNodesRecursively()).thenReturn(singletonList(node));
    lenient().when(process.get()).thenReturn(wp);
    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.variables()).thenReturn(variables);
    lenient().when(processInstance.id()).thenReturn(PROCESS_INSTANCE_ID);
    lenient().when(processInstance.status()).thenReturn(ProcessInstance.STATE_ERROR);
    lenient().when(error.failedNodeId()).thenReturn(NODE_ID_ERROR);
    lenient().when(error.errorMessage()).thenReturn("Test error message");
    lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    tested = spy(new BaseProcessInstanceManagementResource(processes, application) {

        @Override
        protected Object buildOkResponse(Object body) {
            return body;
        }

        @Override
        protected Object badRequestResponse(String message) {
            return message;
        }

        @Override
        protected Object notFoundResponse(String message) {
            return message;
        }

        @Override
        public Object getProcessNodes(String processId) {
            return null;
        }

        @Override
        public Object getInstanceInError(String processId, String processInstanceId) {
            return null;
        }

        @Override
        public Object getWorkItemsInProcessInstance(String processId, String processInstanceId) {
            return null;
        }

        @Override
        public Object retriggerInstanceInError(String processId, String processInstanceId) {
            return null;
        }

        @Override
        public Object skipInstanceInError(String processId, String processInstanceId) {
            return null;
        }

        @Override
        public Object triggerNodeInstanceId(String processId, String processInstanceId, String nodeId) {
            return null;
        }

        @Override
        public Object retriggerNodeInstanceId(String processId, String processInstanceId, String nodeInstanceId) {
            return null;
        }

        @Override
        public Object cancelNodeInstanceId(String processId, String processInstanceId, String nodeInstanceId) {
            return null;
        }

        @Override
        public Object cancelProcessInstanceId(String processId, String processInstanceId) {
            return null;
        }
    });
}
Also used : CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with CollectingUnitOfWorkFactory

use of org.kie.kogito.services.uow.CollectingUnitOfWorkFactory in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method createProcesses.

protected Map<String, BpmnProcess> createProcesses(Map<String, String> classData, Map<String, KogitoWorkItemHandler> handlers) throws Exception {
    MemoryFileSystem srcMfs = new MemoryFileSystem();
    MemoryFileSystem trgMfs = new MemoryFileSystem();
    String[] sources = new String[classData.size()];
    int index = 0;
    for (Entry<String, String> entry : classData.entrySet()) {
        String fileName = entry.getKey().replaceAll("\\.", "/") + ".java";
        sources[index++] = fileName;
        srcMfs.write(fileName, entry.getValue().getBytes());
    }
    CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, trgMfs, this.getClass().getClassLoader());
    assertThat(result).isNotNull();
    assertThat(result.getErrors()).hasSize(0);
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    for (Entry<String, KogitoWorkItemHandler> entry : handlers.entrySet()) {
        wiConfig.register(entry.getKey(), entry.getValue());
    }
    ProcessConfig config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
    TestClassLoader cl = new TestClassLoader(this.getClass().getClassLoader(), trgMfs.getMap());
    Map<String, BpmnProcess> processes = new HashMap<>();
    BpmnProcesses bpmnProcesses = new BpmnProcesses();
    StaticApplication application = new StaticApplication(new StaticConfig(null, config), bpmnProcesses);
    for (String className : classData.keySet()) {
        Class<?> processClass = Class.forName(className, true, cl);
        Method processMethod = processClass.getMethod("process");
        Process process = (Process) processMethod.invoke(null);
        assertThat(process).isNotNull();
        processes.put(process.getId(), new BpmnProcess(process, config, application));
    }
    return processes;
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ProcessConfig(org.kie.kogito.process.ProcessConfig) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) StaticProcessConfig(org.kie.kogito.process.impl.StaticProcessConfig) HashMap(java.util.HashMap) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) StaticConfig(org.kie.kogito.StaticConfig) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) Process(org.kie.api.definition.process.Process) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) Method(java.lang.reflect.Method) BpmnProcesses(org.kie.kogito.process.bpmn2.BpmnProcesses) StaticApplication(org.kie.kogito.StaticApplication) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) CachedWorkItemHandlerConfig(org.kie.kogito.process.impl.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(org.kie.kogito.process.impl.DefaultProcessEventListenerConfig) CompilationResult(org.kie.memorycompiler.CompilationResult) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager)

Aggregations

CollectingUnitOfWorkFactory (org.kie.kogito.services.uow.CollectingUnitOfWorkFactory)7 DefaultUnitOfWorkManager (org.kie.kogito.services.uow.DefaultUnitOfWorkManager)7 BeforeEach (org.junit.jupiter.api.BeforeEach)5 CachedWorkItemHandlerConfig (org.kie.kogito.process.impl.CachedWorkItemHandlerConfig)3 DefaultProcessEventListenerConfig (org.kie.kogito.process.impl.DefaultProcessEventListenerConfig)3 StaticProcessConfig (org.kie.kogito.process.impl.StaticProcessConfig)3 HashMap (java.util.HashMap)2 HumanTaskWorkItemHandler (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler)2 Application (org.kie.kogito.Application)2 ProcessInstance (org.kie.kogito.process.ProcessInstance)2 ProcessInstances (org.kie.kogito.process.ProcessInstances)2 Method (java.lang.reflect.Method)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 StatusType (javax.ws.rs.core.Response.StatusType)1 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)1 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)1 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)1