mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Christophe Sovant
13.24.2008 6d2c064314b2099b55675ec04f8185a687754182
Add tests for SNMP feature
4 files deleted
16 files added
11 files modified
29238 ■■■■■ changed files
opendj-sdk/opends/tests/functional-tests/config/config.py 6 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/agent.security 52 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/manager.security 36 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/snmp_start.ldif 24039 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/staf-installer.xml 154 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/staf-installer/config.py.stubs 6 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/staf-installer/staf-installer.properties 2 ●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/runFuncTests.xml 6 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/setup/general_options.xml 28 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp.xml 98 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_cleanup.xml 138 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_setup.xml 281 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_trap_defaultconf.xml 334 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_v1_defaultconf.xml 222 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_v2c_defaultconf.xml 227 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_v3_defaultconf.xml 597 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/functions/environment.xml 3 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/functions/ldap.xml 11 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/functions/snmp.xml 453 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/functions/stafcmd.xml 162 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/functions/topology.xml 164 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/functions/utils.xml 118 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/addAnEntry.class patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/addAnEntry.java 187 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/ldap/addAnEntry.java 175 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/ldap/modifyAnAttribute.java 206 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/modifyAnAttribute.class patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/modifyAnAttribute.java 214 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/snmp/SNMPGet.java 519 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/snmp/SNMPSet.java 522 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/shared/java/snmp/SNMPTrapListener.java 278 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/functional-tests/config/config.py
@@ -62,3 +62,9 @@
WC_HOST                     = 'localhost'
DSML_WARNAME                = 'OpenDS-1.0.0-DSML.war'
DSML_WARPATH                = '%s/build/package/%s' % (OPENDSDIR, DSML_WARNAME)
SNMP_OPENDS_JARFILE         = '%s/%s/lib/extensions/snmp-mib2605.jar' % (TMPDIR, OPENDSNAME)
SNMP_OPENDMK_LIBDIR         = '/path/to/opendmk/lib'
SNMP_OPENDMK_JARFILE        = '%s/jdmkrt.jar' % SNMP_OPENDMK_LIBDIR
SNMP_PORT                   = '8085'
SNMP_TRAP_PORT              = '8086'
VERBOSE_MODE                = 'False'
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/agent.security
New file
@@ -0,0 +1,52 @@
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at
# trunk/opends/resource/legal-notices/OpenDS.LICENSE
# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at
# trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
# add the following below this CDDL HEADER, with the fields enclosed
# by brackets "[]" replaced with your own identifying information:
#      Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#      Copyright 2008 Sun Microsystems, Inc.
#
###############################################
## BEGIN: OpenDS default agent security file ##
###############################################
localEngineID=0x8000002a017f000001000000a1
localEngineBoots=0
# Admin User to use to add access controls for users
userEntry=localEngineID,snmpAdmin,null,usmHMACMD5AuthProtocol,passadmin
# User to clone no read or write acess
userEntry=localEngineID,defaultUser,,usmHMACMD5AuthProtocol,password,,,3,true
###############################################
## END: OpenDS default agent security file   ##
###############################################
#######################
## BEGIN: Test users ##
#######################
userEntry=localEngineID,myUser,,usmHMACMD5AuthProtocol,mypasswd
userEntry=localEngineID,myUser2,,usmHMACMD5AuthProtocol,mypasswd2
#######################
## END: Test users   ##
#######################
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/manager.security
New file
@@ -0,0 +1,36 @@
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at
# trunk/opends/resource/legal-notices/OpenDS.LICENSE
# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at
# trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
# add the following below this CDDL HEADER, with the fields enclosed
# by brackets "[]" replaced with your own identifying information:
#      Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#      Copyright 2008 Sun Microsystems, Inc.
#
# Local engine ID
localEngineID=0x8000002a017f00000100001f95
# Number of boots
localEngineBoots=0
# User and security configuration
userEntry=0x8000002a017f000001000000a1,snmpAdmin,null,usmHMACMD5AuthProtocol,passadmin
userEntry=0x8000002a017f000001000000a1,defaultUser,,usmHMACMD5AuthProtocol,password
userEntry=0x8000002a017f000001000000a1,myUser,,usmHMACMD5AuthProtocol,mypasswd
userEntry=0x8000002a017f000001000000a1,myUser2,,usmHMACMD5AuthProtocol,mypasswd2
opendj-sdk/opends/tests/functional-tests/shared/data/snmp/snmp_start.ldif
New file
Diff too large
opendj-sdk/opends/tests/functional-tests/staf-installer.xml
@@ -155,16 +155,51 @@
  </target>
  <target name="download-do-get-services"  unless="bits.services.downloaded.before">
    <if>
      <not>
        <available file="${bits.download.dir}/${bits.email.archive}" />
      </not>
      <then>
    <get src="${bits.download.url}/${bits.email.archive}" 
         dest="${bits.download.dir}/${bits.email.archive}" />
      </then>
    </if>
    <if>
      <not>
        <available file="${bits.download.dir}/${bits.event.archive}" />
      </not>
      <then>
    <get src="${bits.download.url}/${bits.event.archive}" 
         dest="${bits.download.dir}/${bits.event.archive}" />
      </then>
    </if>
    <if>
      <not>
        <available file="${bits.download.dir}/${bits.eventmanager.archive}" />
      </not>
      <then>
    <get src="${bits.download.url}/${bits.eventmanager.archive}" 
         dest="${bits.download.dir}/${bits.eventmanager.archive}" />
      </then>
    </if>
    <if>
      <not>
        <available file="${bits.download.dir}/${bits.stax.archive}" />
      </not>
      <then>
    <get src="${bits.download.url}/${bits.stax.archive}" 
         dest="${bits.download.dir}/${bits.stax.archive}" />
      </then>
    </if>
    <if>
      <not>
        <available file="${bits.download.dir}/${bits.http.archive}" />
      </not>
      <then>
    <get src="${bits.download.url}/${bits.http.archive}" 
         dest="${bits.download.dir}/${bits.http.archive}" />
      </then>
    </if>
    <property name="bits.services.downloaded" value="true" />
  </target>
  
@@ -176,6 +211,8 @@
        <or>
          <isset property="bits.staf.downloaded"/>
          <isset property="bits.staf.downloaded.before" />
        </or>
        <or>
          <isset property="bits.tomcat.downloaded"/>
          <isset property="bits.tomcat.downloaded.before" />
        </or>
@@ -469,9 +506,9 @@
  <target name="run-tests-build-pkg" 
    if="product.package.build" 
    depends="run-tests-get-pkg">
    <ant dir="${project.home}"
      antfile="${project.home}/build.xml"
      target="package"/>
      <ant antfile="${project.home}/build.xml"
           target="package"
           inheritAll="false"/>
  </target>
  
  <target name="run-tests-get-pkg">
@@ -480,9 +517,30 @@
               else="${project.home}/build/package">
       <isset property="tests.run.daily"/>
     </condition>
     <loadproperties srcFile="${project.home}/build.properties">
       <filterchain>
         <linecontains>
           <contains value="opendmk."/>
         </linecontains>
       </filterchain>
     </loadproperties>
     <loadproperties srcFile="${tests.config.stubs}">
       <filterchain>
         <linecontains>
           <contains value="SNMP_"/>
         </linecontains>
         <tokenfilter>
           <replacestring from="'" to=""/>
         </tokenfilter>
       </filterchain>
     </loadproperties>
     <!-- <echo>opendm.lib.dir=${opendmk.lib.dir}</echo> -->
     <!-- <echo>SNMP_OPENDMK_LIBDIR=${SNMP_OPENDMK_LIBDIR}</echo> -->
     <property name="product.package" 
               value="${product.package.dir}/${product.name}.zip"/>
     <condition property="product.package.build">
     <if>
       <and> 
         <not>
           <isset property="tests.run.daily"/>
@@ -491,7 +549,74 @@
           <available file="${product.package}"/>
         </not>
       </and>
     </condition>
       <then>
         <echo>Daily run not set and ${product.name}.zip not found.</echo>
         <if>
           <available file="${SNMP_OPENDMK_LIBDIR}/${SNMP_OPENDMK_JARFILE}" />
           <then>
             <!-- <echo>SNMP_OPENDMK_LIBDIR is set in ${tests.config.stubs}.</echo> -->
             <if>
               <length string="${opendmk.lib.dir}" when="equal" length="0" />
               <then>
                 <echo>SNMP_OPENDMK_LIBDIR is set in ${tests.config.stubs}.</echo>
                 <echo>opendmk.lib.dir is not set in ${project.home}/build.properties.</echo>
                 <echo>Update opendmk.lib.dir and build ${product.name}.zip with SNMP.</echo>
                 <replace file="${project.home}/build.properties"
                          value="opendmk.lib.dir=${SNMP_OPENDMK_LIBDIR}">
                   <replacefilter token="opendmk.lib.dir="/>
                 </replace>
                 <property name="product.package.build" value="true"/>
               </then>
             </if>
           </then>
           <else>
             <echo>SNMP_OPENDMK_LIBDIR is not set or is wrong in ${tests.config.stubs}.</echo>
             <echo>Build ${product.name}.zip without SNMP.</echo>
           </else>
         </if>
       </then>
       <else>
         <if>
           <available file="${product.package}"/>
           <then>
             <!-- <echo>${product.name}.zip found</echo> -->
             <if>
               <available file="${SNMP_OPENDMK_LIBDIR}/${SNMP_OPENDMK_JARFILE}" />
               <then>
                 <!-- <echo>SNMP_OPENDMK_LIBDIR is set in ${tests.config.stubs}.</echo> -->
                 <if>
                   <not>
                     <length string="${opendmk.lib.dir}" when="equal" length="0" />
                   </not>
                   <then>
                     <!-- <echo>opendmk.lib.dir is set in ${project.home}/build.properties.</echo> -->
                     <!-- <echo>Nothing to do.</echo> -->
                   </then>
                   <else>
                     <echo>SNMP_OPENDMK_LIBDIR is set in ${tests.config.stubs}.</echo>
                     <echo>opendmk.lib.dir is not set in ${project.home}/build.properties.</echo>
                     <echo>Update opendmk.lib.dir and build again ${product.name}.zip with SNMP.</echo>
                     <replace file="${project.home}/build.properties"
                              value="opendmk.lib.dir=${SNMP_OPENDMK_LIBDIR}">
                       <replacefilter token="opendmk.lib.dir="/>
                     </replace>
                     <property name="product.package.build" value="true"/>
                   </else>
                 </if>
               </then>
               <else>
                 <!-- <echo>SNMP_OPENDMK_LIBDIR is not set or is wrong in ${tests.config.stubs}.</echo> -->
                 <!-- <echo>Nothing to do.</echo> -->
               </else>
             </if>
           </then>
           <else>
             <!-- <echo>Daily run is set.</echo> -->
             <!-- <echo>Nothing to do.</echo> -->
           </else>
         </if>
       </else>
     </if>
  </target>
  <target name="run-tests-check" depends="run-tests-build-pkg">
@@ -588,7 +713,7 @@
    <fail message="Could not run the functional tests"/>
  </target>
  <target name="run-tests"
    depends="status-do,run-tests-check,run-tests-cant,run-tests-prepare,run-my-tests-default-plan"
    depends="run-my-tests-define,status-do,run-tests-check,run-tests-cant,run-tests-prepare,run-my-tests-default-plan"
    if="run-tests.proceed">
    <property name="tests.request" value="EXECUTE FILE ${tests.xml} JOBNAME OpenDS_Functional_Tests SCRIPTFILE ${tests.config} WAIT CLEARLOGS"/>
    <condition property="tests.replay.script" value="replay.bat" else="replay.sh">
@@ -621,10 +746,15 @@
    <move file="${tests.config.backup}" 
          tofile="${tests.config}"/>
    <echo file="${tests.run.dir}/last.run">${tests.run.time}</echo>
    <if>
      <available file="${staf.tmp.dir}/${product.name}/logs" />
      <then>
    <echo>Saving server logs</echo>
    <copy todir="${tests.run.dir}/${tests.run.time}/server-logs">
      <fileset dir="${staf.tmp.dir}/${product.name}/logs"/>
    </copy>
      </then>
    </if>
    <echo>Saving Staf/Stax logs</echo>
    <copy todir="${tests.run.dir}/${tests.run.time}/staf-logs">
      <fileset dir="${staf.home}/logs"/>
@@ -741,7 +871,7 @@
         <contains value='font size="+2'/>
        </linecontains>
        <tokenfilter>
          <replaceregex pattern=".*font size=.+2..(\d+)%./font.*" replace="test.percentage=\1"/>
          <replaceregex pattern=".*font size=.+2..(.*\d+)%./font.*" replace="test.percentage=\1"/>
        </tokenfilter>
      </filterchain>
    </copy>
@@ -884,7 +1014,7 @@
  <target name="daily-coverage" depends="coverage-on,run-daily,restore-pkg,coverage-report"/>
  
  <target name="testwithcoverage" depends="coverage-on,coverage-instrument,run-tests,restore-pkg,coverage-report"/>
  <target name="testwithcoverage" depends="run-my-tests-define,coverage-on,coverage-instrument,run-tests,restore-pkg,coverage-report"/>
<!-- Run tests section - bottom -->
  
<!-- Uninstallation section - top    -->
@@ -1049,7 +1179,13 @@
        <available file="${bits.download.dir}/${bits.staf.archive}"/>
      </condition>
      <condition property="bits.services.downloaded.before" >
        <and>
        <available file="${bits.download.dir}/${bits.stax.archive}" />
          <available file="${bits.download.url}/${bits.email.archive}" />
          <available file="${bits.download.url}/${bits.event.archive}" />
          <available file="${bits.download.url}/${bits.eventmanager.archive}" />
          <available file="${bits.download.url}/${bits.http.archive}" />
        </and>
      </condition>
      <condition property="bits.tomcat.downloaded.before">
        <available file="${bits.webcontainer.download.dir}/${bits.tomcat.archive}"/>
@@ -1136,7 +1272,7 @@
<!-- Status section - bottom -->
<!-- Macros section - top -->
  <target name="bootstrap">
  <target name="bootstrap" depends="run-my-tests-define">
    <antcall target="download"  />
    <antcall target="install"   />
    <antcall target="start"     />
