This procedure describes how to DevTest-enable a server-side component.
Follow these steps:
The component must at least import the appropriate integrator and the TransInfo class. For example, to import the classes necessary to integrate a servlet, add the following import statements:
import com.itko.lisaint.servlet.ServletIntegrator; import com.itko.lisaint.TransInfo;
For more information about the TransInfo class, see the JavaDocs in the doc folder of your installation directory.
The integrated component needs at least an integrator and a TransInfo variable, as seen in the following code:
ServletIntegrator si = null; TransInfo ti = null;
The integration API lets you control when the integrated component begins to communicate with the DevTest software. All the communication must happen in context of a transaction. Therefore, before beginning to communicate, start a transaction using the application-specific integrator. You can ensure that DevTest is on before that by checking with the application-specific integrator class. The following code checks if DevTest is on, then retrieves the servlet integrator from the integrator class and stores it in the variable si. The code then starts the transaction using the servlet integrator and stores the result in the TransInfo object.
if( ServletIntegrator.isLisaOn( request ) ) { si = ServletIntegrator.getServletIntegrator( request ); ti = si.startTransaction( "Hello World" ); }
Report component status. The TransInfo class provides a method, setBuildStatus(), that allows you to specify information that the system can use to determine how to run the test. For example, to tell DevTest that the component has failed, set the build status to STATUS_FAILED, as seen in the following code:
if( /* component failed */ ) { // ... ti.setBuildStatus( TransInfo.STATUS_FAILED, failMsg ); }
For more information about valid build status codes, see Build Status under Collect Transaction Information.
For example, if your application calculates the Dow average, you could store that value in a property that can be checked while testing. The following code creates a property named DOW_AVERAGE and assigns the value CalculatedDowAverage.
ti.setLISAProp( "DOW_AVERAGE", CalculatedDowAverage );
This mechanism can be used to send data cache data from the system under test to the Test Manager as property values. These property values can be any serializable object, including strings, any of the Java object wrappers for primitive types, or even your own classes as long as the class path contains the proper classes to deserialize the data.
ti.assertFailTest( boolean_assertion, "ASSERT FAILED" );
For more information about TransInfo assertion methods, see Assertion Methods under Collect Transaction Information.
if (special_condition) ti.setForcedNode("specialStep");
For more information about sending responses back to DevTest, see Handle Integrated Output.
JSP Tag Library
In addition to the Java API shown previously, DevTest provides a JSP tag library for Java web development. This API makes using the Integration API easy for JSP developers.
Pure XML Integration
DevTest makes available a pure XML form of the Integration for web applications on an as-needed basis. If you require this form of integration, contact your sales or support representative.
Test Components
Sometimes a server-side application has a number of checks and it is not clear where the test step failed. You can separate out parts of the transaction using subcomponents and can report their individual statuses. The com.itko.lisaint.CompInfo class represents a subcomponent.
For example, the following code creates a subcomponent of the transaction and sets its build status to STATUS_SUCCESS:
CompInfo ci = ti.newChildComp( "SUBCOMP" ); ci.setBuildStatus( CompInfo.STATUS_SUCCESS, "" ); ci.finished();
Subcomponents are treated as part of the overall transaction. If one subcomponent fails, the entire transaction fails. The following code creates a subcomponent and sets the build status to STATUS_FAILED. In this case, the entire transaction fails.
CompInfo ci = ti.newChildComp( "SUBCOMP" ); ci.setBuildStatus( CompInfo.STATUS_FAILED, "" );
For more information about the CompInfo class, see the JavaDocs in the doc folder of your installation directory.
Copyright © 2014 CA Technologies.
All rights reserved.
|
|