use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.
the class JbpmBpmn2TestCase method config.
protected ProcessConfig config(List<WorkItemHandler> handlers, List<ProcessEventListener> listeners) {
DefaultWorkItemHandlerConfig handlerConfig = new DefaultWorkItemHandlerConfig();
handlers.forEach(h -> handlerConfig.register(h.getName(), h));
DefaultProcessEventListenerConfig listenerConfig = new DefaultProcessEventListenerConfig();
listeners.forEach(h -> listenerConfig.register(h));
ProcessConfig config = new StaticProcessConfig(handlerConfig, listenerConfig, new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
return config;
}
use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.
the class PredictionAwareHumanTaskLifeCycleTest method configure.
@BeforeEach
public void configure() {
predictNow = new AtomicBoolean(false);
trainedTasks = new ArrayList<>();
predictionService = new PredictionService() {
@Override
public void train(io.automatiko.engine.api.runtime.process.WorkItem task, Map<String, Object> inputData, Map<String, Object> outputData) {
trainedTasks.add(task.getId());
}
@Override
public PredictionOutcome predict(io.automatiko.engine.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, new DefaultVariableInitializer(), null);
}
use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.
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);
Map<String, Process<?>> processes = Mockito.mock(Map.class);
Process process = mock(Process.class);
ProcessInstances instances = mock(ProcessInstances.class);
processInstance = mock(ProcessInstance.class);
errors = mock(ProcessErrors.class);
lenient().when(processes.get(anyString())).thenReturn(process);
lenient().when(process.instances()).thenReturn(instances);
lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance));
lenient().when(instances.findById(anyString(), eq(5), any())).thenReturn(Optional.of(processInstance));
lenient().when(processInstance.errors()).thenReturn(Optional.of(errors));
lenient().when(processInstance.id()).thenReturn("abc-def");
lenient().when(processInstance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
lenient().when(errors.failedNodeIds()).thenReturn("xxxxx");
lenient().when(errors.errorMessages()).thenReturn("Test error message");
lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
IdentitySupplier identitySupplier = new IdentitySupplier() {
@Override
public IdentityProvider buildIdentityProvider(String user, List<String> roles) {
return new StaticIdentityProvider("test");
}
};
resource = spy(new ProcessInstanceManagementResource(processes, application, identitySupplier));
}
use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.
the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstanceReload.
@Test
public void testScheduleJobsForProcessInstanceReload() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
when(processes.processById("processId_1")).then(i -> {
return process;
});
when(processes.processIds()).then(i -> {
return Collections.singletonList("processId_1");
});
when(process.instances()).then(i -> {
latch.countDown();
return Mockito.mock(ProcessInstances.class);
});
FileSystemBasedJobService jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(123, DurationExpirationTime.after(100), "processInstanceId", "processId", "1");
jobs.scheduleProcessInstanceJob(processInstanceJobDescription);
jobs.shutown(null);
jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
jobs.scheduleOnLoad(null);
boolean achieved = latch.await(2, TimeUnit.SECONDS);
assertThat(achieved).isTrue();
}
use of io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory in project automatiko-engine by automatiko-io.
the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstance.
@Test
public void testScheduleJobsForProcessInstance() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
when(processes.processById("processId_1")).then(i -> {
return process;
});
when(processes.processIds()).then(i -> {
return Collections.singletonList("processId_1");
});
when(process.instances()).then(i -> {
latch.countDown();
return Mockito.mock(ProcessInstances.class);
});
FileSystemBasedJobService jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(123, DurationExpirationTime.after(500), "processInstanceId", "processId", "1");
jobs.scheduleProcessInstanceJob(processInstanceJobDescription);
boolean achieved = latch.await(2, TimeUnit.SECONDS);
assertThat(achieved).isTrue();
verify(process, times(1)).instances();
}
Aggregations