Emulating modelled faults in WebSphere Integration Developer
July 5, 2009 3 Comments
Since version 6.1, WebSphere Integration Developer has come with the ability to create test projects containing test suites and programmatic emulators, allowing developers to create repeatable automated tests for their modules. Projects can contain any number of suites, test cases and variations to cover all the behaviours of the module.
One scenario often overlooked in user-defined test suites is the one where the partner reference returns a modelled fault.
Fortunately, it is possible to return a fault using a programmatic emulator. In this example we will use Java, but the same behaviour can be accomplished using a visual snippet.
First create the payload for the fault. If the payload is a String or other Java type, you can simply create it and assign it to a variable. If the object is a business object then locate the BOFactory and create it as you would any other SDO DataObject
BOFactory boFactory = (BOFactory) ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOFactory"); DataObject reservationFault = boFactory.create("http://LB_Example","ReservationFault");
Once you have the object set any attributes that are required.
Next create a Java ServiceBusinessException. The exception has four constructor methods, and we want the one that accepts a String and an Object. The string will be name of the fault being returned, and the object will be the payload created above.
Finally, you throw (not return) the ServiceBusinessException
ServiceBusinessException sbe = new ServiceBusinessException(reservationFault,"unknownEventFault"); throw sbe;
For completeness, here is the same code represented visually.