Search in sources :

Example 1 with AbstractAuditLogger

use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.

the class AsyncAuditLogProducerTest method testAsyncAuditProducer.

@Test
public void testAsyncAuditProducer() throws Exception {
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    Map<String, Object> jmsProps = new HashMap<String, Object>();
    jmsProps.put("jbpm.audit.jms.transacted", false);
    jmsProps.put("jbpm.audit.jms.connection.factory", factory);
    jmsProps.put("jbpm.audit.jms.queue", queue);
    AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    // start process instance
    long processInstanceId = session.startProcess("com.sample.ruleflow").getId();
    // setup listener
    MessageReceiver receiver = new MessageReceiver();
    List<Message> messages = receiver.receive(queue);
    Assertions.assertThat(messages).isNotNull();
    Assertions.assertThat(messages.size()).isEqualTo(11);
}
Also used : Message(javax.jms.Message) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with AbstractAuditLogger

use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.

the class AsyncAuditLogProducerTest method testAsyncAuditProducerTransactional.

@Test
public void testAsyncAuditProducerTransactional() throws Exception {
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    Map<String, Object> jmsProps = new HashMap<String, Object>();
    jmsProps.put("jbpm.audit.jms.transacted", true);
    jmsProps.put("jbpm.audit.jms.connection.factory", factory);
    jmsProps.put("jbpm.audit.jms.queue", queue);
    AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    // start process instance
    long processInstanceId = session.startProcess("com.sample.ruleflow").getId();
    ut.commit();
    MessageReceiver receiver = new MessageReceiver();
    List<Message> messages = receiver.receive(queue);
    Assertions.assertThat(messages).isNotNull();
    Assertions.assertThat(messages.size()).isEqualTo(11);
}
Also used : UserTransaction(javax.transaction.UserTransaction) Message(javax.jms.Message) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with AbstractAuditLogger

use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.

the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteDirectCreation.

@Test
public void testAsyncAuditLoggerCompleteDirectCreation() throws Exception {
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    AbstractAuditLogger logger = AuditLoggerFactory.newJMSInstance(true, factory, queue);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    session.addEventListener(logger);
    // start process instance
    ProcessInstance processInstance = session.startProcess("com.sample.ruleflow");
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 6000, 11);
    // validate if everything is stored in db
    AuditLogService logService = new JPAAuditLogService(env);
    List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow");
    Assertions.assertThat(processInstances.size()).isEqualTo(1);
    List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
    Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
        Assertions.assertThat(nodeInstance.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
        Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow");
        Assertions.assertThat(nodeInstance.getDate()).isNotNull();
    }
    logService.clear();
    processInstances = logService.findProcessInstances("com.sample.ruleflow");
    logService.dispose();
    Assertions.assertThat(processInstances).isEmpty();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 4 with AbstractAuditLogger

use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.

the class AsyncAuditLogProducerTest method testAsyncAuditProducerNonTransactionalWithRollback.

@Test
public void testAsyncAuditProducerNonTransactionalWithRollback() throws Exception {
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    Map<String, Object> jmsProps = new HashMap<String, Object>();
    jmsProps.put("jbpm.audit.jms.transacted", false);
    jmsProps.put("jbpm.audit.jms.connection.factory", jmsServer.lookup("ConnectionFactory"));
    jmsProps.put("jbpm.audit.jms.queue", queue);
    AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    // start process instance
    long processInstanceId = session.startProcess("com.sample.ruleflow").getId();
    ut.rollback();
    MessageReceiver receiver = new MessageReceiver();
    List<Message> messages = receiver.receive(queue);
    Assertions.assertThat(messages).isNotNull();
    Assertions.assertThat(messages.size()).isEqualTo(11);
}
Also used : UserTransaction(javax.transaction.UserTransaction) Message(javax.jms.Message) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with AbstractAuditLogger

use of org.jbpm.process.audit.AbstractAuditLogger in project jbpm by kiegroup.

the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteWithVariablesCustomIndexer.

@Test
public void testAsyncAuditLoggerCompleteWithVariablesCustomIndexer() throws Exception {
    Environment env = createEnvironment(context);
    // load the process
    KieBase kbase = createKnowledgeBase();
    // create a new session
    KieSession session = createSession(kbase, env);
    Map<String, Object> jmsProps = new HashMap<String, Object>();
    jmsProps.put("jbpm.audit.jms.transacted", false);
    jmsProps.put("jbpm.audit.jms.connection.factory", factory);
    jmsProps.put("jbpm.audit.jms.queue", queue);
    AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
    Assertions.assertThat(logger).isNotNull();
    Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
    List<String> names = new LinkedList<String>();
    names.add("john");
    names.add("mary");
    names.add("peter");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("list", names);
    // start process instance
    ProcessInstance processInstance = session.startProcess("com.sample.ruleflow3", params);
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 6000, 28);
    // validate if everything is stored in db
    AuditLogService logService = new JPAAuditLogService(env);
    List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow3");
    Assertions.assertThat(processInstances.size()).isEqualTo(1);
    List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
    Assertions.assertThat(nodeInstances.size()).isEqualTo(12);
    for (NodeInstanceLog nodeInstance : nodeInstances) {
        Assertions.assertThat(nodeInstance.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
        Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow3");
        Assertions.assertThat(nodeInstance.getDate()).isNotNull();
    }
    // verify variables
    List<VariableInstanceLog> variables = logService.findVariableInstances(processInstance.getId());
    Assertions.assertThat(variables).isNotNull();
    Assertions.assertThat(variables.size()).isEqualTo(8);
    List<VariableInstanceLog> listVariables = new ArrayList<VariableInstanceLog>();
    // collect only those that are related to list process variable
    for (VariableInstanceLog v : variables) {
        if (v.getVariableInstanceId().equals("list")) {
            listVariables.add(v);
        }
    }
    Assertions.assertThat(listVariables.size()).isEqualTo(3);
    List<String> variableValues = new ArrayList<String>();
    List<String> variableIds = new ArrayList<String>();
    for (VariableInstanceLog var : listVariables) {
        variableValues.add(var.getValue());
        variableIds.add(var.getVariableId());
        Assertions.assertThat(var.getOldValue()).isIn("", " ", null);
        Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
        Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
        Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("list");
    }
    Assertions.assertThat(variableValues).contains("john", "mary", "peter");
    Assertions.assertThat(variableIds).contains("list[0]", "list[1]", "list[2]");
    logService.clear();
    processInstances = logService.findProcessInstances("com.sample.ruleflow3");
    logService.dispose();
    Assertions.assertThat(processInstances).isNullOrEmpty();
}
Also used : JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) AuditLogService(org.jbpm.process.audit.AuditLogService) NodeInstanceLog(org.jbpm.process.audit.NodeInstanceLog) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) LinkedList(java.util.LinkedList) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceUtil.createEnvironment(org.jbpm.persistence.util.PersistenceUtil.createEnvironment) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractAuditLogServiceTest.createKieSession(org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractAuditLogger(org.jbpm.process.audit.AbstractAuditLogger) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

AbstractAuditLogger (org.jbpm.process.audit.AbstractAuditLogger)13 Test (org.junit.Test)11 KieSession (org.kie.api.runtime.KieSession)10 HashMap (java.util.HashMap)9 Environment (org.kie.api.runtime.Environment)9 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)8 AbstractAuditLogServiceTest.createKieSession (org.jbpm.process.audit.AbstractAuditLogServiceTest.createKieSession)8 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)8 KieBase (org.kie.api.KieBase)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)6 Message (javax.jms.Message)4 EntityManagerFactory (javax.persistence.EntityManagerFactory)4 AuditLogService (org.jbpm.process.audit.AuditLogService)4 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)4 NodeInstanceLog (org.jbpm.process.audit.NodeInstanceLog)4 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)4 ArrayList (java.util.ArrayList)3 UserTransaction (javax.transaction.UserTransaction)3 ServicesAwareAuditEventBuilder (org.jbpm.kie.services.impl.audit.ServicesAwareAuditEventBuilder)3 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)3