Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Unit-testing your BPM processes by bending time.

July 18, 2016
Duncan Doyle
Related topics:
CI/CDDevOps
Related products:
Developer Tools

Share:

    One of the core drivers behind modern application architecture, development and delivery methodologies like micro-services, agile and CI/CD is the ability to automatically test any software artifact, from application code to server configuration. Automated testing gives us the reliable, repeatable, assurance that our software meets the required quality with respect to aspects like functionality, performance, and scalability and is ready to be deployed in production. Why should testing of a business-process defined in BPMN2, a deployable software artifact, be any different?

    One of the unique features of Red Hat JBoss BPMSuite is that, due to it's adoption of Maven as de-facto build platform, it allows to utilize standard Java testing practices and methodologies in the business process space. In fact, jBPM (the upstream community project thatforms the base of Red Hat JBoss BPMSuite), provides out-of-the-box JUnit test classes that allow one to easily unit-test business processes defined in BPMN2 (see the jBPM User Guide for more detail).

    An interesting challenge when automatically testing business processes is testing constructs that provide behaviour based on time, e.g. Timer Intermediate Catching Events, Timer Boundary Events, etc. When unit-testing a software artifact, we want to complete the test as soon as possible, providing the ability to quickly determine whether our latest change breaks the build and thus the deployment pipeline or not. In other words, we want a quick feedback-loop. Having to wait minutes, hours or even a days for a timer to trigger when automatically testing business processes is therefore a non-feasible solution.

    The answer to this problem is provided by the Drools PseudoClock. The PseudoClock is a simple, yet sophisticated, component that allows us to manipulate time from within Java code. When configured on the business process engine's session (KieSession), it provides an API to programatically advance time. This allows us to, in our automatic tests, manipulate time in such a way that causes our process timers to fire (or not, depending on the test-case).

    A sample process and JUnit test-case is provided here.

    Note the configuration of the PseudoClock in the @Before annotated method. Setting the Drools property configures the PseudoClock on all sessions:

    @Before
    public void init() {
        //Enable the PseudoClock using the following system property.
        System.setProperty("drools.clockType", "pseudo");
        runtimeManager = createRuntimeManager("sample-process.bpmn");
        runtimeEngine = getRuntimeEngine(null);
        kieSession = runtimeEngine.getKieSession();
    }

    Our business process contains 2 script nodes and a timer intermediate catch events that waits 60 seconds:

     

    In both testcase we advance the clock programatically. In the first testcase, we advance the clock with 70 seconds, causing the timer to fire and thus the process to complete:

    @Test
    public void testTimerActivated() {
        ProcessInstance pInstance = kieSession.startProcess("sample-process");
        long pInstanceId = pInstance.getId();
    
        PseudoClockScheduler sessionClock = kieSession.getSessionClock();
        // Timer is set to 60 seconds, so advancing with 70.
        sessionClock.advanceTime(70, TimeUnit.SECONDS);
    
        // Test that the timer has triggered.
        assertNodeTriggered(pInstanceId, "Goodbye Process");
        assertProcessInstanceCompleted(pInstanceId);
    }

     

    In the second case, we advance the clock with 10 seconds, which does not cause the timer to complete. Therefore, we test that the process is still active:

    @Test
    public void testTimerNotActivated() {
        ProcessInstance pInstance = kieSession.startProcess("sample-process");
        long pInstanceId = pInstance.getId();</code>
    
        PseudoClockScheduler sessionClock = kieSession.getSessionClock();
        // Only advancing time by 10 seconds, so process should still be waiting.
        sessionClock.advanceTime(10, TimeUnit.SECONDS);
    
        // Test that the process is still active.
        assertProcessInstanceActive(pInstanceId);
    }

    This simple piece of configuration and code allows us to test processes and timers that span hours, days or even years in a number of milliseconds. This provides us with both the ability to automatically test our business process definition, as well as provide a quick feedback-loop from our CI/CD deployment pipeline.

    To run this simple unit-test demonstration:

    • Clone the Git repository from: https://github.com/DuncanDoyle/jbpm-unit-test-timers-example
    • cd into the "jbpm-unit-test-timers-example" directory
    • run "mvn clean test"

     

    Conclusion:
    Testing of BPMN2 process definitions tends to be a manual task in many platforms. Red Hat JBoss BPMSuite provides the unique capability of writing (unit-) tests in Java using de-facto test technologies like JUnit and Maven. In combination with the Drools PseudoClock, this allows for testing of complex business processes, which can include timer-based BPMN2 constructs like Timer Intermediate Catching Events and Timer Boundary Events, while at the same time providing a quick feedback-loop from our CI/CD deployment pipeline.

    Thanks to Donato Marrazzo and Anton Giertli for the inspiration for this blog-post and initial code.

    Last updated: January 22, 2024

    Recent Posts

    • Cloud bursting with confidential containers on OpenShift

    • Reach native speed with MacOS llama.cpp container inference

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue