Saturday, October 29, 2011

jBPM Form Builder follow-up: Flexible tables

Form Builder continues growing. In the following video you can see a new UI component (flexible table) that allows to create tables with cells that have a flexible row and column span

Also, the project is starting to get partitioned to allow other projects to use some of the functionalities implemented in the Form Builder project.

Form Builder API: It contains the representation objects of the model for form representing, as well as the translator and renderer interfaces.

Form Exporter for Freemarker: It contains the translator and renderer implementations for freemarker

Form Exporter for GWT (soon): Same as freemarker exporter, but for rendering with GWT

Other enhancements will come soon enough. Cheers,

Mariano

Friday, October 28, 2011

Friday Agenda - Drools & jBPM Boot Camp (Healthcare Focus) : San Francisco Oct 2011

Here is the agenda, with times, for friday's Healthcare bootcamp.

time
Name
Company
Presentation Title and Abstract
9.00Emory Fry US Navy Healthcare

Drools Enhancements In Support of Real-Time Clinical Decision Support.

Distributed Decision Support Services and Knowledge Management Repository (KMR-II) is a second generation Clinical Decision Support (CDS) platform for healthcare environments. This presentation will provide a brief overview of the overall architecture and then discuss in more detail specific enhancements to Drools that enables it to better support rule execution using standards-based object models, semantics, and data structures. KMR extends Drools with Predictive Model Markup Language (PMML), Grid Services, and Semantic Web technologies within an agent architecture. KMR-II provides integrated knowledge management, analytic, and predictive modeling capabilities critical to the immediate and long-term care of our patients. As a sophisticated, standards-based Clinical Decision Support environment, it is uniquely suited to deliver “knowledge services” that can be layered on a variety of health information networks.

10.30John KoischGuidewire Consulting

Part 1 - Health IT, Informatics, and Rich Information Structures - working with ontologies in the Health space

1.1) What Health IT is and what it isn't - why health IT is hard

1.2) Standards and Health IT - the RIM, vocabularies, CDA and standardizing information

1.3) The changing nature of Health IT - Disecting a typical health system design and why using ontologies makes sense

1.4) Why ontologies and information models are not enough - Why we need rule-based systems and architecture to build extensible IT solutions

Part 2 - Ontologies for the working Health IT shop - working with ontologies in a development and production environment

2.1) Examining system design - using ontologies and rule-based systems with rich information structures in a distributed setting

2.2) Why good developers have trouble in Health IT - where java and other frameworks are great, and where rich information ties you down

2.3) An example rule based system - dealing with DVT in a clinical setting

2.4) Towards an industrial-strength development framework - Working with ontologies and rules in health IT

11.30Nathan BellPharmacy OneSource

Speed Saves Lives: Leveraging a massively parallel expert system for patient surveillance

Pharmacy OneSource is a SaaS provider of applications for hospital pharmacy and infection prevention professionals. This case study will discuss the steps taken to develop a next-generation patient surveillance platform that allows clinicians to accurately detect risk factors, and perform interventions. The platform leverages the GigaSpaces implementation of Tuple-space and the Drools rule engine to create a massively parallel expert system. This architecture allows for customizable handling of millions of HL7 messages per day, evaluation of thousands of clinician created business rules, and reasoning over hundreds of thousands of patient data facts to provide near-real-time surveillance.

12.30lunch

1.30Diego NayaOSDEImproving Healthcare customer service with Drools and jBPM5
2.30Kris VerlaenenRed Hat

Clinical Pathways for doing Clinical Decision Support (CDS)

This presentation will describe how you can use clinical pathways to describe the treatment of patients. The pathways are usually the combination of processes describing the overall plan (for example using a flow chart approach but other representations like a time-task-matrix are possible as well) and rules adding additional constraints. It takes advantages of some of the more advanced features of jBPM5 to create flexible and adaptive, domain-specific processes that integration closely with rules.

3.00Dave WalsheServices Group

Medicare and Medicaid look to rules for the future of healthcare

The Center for Medicare and Medicaid Services (CMS), an agency of the Federal government, has aggressive plans to modernize healthcare administrative systems and Electronic Healthcare Records (EHR).

The use of Rules and Business Process Management are a focal point for the new systems. This session will describe how Medicare and Medicaid work and how the government (Federal and State) is looking for Rules and BPM to help change both the administrative and clinical environments. This session will look at the Medicaid Information Technology Architecture (MITA) and how Rules and BPM can augment this Service Oriented Architecture. We will discuss how to get involved in some of the many projects that are currently underway.

4.00Esteban AlivertiPlug TreeResource planning for healthcare services using Drools.


ss

Tuesday, October 25, 2011

RuleML2011@BRF - Ft. Lauderdale, Florida, 3-5 November 2011

Don't miss RuleML-2011@BRF - http://2011.ruleml.org/america/
===================================================================
Last day for regular price: 29th October. On-site rate after this.
http://www.businessrulesforum.com/register.php
9 Challenge Demo presentations will compete for the Demo Award.
NIEM, OASIS, OMG, IBM, Oracle, Microsoft, EMC related presentations.
===================================================================
RuleML 2011@BRF
5th International Symposium on Rules: Research-Based, Industry-Focused
Ft. Lauderdale, Florida, 3-5 November 2011
http://2011.ruleml.org/america/
===================================================================

We cordially invite you to participate to the 5th International Symposium on
Rules: Research-Based and Industry-Focused (RuleML-2011@BRF) - the premier
conference event emphasizing the synergy between high-quality research and
industry operating in the rule modeling, markup and reasoning domain, with
particular regard to the usability of such rule systems in the Web environment.
It takes place in Ft. Lauderdale, Florida, November 3-5, 2011, collocated with
the International Business Rules Forum.

News
===================================================================
Best paper prize
Challenge-2011 Demo Award
Special invited speakers included in the programme:
- Keynotes: Christian de Sainte Marie (IBM ILOG), Marcus Spies
(Ludwig-Maximilians University, Munich), Paul Vincent, (CTO Business Rules &
CEP, TIBCO Software) and Jan Vanthienen (KU Leuven, World Authority on Decision
Tables).
- An OMG presentation will be given by Said Tabet (EMC) and one from
NIEM and OASIS by David Webber (Oracle Corporation).
- Special invited demos will be presented by Jans Aasman (Franz Inc.)
and by Benjamin Grosof (Vulcan Inc.)

Supported by
===================================================================
W3C, OMG, OASIS, AAAI, ECCAI, EPTS
15% special discount code for OASIS, OMG, W3C, ACM, ECCAI, EPTS, SemWeb
and WSWM members.
15% special discount code for RuleML2011@IJCAI attendees and Ph.D students

Sponsored by
===================================================================
Franz Inc.
NICTA (National ICT Australia) Ltd
Vulcan Inc.
CIRSFID - University of Bologna
Corporate Semantic Web
Model Systems Ltd
OASIS-LEGALXML

(sponsoring opportunities:http://2011.ruleml.org/america/?page_id=30)
===================================================================

Friday, October 21, 2011

Drools 5.3.0.Final released (including Expert, Fusion, Planner and Guvnor)

We're happy to announce the release of Drools (Expert, Fusion, Planner, Guvnor) 5.3.0.Final.

Try it out and give us some feed-back (user list, issue tracker).

Thursday, October 20, 2011

Adding MVEL to the Java Developers Toolkit

An MVEL integration article that myself and Mike Brock wrote.
http://www.theserverside.com/news/thread.tss?thread_id=63139

It helps describe much of the integration code that Drools uses with MVEL.

New Features in jBPM5 Web Designer added!


Click to view the video!


In this video we presents a number of new features added to the jBPM5 Web Designer. These include:

1. Integration with the jbpmmigration project. Allows users to migrate their existing jPDL 3.2 based processes to BPMN2.
2. Ability to view process sources in a number of different formats (BPMN2, JSON, PNG, PDF, ERDF, and SVG)
3. Default installation of jBPM Service Nodes on process creation
4. Integration with the jBPM5 service repository.
5. Visual process validation

These features will be available in the next Web Designer release, however if you would like to start playing with them, you can download a snapshot version here: people.redhat.com/​tsurdilo/​oryx/​latest/​

Please give us your feedback!
Thanks.

Wednesday, October 19, 2011

Impossible matches and conflict detection in Guvnor decision tables

The guided decision tables in Guvnor 5.4 will have a new button Analyze. This will help you detect mistakes in your decision table. Currently we already detect 2 types of problems:
  • Impossible matches
  • Conflicting matches (conflict detection)
Impossible matches

Here is a decision table to charge traffic violators a fee depending on their age and whether or not it is their first offense:

When will row 2 match? How can someone be at least 21 years old but at maximum 20 years old?

Never of course. That's an impossible match. Click on the button Analyze and Guvnor will detect this problem for you:


Conflict detection

Here we have the same decision table, with different values.
What fee does a 67 your old need to pay if it's his first offense? 200 according to row 2 or 100 according to row 3?

Both rows apply: they are in conflict. That's a conflicting match. Click on the button Analyze and Guvnor will detect this problem for you:

Notice that row 4 applies to any age, yet it does not conflict with any of the other rows. That's because it only applies if it's not his/her first offense and the other rows only apply if it is.

Here's a video:

Sunday, October 16, 2011

It's ongoing mission.....

A cheesy intro I'm thinking of using for one of my talks :)
"Drools is the leading open source, industry focused, rule engine. While Drools started life as a Rete based forward chaining engine, it has since transcended. It's ongoing mission is to explore declarative paradigms from a practical and industrial perspective, to boldly go where no engine has gone before."

Wednesday, October 12, 2011

Drools & jBPM Boot Camp (Healthcare Focus) : San Francisco Oct 2011

Interested in HL7?
Semantic Ontologies with OWL-DL?
Want to know how to improve your healthcare services with Open source?
THEN SIGN UP NOW!!! :)

As previously reported the date is very close now for RulesFest as well as the co-located Drools & jBPM tech and healthcare days.