opendj-sdk/opends/tests/functional-tests/staf-installer/config.py.stubs
@@ -62,3 +62,9 @@
WC_HOST                     = 'localhost'
DSML_WARNAME                = 'OpenDS-1.0.0-DSML.war'
DSML_WARPATH                = '%s/build/package/%s' % (OPENDSDIR, DSML_WARNAME)
SNMP_OPENDS_JARFILE         = '%s/%s/lib/extensions/snmp-mib2605.jar' % (TMPDIR, OPENDSNAME)
SNMP_OPENDMK_LIBDIR         = '/path/to/opendmk/lib'
SNMP_OPENDMK_JARFILE        = '%s/jdmkrt.jar' % SNMP_OPENDMK_LIBDIR
SNMP_PORT                   = '8085'
SNMP_TRAP_PORT              = '8086'
VERBOSE_MODE                = 'False'
opendj-sdk/opends/tests/functional-tests/staf-installer/staf-installer.properties
@@ -105,7 +105,7 @@
# Tests section - bottom
# test plan customization - top  <property name="test.plan.file" value="${basedir}/testcases/run-custom-suites.dat" />
test.plan.list=sample,main_security,main_aci,main_clu,main_privileges,main_dsconfig,main_backends,main_core,main_schema,main_replication,indexes,main_groups,main_logging,main_plugins,main_tasks,main_virtualAttributes,main_dsml,main_setup
test.plan.list=sample,main_security,main_aci,main_clu,main_privileges,main_dsconfig,main_backends,main_core,main_schema,main_replication,indexes,main_groups,main_logging,main_plugins,main_tasks,main_virtualAttributes,main_dsml,main_setup,main_snmp
test.plan.dir=testcases
test.plan.custom=${test.plan.dir}/run-custom-suites.dat
test.plan.default=${test.plan.dir}/run-default-suites.dat
opendj-sdk/opends/tests/functional-tests/testcases/runFuncTests.xml
@@ -143,6 +143,12 @@
      add keyword 'main_setup' in run-custom-suites.dat file to run this specific testsuite or run CLI : build run-my-tests
      -->
      <import machine="STAF_LOCAL_HOSTNAME"
              file="'%s/testcases/snmp/snmp.xml' % TESTS_DIR" />
      <!--
      add keyword 'main_snmp' in run-custom-suites.dat file to run this specific testsuite or run CLI : build run-my-tests
      -->
      <import machine="STAF_LOCAL_HOSTNAME"
              file="'%s/testcases/sample/sample.xml' % TESTS_DIR" />
      <script>
opendj-sdk/opends/tests/functional-tests/testcases/setup/general_options.xml
@@ -84,9 +84,7 @@
              'command'   : setupCmd,
              'arguments' : setupParams,
              'path'      : ODS_UNZIPPED,
              'expectedRC': 0,
              'outputPath': OUT_GROUP,
              'outputFile': 'go-setup-version.txt',
              'outputFile': '%s/go-setup-version.txt' % OUT_GROUP
            }
          </call>
@@ -97,8 +95,7 @@
          <call function="'grep'">
            { 'location'  : STAXServiceMachine,
              'filename'  : grepFile,
              'testString': 'OpenDS Directory Server',
              'expectedRC': 0,
              'testString': 'OpenDS Directory Server'
            }
          </call>
@@ -115,9 +112,7 @@
              'command'   : uninstallCmd,
              'arguments' : uninstallParams,
              'path'      : ODS_UNZIPPED,
              'expectedRC': 0,
              'outputPath': OUT_GROUP,
              'outputFile': 'go-uninstall-version.txt',
              'outputFile': '%s/go-uninstall-version.txt' % OUT_GROUP
            }
          </call>
@@ -128,8 +123,7 @@
          <call function="'grep'">
            { 'location'  : STAXServiceMachine,
              'filename'  : grepFile,
              'testString': 'OpenDS Directory Server',
              'expectedRC': 0,
              'testString': 'OpenDS Directory Server'
            }
          </call>
@@ -169,9 +163,7 @@
              'command'   : setupCmd,
              'arguments' : setupParams,
              'path'      : ODS_UNZIPPED,
              'expectedRC': 0,
              'outputPath': OUT_GROUP,
              'outputFile': 'go-setup-help.txt',
              'outputFile': '%s/go-setup-help.txt' % OUT_GROUP
            }
          </call>
@@ -182,8 +174,7 @@
          <call function="'grep'">
            { 'location'  : STAXServiceMachine,
              'filename'  : grepFile,
              'testString': 'Usage',
              'expectedRC': 0,
              'testString': 'Usage'
            }
          </call>
@@ -200,9 +191,7 @@
              'command'   : uninstallCmd,
              'arguments' : uninstallParams,
              'path'      : ODS_UNZIPPED,
              'expectedRC': 0,
              'outputPath': OUT_GROUP,
              'outputFile': 'go-uninstall-help.txt',
              'outputFile': '%s/go-uninstall-help.txt' % OUT_GROUP
            }
          </call>
@@ -213,8 +202,7 @@
          <call function="'grep'">
            { 'location'  : STAXServiceMachine,
              'filename'  : grepFile,
              'testString': 'Usage',
              'expectedRC': 0,
              'testString': 'Usage'
            }
          </call>
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp.xml
New file
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, exclude this CDDL HEADER in each
 ! file and exclude the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
! -->
<stax>
  <defaultcall function="main_snmp"/>
  <function name="main_snmp">
    <sequence>
      <block name="'snmp'">
        <sequence>
          <!--- Test Group information
            #@TestGroupName          SNMP tests
            #@TestGroupPurpose       Test the tools commands.
          -->
          <script>
            CurrentTestPath['group'] = 'snmp'
          </script>
          <call function="'testGroup_Preamble'"/>
          <!--- Activate the verbose mode -->
          <script>
            VERBOSE_MODE = 'True'
          </script>
          <script>
            STOP_RUN = 'False'
            testList = []
            testList.append(['.','snmp_setup'])
            testList.append(['.','snmp_v1_defaultconf'])
            testList.append(['.','snmp_v2c_defaultconf'])
            testList.append(['.','snmp_v3_defaultconf'])
            testList.append(['.','snmp_trap_defaultconf'])
            testList.append(['.','snmp_cleanup'])
          </script>
          <iterate var="_test" in="testList">
            <if expr="STOP_RUN == 'False'">
              <sequence>
                <import machine="STAF_LOCAL_HOSTNAME"
                        file="'%s/testcases/snmp/%s/%s.xml' %
                (TESTS_DIR,_test[0],_test[1])"/>
                <call function="'%s' % _test[1]" />
              </sequence>
            </if>
          </iterate>
          <!--- Desactivate the verbose mode -->
          <script>
            VERBOSE_MODE = 'False'
          </script>
          <call function="'testGroup_Postamble'"/>
        </sequence>
      </block>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_cleanup.xml
