Setup Calculator demo (Jtest 10.2.2) with Weblogic (10.3.6)
Pre-reqs: Maven, Java JDK 7, Weblogic 10.3.6, Jtest Engine 10.2.2
- Make sure you configure Maven to be able to use Jtest. See Jtest plugins manual for details. This can be found under: ”\manuals\plugins-manual.html”.
- Set up a domain in Weblogic with an Admin server.
- Copy the ”\examples\calculator\” folder to a new location. This will be the application that we will deploy on Weblogic to demonstrate application coverage.
Weblogic 10.3.6 only supports up to Java EE Servlet 2.5, and the Calculator example from Jtest 10.2.2 uses 3.0. Thus, we will need to modify the “web.xml” file as follows:
<web-app version="3.0 " xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Now our Calculator project is ready to be built. First we will need to generate the static coverage files so that application coverage can be collected on this application. To do this, we need to build our Calculator project and use the “monitor” goal to generate our needed files. First, make sure the build is clean by running “mvn clean”. Then use the following command from the Calculator’s project root directory:
mvn package jtest:monitor
Once this is completed, a “monitor.zip” archive will have been created within the “calculator\target\jtest\”. Extract this archive and double-click “agent.bat”. This will output the -javaagent argument that you will need to provide to Weblogic. Copy this generated argument somewhere such as in a text file.
Now we need to add this -javaagent argument to Weblogic’s server startup script. For Windows, this would be “startWebLogic.cmd”. This is found under ”\user_projects\domains\””\bin\startWebLogic.cmd”. Open this file and place the -javaagent generated flag (the one you got from “agent.bat”) before java executions (after “START WEBLOGIC” comment):
set JAVA_OPTIONS=%JAVA_OPTIONS% [generated javaagent flag]
See below image for an example:
Start your Weblogic Admin server. Open a web browser and navigate to your admin server URL with “/console” added to the end, example: “http://shuji-pc:7001/console”. In this example, the name of my local pc is "shuji-pc", but I could also have used "localhost" since my admin server is my local machine. This runs and brings you to the admin console where you can add deployments to your server. In this case, we are going to add the Calculator example project to our Admin server. From the Weblogic admin console, under the left pane in the “Domain Structure” category, click on “Deployments”.
From here, click on “install” and select the Calculator.war file that was built in the Calculator example. This can be found under the “target” folder from within the calculator example project.
Click “Next”. You are then presented with this page:
Select “Install this deployment as an application” and click “Next”. The next page has many more options such as these:
Leave the defaults here and click “Finish”.
Open a new tab and navigate to your server URL followed by “/Calculator”. Example: http://shuji-pc:7001/Calculator/.
The following page should appear:
Note: “shuji-pc” can also be “localhost” instead.
Interact with the application. Once you have interacted with the application, stop the server. Run the following command to calculate the coverage:
jtestcli -staticcoverage [path to static_coverage.xml file] -runtimecoverage [path/dir] -config "builtin://Calculate Application Coverage"
For my example, I ran:
jtestcli -staticcoverage "C:\Users\Shuji\Documents\Weblogic_application_example\calculator\target\jtest\monitor\monitor\monitor\static_coverage.xml" -runtimecoverage "C:\Users\Shuji\Documents\Weblogic_application_example\calculator\target\jtest\monitor\monitor\monitor\runtime_coverage" -config "builtin://Calculate Application Coverage"
Once this finishes, you will receive a report with the application coverage. The console output from running the above command will output where this report.html is stored.