Spaces are filling up fast, so register quickly!!! We have a full plethora of speakers and talks now. Please take a look at the updated details below, for a full list of talks and speaker bios.

You can get the most up to date information from the wiki page (which is copied below):
http://community.jboss.org/wiki/DroolsJBPMBootCampHealthcareFocusSanFranciscoOct2011

Mark

Hyatt Regency San Francisco.jpg

The Drools & jBPM event is free, but you MUST BE REGISTERED to attend. Registration is from the main rulesfest website, here - http://rulesfest.org/html/registration.html.

Logistics

Where

  • Hyatt Regency, Burlingame, San Francisco, CA

When

  • Rules Fest - October 2011 - Mon 24th to Wed 26th
  • Drools & jBPM Boot Camp - October 2011 - Thu 27th to Fri 28th
    • Thu general tech for Drools & jBPM rules, workflow, event processing, ontologies
    • Fri Healthcare focus

What

  • Rules Fest
    • General reasoning technologies, rules, workflow, agents, ontologies, uncertainty.
  • Drools & jBPM Boot Camp
    • Thu general tech for Drools & jBPM rules, workflow, event processing, ontologies
    • Fri Healthcare focus

Time

  • Monday to Friday 9am to 6pm

Price

Accomodation

Contact Details

  • Rules Fest - Jason Morris - info at rulesfest d0t org
  • Drools & jBPM (general) - Prakash Aradhya - paradhya at redhat d0t com
  • Drools & jBPM (technical) - Mark Proctor - mproctor at codehaus d0t com

Previous Boot Camps

Drools Boot Camp : San Diego April 2010

Drools Boot Camp : San Francisco June 2009

Agenda

Mon - Wed (Rules Fest)

General talks covering a variety of topics related to reasoning systems, rules, workflow, agents, ontologies, uncertainty.

Paul Haley will give the key note (not to be missed) "Paul Haley to Keynote Rules Fest".

Rest of agenda see here http://rulesfest.org/html/agenda.html

Thu (Drools & jBPM, Free)

General Drools & jBPM day with presenters from Red Hat and core community members. This day is suitable for all and will provide an introduction and overview to Drools and jBPM and how they are used.

Name
Company
SubjectPresentation Title
Mark Proctor Red HatDrools Expert
(rules)
Introduction to what a Rule Engine is and the capabilities of Drools Expert. This will cover both the Drools technical language and Decision Table theory.
EdsonTirelliRed HatDrools Fusion (CEP)Complex Event Processing facilitates event correlation and temporal comparison. Fusion extends Drools to provide capabilities. Come learn what , what type of problems it helps solve and how it's done with Drools.

Mauricio

Salatno

PlugtreejBPM
(workflow)
Introduction to what BPMN2 is, why it matters and how jBPM works.
Ray PloskiRed Hat

Guvnor

(web tooling/brms)

Guvnor provides server side knowledge mangement, authoring and deployment capalities. This talk introduces these conts and provides live demos of everything coming together.
Davide SottaraUS Navy Healthcare

Drools Expert

(Semantics and Ontologies)

What are semantic ontologies and what research is underway with Drools to help. Will also introduce the base foundation of Traits, which provides dynamic and type safe duck typing.
Mark ProctorRed Hat

Drools Expert

(rules)

Learn how to write Adventure games with Drools.

Fri (Drools & jBPM & Healthcare, Free)

Healthcare focus, especially clinical. This day will be predominantly industry lead with professionals doing most of the talks. None healthcare people are welcome to join, but be aware that this day is specialised for a focus on healthcare problems.

Titles and abstracts are still being fleshed out and subject to change, check back regularly for changes.

Name
Company
Presentation Title and Abstract
Emory Fry US Navy Healthcare

Drools Enhancements In Support of Real-Time Clinical Decision Support.

Distributed Decision Support Services and Knowledge Management Repository (KMR-II) is a second generation Clinical Decision Support (CDS) platform for healthcare environments. This presentation will provide a brief overview of the overall architecture and then discuss in more detail specific enhancements to Drools that enables it to better support rule execution using standards-based object models, semantics, and data structures. KMR extends Drools with Predictive Model Markup Language (PMML), Grid Services, and Semantic Web technologies within an agent architecture. KMR-II provides integrated knowledge management, analytic, and predictive modeling capabilities critical to the immediate and long-term care of our patients. As a sophisticated, standards-based Clinical Decision Support environment, it is uniquely suited to deliver “knowledge services” that can be layered on a variety of health information networks.

Diego NayaOSDEImproving Healthcare customer service with Drools and jBPM5

Mauricio

Salatino

Plugtree

Emergency Services in action.

The application was created to represent complex scenarios that are being exe-cuted by an Emergency Services company that deals with concurrent emergencies within a city. The company needs to solve different situations where different entities need to be coordinated to deal with an emergency situation. The Emergency Services Application shows how we can provide a tool that helps the company to improve their services by giving them full visibility of their actions, traceability of their resources, suggestions and advice based on the con-text without sacrifficing any degree of exibility that they need to solve real life situations.

