Entering content frame

Background documentation Portal Runtime Test Mode Locate the document in its SAP Library structure

Rendering a Portal Component in test mode will perform the following operations:

·        Check if the Portal Component provides support for this mode.

·        Invoke all test methods defined in the Portal Component.

·        Format the output of the test to HTML or XML format.

A Portal Component provides support for the test mode

·        By implementing the ITestable interface defined in the PRT API.

·        By changing the portalapp.xml descriptor to mark the component as testable:

ITestable interface

public class MyAbstractPortalComponent

   extends AbstractPortalComponent

   implements ITestable {

   public String getTestName() {

      return "MyAbstractPortalComponent";

   }

}

PortalApp.xml

<property name="Testable" value="true" />

Example

<?xml version="1.0" encoding="ISO-8859-1"?>

<application>

  <application-config>

   <property name="SharingReference" value="unittest.facilities"/>

   <property name="Testable" value="true" />

  </application-config>

  <components>

   <component name="DeadLoad">

     <component-config>

      <property name="ClassName" value="unittest.component.TestLocks"/>

     </component-config>

    </component>

  </components>

</application>

The Portal component is invoked in test mode using the following URL:

·        /irj/servlet/prt/portal/prtroot/<MyComponent>/prtmode/test

Each test methods invoked by the Test Mode execution is written against the following pattern:

public void testXXX(

   IPortalComponentRequest aRequest,

   IPortalComponentTestResponse aResponse);

A test method expects two parameters:

·        IPortalComponentRequest : the standard Portal request.

·        IPortalComponentTestResponse interface. An extension of the standard IportalComponentResponse.

The IPortalComponentTestResponse is an IPortalComponentResponse enriched with the following test methods

·        log(String mgLog, String msgId)

Logs a message in the output of the Portal Component

·        assert (boolean condition, String msgLog, String msgId)

Stops the execution of the test when the test condition fails by outputting a message in the test output.

·        void verify (boolean status, String msgLog, String msgId)

Same as the assert behavior but the verify will not stop its execution

·        void verify (boolean status, String msgLog, Exception e, String msgId)

Allows an exception to be logged.

A typical test case looks like this:

public void testMode(

   IPortalComponentRequest request,

   IPortalComponentTestResponse response) {

   //...DO SOME CODE...

   INode node = request.getNode();

   NodeMode nodeMode = node.getNodeMode();

   response.assert(nodeMode != INode.EDIT, "EDIT Mode not set!", " ");

}

The assert() method checks the condition. If the condition is false the test case will show up as an error in the test result. The assert method interrupts the test case at the first error.

The verify method does the equivalent, but does not interrupt the test case. This makes it possible to put several checks in a single test case.

The log method can be used to write additional information to the PortalComponentTestResponse. This information will be included in the test result.

 

 

Leaving content frame