New file
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<stax>
  <defaultcall function="snmp_cleanup"/>
  <function name="snmp_cleanup">
    <sequence>
      <block name="'snmp_cleanup'">
        <sequence>
          <!--- Test Suite information
            #@TestSuiteName       cleanup
            #@TestSuitePurpose    Cleanup for the snmp test suite.
            #@TestSuiteGroup      cleanup
            #@TestScript          snmp_cleanup.xml
          -->
          <script>
            if not CurrentTestPath.has_key('group'):
              CurrentTestPath['group'] = 'snmp'
            CurrentTestPath['suite'] = STAXCurrentBlock
          </script>
          <call function="'testSuite_Preamble'"/>
          <!--- Test Case information
            #@TestMarker          cleanup
            #@TestName            cleanup: stop DS
            #@TestIssue           none
            #@TestPurpose         Stop DS.
            #@TestPreamble        none
            #@TestStep            Stop DS.
            #@TestPostamble       none
            #@TestResult          Success if StopDsWithScript returns 0.
          -->
          <testcase name="getTestCaseName('cleanup: stop DS')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'cleanup: stop DS running on port %s' \
                % (DIRECTORY_INSTANCE_PORT)
              </message>
              <call function="'StopDsWithScript'">
                {
                'location'  : STAF_REMOTE_HOSTNAME,
                'dsHost'    : DIRECTORY_INSTANCE_HOST,
                'dsPort'    : DIRECTORY_INSTANCE_PORT,
                'dsBindDN'  : DIRECTORY_INSTANCE_DN,
                'dsBindPwd' : DIRECTORY_INSTANCE_PSWD
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          cleanup
            #@TestName            cleanup: remove DS topology
            #@TestIssue           none
            #@TestPurpose         Remove the topology created for
                                  the test suite.
            #@TestPreamble        none
            #@TestStep            Remove the topology created for
                                  the test suite.
            #@TestPostamble       none
            #@TestResult          Success if removeTopology returns 0.
          -->
          <testcase name="getTestCaseName('cleanup: remove DS topology')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'cleanup: remove DS topology created for the test suite'
              </message>
              <call function="'removeTopology'"/>
              <call function="'checktestRC'">
                {
                'returncode' : RC ,
                'result'     : STAXResult
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <call function="'testSuite_Postamble'"/>
        </sequence>
      </block>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_setup.xml
New file
@@ -0,0 +1,281 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
! -->
<stax>
  <defaultcall function="snmp_setup" />
  <function name="snmp_setup">
    <sequence>
      <block name="'snmp_setup'">
        <sequence>
          <!--- Test Suite information
            #@TestSuiteName       setup
            #@TestSuitePurpose    Setup for the snmp test suite.
            #@TestSuiteGroup      setup
            #@TestScript          snmp_setup.xml
          -->
          <script>
            if not CurrentTestPath.has_key('group'):
              CurrentTestPath['group'] = 'snmp'
            CurrentTestPath['suite'] = STAXCurrentBlock
          </script>
          <call function="'testSuite_Preamble'"/>
          <!--- Define default value for manager -->
          <script>
            snmpPath    = '%s/../%s/snmp' % (dsPath,relativeJavaDir),
            opendmkPath = '%s/jdmkrt.jar' % snmpPath
          </script>
          <!--- Test Case information
            #@TestMarker          setup
            #@TestName            setup: create DS topology
            #@TestIssue           none
            #@TestPurpose         Create the topology necessary to the
                                  test suite.
            #@TestPreamble        none
            #@TestStep            Create DS topology as described in config.py.
            #@TestPostamble       none
            #@TestResult          Success if createTopology returns 0.
          -->
          <testcase name="getTestCaseName('setup: create DS tpology')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'setup: create DS topology as described in config.py'
              </message>
              <call function="'createTopology'">
                { 'initialiseInstance' : False }
              </call>
              <call function="'checktestRC'">
                {
                'returncode' : RC ,
                'result'     : STAXResult
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!-- Check if 'opendmkPath' already created -->
          <call function="'GetEntry'">
            {
            'location'  : STAF_REMOTE_HOSTNAME ,
            'entry'     : opendmkPath ,
            'attribute' : 'TYPE'
            }
          </call>
          <!-- 'opendmkPath' exists so we can continue -->
          <if expr="RC != 48">
            <sequence>
              <!--- Test Case information
               #@TestMarker          setup
               #@TestName            setup: add initial entries
               #@TestIssue           none
               #@TestPurpose         Load the data needed by the test suite.
               #@TestPreamble        none
               #@TestStep            Load the data needed by the test suite.
               #@TestPostamble       none
               #@TestResult          Success if importLdif returns 0.
              -->
              <testcase name="getTestCaseName('setup: add initial entries')">
                <sequence>
                  <call function="'testCase_Preamble'"/>
                  <message>
                    'setup: add initial entries'
                  </message>
                  <call function="'importLdif'">
                    {
                    'ldifFile'    : '%s/snmp/snmp_start.ldif'
                                    % logsRemoteDataDir
                    }
                  </call>
                  <call function="'testCase_Postamble'"/>
                </sequence>
              </testcase>
              <!--- Test Case information
                #@TestMarker          setup
                #@TestName            setup: start DS
                #@TestIssue           none
                #@TestPurpose         Start DS.
                #@TestPreamble        none
                #@TestStep            Start the server.
                #@TestStep            Check that the server is alive.
                #@TestPostamble       none
                #@TestResult          Success if StartDsWithScript returns 0.
              -->
              <testcase name="getTestCaseName('setup: start DS')">
                <sequence>
                  <call function="'testCase_Preamble'"/>
                  <message>
                    'setup: start DS to run on port %s' \
                    % (DIRECTORY_INSTANCE_PORT)
                  </message>
                  <!--- Start DS -->
                  <call function="'StartDsWithScript'">
                    { 'location' : STAF_REMOTE_HOSTNAME }
                  </call>
                  <!--- Check that DS started -->
                  <call function="'isAlive'">
                    {
                    'noOfLoops'        : 5 ,
                    'noOfMilliSeconds' : 2000
                    }
                  </call>
                  <call function="'testCase_Postamble'"/>
                </sequence>
              </testcase>
              <!--- Test Case information
                #@TestMarker          setup
                #@TestName            setup: enable SNMP Connection Handler
                #@TestIssue           none
                #@TestPurpose         Enable SNMP Connection Handler.
                #@TestPreamble        none
                #@TestStep            enable SNMP Connection Handler using
                                      dsconfig.
                #@TestPostamble       none
                #@TestResult          Success if dsconfig returns 0.
              -->
              <testcase name="getTestCaseName
              ('setup: enable SNMP Connection Handler')">
                <sequence>
                  <call function="'testCase_Preamble'"/>
                  <message>
                    'setup: enable SNMP Connection Handler'
                  </message>
                  <call function="'dsconfig'">
                    {
                    'dsInstanceHost'   : DIRECTORY_INSTANCE_HOST ,
                    'dsInstancePort'   : DIRECTORY_INSTANCE_PORT ,
                    'dsInstanceDn'     : DIRECTORY_INSTANCE_DN ,
                    'dsInstancePswd'   : DIRECTORY_INSTANCE_PSWD ,
                    'subcommand'       : 'set-connection-handler-prop' ,
                    'objectType'       : 'handler-name' ,
                    'objectName'       : 'SNMP Connection Handler' ,
                    'optionsString'    : '--set enabled:true \
                                          --set listen-port:%s \
                                          --set trap-port:%s \
                                          --set opendmk-jarfile:%s' \
                                     % (SNMP_PORT, SNMP_TRAP_PORT, opendmkPath)
                    }
                  </call>
                  <call function="'testCase_Postamble'"/>
                </sequence>
              </testcase>
            </sequence>
            <else>
              <sequence>
              <!--- Test Case information
                #@TestMarker          setup
                #@TestName            setup: enable SNMP Connection Handler
                #@TestIssue           none
                #@TestPurpose         Enable SNMP Connection Handler.
                #@TestPreamble        none
                #@TestStep            enable SNMP Connection Handler using
                                      dsconfig.
                #@TestPostamble       none
                #@TestResult          Success if dsconfig returns 0.
              -->
              <testcase name="getTestCaseName('setup: Warning')">
                <sequence>
                  <call function="'testCase_Preamble'"/>
                  <script>
                    STOP_RUN = 'True'
                  </script>
                  <message log="1" level="'Error'">
                    'WARNING: Check if SNMP_OPENDMK_LIBDIR is set \
                    in the config.py.stubs file.'
                  </message>
                  <tcstatus result="'fail'"></tcstatus>
                  <call function="'testCase_Postamble'"/>
                </sequence>
              </testcase>
              </sequence>
            </else>
          </if>
          <call function="'testSuite_Postamble'"/>
        </sequence>
      </block>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_trap_defaultconf.xml
New file
@@ -0,0 +1,334 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<stax>
  <defaultcall function="snmp_trap_defaultconf"/>
  <function name="snmp_trap_defaultconf">
    <sequence>
      <block name="'snmp_trap_defaultconf'">
        <sequence>
          <!--- Test Suite information
            #@TestSuiteName       SNMP trap with default configuration
            #@TestSuitePurpose    Check SNMP trap with default configuration.
            #@TestSuiteGroup      SNMP trap with default configuration
            #@TestScript          snmp_trap_defaultconf.xml
          -->
          <script>
            if not CurrentTestPath.has_key('group'):
              CurrentTestPath['group'] = 'snmp'
            CurrentTestPath['suite'] = STAXCurrentBlock
          </script>
          <call function="'testSuite_Preamble'"/>
          <!--- Test Case information
            #@TestMarker          SNMP trap with default configuration
            #@TestName            snmp_trap_defaultconf: trap on stop-ds
            #@TestIssue           3241
            #@TestPurpose         Check that a trap is sent on OpenDS trap
                                  community after stop-ds command.
            #@TestPreamble        none
            #@TestStep            Run the trap listener, it send an event to
                                  notify that it is ready.
            #@TestStep            When this event is received, stop-ds command
                                  is executed and a another event is sent to
                                  notify that the command is completed.
            #@TestStep            The trap listener catches this event and send
                                  a result.
            #@TestPostamble       none
            #@TestResult          Success if SNMPTrapListener returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_trap_defaultconf: trap on stop-ds')">
            <sequence>
              <parallel>
                <sequence>
                  <message>
                    'snmp_trap_defaultconf: run the trap listener'
                  </message>
                  <call function="'SNMPTrapListener'">
                    {
                    'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                    'snmpTrapPort'      : SNMP_TRAP_PORT ,
                    'snmpTrapCommunity' : 'OpenDS' ,
                    'snmpTrapNumber'    : '1,0,0,0,0,0'
                    }
                  </call>
                </sequence>
                <sequence>
                  <message>
                    'snmp_trap_defaultconf: wait event from the trap listener'
                  </message>
                  <call function="'WaitEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SNMPTrapLister/Ready'
                    }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: delete event from the trap listener'
                  </message>
                  <call function="'DeleteEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SNMPTrapLister/Ready'
                    }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: stop the server'
                  </message>
                  <call function="'StopDsWithScript'">
                    { 'location' : STAF_REMOTE_HOSTNAME }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: send event to the trap listener'
                  </message>
                  <call function="'SendEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SendTrap/Complete'
                    }
                  </call>
                </sequence>
              </parallel>
              <script>
                knownIssue(3241)
              </script>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP trap with default configuration
            #@TestName            snmp_trap_defaultconf: trap on start-ds
            #@TestIssue           3241
            #@TestPurpose         Check that a trap is sent on OpenDS trap
                                  community after start-ds command.
            #@TestPreamble        none
            #@TestStep            Run the trap listener, it send an event to
                                  notify that it is ready.
            #@TestStep            When this event is received, start-ds command
                                  is executed and a another event is sent to
                                  notify that the command is completed.
            #@TestStep            The trap listener catches this event and send
                                  a result.
            #@TestPostamble       none
            #@TestResult          Success if SNMPTrapListener returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_trap_defaultconf: trap on start-ds')">
            <sequence>
              <parallel>
                <sequence>
                  <message>
                    'snmp_trap_defaultconf: run the trap listener'
                  </message>
                  <call function="'SNMPTrapListener'">
                    {
                    'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                    'snmpTrapPort'      : SNMP_TRAP_PORT ,
                    'snmpTrapCommunity' : 'OpenDS' ,
                    'snmpTrapNumber'    : '1,0,0,0,0,0'
                    }
                  </call>
                </sequence>
                <sequence>
                  <message>
                    'snmp_trap_defaultconf: wait event from the trap listener'
                  </message>
                  <call function="'WaitEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SNMPTrapLister/Ready'
                    }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: delete event from the trap listener'
                  </message>
                  <call function="'DeleteEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SNMPTrapLister/Ready'
                    }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: start the server'
                  </message>
                  <call function="'StartDsWithScript'">
                    { 'location' : STAF_REMOTE_HOSTNAME }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: send event to the trap listener'
                  </message>
                  <call function="'SendEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SendTrap/Complete'
                    }
                  </call>
                </sequence>
              </parallel>
              <script>
                knownIssue(3241)
              </script>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP trap with default configuration
            #@TestName            snmp_trap_defaultconf: trap on stop-ds -R
            #@TestIssue           3241
            #@TestPurpose         Check that 2 traps are sent on OpenDS trap
                                  community after stop-ds -R command.
            #@TestPreamble        none
            #@TestStep            Run the trap listener, it send an event to
                                  notify that it is ready.
            #@TestStep            When this event is received, stop-ds -R
                                  command is executed and a another event is
                                  sent to notify that the command is completed.
            #@TestStep            The trap listener catches this event and send
                                  a result.
            #@TestPostamble       none
            #@TestResult          Success if SNMPTrapListener returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_trap_defaultconf: trap on stop-ds -R')">
            <sequence>
              <parallel>
                <sequence>
                  <message>
                    'snmp_trap_defaultconf: run the trap listener'
                  </message>
                  <call function="'SNMPTrapListener'">
                    {
                    'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                    'snmpTrapPort'      : SNMP_TRAP_PORT ,
                    'snmpTrapCommunity' : 'OpenDS' ,
                    'snmpTrapNumber'    : '2,0,0,0,0,0'
                    }
                  </call>
                </sequence>
                <sequence>
                  <message>
                    'snmp_trap_defaultconf: wait event from the trap listener'
                  </message>
                  <call function="'WaitEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SNMPTrapLister/Ready'
                    }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: delete event from the trap listener'
                  </message>
                  <call function="'DeleteEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SNMPTrapLister/Ready'
                    }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: restart the server'
                  </message>
                  <call function="'StopDsWithScript'">
                    {
                    'location'  : STAF_REMOTE_HOSTNAME ,
                    'dsRestart' : 'True'
                    }
                  </call>
                  <message>
                    'snmp_trap_defaultconf: send event to the trap listener'
                  </message>
                  <call function="'SendEvent'">
                    {
                    'location' : STAF_REMOTE_HOSTNAME ,
                    'name'     : 'SendTrap/Complete'
                    }
                  </call>
                </sequence>
              </parallel>
              <script>
                knownIssue(3241)
              </script>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <call function="'testSuite_Postamble'"/>
        </sequence>
      </block>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_v1_defaultconf.xml
New file
@@ -0,0 +1,222 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<stax>
  <defaultcall function="snmp_v1_defaultconf"/>
  <function name="snmp_v1_defaultconf">
    <sequence>
      <block name="'snmp_v1_defaultconf'">
        <sequence>
          <!--- Test Suite information
            #@TestSuiteName       SNMP v1 with default configuration
            #@TestSuitePurpose    Check SNMP v1 with default configuration.
            #@TestSuiteGroup      SNMP v1 with default configuration
            #@TestScript          snmp_v1_defaultconf.xml
          -->
          <script>
            if not CurrentTestPath.has_key('group'):
              CurrentTestPath['group'] = 'snmp'
            CurrentTestPath['suite'] = STAXCurrentBlock
          </script>
          <call function="'testSuite_Preamble'"/>
          <!--- Test Case information
            #@TestMarker          SNMP v1 with default configuration
            #@TestName            snmp_v1_defaultconf: get with OpenDS@OpenDS
                                  commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with
                                  OpenDS@OpenDS community succeeds.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v1_defaultconf: get with OpenDS@OpenDS commnunity')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v1_defaultconf: get with OpenDS@OpenDS community'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'   : '1',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS@OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'noError'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v1 with default configuration
            #@TestName            snmp_v1_defaultconf: get with wrong commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with wrong
                                  community fails with noSuchName.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v1_defaultconf: get with wrong community')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v1_defaultconf: get with wrong community'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'   : '1',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'noSuchName'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v1 with default configuration
            #@TestName            snmp_v1_defaultconf: set with OpenDS@OpenDS
                                  commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with
                                  OpenDS@OpenDS community fails with noSuchName.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v1_defaultconf: set with OpenDS@OpenDS community')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v1_defaultconf: set with OpenDS@OpenDS community'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'   : '1',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS@OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'noSuchName'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v1 with default configuration
            #@TestName            snmp_v1_defaultconf: set with wrong commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with wrong
                                  community fails with noSuchName.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v1_defaultconf: set with wrong community')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v1_defaultconf: set with wrong community'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'   : '1',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'noSuchName'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <call function="'testSuite_Postamble'"/>
        </sequence>
      </block>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_v2c_defaultconf.xml
New file
@@ -0,0 +1,227 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<stax>
  <defaultcall function="snmp_v2c_defaultconf"/>
  <function name="snmp_v2c_defaultconf">
    <sequence>
      <block name="'snmp_v2c_defaultconf'">
        <sequence>
          <!--- Test Suite information
            #@TestSuiteName       SNMP v2c with default configuration
            #@TestSuitePurpose    Check SNMP v2c with default configuration.
            #@TestSuiteGroup      SNMP v2c with default configuration
            #@TestScript          snmp_v2c_defaultconf.xml
          -->
          <script>
            if not CurrentTestPath.has_key('group'):
              CurrentTestPath['group'] = 'snmp'
            CurrentTestPath['suite'] = STAXCurrentBlock
          </script>
          <call function="'testSuite_Preamble'"/>
          <!--- Test Case information
            #@TestMarker          SNMP v2c with default configuration
            #@TestName            snmp_v2c_defaultconf: get with OpenDS@OpenDS
                                  commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with
                                  OpenDS@OpenDS community succeeds.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v2c_defaultconf: get with default commnunity')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v2c_defaultconf: get with OpenDS@OpenDS community'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'   : '2',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS@OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'noError'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v2c with default configuration
            #@TestName            snmp_v2c_defaultconf: get with wrong
                                  commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with wrong
                                  community succeeds but the OIDs values are
                                  not correct.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v2c_defaultconf: get with wrong community')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v2c_defaultconf: get with wrong community'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'   : '2',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'noError' ,
                'snmpValidOIDs' : 'False'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v2c with default configuration
            #@TestName            snmp_v2c_defaultconf: set with OpenDS@OpenDS
                                  commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with
                                  OpenDS@OpenDS community fails with
                                  authorizationError.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v2c_defaultconf: set with OpenDS@OpenDS community')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v2c_defaultconf: set with OpenDS@OpenDS community'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'   : '2',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS@OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'authorizationError'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v2c with default configuration
            #@TestName            snmp_v2c_defaultconf: set with wrong
                                  commnunity
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with wrong
                                  community fails with noAccess.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v2c_defaultconf: set with wrong community')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v2c_defaultconf: set with wrong community'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'   : '2',
                'snmpHost'      : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'      : SNMP_PORT ,
                'snmpCommunity' : 'OpenDS' ,
                'snmpOIDs'      : 'dsServerType.1' ,
                'snmpStatus'    : 'noAccess'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <call function="'testSuite_Postamble'"/>
        </sequence>
      </block>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/functional-tests/testcases/snmp/snmp_v3_defaultconf.xml
