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

madiot
29.17.2009 20502e10969c8b2378f3f85a27390c861df809e4
add extension to STAF dsml service to check result file against know error strings
1 files added
4 files modified
217 ■■■■ changed files
opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_setup.xml 9 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_test.xml 24 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/ant/tests.xml 9 ●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/dsml/resource/errorStrings.properties 43 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/dsml/src/com/ibm/staf/service/opends/DSMLService.java 132 ●●●● patch | view | raw | blame | history
opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_setup.xml
@@ -120,6 +120,15 @@
                }
              </call>
              <call function="'copyFile'">
                {
                'location'   : STAXServiceMachine,
                'srcfile'    : '%s/resource/errorStrings.properties' % TESTS_DSML_DIR,
                'destfile'   : '%s/dsml/STAF-INF/classes/errorStrings.properties' % TMPDIR,
                'remotehost' : STAXServiceMachine
                }
              </call>
              <call function="'createFolder'">
                {
                'location'   : location,
opends/tests/staf-tests/functional-tests/testcases/dsml/dsml_test.xml
@@ -367,6 +367,30 @@
                                            </sequence>
                                          </iterate>
                                        </if>
                                        <message>'checking string marker issues in result'</message>
                                        <call function="'runSTAFCommand'">
                                          { 'name'      :  'check if known issue %s' % issue,
                                            'location'  :  STAXServiceMachine,
                                            'service'   :  'DSML',
                                            'request'   :  'CHECK_ERROR_STRINGS',
                                            'arguments' :  'FILE %s ' %(runFilePath)
                                          }
                                        </call>
                                        <if expr="RC >= 100000000">
                                          <!-- string marked issues start from 100000000 -->
                                          <sequence>
                                            <script>
                                              issue = RC - 100000000
                                            </script>
                                            <!-- this is a known issue -->
                                            <call function="'setKnownIssue'">
                                              { 'issueId' : issue }
                                            </call>
                                            <break/>
                                          </sequence>
                                        </if>
                                      </sequence>
                                      <catch exception="'...'" typevar="eType" var="eInfo">
                                        <sequence>
opends/tests/staf-tests/shared/ant/tests.xml
@@ -32,11 +32,18 @@
  <target name="specs">
    <javac srcdir="${shared.dir}/java/parsingtool"
           destdir="${shared.dir}/java/parsingtool"/>
           destdir="${shared.dir}/java/parsingtool"
           debug="true"
           debuglevel="lines,vars,source"
           verbose="yes"
           />
    <delete dir="${logs.dir}/specs" failonerror="false"/>
    <mkdir dir="${logs.dir}/specs"/>
    <java classpath="${shared.dir}/java/parsingtool"
          classname="GenerateOpenDSTestSpecs" fork="true">
        <!-- uncomment "agentlib" if need debugger waiting for you
        <jvmarg value="-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=7778"/>
        -->
        <arg value="${tests.dir}"/>
        <arg value="${logs.dir}/specs"/>
        <arg value="xml" />
opends/tests/staf-tests/shared/dsml/resource/errorStrings.properties
New file
@@ -0,0 +1,43 @@
# 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
# information:
#      Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#      Copyright 2009 Sun Microsystems, Inc.
# This file contains a list of generic issues that arise accross potentially
# multiple DSML suites.
# The expected format is : ISSUEID[_label][.r]=substring | regexp
# When suffixed with '.r' the string is assumed to be a valid java regexp
#   see : http://java.sun.com/developer/technicalArticles/releases/1.4regex
#
# examples :
#
#0001_generic=<errorMessage>The maximum time limit of 1 seconds for processing this search operation has expired</errorMessage>
#0002_import=<errorMessage>You do not have sufficient privileges to perform an unindexed search</errorMessage>
#0003.r=.*maximum.*
#0004_generic.r.r=[^@]privileges
#
# multiple string might correspond to a single bug, hence property are better
# sorted out by ISSUEID
# Note : the lookup will raise an issue for the first match
0000_lengthyRequest=<errorMessage>The maximum time limit of 1 seconds for processing this search operation has expired</errorMessage>
4178_importRelated=<errorMessage>You do not have sufficient privileges to perform an unindexed search</errorMessage>
opends/tests/staf-tests/shared/dsml/src/com/ibm/staf/service/opends/DSMLService.java
@@ -30,7 +30,7 @@
import com.ibm.staf.wrapper.*;
import com.ibm.staf.service.*;
import com.ibm.staf.service.opends.tester.*;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
import java.util.ArrayList;
@@ -43,6 +43,7 @@
public class DSMLService implements STAFServiceInterfaceLevel30 {
  private static final String OP_COMPARE = "COMPARE";
  private static final String OP_CHECK_ERROR_STRINGS = "CHECK_ERROR_STRINGS";
  private static final String OP_HELP = "HELP";
  private static final String OP_FILE = "FILE";
  private static final String OP_EXP_FILE = "EXP_FILE";
@@ -55,12 +56,11 @@
  private STAFHandle fHandle;
  private String fLocalMachineName = "";
  private STAFLog logger = null;
  // Define any error codes unique to this service
  private static final int kDSMLInvalidSomething = 4001;
  private static final int kErrorStringMatchOffset = 100000000;
  // STAFCommandParsers for each request
  private STAFCommandParser fCompareParser;
  private STAFCommandParser fParser;
  private String fLineSep;
  public STAFResult init(STAFServiceInterfaceLevel30.InitInfo info) {
@@ -75,31 +75,22 @@
    }
    // COMPARE parser
    fCompareParser = new STAFCommandParser(0, false);
    fCompareParser.addOption(OP_COMPARE, 1, STAFCommandParser.VALUENOTALLOWED);
    fCompareParser.addOption(OP_FILE, 1, STAFCommandParser.VALUEREQUIRED);
    //fCompareParser.addOption(OP_F_SHORTCUT, 0, STAFCommandParser.VALUEREQUIRED);
    fCompareParser.addOption(OP_DIR, 1, STAFCommandParser.VALUEREQUIRED);
    fCompareParser.addOption(OP_EXP_FILE, 1, STAFCommandParser.VALUEREQUIRED);
    fCompareParser.addOption(OP_EXP_DIR, 1, STAFCommandParser.VALUEREQUIRED);
    //fCompareParser.addOption(OP_DIR_SHORT, 0, STAFCommandParser.VALUEREQUIRED);
    //fCompareParser.addOption(OP_D_SHORTCUT, 0, STAFCommandParser.VALUEREQUIRED);
    // either we compare directory or file
    //fCompareParser.addOptionGroup(OP_FILE_GROUP, 1, 3);
    //fCompareParser.addOptionGroup(OP_DIR_GROUP, 1, 3);
    //TODO.1 not needed per dependency below
    //TODO.1 fCompareParser.addOptionGroup(OP_EXPECTED_GROUP, 0, 1);
    //TODO.1 fCompareParser.addOptionNeed(OP_EXPECTED_RESULT_FILE, OP_RESULT_FILE);
    //TODO.1 fCompareParser.addOptionNeed(OP_EXPECTED_RESULT_DIR, OP_RESULT_DIR);
    fParser = new STAFCommandParser(0, false);
    fParser.addOption(OP_COMPARE, 1, STAFCommandParser.VALUENOTALLOWED);
    fParser.addOption(OP_FILE, 1, STAFCommandParser.VALUEREQUIRED);
    fParser.addOption(OP_DIR, 1, STAFCommandParser.VALUEREQUIRED);
    fParser.addOption(OP_EXP_FILE, 1, STAFCommandParser.VALUEREQUIRED);
    fParser.addOption(OP_EXP_DIR, 1, STAFCommandParser.VALUEREQUIRED);
    // if you specify COMPARE, RESULT_FILE is required
    fCompareParser.addOptionNeed(OP_FILE, OP_EXP_FILE);
    fCompareParser.addOptionNeed(OP_EXP_FILE, OP_FILE);
    fCompareParser.addOptionNeed(OP_DIR, OP_EXP_DIR);
    fCompareParser.addOptionNeed(OP_EXP_DIR, OP_DIR);
    fCompareParser.addOptionNeed(OP_COMPARE, OP_FILE + " " + OP_DIR);
    fCompareParser.addOptionNeed(OP_FILE + " " + OP_DIR, OP_COMPARE);
    fParser.addOptionNeed(OP_EXP_FILE, OP_FILE);
    fParser.addOptionNeed(OP_EXP_DIR, OP_DIR);
    fParser.addOptionNeed(OP_COMPARE, OP_EXP_FILE + " " + OP_EXP_DIR);
    fParser.addOptionNeed(OP_EXP_FILE + " " + OP_EXP_DIR, OP_COMPARE);
    // CHECK_ERROR_STRINGS parser
    fParser.addOption(OP_CHECK_ERROR_STRINGS, 1, STAFCommandParser.VALUENOTALLOWED);
    fParser.addOptionNeed(OP_CHECK_ERROR_STRINGS, OP_FILE);
    STAFResult res = new STAFResult();
    // Resolve the line separator variable for the local machine
@@ -130,9 +121,6 @@
  }
  public STAFResult acceptRequest(STAFServiceInterfaceLevel30.RequestInfo info) {
    // dumping the RequestInfo
    //TODO
    //delegate the request handling
    StringTokenizer requestTokenizer = new StringTokenizer(info.request);
    String request = requestTokenizer.nextToken().toLowerCase();
@@ -140,6 +128,8 @@
    // call the appropriate method to handle the command
    if (request.equalsIgnoreCase(OP_COMPARE)) {
      return handleCompare(info);
    } else if (request.equalsIgnoreCase(OP_CHECK_ERROR_STRINGS)) {
      return handleCheckErrorStrings(info);
    } else if (request.equalsIgnoreCase(OP_HELP)) {
      return handleHelp(info);
    } else {
@@ -165,11 +155,79 @@
    return new STAFResult(STAFResult.Ok);
  }
  private STAFResult handleCheckErrorStrings(STAFServiceInterfaceLevel30.RequestInfo info) {
    STAFResult sr = new STAFResult(0);
    STAFCommandParseResult parsedRequest = fParser.parse(info.request);
    if (parsedRequest.rc != STAFResult.Ok) {
      return new STAFResult(STAFResult.InvalidRequestString,
              parsedRequest.errorBuffer);
    }
    String resultFile = parsedRequest.optionValue(OP_FILE);
    Properties errProps = new Properties();
    final String RE = ".r";
    final String lblMarker = "_";
    try {
      ClassLoader cl = this.getClass().getClassLoader();
      InputStream in = cl.getResourceAsStream("errorStrings.properties");
      errProps.load(in);
      in.close();
      Enumeration errEnum = errProps.propertyNames();
      while (errEnum.hasMoreElements()) {
        String k = (String) errEnum.nextElement();
        String issueID = null;
        String lbl = null;
        boolean re = k.endsWith(RE);
        int lblNdx = k.indexOf(lblMarker);
        if (lblNdx != -1) {
          if (re) {
            lbl = k.substring(lblNdx + 1, k.length() - RE.length());
          } else {
            lbl = k.substring(lblNdx + 1);
          }
        }
        if (lblNdx != -1) {
          issueID = k.substring(0, lblNdx);
        } else if (re) {
          issueID = k.substring(0, k.length() - RE.length());
        } else {
          issueID = k;
        }
        String v = errProps.getProperty(k);
        BufferedReader rbr = new BufferedReader(new FileReader(resultFile));
        String line = "";
        while ((line = rbr.readLine()) != null) {
          if (re) {
            if (line.matches(v)) {
              sr = new STAFResult(kErrorStringMatchOffset +
                                  Integer.parseInt(issueID),""+lbl+line);
            }
          } else {
            if (line.indexOf(v) != -1) {
              sr = new STAFResult(kErrorStringMatchOffset +
                                  Integer.parseInt(issueID),""+lbl+line);
              break;
            }
          }
        }
      }
    } catch (FileNotFoundException fnfe) {
      sr.rc = kDSMLInvalidSomething + 11;
      sr.result = fnfe.getMessage();
    } catch (IOException ioe) {
      sr.rc = kDSMLInvalidSomething + 12;
      sr.result = ioe.getMessage();
    } catch (Exception e) {
      sr.rc = kDSMLInvalidSomething + 13;
      sr.result = e.getMessage();
    }
    return sr;
  }
  private STAFResult handleCompare(STAFServiceInterfaceLevel30.RequestInfo info) {
    STAFResult sr = new STAFResult(0);
    //parse the input request 
    STAFCommandParseResult parsedRequest = fCompareParser.parse(info.request);
    STAFCommandParseResult parsedRequest = fParser.parse(info.request);
    if (parsedRequest.rc != STAFResult.Ok) {
      return new STAFResult(STAFResult.InvalidRequestString,
              parsedRequest.errorBuffer);
@@ -255,7 +313,7 @@
        erl.add(expectedContent.toString());
        expectedBufferReader.close();
        if (rl.size() != erl.size()) {
          sr.rc = kDSMLInvalidSomething+3;//TODO
          sr.rc = kDSMLInvalidSomething + 3;
          sr.result = "number of results " +
                  resultFile + "[" + rl.size() + "]" +
                  expectedFile + "[" + erl.size() + "]";
@@ -263,10 +321,6 @@
          boolean identical = true;
          for (int i = 0; i < rl.size(); i++) {
            //starting from 1, because the first is always empty
            /*PIERRE choose this one or below
             identical &= compareResults("HTTP" + erl.get(i),
                    "HTTP" + rl.get(i));
             * */
             identical &= compareResults((String) erl.get(i), (String) rl.get(i));
             logger.log(STAFLog.Warning, "comparing\n"+(String)erl.get(i)+"\nwith\n"+ (String)rl.get(i));
            if (identical) {
@@ -284,13 +338,13 @@
          }
        }
      } catch (FileNotFoundException fnfe) {
        sr.rc = kDSMLInvalidSomething+5;//TODO
        sr.rc = kDSMLInvalidSomething + 5;
        sr.result = fnfe.getMessage();
      } catch (IOException ioe) {
        sr.rc = kDSMLInvalidSomething+6;//TODO
        sr.rc = kDSMLInvalidSomething + 6;
        sr.result = ioe.getMessage();
      } catch (Exception e) {
        sr.rc = kDSMLInvalidSomething+7;//TODO
        sr.rc = kDSMLInvalidSomething + 7;
        sr.result = e.getMessage();
      }
    }
@@ -422,10 +476,10 @@
            "DSML Service Help :" + fLineSep + fLineSep + OP_COMPARE + "(" +
            OP_EXP_FILE + " filename " + OP_FILE + " filename " + " | " +
            OP_EXP_DIR + " dirname " + OP_DIR + " dirname )" +
            fLineSep + OP_CHECK_ERROR_STRINGS + " " + OP_FILE + " filename " +
            fLineSep + OP_HELP);
  }
  // Register error codes for the STAX Service with the HELP service
  private void registerHelpData(int errorNumber, String info,
          String description) {