Sun Identity Manager Deployment Guide

Example 4: Executing Javascript or Beanshell Script

The compatibility tests enable you to execute a javascript or beanshell script and then import the script results into the repository. Either script must return a string that contains the XML to be imported.

Identity Manager provides an example Apache Velocity template and some supporting beanshell script that uses the template. The beanshell script was created just to fill in the required variables, which makes it very easy to work with the default DataProvider.

Prepare the Test

Prepare the compatibility test to execute with a beanshell script

ProcedureTo Prepare the Test

  1. Set up the following files:

    sample/compat/example.4/example.properties

    sample/compat/example.4/SimulatedCompatibilityConfig.bsh


    Note –

    The default path to the simulated resource in SimulatedCompatibilityConfig is /tmp/mySimulatedResource.xml.

    You can edit this path if you want to specify a different location.

    You must change two lines in the file.


  2. Before executing the example, copy ant-junit.jar from Apache ant 1.6.5 to your $WSHOME/WEB-INF/lib directory.

Execute the Tests

Execute the compatibility tests as follows:

ProcedureTo Execute the Test

  1. Open a command window.

  2. At the prompt, type

    cd $WSHOME

    bin/lh com.sun.idm.testing.adapter.CompatibilitySuite -propsFile sample/compat/example.4/example.properties

    Your output should look similar to the following example:


    TestSuite: com.sun.idm.testing.adapter.CompatibilitySuite
    Starting internal database server ...
    DB Server @ jdbc:hsqldb:hsql://127.0.0.1:57022/idm
    Executing script /opt/build/dv207518/adapterTestsTemp/waveset/export/pipeline/./sample/
    compat/example.4/SimulatedCompatibilityConfig.bsh
    Importing results
    ’Create(com.sun.idm.testing.adapter.compatibility.Create)’ passed  (25 ms)
    ’Authenticate(com.sun.idm.testing.adapter.compatibility.AuthenticateUser)’ passed  (11 ms)
    ’DeleteExisting(com.sun.idm.testing.adapter.compatibility.DeleteExisting)’ passed  (5 ms)
    ’DeleteMissing(com.sun.idm.testing.adapter.compatibility.DeleteMissing)’ passed  (4 ms)
    ’UpdateExisting(com.sun.idm.testing.adapter.compatibility.UpdateExisting)’ passed  (4 ms)
    ’RenameExisting(com.sun.idm.testing.adapter.compatibility.RenameExisting)’ passed  (3 ms)
    ’EnableExisting(com.sun.idm.testing.adapter.compatibility.EnableExisting)’ passed  (11 ms)
    ’DisableExisting(com.sun.idm.testing.adapter.compatibility.DisableExisting)’ passed  (5 ms)
    ’Iterate(com.sun.idm.testing.adapter.compatibility.Iterate)’ passed  (22 ms)
    
    Tests run: 9, failures: 0, errors: 0, skipped: 0, Time elapsed: 11354 ms

What Happened

The DataProvider supplied an importScript property, which caused the SimulatedCompatibilityConfig.bsh script to run. This script returns an XML string that is imported into the repository as a configuration object. The script specified the necessary items, and the velocity template creates the string.

You can use one of the following methods to debug the import script:


Note –

This example used beanshell scripting, but you can also use Javascript.


Several beanshell helpers are provided in the sample/compat/beanshell directory to make scripting easier by using the Apache Velocity template engine.


Note –

Commented examples are included to help you use the beanshell helpers.


To use the templates, add the following code at the top of your beanshell script:


// import helpers
String wavesetHome = Util.getWavesetHome();

if(wavesetHome != null) {
    if ( wavesetHome.startsWith("file:" ) ) {
        wavesetHome = wavesetHome.substring("file:".length());
    }

    addClassPath(wavesetHome + "./sample/compat/");
}

importCommands("beanshell");

Using the helpers is optional.

When using a script, the only requirement is that the script must return a string containing XML. The script can access any of the parameters that were passed into the CompatibilitySuite using _params.

Where _params can contain any of the following properties.

Property  

Description 

adapter

Classname of the adapter to test 

dp

Name of a custom DataProvider 

importScript

Comma-separated list of paths to the scripts to execute 

Note: These scripts return a string of imported XML.

ns

DataProvider namespace 

includedTests

Comma-separated list of tests to include 

excludedTests

Comma-separated list of tests to exclude 

import

Comma-separated list of files to import 


Note –

These properties are not provided in the _params map unless you set them in the properties file or used the -D command from the command line to add these properties to the _params map.


In beanshell, you can use a call to params.get(“parameter_name”) to retrieve these parameters.

If the beanshell script needs to know how the namespace parameter was set so that the script could form the name of the configuration object, the parameter would be retrieved as follows:

String namespace = _params.get("ns");