New file
@@ -0,0 +1,597 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../../shared/stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<stax>
  <defaultcall function="snmp_v3_defaultconf"/>
  <function name="snmp_v3_defaultconf">
    <sequence>
      <block name="'snmp_v3_defaultconf'">
        <sequence>
          <!--- Test Suite information
            #@TestSuiteName       SNMP v3 with default configuration
            #@TestSuitePurpose    Check SNMP v3 with default configuration.
            #@TestSuiteGroup      SNMP v3 with default configuration
            #@TestScript          snmp_v3_defaultconf.xml
          -->
          <script>
            if not CurrentTestPath.has_key('group'):
              CurrentTestPath['group'] = 'snmp'
            CurrentTestPath['suite'] = STAXCurrentBlock
          </script>
          <call function="'testSuite_Preamble'"/>
          <!--- Define default value for securityFile -->
          <script>
            securityFile = '%s/snmp/manager.security' % logsRemoteDataDir
          </script>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: get with snmpAdmin user
                                  and OpenDS context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with snmpAdmin
                                  user and OpenDS context fails with
                                  authorizationError.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: get with snmpAdmin and OpenDS context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: get with snmpAdmin and OpenDS context'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'snmpAdmin' ,
                'snmpCommunity'     : 'OpenDS' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'authorizationError'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: get with snmpAdmin user
                                  and default context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with snmpAdmin
                                  user and default context succeeds but the OIDs
                                  values are not correct.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: get with snmpAdmin and default context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: get with snmpAdmin and default context'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'snmpAdmin' ,
                'snmpCommunity'     : 'default' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'noError' ,
                'snmpValidOIDs'     : 'False'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: det with snmpAdmin user
                                  and OpenDS context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with snmpAdmin
                                  user and OpenDS context fails with
                                  authorizationError.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: set with snmpAdmin and OpenDS context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: set with snmpAdmin and OpenDS context'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'snmpAdmin' ,
                'snmpCommunity'     : 'OpenDS' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'authorizationError'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: set with snmpAdmin user
                                  and default context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with snmpAdmin
                                  user and default context fails with noAccess.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: set with snmpAdmin and default context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: set with snmpAdmin and default context'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'snmpAdmin' ,
                'snmpCommunity'     : 'default' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'noAccess'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: get with defaultUser user
                                  and OpenDS context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with defaultUser
                                  user and OpenDS context fails with
                                  authorizationError.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: get with defaultUser and OpenDS context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: get with defaultUser and OpenDS context'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'defaultUser' ,
                'snmpCommunity'     : 'OpenDS' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'authorizationError'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: get with defaultUser user
                                  and default context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with defaultUser
                                  user and default context succeeds but the OIDs
                                  values are not correct.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: get with defaultUser and default context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: get with defaultUser and default context'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'defaultUser' ,
                'snmpCommunity'     : 'default' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'noError' ,
                'snmpValidOIDs'     : 'False'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: set with defaultUser user
                                  and OpenDS context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with defaultUser
                                  user and OpenDS context fails with
                                  authorizationError.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: set with defaultUser and OpenDS context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: set with defaultUser and OpenDS context'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'defaultUser' ,
                'snmpCommunity'     : 'OpenDS' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'authorizationError'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: set with defaultUser user
                                  and default context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with defaultUser
                                  user and default context fails with noAccess.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: set with defaultUser and default context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: set with defaultUser and default context'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'defaultUser' ,
                'snmpCommunity'     : 'default' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'noAccess'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: get with unknown user
                                  and OpenDS context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with unknown
                                  user and OpenDS context fails with
                                  SnmpStatusException.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: get with unknown user and OpenDS context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: get with unknown user and OpenDS context'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'myUser' ,
                'snmpCommunity'     : 'OpenDS' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'SnmpStatusException'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: get with unknown user
                                  and default context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Get request with unknown
                                  user and default context fails with
                                  SnmpStatusException.
            #@TestPreamble        none
            #@TestStep            SNMP Get request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPGet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: get with unknown user and default context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: get with unknown user and default context'
              </message>
              <call function="'SNMPGet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'myUser' ,
                'snmpCommunity'     : 'default' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'SnmpStatusException'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: set with unknown user
                                  and OpenDS context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with unknown
                                  user and OpenDS context fails with
                                  SnmpStatusException.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: set with unknown user and OpenDS context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: set with unknown user and OpenDS context'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'myUser' ,
                'snmpCommunity'     : 'OpenDS' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'SnmpStatusException'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <!--- Test Case information
            #@TestMarker          SNMP v3 with default configuration
            #@TestName            snmp_v3_defaultconf: set with unknown user
                                  and default context
            #@TestIssue           none
            #@TestPurpose         Check that a SNMP Set request with unknown
                                  user and default context fails with
                                  SnmpStatusException.
            #@TestPreamble        none
            #@TestStep            SNMP Set request.
            #@TestPostamble       none
            #@TestResult          Success if SNMPSet returns 0.
          -->
          <testcase name="getTestCaseName
          ('snmp_v3_defaultconf: set with unknown user and default context')">
            <sequence>
              <call function="'testCase_Preamble'"/>
              <message>
                'snmp_v3_defaultconf: set with unknown user and default context'
              </message>
              <call function="'SNMPSet'">
                {
                'snmpVersion'       : '3',
                'snmpHost'          : DIRECTORY_INSTANCE_HOST ,
                'snmpPort'          : SNMP_PORT ,
                'snmpUser'          : 'myUser' ,
                'snmpCommunity'     : 'default' ,
                'snmpSecurityLevel' : 'AuthNoPriv' ,
                'snmpSecurityFile'  : securityFile ,
                'snmpOIDs'          : 'dsServerType.1' ,
                'snmpStatus'        : 'SnmpStatusException'
                }
              </call>
              <call function="'testCase_Postamble'"/>
            </sequence>
          </testcase>
          <call function="'testSuite_Postamble'"/>
        </sequence>
      </block>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/shared/functions/environment.xml
@@ -70,6 +70,9 @@
        
      <import machine="STAF_LOCAL_HOSTNAME"
        file="'%s/webcontainer.xml' % (TESTS_FUNCTIONS_DIR)" />
      <import machine="STAF_LOCAL_HOSTNAME"
        file="'%s/snmp.xml' % (TESTS_FUNCTIONS_DIR)" />
        
  </sequence>  
      
opendj-sdk/opends/tests/shared/functions/ldap.xml
@@ -1098,8 +1098,7 @@
          'command'   : STAFCmd,
          'arguments' : STAFCmdParams,
          'location'  : location,
          'outputFile': outputFile,
          'outputPath': outputPath,
          'outputFile': '%s/%s' % (outputPath, outputFile) ,
          'expectedRC': expectedRC ,
          'logStderr' : logStderr
        }
@@ -2716,8 +2715,8 @@
          'command'   : '%s/bin/java' % JAVA_HOME,
          'arguments' : '%s %s' % (STAFCmd,STAFCmdParams),
          'location'  : location,
          'path'      : '%s/../%s' % (dsPath,relativeJavaDir),
          'env'       : ['PATH=/bin:/usr/bin:%s/bin' % dsPath, 'JAVA_HOME=%s' % JAVA_HOME,'CLASSPATH=%s/../%s' % (dsPath,relativeJavaDir)],
          'path'      : '%s/../%s/ldap' % (dsPath,relativeJavaDir),
          'env'       : ['PATH=/bin:/usr/bin:%s/bin' % dsPath, 'JAVA_HOME=%s' % JAVA_HOME,'CLASSPATH=%s/../%s/ldap' % (dsPath,relativeJavaDir)],
          'expectedRC': expectedRC
        }
      </call>
@@ -2959,8 +2958,8 @@
          'command'   : '%s/bin/java' % JAVA_HOME,
          'arguments' : '%s %s' % (STAFCmd,STAFCmdParams),
          'location'  : location,
          'env'       : ['PATH=/bin:/usr/bin:%s/bin' % dsPath, 'JAVA_HOME=%s' % JAVA_HOME,'CLASSPATH=%s/../%s' % (dsPath,relativeJavaDir)],
          'path'      : '%s/../%s' % (dsPath,relativeJavaDir),
          'env'       : ['PATH=/bin:/usr/bin:%s/bin' % dsPath, 'JAVA_HOME=%s' % JAVA_HOME,'CLASSPATH=%s/../%s/ldap' % (dsPath,relativeJavaDir)],
          'path'      : '%s/../%s/ldap' % (dsPath,relativeJavaDir),
          'expectedRC': expectedRC
        }
      </call>
opendj-sdk/opends/tests/shared/functions/snmp.xml
New file
@@ -0,0 +1,453 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../stax.dtd">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
! -->
<stax>
  <!-- SNMP Get -->
  <function name="SNMPGet" scope="local">
    <function-prolog>
      This function performs a SNMP get request
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="snmpVersion" type="required">
        <function-arg-description>
          SNMP request version
        </function-arg-description>
        <function-arg-property name="type" value="version" />
      </function-arg-def>
      <function-arg-def name="snmpHost"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Directory server SNMP hostname or IP address
        </function-arg-description>
        <function-arg-property name="type" value="hostname" />
      </function-arg-def>
      <function-arg-def name="snmpPort" type="required">
        <function-arg-description>
          Directory server SNMP port number
        </function-arg-description>
        <function-arg-property name="type" value="Port number"/>
      </function-arg-def>
      <function-arg-def name="snmpOIDs" type="optional">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpCommunity" type="required">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
      </function-arg-def>
      <function-arg-def name="snmpUser" type="optional">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
      </function-arg-def>
      <function-arg-def name="snmpSecurityLevel" type="optional">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
      </function-arg-def>
      <function-arg-def name="snmpSecurityFile" type="optional">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpStatus" type="required">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpValidOIDs" type="optional">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value. Default value is 0
          Wildcard 'noCheck' to not check the RC
        </function-arg-description>
        <function-arg-property name="type" value="integer"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <!-- Build the command -->
      <script>
        STAFCmdParamsList=[]
        STAFCmdParams=''
        if snmpVersion:
          STAFCmdParamsList.append('-v %s' % snmpVersion)
        if snmpHost:
          STAFCmdParamsList.append('-h %s' % snmpHost)
        if snmpPort:
          STAFCmdParamsList.append('-p %s' % snmpPort)
        if snmpOIDs:
          STAFCmdParamsList.append('-o %s' % snmpOIDs)
        if snmpCommunity:
          STAFCmdParamsList.append('-c %s' % snmpCommunity)
        if snmpUser:
          STAFCmdParamsList.append('-u %s' % snmpUser)
        if snmpSecurityLevel:
          STAFCmdParamsList.append('-l %s' % snmpSecurityLevel)
        if snmpSecurityFile:
          STAFCmdParamsList.append('-f %s' % snmpSecurityFile)
        if snmpStatus:
          STAFCmdParamsList.append('-s %s' % snmpStatus)
        if snmpValidOIDs:
          STAFCmdParamsList.append('-n %s' % snmpValidOIDs)
        STAFCmdParams=' '.join(STAFCmdParamsList)
        STAFCmd='SNMPGet'
        snmpPath = '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir)
        cp = 'CLASSPATH=%s:%s/jdmkrt.jar:.' % (SNMP_OPENDS_JARFILE, snmpPath)
        if isWindows:
          cp = cp.replace(':', ';')
        env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp]
      </script>
      <message>
        '%s %s' % (STAFCmd, STAFCmdParams)
      </message>
      <call function="'runCommand'" >
        {
        'name'       : 'SNMP Get' ,
        'command'    : '%s/bin/java' % JAVA_HOME ,
        'arguments'  : '%s %s' % (STAFCmd, STAFCmdParams) ,
        'location'   : location ,
        'path'       : '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir),
        'env'        : env ,
        'expectedRC' : expectedRC
        }
      </call>
      <return>
        STAXResult
      </return>
    </sequence>
  </function>
  <!-- SNMP Set -->
  <function name="SNMPSet" scope="local">
    <function-prolog>
      This function performs a SNMP Set request
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="snmpVersion" type="required">
        <function-arg-description>
          SNMP request version
        </function-arg-description>
        <function-arg-property name="type" value="version" />
      </function-arg-def>
      <function-arg-def name="snmpHost"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Directory server SNMP hostname or IP address
        </function-arg-description>
        <function-arg-property name="type" value="hostname" />
      </function-arg-def>
      <function-arg-def name="snmpPort" type="required">
        <function-arg-description>
          Directory server SNMP port number
        </function-arg-description>
        <function-arg-property name="type" value="Port number"/>
      </function-arg-def>
      <function-arg-def name="snmpOIDs" type="optional">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpCommunity" type="required">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
      </function-arg-def>
      <function-arg-def name="snmpUser" type="optional">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
      </function-arg-def>
      <function-arg-def name="snmpSecurityLevel" type="optional">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
      </function-arg-def>
      <function-arg-def name="snmpSecurityFile" type="optional">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpStatus" type="required">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="snmpValidOIDs" type="optional">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value. Default value is 0
          Wildcard 'noCheck' to not check the RC
        </function-arg-description>
        <function-arg-property name="type" value="integer"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <!-- Build the command -->
      <script>
        STAFCmdParamsList=[]
        STAFCmdParams=''
        if snmpVersion:
          STAFCmdParamsList.append('-v %s' % snmpVersion)
        if snmpHost:
          STAFCmdParamsList.append('-h %s' % snmpHost)
        if snmpPort:
          STAFCmdParamsList.append('-p %s' % snmpPort)
        if snmpOIDs:
          STAFCmdParamsList.append('-o %s' % snmpOIDs)
        if snmpCommunity:
          STAFCmdParamsList.append('-c %s' % snmpCommunity)
        if snmpUser:
          STAFCmdParamsList.append('-u %s' % snmpUser)
        if snmpSecurityLevel:
          STAFCmdParamsList.append('-l %s' % snmpSecurityLevel)
        if snmpSecurityFile:
          STAFCmdParamsList.append('-f %s' % snmpSecurityFile)
        if snmpStatus:
          STAFCmdParamsList.append('-s %s' % snmpStatus)
        if snmpValidOIDs:
          STAFCmdParamsList.append('-n %s' % snmpValidOIDs)
        STAFCmdParams=' '.join(STAFCmdParamsList)
        STAFCmd='SNMPSet'
        snmpPath = '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir)
        cp = 'CLASSPATH=%s:%s/jdmkrt.jar:.' % (SNMP_OPENDS_JARFILE, snmpPath)
        if isWindows:
          cp = cp.replace(':', ';')
        env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp]
      </script>
      <message>
        '%s %s' % (STAFCmd, STAFCmdParams)
      </message>
      <call function="'runCommand'" >
        {
        'name'       : 'SNMP Set' ,
        'command'    : '%s/bin/java' % JAVA_HOME ,
        'arguments'  : '%s %s' % (STAFCmd, STAFCmdParams) ,
        'location'   : location ,
        'path'       : '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir),
        'env'        : env ,
        'expectedRC' : expectedRC
        }
      </call>
      <return>
        STAXResult
      </return>
    </sequence>
  </function>
  <!-- SNMP Trap listener -->
  <function name="SNMPTrapListener" scope="local">
    <function-prolog>
      This function performs a SNMP Set request
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAF_REMOTE_HOSTNAME">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="snmpHost" type="required">
        <function-arg-description>
          Directory server SNMP port number
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="snmpTrapPort" type="required">
        <function-arg-description>
          Directory server SNMP port number
        </function-arg-description>
        <function-arg-property name="type" value="Port number"/>
      </function-arg-def>
      <function-arg-def name="snmpTrapCommunity" type="required">
        <function-arg-description>
          Bind DN
        </function-arg-description>
        <function-arg-property name="type" value="DN"/>
      </function-arg-def>
      <function-arg-def name="snmpTrapNumber" type="required">
        <function-arg-description>
          Bind password
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value. Default value is 0
          Wildcard 'noCheck' to not check the RC
        </function-arg-description>
        <function-arg-property name="type" value="integer"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <call function="'ResolveVar'" >
        {
        'location' : location ,
        'type'     : 'STRING',
        'name'     : 'STAF/Env/LD_LIBRARY_PATH'
        }
      </call>
      <script>jstaf_jarfile = '%s/JSTAF.jar' % STAFResult</script>
      <!-- Build the command -->
      <script>
        STAFCmdParamsList=[]
        STAFCmdParams=''
        if snmpHost:
          STAFCmdParamsList.append('-h %s' % snmpHost)
        if snmpTrapPort:
          STAFCmdParamsList.append('-p %s' % snmpTrapPort)
        if snmpTrapCommunity:
          STAFCmdParamsList.append('-c %s' % snmpTrapCommunity)
        if snmpTrapNumber:
          STAFCmdParamsList.append('-t %s' % snmpTrapNumber)
        STAFCmdParams=' '.join(STAFCmdParamsList)
        STAFCmd='SNMPTrapListener'
        snmpPath = '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir)
        cp = 'CLASSPATH=%s:%s/jdmkrt.jar:%s:.' \
        % (SNMP_OPENDS_JARFILE, snmpPath, jstaf_jarfile)
        if isWindows:
          cp = cp.replace(':', ';')
        env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp]
      </script>
      <message>
        '%s %s' % (STAFCmd, STAFCmdParams)
      </message>
      <call function="'runCommand'" >
        {
        'name'       : 'SNMP Trap Listener' ,
        'command'    : '%s/bin/java' % JAVA_HOME ,
        'arguments'  : '%s %s' % (STAFCmd, STAFCmdParams) ,
        'location'   : location ,
        'path'       : '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir),
        'env'        : env ,
        'expectedRC' : expectedRC
        }
      </call>
      <return>
        STAXResult
      </return>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/shared/functions/stafcmd.xml
