Search in sources :

Example 51 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesWithLockIT method testUpdate.

@Test
public void testUpdate() {
    MongoDBProcessInstancesFactory factory = new MongoDBProcessInstancesFactory(getMongoClient());
    BpmnProcess process = createProcess(factory);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    MongoDBProcessInstances<?> processInstances = new MongoDBProcessInstances<>(getMongoClient(), process, DB_NAME, factory.transactionManager(), true);
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
    assertEquals(1L, instanceOne.version());
    assertEquals(1L, instanceTwo.version());
    instanceOne.updateVariables(BpmnVariables.create(Collections.singletonMap("s", "test")));
    try {
        BpmnVariables testvar = BpmnVariables.create(Collections.singletonMap("ss", "test"));
        instanceTwo.updateVariables(testvar);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was updated or deleted by other request.");
    }
    foundOne = processInstances.findById(processInstance.id());
    instanceOne = (BpmnProcessInstance) foundOne.get();
    assertEquals(2L, instanceOne.version());
    processInstances.remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 52 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesIT method testMongoDBPersistence.

@Test
void testMongoDBPersistence() {
    MongoDBProcessInstancesFactory factory = new MongoDBProcessInstancesFactory(getMongoClient());
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(factory);
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertEquals(STATE_ACTIVE, processInstance.status());
    MongoDBProcessInstances<?> mongodbInstance = new MongoDBProcessInstances<>(getMongoClient(), process, DB_NAME, factory.transactionManager(), false);
    assertThat(mongodbInstance.size()).isOne();
    assertThat(mongodbInstance.size()).isEqualTo(process.instances().size());
    Optional<?> findById = mongodbInstance.findById(processInstance.id());
    BpmnProcessInstance found = (BpmnProcessInstance) findById.get();
    assertNotNull(found, "ProcessInstanceDocument cannot be null");
    assertThat(found.id()).isEqualTo(processInstance.id());
    assertThat(found.description()).isEqualTo("User Task");
    assertThat(found.variables().toMap()).containsExactly(entry("test", "test"));
    assertThat(mongodbInstance.exists(processInstance.id())).isTrue();
    assertThat(mongodbInstance.values().size()).isOne();
    ProcessInstance<?> readOnlyPI = mongodbInstance.findById(processInstance.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertNotNull(readOnlyPI, "ProcessInstanceDocument cannot be null");
    assertThat(mongodbInstance.values(ProcessInstanceReadMode.READ_ONLY).size()).isOne();
    mongodbInstance.remove(processInstance.id());
    assertThat(mongodbInstance.exists(processInstance.id())).isFalse();
    assertThat(mongodbInstance.values()).isEmpty();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 53 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesIT method testMongoDBPersistenceWithTransaction.

@Test
void testMongoDBPersistenceWithTransaction() {
    MongoDBTransactionManager transactionExecutor = mock(MongoDBTransactionManager.class);
    ClientSession clientSession = mock(ClientSession.class);
    when(transactionExecutor.getClientSession()).thenReturn(clientSession);
    MongoClient mongoClient = mock(MongoClient.class);
    MongoDatabase mongoDatabase = mock(MongoDatabase.class);
    MongoCollection<Document> mongoCollection = mock(MongoCollection.class);
    when(mongoClient.getDatabase(anyString())).thenReturn(mongoDatabase);
    when(mongoDatabase.withCodecRegistry(any())).thenReturn(mongoDatabase);
    when(mongoDatabase.getCollection(anyString(), eq(Document.class))).thenReturn(mongoCollection);
    when(mongoCollection.withCodecRegistry(any())).thenReturn(mongoCollection);
    MongoCursor<Document> cursor = mock(MongoCursor.class);
    when(cursor.hasNext()).thenReturn(false);
    FindIterable<Document> results = mock(FindIterable.class);
    when(results.first()).thenReturn(null);
    when(results.iterator()).thenReturn(cursor);
    when(mongoCollection.find(eq(clientSession), any(Bson.class))).thenReturn(results);
    when(mongoCollection.find(eq(clientSession))).thenReturn(results);
    when(mongoCollection.find(any(Bson.class))).thenReturn(results);
    when(mongoCollection.find()).thenReturn(results);
    String id = "testId";
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new MongoDBProcessInstancesFactory(getMongoClient()));
    process.configure();
    MongoDBProcessInstances<BpmnVariables> mongodbInstance = new MongoDBProcessInstances<>(mongoClient, process, DB_NAME, transactionExecutor, false);
    mongodbInstance.size();
    verify(mongoCollection, times(1)).countDocuments(eq(clientSession));
    mongodbInstance.findById(id, ProcessInstanceReadMode.READ_ONLY);
    verify(mongoCollection, times(1)).find(eq(clientSession), eq(Filters.eq(PROCESS_INSTANCE_ID, id)));
    mongodbInstance.exists(id);
    verify(mongoCollection, times(2)).find(eq(clientSession), eq(Filters.eq(PROCESS_INSTANCE_ID, id)));
    mongodbInstance.values(ProcessInstanceReadMode.READ_ONLY);
    verify(mongoCollection, times(1)).find(eq(clientSession));
    mongodbInstance.remove(id);
    verify(mongoCollection, times(1)).deleteOne(eq(clientSession), eq(Filters.eq(PROCESS_INSTANCE_ID, id)));
    WorkflowProcessInstance updatePi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
    updatePi.setId(id);
    updatePi.setStartDate(new Date());
    AbstractProcessInstance mockUpdateProcessInstance = mock(AbstractProcessInstance.class);
    when(mockUpdateProcessInstance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    when(mockUpdateProcessInstance.internalGetProcessInstance()).thenReturn(updatePi);
    mongodbInstance.update(id, mockUpdateProcessInstance);
    verify(mongoCollection, times(1)).replaceOne(eq(clientSession), eq(Filters.eq(PROCESS_INSTANCE_ID, id)), any());
    WorkflowProcessInstance createPi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
    createPi.setId(id);
    createPi.setStartDate(new Date());
    AbstractProcessInstance mockCreateProcessInstance = mock(AbstractProcessInstance.class);
    when(mockCreateProcessInstance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    when(mockCreateProcessInstance.internalGetProcessInstance()).thenReturn(createPi);
    mongodbInstance.create(id, mockCreateProcessInstance);
    verify(mongoCollection, times(1)).insertOne(eq(clientSession), any());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) MongoDBTransactionManager(org.kie.kogito.mongodb.transaction.MongoDBTransactionManager) Mockito.anyString(org.mockito.Mockito.anyString) Document(org.bson.Document) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Date(java.util.Date) Bson(org.bson.conversions.Bson) MongoClient(com.mongodb.client.MongoClient) ClientSession(com.mongodb.client.ClientSession) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.jupiter.api.Test)

Example 54 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.

the class PostgreProcessInstancesWithLockIT method testRemove.

@Test
public void testRemove() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    PostgreProcessInstances processInstances = (PostgreProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
    assertEquals(1L, instanceOne.version());
    assertEquals(1L, instanceTwo.version());
    processInstances.remove(instanceOne.id());
    try {
        String id = instanceTwo.id();
        processInstances.remove(id);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was updated or deleted by other request.");
    }
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) PostgreProcessInstances(org.kie.kogito.persistence.postgresql.PostgreProcessInstances) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 55 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.

the class AbstractProcessInstancesIT method testUpdate.

@Test
public void testUpdate() {
    var factory = new TestProcessInstancesFactory(getDataSource(), true);
    BpmnProcess process = createProcess(factory, "BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
    assertEquals(1L, instanceOne.version());
    assertEquals(1L, instanceTwo.version());
    instanceOne.updateVariables(BpmnVariables.create(Collections.singletonMap("s", "test")));
    try {
        BpmnVariables testvar = BpmnVariables.create(Collections.singletonMap("ss", "test"));
        instanceTwo.updateVariables(testvar);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was updated or deleted by other request.");
    }
    foundOne = processInstances.findById(processInstance.id());
    instanceOne = (BpmnProcessInstance) foundOne.get();
    assertEquals(2L, instanceOne.version());
    processInstances.remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : JDBCProcessInstances(org.kie.kogito.persistence.jdbc.JDBCProcessInstances) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)64 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)48 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)47 ClassPathResource (org.drools.core.io.impl.ClassPathResource)34 HashMap (java.util.HashMap)19 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)18 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)18 WorkItem (org.kie.kogito.process.WorkItem)16 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)13 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)10 BpmnProcessInstance (org.kie.kogito.process.bpmn2.BpmnProcessInstance)8 WorkItem (io.automatiko.engine.api.workflow.WorkItem)7 Collections (java.util.Collections)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)7 ProcessInstance (org.kie.kogito.process.ProcessInstance)7 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 STATE_ACTIVE (org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE)6 List (java.util.List)5 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)5