Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Unit-testing your BPM processes by bending time.

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

    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

    • Red Hat Hardened Images: Top 5 benefits for software developers

    • How EvalHub manages two-layer Kubernetes control planes

    • Tekton joins the CNCF as an incubating project

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.