@@ -558,7 +558,7 @@
        </function-arg-description>
        <function-arg-property name="type" value="variable"/>
      </function-arg-def>       
      <function-arg-def name="string" type="required">
      <function-arg-def name="name" type="required">
        <function-arg-description>
          Name of string to be resolved
        </function-arg-description>
@@ -568,12 +568,12 @@
    <sequence>
      <message>'Resolve %s Variable %s' % (type,string)</message>
      <message>'Resolve %s Variable %s' % (type, name)</message>
            
      <stafcmd name="'STAF Command: Resolve Var.'">
        <location>'%s' % location</location>
        <service>'var'</service>
        <request>'RESOLVE %s STRING {%s}' % (type,string)</request>
        <request>'RESOLVE %s {%s}' % (type, name)</request>
      </stafcmd>
    </sequence>
@@ -679,6 +679,64 @@
  </function>   
<!-- List a folder by extension -->
  <function name="listFolderByExtension" scope="local">
    <function-prolog>
        This function lists a folder by extension
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location" type="optional" default="STAXServiceMachine">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="foldername" type="required">
        <function-arg-description>
          Name of folder to be list
        </function-arg-description>
        <function-arg-property name="type" value="filepath"/>
    </function-arg-def>
      <function-arg-def name="extension" type="required">
        <function-arg-description>
          he name of the file extension (default txt)
        </function-arg-description>
        <function-arg-property name="type" value="file extension"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <stafcmd name="'STAF Command: list folder by extension'">
        <location>'%s' % location</location>
        <service>'fs'</service>
        <request>' LIST DIRECTORY %s EXT %s ' % (foldername,extension)</request>
      </stafcmd>
      <script>
        cmdRC=RC
        cmdResult=STAFResult
      </script>
      <if expr="cmdRC != 0">
        <sequence>
          <script>
            cmdResult = 'Folder does not exist.'
          </script>
        </sequence>
      </if>
      <call function="'checkRC'">
        {
        'returncode' : cmdRC ,
        'result'     : cmdResult
        }
      </call>
      <return>cmdResult</return>
    </sequence>
  </function>
  <function name="getFile">
    <function-prolog>
      This function get the contents of a file
