This blog post describes how to use the Application Module Tester provided together with JDeveloper to test all your business logic without having to write or design the client UI (view controller part of a Fusion Web Application).
I consider this a ‘best practice’ to do this in each project. It allows the developer(s) of the business logic to run, debug and test all business logic before the designers have worked out the UI. Changes to interfaces can be done without an impact to the UI this way.
One other advantage of using the Application Module Tester is that it starts up really fast compared to the long init phase the full web application needs.
Before going into detail lets talk about what this blog shows and how it’s implemented. A sample work space build in JDeveloper 11.1.2.1.0 using the HR schema as DB can be downloaded using the link provided at the end of the blog.
First of all you can test the data model you designed into the application module, meaning that you can execute the VO and walk over the result set or show the result as table
The application module can implement service methods which your later use in the UI to archive a business need. In the sample the application module defines just one service method ‘howManyEmpEarnMoreThen’ which returns the number of employees who are earning more (or equal) to the given amount.
and the implementation of this method
public oracle.jbo.domain.Number howManyEmpEarnMoreThen(oracle.jbo.domain.Number aSalary) { _logger.info("Call with salary: "+aSalary); EmployeesViewImpl lEmployeesView1 = this.getEmployeesView1(); oracle.jbo.domain.Number n = lEmployeesView1.countEmpWihtSalaly(aSalary); return n; }
Next a VO might have some ViewCriteria attatched which you also want to test
and the last thing to test are service methods which are exposed in the VO instead of the application module (‘countEmpWihtSalaly’ in the sample)
and the implementation of the method
public Number countEmpWihtSalaly(Number aSalary) { RowSet lCreateRowSet = this.createRowSet("counterView"); ViewCriteriaManager lCriteriaManager = this.getViewCriteriaManager(); String[] lAvailableViewCriteriaNames = lCriteriaManager.getAvailableViewCriteriaNames(); for (String vcName :lAvailableViewCriteriaNames) { this.removeApplyViewCriteriaName(vcName) ; } lCreateRowSet.ensureVariableManager().setVariableValue("bindSal", aSalary); ViewCriteria lCriteria = this.getViewCriteria("EmpSalaryVC"); this.applyViewCriteria(lCriteria); lCreateRowSet.executeQuery(); long count = lCreateRowSet.getEstimatedRowCount(); _logger.info("Count Emp wiht salay > " + aSalary + " = " + count); lCreateRowSet.closeRowSet(); return new Number(count); }
Now let start up the the Application Module Tester and debug the business logic. To start the tester in debug mode, right click the application module facade and select ‘Debug’
which shows the tester like
A double click on a ViewObject (e.g. EmployeesView1) opens one record in form mode. You can navigate the result set using the icons in the header
One of the icons (the field glass) allows you to specify one or more of the available view criteria and hitting the ‘Find’ button after selecting a view criteria opens a dialog to enter bind variables
The result of this is again shown as a result set with navigation. If you like to see the result a table you can right click on the VO and select ‘Show Table’.
So how do we execute the ‘countEmpWihtSalaly’ method which is exposed in the client interface of the VO?
If you look at the image above you’ll see the option ‘Operations’ which will open a new tab showing all available operations which are exposed to the client interface of the VO.
After selecting the method you can hit execute and the method is executed
To access the public available methods from the application module you right click on the application module and select ‘Show’. After that you see a tab like the one for the VO operation.
This might not look as much to you, but the advantage of the Application Module Tester is that you can debug the code in the application module methods or view object operation easily. You can set needed variables when calling the methods and use the outcome of the operations in calls to other operations. This way you can easily test the whole business logic without the need to have an UI present.
For more information you can check the Oracle® Fusion Middleware Fusion Developer’s Guide for Oracle Application Development Framework 11g Release 2 (11.1.2.1.0)
You can download the sample workspace, build with JDev 11.1.2.1.0 and depending on the HR db schema, from here: BlogBC4JTester.zip.doc
Please rename the file to ‘.zip’ after downloading it!