Nathan BellPharmacy OneSource

Speed Saves Lives: Leveraging a massively parallel expert system for patient surveillance

Pharmacy OneSource is a SaaS provider of applications for hospital pharmacy and infection prevention professionals. This case study will discuss the steps taken to develop a next-generation patient surveillance platform that allows clinicians to accurately detect risk factors, and perform interventions. The platform leverages the GigaSpaces implementation of Tuple-space and the Drools rule engine to create a massively parallel expert system. This architecture allows for customizable handling of millions of HL7 messages per day, evaluation of thousands of clinician created business rules, and reasoning over hundreds of thousands of patient data facts to provide near-real-time surveillance.

Dave WalsheServices Group

Medicare and Medicaid look to rules for the future of healthcare

The Center for Medicare and Medicaid Services (CMS), an agency of the Federal government, has aggressive plans to modernize healthcare administrative systems and Electronic Healthcare Records (EHR).

The use of Rules and Business Process Management are a focal point for the new systems. This session will describe how Medicare and Medicaid work and how the government (Federal and State) is looking for Rules and BPM to help change both the administrative and clinical environments. This session will look at the Medicaid Information Technology Architecture (MITA) and how Rules and BPM can augment this Service Oriented Architecture. We will discuss how to get involved in some of the many projects that are currently underway.

John KoischCommence Partners

Part 1 - Health IT, Informatics, and Rich Information Structures - working with ontologies in the Health space

1.1) What Health IT is and what it isn't - why health IT is hard

1.2) Standards and Health IT - the RIM, vocabularies, CDA and standardizing information

1.3) The changing nature of Health IT - Disecting a typical health system design and why using ontologies makes sense

1.4) Why ontologies and information models are not enough - Why we need rule-based systems and architecture to build extensible IT solutions

Part 2 - Ontologies for the working Health IT shop - working with ontologies in a development and production environment

2.1) Examining system design - using ontologies and rule-based systems with rich information structures in a distributed setting

2.2) Why good developers have trouble in Health IT - where java and other frameworks are great, and where rich information ties you down

2.3) An example rule based system - dealing with DVT in a clinical setting

2.4) Towards an industrial-strength development framework - Working with ontologies and rules in health IT

Kris VerlaenenRed Hat

Clinical Pathways for doing Clinical Decision Support (CDS)

This presentation will describe how you can use clinical pathways to describe the treatment of patients. The pathways are usually the combination of processes describing the overall plan (for example using a flow chart approach but other representations like a time-task-matrix are possible as well) and rules adding additional constraints. It takes advantages of some of the more advanced features of jBPM5 to create flexible and adaptive, domain-specific processes that integration closely with rules.

Speaker Bios

Emory Fry

Emory Fry, MD, a neonatal intensive care specialist, has over 15 years of experience in the design and development of enterprise clinical information systems with a particular interest in cognitive science and clinical decision support, He is the Principle Investigator for both the Distributed Decision Support Services and Knowledge Management Repository (KMR) program and the real-time Closed-Loop Mechanical Ventilation initiative (SmartVent). His engineering team is actively enhancing the core Drools infrastructure for the purposes of creating an open-source real-time clinical decision support for healthcare. Current Drools projects include Drools Grid, terminology support, ontology integration, and a rule authoring workbench for clinical domain experts.

Nathan Bell

Nathan is Principal Architect at Pharmacy OneSource (Wolters Kluwer Health), a provider of SaaS applications for hospital pharmacy and infection prevention professionals. He has designed and implemented mission critical, near-real-time, high transaction volume systems in several industries including financial, medical, defense and telecommunications. He is currently involved in various projects within Wolters Kluwer Health to apply business rules technology to clinical decision support systems at the point of care.

Dave Walsh

Dave Walsh is CEO of eServices Group. eServices Group is a software development firm focused on supplying software products to meet the needs of Medicaid and Medicare for over 18 years. Mr. Walsh also chairs the MITA Technical Architecture Committee (TAC). The TAC is an industry collaborative that is focused on supporting the Federal government and States in the definition of the next generation Medicaid systems based on SOA, BPM and rules.

John Koisch

John Koisch has over 16 years of experience in information technology with 8 in healthcare IT. He has pioneered efforts at bringing health IT standards into the development space. John has worked at the strategic levels of a number of organizations, and has led architects and developers in a variety of health and life science integration projects. He is a principal in Guidewire, and directs its research efforts, product development, and standards engagements.

Prior to joining Guidewire, John has held a variety of leadership and development roles in healthcare IT and standarards development organizations. He has developed a contract-driven development and system specification framework. He designed and led development in a Service Oriented Architecture to the DoD's Western Regional Medical Command. In addition to application architecture, he also contributed to the DOD's CDA Implementation Guide, participates in HL7 actively on various service-oriented projects, and has developed a framework for binding web services to HL7's rich information models.

John has a bachelor's degree in physics / astronomy, with focuses on math from Texas Christian University and is certified in a number of relevant technologies.