@@ -725,4 +783,102 @@
    </sequence>
  </function>
    
  <!-- Send event -->
  <function name="SendEvent">
    <function-prolog>
      Send event.
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAXServiceMachine">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="name" type="required">
        <function-arg-description>
          Name of event to send
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <message>'Send Event %s on %s' % (name, location)</message>
      <stafcmd name="'STAF Command: Send Event.'">
        <location>'%s' % location</location>
        <service>'sem'</service>
        <request>'PULSE EVENT %s' % name</request>
      </stafcmd>
    </sequence>
  </function>
  <!-- Wait event -->
  <function name="WaitEvent">
    <function-prolog>
      Wait event.
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAXServiceMachine">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="name" type="required">
        <function-arg-description>
          Name of event to wait
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <message>'Wait Event %s on %s' % (name, location)</message>
      <stafcmd name="'STAF Command: Wait Event.'">
        <location>'%s' % location</location>
        <service>'sem'</service>
        <request>'WAIT EVENT %s' % name</request>
      </stafcmd>
    </sequence>
  </function>
  <!-- Delete event -->
  <function name="DeleteEvent">
    <function-prolog>
      Delete event.
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAXServiceMachine">
        <function-arg-description>
          Location of target host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="name" type="required">
        <function-arg-description>
          Name of event to delete
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <message>'Delete Event %s on %s' % (name, location)</message>
      <stafcmd name="'STAF Command: Delete Event.'">
        <location>'%s' % location</location>
        <service>'sem'</service>
        <request>'DELETE EVENT %s' % name</request>
      </stafcmd>
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/shared/functions/topology.xml
@@ -256,21 +256,170 @@
            }
          </call>          
          
          <!-- Archive java (.class) files -->
          <!-- Archive (ldap/.java) files -->
          <script>
            javaSharedDir='%s' % (TESTS_JAVA_DIR)
            javaLocalDir='%s/shared/java' % (logsTestDataDir)
            javaSharedDir='%s/ldap' % (TESTS_JAVA_DIR)
            javaLocalDir='%s/shared/java/ldap' % (logsTestDataDir)
          </script>
          <message>
            'Copy java class files locally to %s.' % javaLocalDir
            'Copy java files locally to %s.' % javaLocalDir
          </message>
          <call function="'CopyFolderByExtension'">
            { 'location'   : STAXServiceMachine,
            {
            'location'   : STAXServiceMachine,
              'srcfolder'  : javaSharedDir,
              'destfolder' : javaLocalDir,
            'extension'  : 'java'
            }
          </call>
          <!---   Check if ldap java files are already compiled -->
          <call function="'listFolderByExtension'" >
            {
            'location'   : STAXServiceMachine,
            'foldername' : javaLocalDir,
              'extension'  : 'class' 
            }
          </call>
          <if expr="STAXResult != ''">
            <sequence>
              <!---   Compile ldap java files on controler host -->
              <message>
                'Compile Java files under %s on %s' \
                % (javaLocalDir, STAXServiceMachine)
              </message>
              <call function="'compileJava'" >
                {
                'location'   : STAXServiceMachine,
                'foldername' : '%s' % javaLocalDir
                }
              </call>
            </sequence>
          </if>
           <!-- Archive (.security) files -->
          <message>
            'Copy security data files locally to %s.' % localTestsGroupDir
          </message>
          <call function="'CopyFolderByExtension'">
            { 'location'   : STAXServiceMachine,
              'srcfolder'  : testsGroupDir,
              'destfolder' : localTestsGroupDir,
              'extension'  : 'security'
            }
          </call>
          <!-- Archive (snmp/.java) files -->
          <script>
            javaSharedDir='%s/snmp' % (TESTS_JAVA_DIR)
            javaLocalDir='%s/shared/java/snmp' % (logsTestDataDir)
          </script>
          <message>
            'Copy java files locally to %s.' % javaLocalDir
          </message>
          <call function="'CopyFolderByExtension'">
            {
            'location'   : STAXServiceMachine,
            'srcfolder'  : javaSharedDir,
            'destfolder' : javaLocalDir,
            'extension'  : 'java'
            }
          </call>
          <!---   Check if snmp java files are already compiled -->
          <call function="'listFolderByExtension'" >
            {
            'location'   : STAXServiceMachine,
            'foldername' : javaLocalDir,
            'extension'  : 'class'
            }
          </call>
          <if expr="STAXResult != ''">
            <sequence>
              <!--- Install DS Copy zip file -->
              <message>
                'Copy DS zip archive locally to %s.' % TMPDIR
              </message>
              <call function="'copyFile'">
                {
                'srcfile'    : '%s/%s' % (ZIPPATH, ZIPNAME),
                'destfile'   : '%s/%s' % (TMPDIR, ZIPNAME),
                'remotehost' : STAXServiceMachine
                }
              </call>
              <!--- Install DS Extract zip file -->
              <message>
                'Extract locally DS zip archive to %s' % TMPDIR
              </message>
              <call function="'unZipFile'">
                {
                'location' : STAXServiceMachine,
                'zipfile'  : '%s/%s' % (TMPDIR, ZIPNAME),
                'unzipdir' : TMPDIR
                }
              </call>
              <call function="'ResolveVar'" >
                {
                'location' : STAXServiceMachine,
                'type'     : 'STRING',
                'name'     : 'STAF/Env/LD_LIBRARY_PATH'
                }
              </call>
              <script>jstaf_jarfile = '%s/JSTAF.jar' % STAFResult</script>
              <!---   Compile snmp java files on controler host -->
              <message>
                'Compile Java files under %s on %s' \
                % (javaLocalDir, STAXServiceMachine)
              </message>
              <call function="'compileJava'" >
                {
                'location'   : STAXServiceMachine,
                'foldername' : javaLocalDir,
                'classpath'  : '%s:%s:%s' \
                % (SNMP_OPENDS_JARFILE, SNMP_OPENDMK_JARFILE, jstaf_jarfile)
                }
              </call>
              <!--  Delete the DS zip archive -->
              <message>
                'Delete %s/%s' % (TMPDIR, ZIPNAME)
              </message>
              <call function="'deleteFile'">
                {
                'location' : STAXServiceMachine,
                'filename' : '%s/%s' % (TMPDIR, ZIPNAME)
                }
              </call>
              <!--  Delete the DS install dir -->
              <message>
                'Delete %s/%s' % (TMPDIR, OPENDSNAME)
              </message>
              <call function="'deleteFolder'">
                {
                'location' : STAXServiceMachine,
                'foldername' : '%s/%s' % (TMPDIR, OPENDSNAME)
                }
              </call>
              <!-- Archive SNMP_OPENDMK_JARFILE file -->
              <message>
                'Copy OpenDMK jar file %s locally to %s.' \
                % (SNMP_OPENDMK_JARFILE,javaLocalDir)
              </message>
              <call function="'copyFile'">
                {
                'remotehost' : STAXServiceMachine,
                'srcfile'    : SNMP_OPENDMK_JARFILE,
                'destfile'   : '%s/jdmkrt.jar' % javaLocalDir,
                'remotehost' : STAXServiceMachine
                }
              </call>
            </sequence>
          </if>
                    
          <!--  Delete the any existing testdata archive -->
          <message>
@@ -306,8 +455,11 @@
          </call>
                      
          <message>
            'Zip up local java class files to %s/testdata.zip' % logsTempDir
            'Zip up local java files to %s/testdata.zip' % logsTempDir
          </message>
          <script>
            javaLocalDir='%s/shared/java' % (logsTestDataDir)
          </script>
          <call function="'zipUpFile'">
            { 'location'   : STAXServiceMachine,
              'zipfile'    : '%s/testdata.zip' % logsTempDir , 
opendj-sdk/opends/tests/shared/functions/utils.xml
@@ -116,9 +116,16 @@
              <tcstatus result="'pass'"/>          
            </sequence>
          </if>        
          <if expr="VERBOSE_MODE == 'True'">
            <message log="1">
              'SUCCESS: RC=%s, Expected %s, Result=%s' % (returncode,expected,result)
            </message>
            <else>
          <message log="1">
            'SUCCESS: RC=%s, Expected %s' % (returncode,expected)
          </message>
            </else>
          </if>
          <script>
            RC=0
          </script>
@@ -1452,14 +1459,6 @@
        </function-arg-description>
        <function-arg-property name="type" value="file"/>
      </function-arg-def>
      <function-arg-def name="outputPath"
                        type="optional"
                        default="'%s/../..' % dsBinPath">
        <function-arg-description>
          Path containing the outputFile
        </function-arg-description>
        <function-arg-property name="type" value="filepath"/>
      </function-arg-def>
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value. Default value is 0.
@@ -1505,7 +1504,7 @@
          <workdir>path</workdir>
          <envs>env</envs>
          <console use="'same'"/>
          <stdout if="outputFile != 'None'" mode="'replace'">'%s/%s' % (outputPath, outputFile)</stdout>
          <stdout if="outputFile != 'None'" mode="'replace'">'%s' % outputFile</stdout>
          <stderr mode="'stdout'"/>
          <returnstdout/>
        </process>
@@ -1517,7 +1516,7 @@
            <workdir>path</workdir>
            <envs>env</envs>
            <console use="'same'"/>
            <stdout if="outputFile != 'None'" mode="'replace'">'%s/%s' % (outputPath, outputFile)</stdout>
            <stdout if="outputFile != 'None'" mode="'replace'">'%s' % outputFile</stdout>
            <returnstdout/>
          </process>
        </else>
@@ -1980,14 +1979,110 @@
    </sequence>
  </function>
  
  <function name="compileJava" scope="local">
    <function-prolog>
      This function compile java files.
    </function-prolog>
    <function-map-args>
      <function-arg-def name="location"
                        type="optional"
                        default="STAXServiceMachine">
        <function-arg-description>
          Location of remote host
        </function-arg-description>
        <function-arg-property name="type" value="hostname"/>
      </function-arg-def>
      <function-arg-def name="foldername" type="required">
        <function-arg-description>
          Path containing java files to compile
        </function-arg-description>
        <function-arg-property name="type" value="filepath"/>
      </function-arg-def>
      <function-arg-def name="classpath" type="optional">
        <function-arg-description>
          Additional classpath
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="expectedRC" type="optional" default="0">
        <function-arg-description>
          Expected return code value.
          0 for successful grep, 1 for unsuccessful grep. Default value is 0.
          Wildcard 'noCheck' to not check the RC
        </function-arg-description>
      </function-arg-def>
    </function-map-args>
  
    <sequence>
      <script>
        if classpath:
          cp = 'CLASSPATH=%s:.' % classpath
        else:
          cp = 'CLASSPATH=.'
        if isWindows:
          cp = cp.replace(':', ';')
        if location == STAXServiceMachine:
          cmd = 'javac'
          env = ['%s' % cp]
        else:
          cmd = '%s/bin/javac' % JAVA_HOME
          env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp]
      </script>
      <call function="'listFolderByExtension'" >
        {
        'location'   : location ,
        'foldername' : foldername ,
        'extension'  : 'java'
        }
      </call>
      <script>
        cmdResult = STAXResult
      </script>
      <if expr="cmdResult != 'Folder does not exist.'">
        <sequence>
          <script>
            list = ""
            for file in cmdResult:
              list = list + " " + file
          </script>
          <call function="'runCommand'" >
            {
            'name'       : 'Compile Java files' ,
            'command'    : cmd ,
            'arguments'  : '-target 1.5 %s' % list ,
            'location'   : location ,
            'path'       : foldername ,
            'env'        : env ,
            'expectedRC' : expectedRC
            }
          </call>
        </sequence>
        <else>
          <tcstatus result="'fail'"></tcstatus>
        </else>
      </if>
      <return>
        STAXResult
      </return>
    </sequence>
  </function>
  
  <function name="getFreePort" scope="local">
    <function-description>
      Returns the first free TCP port greater or equal to given number
    </function-description>
    <function-map-args>
      <function-arg-def name="host" type="optional" default="STAXServiceMachine">
      <function-arg-def name="host"
                        type="optional"
                        default="STAXServiceMachine">
        <function-arg-description>
          Which machine to look for the free port
        </function-arg-description>
@@ -2026,5 +2121,4 @@
    </sequence>
  </function>
</stax>
opendj-sdk/opends/tests/shared/java/addAnEntry.class
Binary files differ
opendj-sdk/opends/tests/shared/java/addAnEntry.java
File was deleted
opendj-sdk/opends/tests/shared/java/ldap/addAnEntry.java
New file
@@ -0,0 +1,175 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 */
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.CompositeName;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.CommunicationException;
import java.util.HashSet;
import java.util.Iterator;
/**
 * Add a new entry.
 * Input :
 *    -D : principal
 *    -w : credential
 *    -p : ldapport
 *    -h : ldaphost
 *    -d : dn to add
 *    -v : attribut name:attribut value
 *       : this option is multi valued
 */
public class addAnEntry {
  /**
   * Main.
   *
   * @param args arguments
   */
  public static void main(String[] args) {
    String hostname=null;
    String ldapPort=null;
    String principal=null;
    String credential=null;
    String dnToAdd=null;
    String attributeToAdd=null;
    String errorCode=null;
    String errorMessage=null;
    int ind1;
    String attributeName;
    String attributeValue;
    Attributes attributes = new BasicAttributes();
    HashSet attributeSet = new HashSet();
    for (int k=0; k< args.length; k++) {
      String opt1 = args[k];
      String val1 = args[k+1];
      if (opt1.equals("-h")) {
        hostname = val1;
      }
      if (opt1.equals("-p")) {
        ldapPort = val1;
      }
      if (opt1.equals("-D")) {
        principal = val1;
      }
      if (opt1.equals("-w")) {
        credential = val1;
      }
      if (opt1.equals("-d")) {
        dnToAdd = val1;
      }
      if (opt1.equals("-v")) {
        attributeToAdd = val1;
        ind1= val1.indexOf(":");
        attributeName=val1.substring(0,ind1);
        attributeValue=val1.substring(ind1+1);
        BasicAttribute attrToComplete = null;
        Iterator it = attributeSet.iterator();
        while (attrToComplete == null && it.hasNext()) {
          BasicAttribute attr = (BasicAttribute) it.next();
          if ((attr.getID()).equalsIgnoreCase(attributeName)) {
            attrToComplete = attr;
          }
        }
        if (attrToComplete == null) {
          attrToComplete = new BasicAttribute(attributeName);
          attributeSet.add(attrToComplete);
        }
        attrToComplete.add(attributeValue);
      }
      k++;
    }
    Iterator it2 = attributeSet.iterator();
    while (it2.hasNext()) {
      BasicAttribute attr = (BasicAttribute)it2.next();
      attributes.put(attr);
    }
    String provider = "ldap://"  + hostname + ":" + ldapPort  + "/";
    Hashtable envLdap  = new Hashtable();
    envLdap.put("java.naming.factory.initial",
        "com.sun.jndi.ldap.LdapCtxFactory");
    envLdap.put(Context.SECURITY_AUTHENTICATION, "simple");
    envLdap.put(Context.SECURITY_PRINCIPAL,  principal);
    envLdap.put(Context.SECURITY_CREDENTIALS, credential);
    envLdap.put(Context.PROVIDER_URL, provider);
    LdapContext ctx;
    try {
      CompositeName entryDN = new CompositeName(dnToAdd);
      System.out.println("Add a new  entry " + entryDN);
      // connect to server
      ctx = new InitialLdapContext(envLdap, null);
      ctx.createSubcontext(entryDN, attributes);
      ctx.close();
    } catch (CommunicationException e1) {
      errorMessage = e1.getMessage();
    } catch (NamingException e2) {
      errorMessage = e2.getMessage();
    } catch (Exception e3) {
      errorMessage= e3.getMessage();
    }
    // No error, the modify is success
    if ( errorMessage == null ) {
      errorCode="0";
    } else {
      System.out.println(errorMessage);
      int ind=errorMessage.indexOf("-");
      if ( ind > 0 ) {
        errorCode=errorMessage.substring(18, ind-1);
      } else errorCode="0";
    }
    int RC = Integer.parseInt(errorCode);
    System.exit(RC);
  }
}
opendj-sdk/opends/tests/shared/java/ldap/modifyAnAttribute.java
New file
@@ -0,0 +1,206 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 */
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.CompositeName;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.CommunicationException;
import java.util.HashSet;
import java.util.Iterator;
/**
 *  Modify an entry with an attribute.
 *  The operation can be a replace, delete or a add new attribute
 *  The function returns the ldap error code
 */
public class modifyAnAttribute {
  /**
   * Main.
   *
   * @param args arguments
   */
  public static void main(String[] args) {
    String hostname=null;
    String ldapPort=null;
    String principal=null;
    String credential=null;
    String attributeToModify=null;
    String dnToModify=null;
    String newAttributeValue=null;
    String changetype=null;
    String errorCode=null;
    String errorMessage=null;
    String listAttributesToModify=null;
    int ind1;
    String attributeName;
    String attributeValue;
    Hashtable envLdap  = new Hashtable();
    LdapContext ctx;
    Attributes attributes = new BasicAttributes();
    HashSet attributeSet = new HashSet();
    for (int k=0; k< args.length; k++) {
      String opt1 = args[k];
      String val1 = args[k+1];
      if (opt1.equals("-h")) {
        hostname = val1;
      }
      if (opt1.equals("-p")) {
        ldapPort = val1;
      }
      if (opt1.equals("-D")) {
        principal = val1;
      }
      if (opt1.equals("-w")) {
        credential = val1;
      }
      if (opt1.equals("-d")) {
        dnToModify = val1;
      }
      if (opt1.equals("-v")) {
        newAttributeValue = val1;
      }
      if (opt1.equals("-a")) {
        attributeToModify = val1;
      }
      if (opt1.equals("-t")) {
        changetype = val1;
      }
      if (opt1.equals("-l")) {
        listAttributesToModify = val1;
        ind1= val1.indexOf(":");
        attributeName=val1.substring(0,ind1);
        attributeValue=val1.substring(ind1+1);
        BasicAttribute attrToComplete = null;
        Iterator it = attributeSet.iterator();
        while (attrToComplete == null && it.hasNext()) {
          BasicAttribute attr = (BasicAttribute) it.next();
          if ((attr.getID()).equalsIgnoreCase(attributeName)) {
            attrToComplete = attr;
          }
        }
        if (attrToComplete == null) {
          attrToComplete = new BasicAttribute(attributeName);
          attributeSet.add(attrToComplete);
        }
        attributeValue=attributeValue.replaceAll("QUOT","\\\"");
        attrToComplete.add(attributeValue);
      }
      k++;
    }
    if ( attributeToModify != null && newAttributeValue != null ) {
      BasicAttribute attrToComplete = null;
      attrToComplete = new BasicAttribute(attributeToModify);
      attributeSet.add(attrToComplete);
      newAttributeValue=newAttributeValue.replaceAll("QUOT","\\\"");
      attrToComplete.add(newAttributeValue);
    }
    Iterator it2 = attributeSet.iterator();
    while (it2.hasNext()) {
      BasicAttribute attr = (BasicAttribute)it2.next();
      attributes.put(attr);
    }
    String provider = "ldap://"  + hostname + ":" + ldapPort  + "/";
    envLdap.put("java.naming.factory.initial",
        "com.sun.jndi.ldap.LdapCtxFactory");
    envLdap.put(Context.SECURITY_AUTHENTICATION, "simple");
    envLdap.put(Context.SECURITY_PRINCIPAL,  principal);
    envLdap.put(Context.SECURITY_CREDENTIALS, credential);
    envLdap.put(Context.PROVIDER_URL, provider);
    try {
      CompositeName entryDN = new CompositeName(dnToModify);
      System.out.println("Modify the entry " + dnToModify);
      // connect to server
      ctx = new InitialLdapContext(envLdap, null);
      // replace attribute
      if (changetype.equals("replace")) {
        ctx.modifyAttributes(entryDN,
            LdapContext.REPLACE_ATTRIBUTE,
            attributes);
      } else if (changetype.equals("add")) {
        // add attribute
        ctx.modifyAttributes(entryDN,
            LdapContext.ADD_ATTRIBUTE,
            attributes);
      } else if (changetype.equals("delete")) {
        // add attribute
        ctx.modifyAttributes(entryDN,
            LdapContext.REMOVE_ATTRIBUTE,
            attributes);
      }
      ctx.close();
    } catch (CommunicationException e1) {
      errorMessage = e1.getMessage();
    } catch (NamingException e2) {
      errorMessage = e2.getMessage();
    } catch (Exception e3) {
      errorMessage= e3.getMessage();
    }
    // No error, the modify is success
    if ( errorMessage == null ) {
      errorCode="0";
    } else {
      System.out.println(errorMessage);
      int ind=errorMessage.indexOf("-");
      if ( ind > 0 ) {
        errorCode=errorMessage.substring(18, ind-1);
      } else errorCode="0";
    }
    int RC = Integer.parseInt(errorCode);
    System.exit(RC);
  }
}
opendj-sdk/opends/tests/shared/java/modifyAnAttribute.class
Binary files differ
opendj-sdk/opends/tests/shared/java/modifyAnAttribute.java
File was deleted
opendj-sdk/opends/tests/shared/java/snmp/SNMPGet.java
New file
@@ -0,0 +1,519 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 */
// OpenDS imports
import org.opends.server.snmp.DIRECTORY_SERVER_MIBOidTable;
// OpenDMK imports
//
import com.sun.management.snmp.SnmpDefinitions;
import com.sun.management.snmp.SnmpVarBindList;
import com.sun.management.snmp.SnmpEngine;
import com.sun.management.snmp.SnmpEngineParameters;
import com.sun.management.snmp.SnmpOid;
import com.sun.management.snmp.SnmpOidTableSupport;
import com.sun.management.snmp.SnmpStatusException;
import com.sun.management.snmp.manager.SnmpRequest;
import com.sun.management.snmp.manager.SnmpSession;
import com.sun.management.snmp.manager.SnmpPeer;
import com.sun.management.snmp.manager.SnmpParameters;
import com.sun.management.snmp.manager.usm.SnmpUsmPeer;
import com.sun.management.snmp.manager.usm.SnmpUsmParameters;
/**
 * This class perform a SNMP get operation.
 */
public class SNMPGet {
  /**
   * Gets the calling arguments.
   *
   * @param args SNMP version + SNMP agent host + SNMP agent port + community
   * @return 0 if the init succeeded or 1 if the init failed
   */
  public int init(String[] args) {
    int rc = 0;
    System.out.println("\n");
    if (args.length < 5) {
      // Missing arguments
      System.out.println(
              "usage: " +
              " -v <SNMP version>" +
              " -h <remoteHost>" +
              " -p <port>" +
              " -o <oids>" +
              " -c <community/context>" +
              " -u <user>" +
              " -l <securityLevel>" +
              " -f <securityFile>" +
              " -s <connectionStatus>" +
              " -n <checkOIDs>");
      rc = 1;
    } else {
      for (int i = 0; i < args.length; i++) {
        String opt = args[i];
        String val = args[i + 1];
        switch (opt.charAt(1)) {
          case 'v':
            version = new Integer(val).intValue();
            break;
          case 'h':
            remoteHost = val;
            break;
          case 'p':
            port = new Integer(val).intValue();
            break;
          case 'o':
            oids = val;
            break;
          case 'c':
            community = val;
            break;
          case 'u':
            user = val;
            break;
          case 'l':
            if (val.compareTo("NoAuthNoPriv") == 0) {
              securityLevel = SnmpDefinitions.noAuthNoPriv;
            } else if (val.compareTo("AuthNoPriv") == 0) {
              securityLevel = SnmpDefinitions.authNoPriv;
            } else if (val.compareTo("AuthPriv") == 0) {
              securityLevel = SnmpDefinitions.authPriv;
            } else {
              System.out.println(
                      "Unknown security level " + opt.charAt(1) + ".");
              rc = 1;
            }
            break;
          case 'f':
            securityFile = val;
            break;
          case 's':
            connectStatus = val;
            break;
          case 'n':
            validOIDs = new Boolean(val).booleanValue();
            break;
          default:
            System.out.println("Unknown option -" + opt.charAt(1) + ".");
            rc = 1;
        }
        if (rc == 1) {
          break;
        }
        i = i + 1;
      }
    }
    if (rc == 0) {
      System.out.println("init() of SNMPGet succeeded");
    } else {
      System.out.println("init() of SNMPGet failed");
    }
    return rc;
  }
  /**
   * Open SNMP connection with SNMP agent.
   *
   * @return 0 if the connect succeeded or 1 if the connect failed
   */
  public int connect() {
    int rc = 0;
    try {
      // The OidTable generated by mibgen when compiling DIRECTORY_SERVER_MIB
      //
      final SnmpOidTableSupport oidTable = new DIRECTORY_SERVER_MIBOidTable();
      // Specify the OidTable containing all the DIRECTORY_SERVER_MIB knowledge
      //
      SnmpOid.setSnmpOidTable(oidTable);
      switch (version) {
        case 1:
        case 2:
          // Create the session
          //
          session = new SnmpSession("Get V" + version + " session");
          // Disable PduFixedOnError option
          //
          session.snmpOptions.setPduFixedOnError(false);
          // Create an SnmpPeer object for representing the entity
          // to communicate with.
          //
          final SnmpPeer agent = new SnmpPeer(remoteHost, port);
          // Specify the read and write community to be used
          //
          final SnmpParameters params = new SnmpParameters(
                  community,
                  community);
          // Specify the protocol version
          //
          switch (version) {
            case 1:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionOne);
              break;
            case 2:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionTwo);
              break;
          }
          // Associate the parameters with the agent
          //
          agent.setTimeout(timeOut);
          agent.setMaxTries(maxRetries);
          agent.setParams(params);
          // Set the default peer (agent) to a SnmpSession
          //
          session.setDefaultPeer(agent);
          break;
        case 3:
          // Custom engine parameters
          final SnmpEngineParameters engineParameters =
                  new SnmpEngineParameters();
          engineParameters.setSecurityFile(securityFile);
          // Create the session
          //
          session = new SnmpSession(
                  engineParameters,
                  null,
                  "Get V3 session",
                  null);
          // SNMP V3 introduces the notion of SnmpEngine. An engine is
          // associated to the session. Other objects  might need
          // the engine. You can access it using getEngine method.
          //
          final SnmpEngine engine = session.getEngine();
          // Create an SnmpUsmPeer object for representing the entity
          // to communicate with
          //
          final SnmpUsmPeer agentV3 = new SnmpUsmPeer(engine, remoteHost, port);
          // Create USM parameters for the principal defaultuser (user used when
          // requests are sent: the defaultUser is a template and for this
          // reason we cannot find it under the user mib (not created as a user)
          //
          final SnmpUsmParameters paramsV3 = new SnmpUsmParameters(
                  engine,
                  user);
          // Set the security level authentication but without privacy
          //
          paramsV3.setSecurityLevel(securityLevel);
          // Set the context name
          //
          if (community.compareTo("default") != 0) {
            paramsV3.setContextName(community.getBytes());
          }
          // Set the contextEngineId discovered by the peer upon
          // its creation
          //
          paramsV3.setContextEngineId(agentV3.getEngineId().getBytes());
          // Associate the parameters with the agent
          //
          agentV3.setTimeout(timeOut);
          agentV3.setMaxTries(maxRetries);
          agentV3.setParams(paramsV3);
          // Discover timeliness of creation and boot
          //
         try {
            agentV3.processUsmTimelinessDiscovery();
         } catch (SnmpStatusException e) {
           if (connectStatus.compareTo("SnmpStatusException") == 0) {
             System.out.println(
                     "connect() of SNMPGet catched as expected a " +
                     "SNMP status exception: " + e.getMessage() + "\"");
           } else {
             System.out.println(
                     "connect() of SNMPGet should not catch a " +
                     "SNMP status exception: " + e.getMessage() + "\"");
             rc = 1;
           }
          } catch (Exception e) {
            System.out.println(
                    "connect() of SNMPGet catched an unexpected exception: " +
                    e.getMessage() + "\"");
            rc = 1;
          }
          if (rc == 0) {
            // Set the default peer (agent) to a SnmpSession
            //
            session.setDefaultPeer(agentV3);
          }
          break;
        default:
          System.out.println(
                  "connect() of SNMPGet: Unknown SNMP version: " +
                  version + " .");
          rc = 1;
      }
    } catch (Exception e) {
      System.out.println(
              "connect() of SNMPGet catched an unexpected exception: " +
              e.getMessage() + "\"");
      rc = 1;
    }
    if (rc == 0) {
      System.out.println("connect() of SNMPGet succeeded");
    } else {
      System.out.println("connect() of SNMPGet failed");
    }
    return rc;
  }
  /**
   * Perform an SNMP get request on SNMP agent.
   *
   * @return 0 if the getRequest succeeded or 1 if the getRequest failed
   */
  public int getRequest() {
    int rc = 0;
    try {
      // Build the list of variables you want to query
      //
      final SnmpVarBindList list = new SnmpVarBindList("Get varbind list");
      // Read all TEST-MIB variables.
      //
      list.addVarBind(oids);
      // Make the SNMP get request
      //
      System.out.println(
              "getRequest() of SNMPGet: Start SNMP V" + version +
              " GET request for SNMP agent on \"" + remoteHost +
              "\" at port \"" + port + "\".");
      // Get request
      //
      SnmpRequest request = session.snmpGetRequest(null, list);
      // Check for a timeout of the request
      //
      boolean completed = request.waitForCompletion((maxRetries + 1) * timeOut);
      if (completed == false) {
        System.out.println(
                "getRequest() of SNMPGet: Request timed out, " +
                "check reachability of agent.");
        // Print request
        //
        System.out.println(
                "getRequest() of SNMPGet: Request= " +
                request.toString() + ".");
        rc = 1;
      }
      if (rc == 0) {
        System.out.println(
                "getRequest() of SNMPGet: Finish SNMP V" +
                version + " GET request.");
        // Now we have a response. Check if the response contains an error
        //
        String errorStatus = SnmpRequest.snmpErrorToString(
                request.getErrorStatus());
        if (errorStatus.compareTo("noError") != 0) {
          System.out.println(
                  "getRequest() of SNMPGet: Error status= " +
                  errorStatus + ".");
          System.out.println(
                  "getRequest() of SNMPGet: Error index= " +
                  request.getErrorIndex() + ".");
          if (errorStatus.compareTo(connectStatus) == 0) {
            System.out.println(
                    "getRequest() of SNMPGet: Get request failed as " +
                    "expected with " + connectStatus + " status.");
          } else {
            System.out.println(
                    "getRequest() of SNMPGet: Get request should " +
                    "fail with " + connectStatus + " status.");
            rc = 1;
          }
        } else {
          // Now we shall display the content of the result
          //
          SnmpVarBindList resp = request.getResponseVarBindList();
          System.out.println("getRequest() of SNMPGet: Result=");
          for (int i = 0; i < resp.getVarBindCount(); i++) {
            System.out.println(resp.getVarBindAt(i));
          }
          if (connectStatus.compareTo("noError") != 0) {
            // Request should failed
            //
            System.out.println(
                    "getRequest() of SNMPGet: Get request should " +
                    "fail with " + connectStatus + " status.");
            rc = 1;
          } else {
            if (validOIDs) {
              // Check that we obtain correct values for the OIDs
              //
              if (resp.checkForValidValues()) {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs are correct.");
              } else {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs are not correct.");
                rc = 1;
              }
            } else {
              // Check that we obtain incorrect values for the OIDs
              //
              if (resp.checkForValidValues()) {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs should not be correct.");
                rc = 1;
              } else {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs are not correct as expected.");
              }
            }
          }
        }
      }
    } catch (Exception e) {
      System.out.println(
              "connect() of SNMPGet catched an unexpected exception: " +
              e.getMessage() + "\"");
      rc = 1;
    }
    if (rc == 0) {
      System.out.println("getRequest() of SNMPGet succeeded");
    } else {
      System.out.println("getRequest() of SNMPGet failed");
    }
    return rc;
  }
  /**
   * Close SNMP connection with SNMP agent.
   */
  public void disconnect() {
    // Stop and destroy the SnmpSession if still there
    try {
      session.destroySession();
      session = null;
    } catch (Exception e) {
    // possible session already ended
    }
    System.out.println("disconnect() of SNMPGet succeeded");
  }
  /**
   * Main.
   *
   * @param args arguments
   */
  public static void main(String[] args) {
    SNMPGet client = new SNMPGet();
    int rc = 0;
    // Retrieve parameters
    rc = client.init(args);
    // If init() succeeded then open connection
    if (rc == 0) {
      rc = client.connect();
    }
    // If connect() succeeded then perform get request
    if (rc == 0 && connectStatus.compareTo("SnmpStatusException") != 0) {
      rc = client.getRequest();
    }
    // Close connection
    client.disconnect();
    System.exit(rc);
  }
  // Arguments
  int version = 0;
  String remoteHost = null;
  int port = 0;
  String oids = null;
  String community = null;
  String user = null;
  int securityLevel = SnmpDefinitions.authNoPriv;
  String securityFile = null;
  static String connectStatus = null;
  boolean validOIDs = true;
  // SnmpSession
  SnmpSession session = null;
  int timeOut = 30000;  // default value
  int maxRetries = 1;
}
opendj-sdk/opends/tests/shared/java/snmp/SNMPSet.java
New file
@@ -0,0 +1,522 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 */
// OpenDS imports
import org.opends.server.snmp.DIRECTORY_SERVER_MIBOidTable;
// OpenDMK imports
//
import com.sun.management.snmp.SnmpDefinitions;
import com.sun.management.snmp.SnmpVarBindList;
import com.sun.management.snmp.SnmpEngine;
import com.sun.management.snmp.SnmpEngineParameters;
import com.sun.management.snmp.SnmpOid;
import com.sun.management.snmp.SnmpOidTableSupport;
import com.sun.management.snmp.SnmpStatusException;
import com.sun.management.snmp.SnmpString;
import com.sun.management.snmp.SnmpVarBind;
import com.sun.management.snmp.manager.SnmpRequest;
import com.sun.management.snmp.manager.SnmpSession;
import com.sun.management.snmp.manager.SnmpPeer;
import com.sun.management.snmp.manager.SnmpParameters;
import com.sun.management.snmp.manager.usm.SnmpUsmPeer;
import com.sun.management.snmp.manager.usm.SnmpUsmParameters;
/**
 * This class perform a SNMP set operation.
 */
