use of org.kie.kogito.services.uow.DefaultUnitOfWorkManager 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.services.uow.DefaultUnitOfWorkManager 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);
}
use of org.kie.kogito.services.uow.DefaultUnitOfWorkManager 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"));
}
}
use of org.kie.kogito.services.uow.DefaultUnitOfWorkManager 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;
}
});
}
use of org.kie.kogito.services.uow.DefaultUnitOfWorkManager 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;
}
Aggregations