Diego Naya

Diego Naya is the Application Development Manager for OSDE, Argentina’s biggest healthecare company. He has extensive experience in BPMS and BRMS implementation in the healthcare industry. Diego wrote the book “OSWorkflow: A guide for implementing Business Processes” and several related articles.

Mauricio Salatino

Davide Sottara

Davide is currently working as an independent private consultant and as a post-doc researcher at the University of Bologna, being involved the development of remote health-care systems, enhanced with AI-based predictive, diagnostic and planning features.

In 2006, he has been awarded a SPINNER grant from the region Emilia Romagna, attending a post-graduate course in "Research, Innovation and Technology Transfer". Since 2006, he has been working on the development of intelligent DSSs in the environmental (in cooperation with the Italian National Agency for the Energy, Environment and New Technologies) and medical field and is a member of the Drools Community, leading a sub-project on the extension of production rule engines to support uncertain and fuzzy reasoning.

Davide Sottara got his Ms. Degree (2006) and his Ph.D (2010) in Computer Science, Electronics and Telecommunications from the University of Bologna. His research and development interests include artificial intelligence in general and decision support systems in particular, focusing on hybrid systems combining predictive models and rule-based systems.

Mauricio Salatino

Mauricio has been a Drools and jBPM5 Community Contributor for more than three years now. As CTO of Plug Tree, he has been an active community member, trainer, developer and Open Source Software Evangelist.

Mauricio is the author of the jBPM Developer Guide for Packt Publishing (2009). He was a JBoss Community Award Winner 2011 (New Features – Bug Fixes).

blog: http://salaboy.wordpress.com

Mark Proctor

Mark Proctor received his B.S. Eng. in Engineer Science and Technology and then his M.S. in Business and Information Systems; both from Brunel University, West London. His M.S. thesis was in the field of Genetic Algorithms; which is where he first got his interest for anything AI related.

Mark became involved in the Drools expert system project at an early stage and soon became its project lead. Mark then joined JBoss (later acquired by RedHat) as an employee when the Drools project was federated into the JBoss JEMS stack.

Having developed a powerful expert system, Mark is now turning his attention to other declarative paradigms in an effort to unify them to allow for richer domain modeling environments.

Kris Verlaenen

Kris is a Software Engineer at JBoss, by Red Hat, where he leads on the jBPM project (an open-source business process management (BPM) suite), and is also part of the Drools project (an open-source Java rules engine). The jBPM project consists of a lightweight workflow engine in Java that support native BPMN 2.0 execution and various tools and features around that to support business processes throughout their entire life cycle.

Kris did a PhD in Computer Science at the Katholieke Universiteit Leuven, Belgium. His main research area is policy-based management, i.e. using declarative policy rules for configuring services, resulting in highly-configurable, reusable services. He has experience and a great intrest in policy-based and rule-based systems, workflow management, service-oriented software development and clinical decision support.

Edson Tirelli

Edson Tirelli is a Senior Software Engineer at Red Hat with over 10 years of experience in the Middleware and Telecom Industries. He has been working on the Drools project (part of the JBoss Enterprise BRMS product) design and development for 5+ years and is the Lead Designer of the Drools Fusion CEP engine.

Ray Ploski

Ray Ploski is the Director of Application Platforms and Developer Strategy for JBoss. He has been an active contributor, consultant, developer, architect and trainer aiding organizations and companies adopt open source for the past fifteen years. Ray has been regularly recognized for his contributions in advancing the adoption of open source and is one of the few Red Hat employees to have earned the Chairman's Award[1] . In his current role he is responsible for JBoss's evangelism and developer programs.

Tuesday, October 11, 2011

Introducing the service repository

(If you want to help out and contribute to jBPM, read this blog all the way to the end, as we're looking for community assistance here!)

Using jBPM5, you can introduce your own domain-specific services in your processes. By defining your own services, they show up as custom service tasks in the graphical process editor. For example, if you would like to send tweets inside your business processes, a special twitter service task can be defined, as shown in the following screenshot.


Configuring domain-specific services has become even easier now, as we now allow you to import services like this from a service repository. You can just browse such a service repository and import the services you would like to use inside your processes. These will then automatically be added to your palette. You can also import a default handler that will be used to execute the service (although you're always free to override the defaults, for example for testing).

The import wizard is created as part of the latest version of the jBPM Eclipse plugin (and will be part of the next release, or you can already try it out by installing the latest plugin from the latest update site). It supports both repositories that are on your file system, or URL-based.

Click on the image below to see a screencast where we import the twitter service in a new jBPM project and create a simple process with it that sends an actual tweet.


[Note that you need the necessary twitter keys and secrets to be able to programatically send tweets to your twitter account. How to create these is explained here, but once you have these, you can just drop them in your project using a simple configuration file.]

We're building a service repository that contains predefined services that people can use out-of-the-box if they want to: http://people.redhat.com/kverlaen/repository. Currently it only contains a few services but we will migrate all existing services there over time.

And this is where we are looking for contributions! There are tons of interesting services and excellent projects that we would like to integrate with. We would like to offer out-of-the-box integration with a lot of those, by defining them as domain-specific services and adding them to the service repository, so people can import them in their processes. So if you would like to contribute integration with a service like that (e.g. facebook, google maps, etc.), or even your own project, let us know!

Thursday, October 06, 2011

Cookbook: How to Test Rules using xUnit

As most users know, Drools offers a user friendly web based scenario testing tool in Guvnor. Sometimes, though, the rules are developed by the technical team and the team might have a testing process in place using standard xUnit frameworks.

The good news is that testing rules with your favorite xUnit framework is simple and no different from testing any other piece of code. This quick tutorial presents simple recipes to test rules using:

* JUnit 4 - www.junit.org
* Mockito - www.mockito.org

This tutorial assumes familiarity with the above frameworks. Please consult the appropriate documentation if you are not familiar with them. The same approach can be used with any xUnit framework and with any mocking framework.

During this tutorial we will test these 2 simple rules:
package com.sample

rule "Name is Bob"
salience 10
when
$p : Person( name == "Bob", $age : age )
then
insert( "Bob is "+$age+" years old." );
end

rule "Person is 35 years old"
salience 5
when
Person( age == 35, $name : name )
then
insert( "Person is 35 years old" );
end

Before and after each test, we have to create the knowledge base and load the rules. In JUnit we can use the @Before and @After annotations to create setup and teardown methods:
   @Before
public void setup() {
try {
// load up the knowledge base
kbase = readKnowledgeBase();
// create the session
ksession = kbase.newStatefulKnowledgeSession();
} catch ( Exception e ) {
e.printStackTrace();
Assert.fail( e.getMessage() );
}
}

@After
public void tearDown() {
if ( ksession != null ) {
ksession.dispose();
}
}

Each unit test, has to follow basically 3 steps:

1. Prepare the listeners
2. Execute the scenario
3. Verify the scenario results

In the next few sections, we will detail a few ways to test different aspects of the rules execution.

R1. How to check that the rules execute and no exception is raised

An easy way to check that the rules execute is to test the return value of the fire all rules. So to check that for a given fact, both rules execute and no exception is raised, we just need to create a unit test:
   @Test
public void testRulesFire() throws Exception {
// ***********************************************************
// execute the scenario to be tested
// ***********************************************************
// insert the required data
Person bob = new Person( "Bob",
35 );
ksession.insert( bob );

int rulesFired = ksession.fireAllRules( );

// ***********************************************************
// verify the results
// ***********************************************************
Assert.assertEquals( 2, rulesFired );
}


R2. How to prevent infinite loops in tests

To prevent infinite loops during testing, an easy way is to simply use the limit parameter on fire all rules. The engine will pause execution and return the control to the test once all rules have fired or the limit was reached. E.g.:
   @Test
public void testRulesFire2() throws Exception {
// ***********************************************************
// execute the scenario to be tested
// ***********************************************************
// insert the required data
Person bob = new Person( "Bob",
35 );
ksession.insert( bob );

// do not fire more than 10 rules
int rulesFired = ksession.fireAllRules( 10 );

// ***********************************************************
// verify the results
// ***********************************************************
Assert.assertEquals( 2, rulesFired );
}


R3. How to test Individual Rules

The problem with previous tests is that the initial data will fire both rules. Sometimes it is necessary to test individual rules. To test individual rules, we need to prevent any other rule from firing. To allow that, we can use Agenda Filters. The AgendaFilter is a one-method interface that the user can implement or he can use one of the implementations that come with Drools.

Drools ships with several implementations, including some that check the rule name to allow or prevent rules from firing. For instance, if we want to test the rule "Name is Bob" individually, all we need to do is to use an appropriate agenda filter when firing the rules:
   @Test
public void testBobRuleOnly() throws Exception {
// ***********************************************************
// execute the scenario to be tested
// ***********************************************************
// insert the required data
Person bob = new Person( "Bob",
35 );
ksession.insert( bob );

// we only want to fire the Bob rule, so use an agenda filter for that
int rulesFired = ksession.fireAllRules( new org.drools.base.RuleNameEqualsAgendaFilter( "Name is Bob" ) );

// ***********************************************************
// verify the results
// ***********************************************************
Assert.assertEquals( 1, rulesFired );
}

To know more about AgendaFilters, check the Drools javadoc documentation for org.drools.runtime.rule.AgendaFilter and its implementations.

R4. How to check executed rules

Unfortunately, just checking the number of executed rules is rarely enough to make sure the rules are correct. Many times, the test must make sure that the rules executing are the ones that should be executing and that they are doing so in the expected sequence.

Fortunately, Drools offers a listener framework that allows the application (and the tests) to be notified about every single step the engine is taking. Combine that with a mocking framework like Mockito and you have a really powerful and flexible testing infrastructure.

There are several different listeners, but the 2 most frequently used are the AgendaEventListener (that listens for agenda changes like rules being activated, fired, cancelled, etc) and the WorkingMemoryEventListener (that listens for changes on the working memory, like facts being inserted, modified or retracted). For a list of all listeners and their methods, please consult the Drools javadoc documentation and look for org.drools.event.rule.AgendaEventListener, org.drools.event.rule.WorkingMemoryEventListener, org.drools.event.process.ProcessEventListener and org.drools.event.knowledgebase.KnowledgeBaseEventListener.

To test that 2 rules are fired using the listener framework, on can use Mockito to create mock listeners, like the mock AgendaEventListener bellow, and check that the afterActivationFired method was called twice.
   @Test
public void testRulesFired() throws Exception {
// ***********************************************************
// create the mock listeners and add them to the session
// ***********************************************************

// AgendaEventListeners allow one to monitor and check rules that activate, fire, etc
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );

// ***********************************************************
// execute the scenario to be tested
// ***********************************************************
// insert the required data
Person bob = new Person( "Bob",
35 );
ksession.insert( bob );

ksession.fireAllRules( 10 );

// ***********************************************************
// verify the results
// ***********************************************************

verify( ael, times(2) ).afterActivationFired( any( AfterActivationFiredEvent.class ) );
}

More than that, using Mockito's capture feature, it is possible to capture the exact event instances and verify values, like the rule names that were fired. For more details on how to capture parameters, please consult the Mockito documentation.
   @Test
public void testRulesFiredInSequence() throws Exception {
// ***********************************************************
// create the mock listeners and add them to the session
// ***********************************************************
// AgendaEventListeners allow one to monitor and check rules that activate, fire, etc
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );

// ***********************************************************
// execute the scenario to be tested
// ***********************************************************
// insert the required data
Person bob = new Person( "Bob",
35 );
ksession.insert( bob );

ksession.fireAllRules( 10 );

// ***********************************************************
// verify the results
// ***********************************************************
// create and argument captor for AfterActivationFiredEvent
ArgumentCaptor<AfterActivationFiredEvent> aafe = ArgumentCaptor.forClass( AfterActivationFiredEvent.class );

// check that the method was called twice and capture the arguments
verify( ael, times(2) ).afterActivationFired( aafe.capture() );
List<AfterActivationFiredEvent> events = aafe.getAllValues();

// check the rule name for the first rule to fire
AfterActivationFiredEvent first = events.get( 0 );
Assert.assertThat( first.getActivation().getRule().getName(),
is("Name is Bob") );

// check the rule name of the second rule to fire
AfterActivationFiredEvent second = events.get( 1 );
Assert.assertThat( second.getActivation().getRule().getName(),
is("Person is 35 years old") );
}