public class SNMPSet {
  /**
   * Gets the calling arguments.
   *
   * @param args SNMP agent version + SNMP agent host + SNMP agent port
   * @return 0 if the init succeeded or 1 if the init failed
   */
  public int init(String[] args) {
    int rc = 0;
    System.out.println("\n");
    if (args.length < 5) {
      // Missing arguments
      System.out.println(
              "usage: " +
              " -v <SNMP version>" +
              " -h <remoteHost>" +
              " -p <port>" +
              " -o <oids>" +
              " -c <community>" +
              " -u <user>" +
              " -l <securityLevel>" +
              " -f <securityFile>" +
              " -s <connectionStatus>" +
              " -n <checkOIDs>");
      rc = 1;
    } else {
      for (int i = 0; i < args.length; i++) {
        String opt = args[i];
        String val = args[i + 1];
        switch (opt.charAt(1)) {
          case 'v':
            version = new Integer(val).intValue();
            break;
          case 'h':
            remoteHost = val;
            break;
          case 'p':
            port = new Integer(val).intValue();
            break;
          case 'o':
            oids = val;
            break;
          case 'c':
            community = val;
            break;
          case 'u':
            user = val;
            break;
          case 'l':
            if (val.compareTo("NoAuthNoPriv") == 0) {
              securityLevel = SnmpDefinitions.noAuthNoPriv;
            } else if (val.compareTo("AuthNoPriv") == 0) {
              securityLevel = SnmpDefinitions.authNoPriv;
            } else if (val.compareTo("AuthPriv") == 0) {
              securityLevel = SnmpDefinitions.authPriv;
            } else {
              System.out.println(
                      "Unknown security level " + opt.charAt(1) + ".");
              rc = 1;
            }
            break;
          case 'f':
            securityFile = val;
            break;
          case 's':
            connectStatus = val;
            break;
          case 'n':
            validOIDs = new Boolean(val).booleanValue();
            break;
          default:
            System.out.println("Unknown option -" + opt.charAt(1) + ".");
            rc = 1;
        }
        if (rc == 1) {
          break;
        }
        i = i + 1;
      }
    }
    if (rc == 0) {
      System.out.println("init() of SNMPSet succeeded");
    } else {
      System.out.println("init() of SNMPSet failed");
    }
    return rc;
  }
  /**
   * Open SNMP connection with SNMP agent.
   *
   * @return 0 if the connect succeeded or 1 if the connect failed
   */
  public int connect() {
    int rc = 0;
    try {
      // The OidTable generated by mibgen when compiling DIRECTORY_SERVER_MIB
      //
      final SnmpOidTableSupport oidTable = new DIRECTORY_SERVER_MIBOidTable();
      // Specify the OidTable containing all the DIRECTORY_SERVER_MIB knowledge
      //
      SnmpOid.setSnmpOidTable(oidTable);
      switch (version) {
        case 1:
        case 2:
          // Create the session
          //
          session = new SnmpSession("Set V" + version + " session");
          // Create an SnmpPeer object for representing the entity
          // to communicate with.
          //
          final SnmpPeer agent = new SnmpPeer(remoteHost, port);
          // Specify the read and write community to be used
          //
          final SnmpParameters params = new SnmpParameters(
                  community,
                  community);
          // Specify the protocol version
          //
          switch (version) {
            case 1:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionOne);
              break;
            case 2:
              params.setProtocolVersion(SnmpDefinitions.snmpVersionTwo);
              break;
            default:
              break;
          }
          // Associate the parameters with the agent
          //
          agent.setTimeout(timeOut);
          agent.setMaxTries(maxRetries);
          agent.setParams(params);
          // Set the default peer (agent) to a SnmpSession
          //
          session.setDefaultPeer(agent);
          break;
        case 3:
          // Custom engine parameters
          final SnmpEngineParameters engineParameters =
                  new SnmpEngineParameters();
          engineParameters.setSecurityFile(securityFile);
          // Create the session
          //
          session = new SnmpSession(
                  engineParameters,
                  null,
                  "Set V3 session",
                  null);
          // SNMP V3 introduces the notion of SnmpEngine. An engine is
          // associated to the session. Other objects  might need
          // the engine. You can access it using getEngine method.
          //
          final SnmpEngine engine = session.getEngine();
          // Create an SnmpUsmPeer object for representing the entity
          // to communicate with
          //
          final SnmpUsmPeer agentV3 = new SnmpUsmPeer(engine, remoteHost, port);
          // Create USM parameters for the principal defaultuser (user used when
          // requests are sent: the defaultuser is a template and for this
          // reason we cannot find it under the user mib (not created as a user)
          //
          final SnmpUsmParameters paramsV3 = new SnmpUsmParameters(
                  engine,
                  user);
          // Set the security level authentication but without privacy
          //
          paramsV3.setSecurityLevel(securityLevel);
          // Set the context name
          //
          if (community.compareTo("default") != 0) {
            paramsV3.setContextName(community.getBytes());
          }
          // Set the contextEngineId discovered by the peer upon
          // its creation
          //
          paramsV3.setContextEngineId(agentV3.getEngineId().getBytes());
          // Associate the parameters with the agent
          //
          agentV3.setTimeout(timeOut);
          agentV3.setMaxTries(maxRetries);
          agentV3.setParams(paramsV3);
          // Discover timeliness of creation and boot
          //
         try {
            agentV3.processUsmTimelinessDiscovery();
         } catch (SnmpStatusException e) {
           if (connectStatus.compareTo("SnmpStatusException") == 0) {
             System.out.println(
                     "connect() of SNMPSet catched as expected a " +
                     "SNMP status exception: " + e.getMessage() + "\"");
           } else {
             System.out.println(
                     "connect() of SNMPSet should not catch a " +
                     "SNMP status exception: " + e.getMessage() + "\"");
             rc = 1;
           }
          } catch (Exception e) {
            System.out.println(
                    "connect() of SNMPSet catched an unexpected exception: " +
                    e.getMessage() + "\"");
            rc = 1;
          }
          if (rc == 0) {
            // Set the default peer (agent) to a SnmpSession
            //
            session.setDefaultPeer(agentV3);
          }
          break;
        default:
          System.out.println(
                  "connect() of SNMPSet: Unknown SNMP version: "
                  + version + " .");
          rc = 1;
      }
    } catch (Exception e) {
      System.out.println(
              "connect() of SNMPSet catched an unexpected exception: " +
              e.getMessage() + "\"");
      rc = 1;
    }
    if (rc == 0) {
      System.out.println("connect() of SNMPSet succeeded");
    } else {
      System.out.println("connect() of SNMPSet succeeded");
    }
    return rc;
  }
  /**
   * Perform an SNMP set request on SNMP agent.
   *
   * @return 0 if the setRequest succeeded or 1 if the setRequest failed
   */
  public int setRequest() {
    int rc = 0;
    try {
      // Build the list of variables you want to query
      //
      final SnmpVarBindList list = new SnmpVarBindList("Get varbind list");
      // Write one specific OID
      //
      SnmpVarBind oid = new SnmpVarBind(oids);
      oid.setSnmpValue(new SnmpString("myValue"));
      list.addVarBind(oid);
      // Make the SNMP set request
      //
      System.out.println(
              "setRequest() of SNMPSet: Start SNMP V" + version +
              " GET request for SNMP agent on \"" + remoteHost +
              "\" at port \"" + port + "\".");
      // Set request
      //
      SnmpRequest request = session.snmpSetRequest(null, list);
      // Check for a timeout of the request
      //
      boolean completed = request.waitForCompletion((maxRetries + 1) * timeOut);
      if (completed == false) {
        System.out.println(
                "setRequest() of SNMPSet: Request timed out, " +
                "check reachability of agent.");
        // Print request
        //
        System.out.println(
                "setRequest() of SNMPSet: Request= " +
                request.toString() + ".");
        rc = 1;
      }
      if (rc == 0) {
        System.out.println(
                "getRequest() of SNMPGet: Finish SNMP V" +
                version + " GET request.");
        // Now we have a response. Check if the response contains an error
        //
        String errorStatus = SnmpRequest.snmpErrorToString(
                request.getErrorStatus());
        if (errorStatus.compareTo("noError") != 0) {
          System.out.println(
                  "getRequest() of SNMPGet: Error status= " +
                  errorStatus + ".");
          System.out.println(
                  "getRequest() of SNMPGet: Error index= " +
                  request.getErrorIndex() + ".");
          if (errorStatus.compareTo(connectStatus) == 0) {
            System.out.println(
                    "getRequest() of SNMPGet: Get request failed as " +
                    "expected with " + connectStatus + " status.");
          } else {
            System.out.println(
                    "getRequest() of SNMPGet: Get request should " +
                    "fail with " + connectStatus + " status.");
            rc = 1;
          }
        } else {
          // Now we shall display the content of the result
          //
          SnmpVarBindList resp = request.getResponseVarBindList();
          System.out.println("getRequest() of SNMPGet: Result=");
          for (int i = 0; i < resp.getVarBindCount(); i++) {
            System.out.println(resp.getVarBindAt(i));
          }
          if (connectStatus.compareTo("noError") != 0) {
            // Request should failed
            //
            System.out.println(
                    "getRequest() of SNMPGet: Get request should " +
                    "fail with " + connectStatus + " status.");
            rc = 1;
          } else {
            if (validOIDs) {
              // Check that we obtain correct values for the OIDs
              //
              if (resp.checkForValidValues()) {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs are correct.");
              } else {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs are not correct.");
                rc = 1;
              }
            } else {
              // Check that we obtain incorrect values for the OIDs
              //
              if (resp.checkForValidValues()) {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs should not be correct.");
                rc = 1;
              } else {
                System.out.println(
                        "getRequest() of SNMPGet: Returned values for" +
                        " OIDs are not correct as expected.");
              }
            }
          }
        }
      }
    } catch (Exception e) {
      System.out.println(
              "setRequest() of SNMPSet catched an unexpected exception: " +
              e.getMessage() + "\"");
      rc = 1;
    }
    if (rc == 0) {
      System.out.println("setRequest() of SNMPSet succeeded");
    } else {
      System.out.println("setRequest() of SNMPSet failed");
    }
    return rc;
  }
  /**
   * Close SNMP connection with SNMP agent.
   */
  public void disconnect() {
    // Stop and destroy the SnmpSession if still there
    try {
      session.destroySession();
      session = null;
    } catch (Exception e) {
    // possible session already ended
    }
    System.out.println("disconnect() of SNMPSet succeeded");
  }
  /**
   * Main.
   *
   * @param args arguments
   */
  public static void main(String[] args) {
    SNMPSet client = new SNMPSet();
    int rc = 0;
    // Retrieve parameters
    rc = client.init(args);
    // If init() succeeded then open connection
    if (rc == 0) {
      rc = client.connect();
    }
    // If connect() succeeded then perform set request
    if (rc == 0 && connectStatus.compareTo("SnmpStatusException") != 0) {
      rc = client.setRequest();
    }
    // Close connection
    client.disconnect();
    System.exit(rc);
  }
  // Arguments
  int version = 0;
  String remoteHost = null;
  int port = 0;
  String oids = null;
  String community = null;
  String user = null;
  int securityLevel = SnmpDefinitions.authNoPriv;
  String securityFile = null;
  static String connectStatus = null;
  boolean validOIDs = true;
  // SnmpSession
  SnmpSession session = null;
  int timeOut = 30000;  // default value
  int maxRetries = 1;
}
opendj-sdk/opends/tests/shared/java/snmp/SNMPTrapListener.java
New file
@@ -0,0 +1,278 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 */
// OpenDMK Imports
//
import com.ibm.staf.STAFHandle;
import com.sun.management.snmp.SnmpPduTrap;
import com.sun.management.snmp.SnmpPduRequest;
import com.sun.management.snmp.SnmpScopedPduRequest;
import com.sun.management.snmp.manager.SnmpTrapListener;
import com.sun.management.snmp.SnmpEventReportDispatcher;
/**
 * This class perform a SNMP trap listener.
 */