R5. How to check working memory changes

The same way that it is possible to check rules, we can also check changes to the working memory using a mock WorkingMemoryEventListener. The first rule inserts in its consequence a new fact into the working memory. We can check the inserted fact like this:
   @Test
public void testWorkingMemoryChanges() throws Exception {
// ***********************************************************
// create the mock listeners and add them to the session
// ***********************************************************
// WorkingMemoryEventListeners allow the test to check facts that are inserted, modified, retracted
WorkingMemoryEventListener wmel = mock( WorkingMemoryEventListener.class );
ksession.addEventListener( wmel );

// ***********************************************************
// execute the scenario to be tested
// ***********************************************************
// insert the required data
Person bob = new Person( "Bob",
35 );
ksession.insert( bob );

ksession.fireAllRules( new RuleNameEqualsAgendaFilter("Person is 35 years old") );

// ***********************************************************
// verify the results
// ***********************************************************
// create and argument captor for ObjectInsertedEvent
ArgumentCaptor<ObjectInsertedEvent> oie = ArgumentCaptor.forClass( ObjectInsertedEvent.class );

// check that the method was called twice: once for the "bob" fact,
// and a second time for the fact inserted by the rule
verify( wmel, times(2) ).objectInserted( oie.capture() );
List<ObjectInsertedEvent> events = oie.getAllValues();

// check the fact that was inserted by the test
ObjectInsertedEvent first = events.get( 0 );
Assert.assertThat( (Person) first.getObject(),
is( bob ) );

// check the fact that was inserted by the rule
ObjectInsertedEvent second = events.get( 1 );
Assert.assertThat( (String) second.getObject(),
is("Person is 35 years old" ) );
}

Please note that we added the mock working memory listener before inserting the facts into the working memory, so the Person fact (bob) was also captured by the lisneter. If you don't want to capture the facts that were inserted by the test, you can add the listener after seeding the working memory with the initial dataset, or you can reset the listener after doing it.

R6. How to check bound values on rules

Finally, for our last recipe, what happens if it is necessary to check the value of a given bound variable in a rule? Easily enough, we do the same we have been doing, using the agenda listener. Also, we can use MVEL to evaluate arbitrary expressions and check the result of the expression.
   @Test
public void testCheckBindingValues() throws Exception {
// ***********************************************************
// create the mock listeners and add them to the session
// ***********************************************************
// AgendaEventListeners allow one to monitor and check rules that activate, fire, etc
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );

// ***********************************************************
// execute the scenario to be tested
// ***********************************************************
// insert the required data
Person bob = new Person( "Bob",
35 );
ksession.insert( bob );

ksession.fireAllRules( new RuleNameEqualsAgendaFilter("Name is Bob") );

// ***********************************************************
// verify the results
// ***********************************************************
// create and argument captor for AfterActivationFiredEvent
ArgumentCaptor<AfterActivationFiredEvent> aafe = ArgumentCaptor.forClass( AfterActivationFiredEvent.class );

// check that the method was called twice and capture the arguments
verify( ael ).afterActivationFired( aafe.capture() );

// check the rule name for the first rule to fire
AfterActivationFiredEvent first = aafe.getValue();
Assert.assertThat( first.getActivation().getRule().getName(),
is("Name is Bob") );

// check value of $age
Assert.assertThat( (Integer) first.getActivation().getDeclarationValue( "$age" ),
is( 35 ) );

// check the value of an arbitrary expression using MVEL
Person $p = (Person) first.getActivation().getDeclarationValue( "$p" );
Integer age = (Integer) MVEL.eval( "$p.age", Collections.singletonMap( "$p", $p ) );
Assert.assertThat( age, is( 35 ) );

}

Guvnor - Support for Limited Entry decision tables

Work has completed for Guvnor's support of Limited Entry decision tables and will be first available in 5.4.0.Beta1 (or now, if you are able to work with the source from github).



This facility, coupled with use of either Java or Guvnor enumerations and the ability to create an expanded-form decision table makes the whole decision table authoring process much, much easier in Guvnor than ever before.

You can choose to construct either a Limited or Extended entry decision table when selecting to create a new web-based, or guided, decision table. Limited Entry column definitions now support the capture of all constraint or action parameters and the table itself becomes a simple choice of selecting the appropriate combinations.

Of course, when electing to create an expanded decision table using the Wizard all possible constraint combinations, or a sub-set if the user so chooses, are provided and populated in the grid as a starting point.

These recent enhancements really represent a huge step forward.

Watch it in action here.

Wednesday, October 05, 2011

AGTIVE International Symposium Oct 2011 - Budapest

I'll be in Budapest tomorrow presenting a talk on Drools at the "Applications of Graph Transformations with Industrial Relevance" AGTIVE 2011
http://avalon.aut.bme.hu/agtive2011/

XText and Attempto for Controlled Natural Language

Drools has always been independant of the parser. DRL is just a general purpose technical language for logic programming. We've always been big proponents of the conceptual idea of DSLs.

An early hack for our "DSL" was a simple string interpolation framework, for sentence templating. We always hoped to do more, as this was unstructured, but DSL's need tooling to fulfill their potential and this was beyond the resources we had.

I've been following XText for some time now and I think it now offers a real alternative to our DSLs, for domain specific structured content authoring. Version 2.0 is looking particularly sexy.

A recent blog "Using Xbase for Home Automation Rules " by Kai Kreuzer confirms that Xtext has a lot of potential here. I've suggested to Kai that he can use XText to drive our fluent descr api, which is what Antlr uses. Examples of the descr api for programmatic rule generation can be seen in this unit test:
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/lang/api/DescrBuilderTest.java

In essence I think a number of examples can be done to develop best practices, as well as fleshing our helper classes and abstract classes to make it quicker to developer DSLs in XText for Drools.

This started to make me think about how XText can be leveraged for natural language rule authoring.

Attempto is a project for controlled natural language. You provide mappings from your classes and fields to nouns, verbs and adjectives and it's parser will then allow you to author rules via controlled natural language. However there is no IDE for this.

Enter XText, a rising star in the Eclipse world. Xtext provides complete tooling, code completion, refactoring, outlines, based on an antlr like grammar.

Using the class and field mappings and the techniques in the Attempto parser, it should be possibe to generate an XText grammar. This would allow for controlled natural language rule authoring.

I think this is a fantastic project idea and XText really is catalyst for making this easy to realise it's potential. Any takers?

If you're interested, you know where to find us:
http://www.jboss.org/drools/irc.html

Mark

Tuesday, October 04, 2011

Job opening to work on Drools & jBPM in Argentina

repost to bump up again

--------

One of the largest healthcare organisations in Argentina is looking to find two senior developers, full time, to work on Drools and jBPM. The position is a long term contractual one and you must be based in Buenos Aries, Argentina

The work is for R&D enhancements to Drools and jBPM, not for building end user applications. It involves developing next generation authoring environments for rules, workflow and the semantic web. The ideal candidates would have a mixed set of skills including java, gwt and javascript. Knowledge of Drools and jBPM is a plus, but not mandatory.

You will work day to day with the Drools and jBPM team, as part of their community. All your work will be open source and you'll be able to evangelise your work via community facilities, such as mailing lists and blogs. This provides a unique opportunity to work on high profile projects in a public manner and gain recognition for yourself and your work.

You can apply for the job here : http://jobs.athico.com/job/senior-java-and-javascript-developer-to-work-on-ciudad-aut-noma-de-017e8dd315