public class SNMPTrapListener implements SnmpTrapListener {
  /**
   * Callback for SNMP v1 traps.
   *
   * @param trap trap information
   */
  public void processSnmpTrapV1(SnmpPduTrap trap) {
    trapCommunity = new String(trap.community);
    if (trapCommunity.compareTo(community) == 0) {
      nbTrapV1_community++;
    } else {
      nbTrapV1_otherCommunity++;
    }
  }
  /**
   * Callback for SNMP v2c traps.
   *
   * @param trap trap information
   */
  public void processSnmpTrapV2(SnmpPduRequest trap) {
    trapCommunity = new String(trap.community);
    if (trapCommunity.compareTo(community) == 0) {
      nbTrapV2_community++;
    } else {
      nbTrapV2_otherCommunity++;
    }
  }
  /**
   * Callback for SNMP v3 traps.
   *
   * @param trap trap information
   */
  public void processSnmpTrapV3(SnmpScopedPduRequest trap) {
    trapCommunity = new String(trap.contextName);
    if (trapCommunity.compareTo(community) == 0) {
      nbTrapV3_community++;
    } else {
      nbTrapV3_otherCommunity++;
    }
  }
  /**
   * Gets the calling arguments.
   *
   * @param args SNMP agent version + SNMP agent host + SNMP agent port
   * @return 0 if the init succeeded or 1 if the init failed
   */
  public int init(String[] args) {
    int rc = 0;
    System.out.println("\n");
    if (args.length < 3) {
      // Missing arguments
      System.out.println(
              "usage: " +
              " -h <remoteHost>" +
              " -p <port>" +
              " -t <number>" +
              " -c <community>");
      rc = 1;
    } else {
      for (int i = 0; i < args.length; i++) {
        String opt = args[i];
        String val = args[i + 1];
        switch (opt.charAt(1)) {
          case 'h':
            remoteHost = val;
            break;
          case 'p':
            port = new Integer(val).intValue();
            break;
          case 't':
            expectedTrapList = val;
            break;
          case 'c':
            community = val;
            break;
          default:
            System.out.println("Unknown option -" + opt.charAt(1) + ".");
            rc = 1;
        }
        if (rc == 1) {
          break;
        }
        i = i + 1;
      }
    }
    if (rc == 0) {
      System.out.println("init() of SNMPTrapListener succeeded");
    } else {
      System.out.println("init() of SNMPTrapListener failed");
    }
    return rc;
  }
  /**
   * Run the trap listener.
   *
   * @return 0 if the run succeeded or 1 if the run failed
   */
  public int run() {
    int rc = 0;
    try {
      SnmpEventReportDispatcher trapAgent = new SnmpEventReportDispatcher(port);
      trapAgent.addTrapListener(this);
      Thread t = new Thread(trapAgent);
      t.start();
      System.out.println(
              "run() of SNMPTrapListener: Listen traps on port " + port);
      System.out.println("run() of SNMPTrapListener: Wait 10s.");
      Thread.sleep(10000);
      // Register with STAF
      STAFHandle handle = new STAFHandle("SNMPTrapListener");
      // Post event to notice that the trap listener is ready
      System.out.println(
              "run() of SNMPTrapListener: Send \"SNMPTrapLister/Ready\" event" +
              " to " + remoteHost + ".");
      handle.submit2(remoteHost, "SEM", "PULSE EVENT SNMPTrapLister/Ready");
      // Wait event which notices that all the traps have been sent
      System.out.println(
              "run() of SNMPTrapListener: Wait \"SendTrap/Complete\" event " +
              "from " + remoteHost + ".");
      handle.submit2(remoteHost, "SEM", "WAIT EVENT SendTrap/Complete");
      // Delte event
      System.out.println(
              "run() of SNMPTrapListener: Delte \"SendTrap/Complete\" event " +
              "on " + remoteHost + ".");
      handle.submit2(remoteHost, "SEM", "DELETE EVENT SendTrap/Complete");
      // Display status of the traps
      currentTrapNumber =
              nbTrapV1_community +
              nbTrapV1_otherCommunity +
              nbTrapV2_community +
              nbTrapV2_otherCommunity +
              nbTrapV3_community +
              nbTrapV3_otherCommunity;
      System.out.println(
              "run() of SNMPTrapListener has catched " +
              currentTrapNumber + " traps.");
      String[] tmp = expectedTrapList.split(",");
      System.out.println("Number of trap V1 in " + community + " community: " +
              nbTrapV1_community + "/" + tmp[0]);
      System.out.println("Number of trap V1 in other community: " +
              nbTrapV1_otherCommunity + "/" + tmp[1]);
      System.out.println("Number of trap V2 in " + community + " community: " +
              nbTrapV2_community + "/" + tmp[2]);
      System.out.println("Number of trap V2 in other community: " +
              nbTrapV2_otherCommunity + "/" + tmp[3]);
      System.out.println("Number of trap V3 in " + community + " community: " +
              nbTrapV3_community + "/" + tmp[4]);
      System.out.println("Number of trap V3 in other community: " +
              nbTrapV3_otherCommunity + "/" + tmp[5]);
      // Status of the trap listener
      currentTrapList =
              nbTrapV1_community + "," +
              nbTrapV1_otherCommunity + "," +
              nbTrapV2_community + "," +
              nbTrapV2_otherCommunity + "," +
              nbTrapV3_community + "," +
              nbTrapV3_otherCommunity;
      if (currentTrapList.compareTo(expectedTrapList) != 0) {
        rc = 1;
      }
    } catch (Exception e) {
      System.out.println(
              "connect() of SNMPGet catched execption: " + e.toString() + "\"");
      rc = 1;
    }
    if (rc == 0) {
      System.out.println("run() of SNMPTrapListener succeeded");
    } else {
      System.out.println("run() of SNMPTrapListener failed");
    }
    return rc;
  }
  /**
   * Main.
   *
   * @param args arguments
   */
  public static void main(String[] args) {
    SNMPTrapListener client = new SNMPTrapListener();
    int rc = 0;
    // Retrieve parameters
    rc = client.init(args);
    // If init() succeeded then run the trap listener
    if (rc == 0) {
      rc = client.run();
    }
    System.exit(rc);
  }
  // Arguments
  String remoteHost = null;
  int port = 0;
  String community = null;
  String expectedTrapList = null;
  String trapCommunity = "";
  String currentTrapList = null;
  int currentTrapNumber = 0;
  int nbTrapV1_community = 0;
  int nbTrapV1_otherCommunity = 0;
  int nbTrapV2_community = 0;
  int nbTrapV2_otherCommunity = 0;
  int nbTrapV3_community = 0;
  int nbTrapV3_otherCommunity = 0;
}