dsml_test.xml revision e40639fdd7b54f787c782ae98c1cc3c3c6484a5b
<?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
!
! Portions Copyright 2008-2009 Sun Microsystems, Inc.
! -->
<stax>
<defaultcall function="dsml_test" />
<function name="dsml_test">
<sequence>
<block name="'dsml_test'">
<try>
<sequence>
<!--- Test Suite information
#@TestSuiteName test
#@TestSuitePurpose test for the dsml test suite.
#@TestSuiteGroup dsml test
#@TestScript dsml_test.xml
-->
<script>
if not CurrentTestPath.has_key('group'):
CurrentTestPath['group'] = 'dsml'
CurrentTestPath['suite'] = STAXCurrentBlock
</script>
<call function="'testSuite_Preamble'"/>
<import machine="STAF_LOCAL_HOSTNAME"
file="'%s/testcases/%s/dsml_setup.xml' % (TESTS_DIR,_group)"/>
<call function="'dsml_setup'"/>
<message>'TESTS_DATA_DIR=%s ' % (local.data)</message>
<!--- Test Case information
#@TestMarker test
#@TestName test: test webcontainer
#@TestIssue none
#@TestPurpose test webcontainer responding necessary to the
test suite.
#@TestPreamble none
#@TestSteps get the list of DSML test family
#@TestSteps for each family get the list of DSML SOAP requests (testXYZ.dat)
#@TestSteps for each SOAP request, submit it and store the result (testXYZ.run)
#@TestSteps for each SOAP result, compare it with reference (testXYZ.run vs testXYZ.res)
#@TestResult Success if returns 0.
-->
<message>'List DSML suites families'</message>
<call function="'runSTAFCommand'">
{ 'name' : 'list DSML suites families',
'location' : STAXServiceMachine,
'service' : 'FS',
'request' : 'LIST DIRECTORY',
'arguments' : '%s/dsml/suites SORTBYNAME TYPE d' % local.data
}
</call>
<if expr="RC != 0">
<sequence>
<message>
'Folder %d/dsml/suites does not exist.' % (local.data)
</message>
<return>0</return>
</sequence>
</if>
<script>
cmdRC=RC
familyList=STAFResult
# The subversion folder could be present, if so remove it
if familyList.count != 0:
try:
familyList.remove('genericIssues')
except ValueError:
print "List element genericIssues does not exist"
try:
familyList.remove('.svn')
except ValueError:
print "List element .svn does not exist"
import re
import base64
runFileRE = re.compile( 'dat$')
validAuthRE = re.compile ( '\%VALIDAUTH\%' )
sslRE = re.compile( '_ssl' )
urls = { \
'noSSL' : 'http://%s:%s/dsml/DSMLServlet' % (WC_HOST,WC_PORT), \
'SSL' : 'https://%s:%s/dsml/DSMLServlet' % (WC_HOST,WC_SSL_PORT) \
}
</script>
<message>'dsml list of suites %s' % familyList</message>
<message>'getting the list of generic known Issues spanning multiple tests'</message>
<call function="'runSTAFCommand'">
{ 'name' : 'list known generic issues',
'location' : STAXServiceMachine,
'service' : 'FS',
'request' : 'LIST DIRECTORY',
'arguments' : '%s/dsml/suites/genericIssues EXT issue RECURSE' % (local.data)
}
</call>
<if expr="RC != 0">
<sequence>
<message>
'Failed to get known generic issues from %s/dsml/suites/genericIssues' % (local.data)
</message>
<return>0</return>
</sequence>
<else>
<script>
genericIssues = STAFResult
</script>
</else>
</if>
<message>'DSML familyList = %s' % familyList</message>
<iterate var="family" in="familyList">
<sequence>
<message>'DSML family %s ' % family</message>
<call function="'runSTAFCommand'">
{ 'name' : 'List DSML suite %s input' % family,
'location' : STAXServiceMachine,
'service' : 'FS',
'request' : 'LIST DIRECTORY',
'arguments' : '%s/dsml/suites/%s/data \
SORTBYNAME EXT dat TYPE f' % (local.data,family)
}
</call>
<script>
familyInput = STAFResult
</script>
<call function="'runSTAFCommand'">
{ 'name' : 'List DSML suite %s expected results' % family,
'location' : STAXServiceMachine,
'service' : 'FS',
'request' : 'LIST DIRECTORY',
'arguments' : '%s/dsml/suites/%s/data \
SORTBYNAME EXT res TYPE f' % (local.data,family)
}
</call>
<script>
familyExpected = STAFResult
</script>
<iterate var="test" in="familyInput">
<testcase name="getTestCaseName('%s-%s' % (family,test))">
<sequence>
<try>
<sequence>
<message>
'Test Name = %s' % STAXCurrentTestcase
</message>
<call function="'testCase_Preamble'"/>
<script>
runFileName = runFileRE.sub('run',test)
runFilePath = '%s/%s_%s' % (local.temp, family, runFileName)
requestFilePath = '%s/dsml/suites/%s/data/%s' % \
(local.data,family,test)
expectedFileName = runFileRE.sub('res',test)
expectedFilePath = '%s/dsml/suites/%s/data/%s' % \
(local.data,family,expectedFileName)
if (sslRE.search(test) != None):
url = urls['SSL']
else:
url = urls['noSSL']
</script>
<call function="'runSTAFCommand'">
{ 'name' : 'List DSML suite %s file %s' % (family,test),
'location' : STAXServiceMachine,
'service' : 'FS',
'request' : 'GET FILE',
'arguments' : requestFilePath
}
</call>
<script>
from com.ibm.staf import STAFUtil
BODYSeparator = '\n\n'
BODYStart = STAFResult.index(BODYSeparator)
h = STAFResult[:BODYStart]
kvs=h.split("\n")
SOAPHeaders = "HEADER content-type=text/xml "
for e in kvs[1:]:
if (e.upper().startswith("CONTENT-LENGTH:")):
continue
if len(e.strip()) == 0:
continue
if (e.upper().startswith("AUTHORIZATION:")):
e = validAuthRE.sub( base64.encodestring('%s:%s' % \
(DIRECTORY_INSTANCE_DN,DIRECTORY_INSTANCE_PSWD)) , \
e )
s = e.split(':')
rs = re.compile(' ')
s[1]=s[1].strip()
if (rs.search(s[1]) != None):
s[1] = '"' + s[1] + '"'
SOAPHeaders = SOAPHeaders + 'HEADER ' + s[0] + '=' + s[1] + ' '
SOAPBody = STAFUtil.wrapData(STAFResult[BODYStart+len(BODYSeparator):])
</script>
<call function="'runSTAFCommand'">
{ 'name' : 'Submit SOAPBody',
'location' : STAXServiceMachine,
'service' : 'HTTP',
'request' : 'REQUEST METHOD POST',
'arguments' : 'URL %s FOLLOWREDIRECT %s CONTENT %s RETURNHEADERS ' \
% (url, SOAPHeaders, SOAPBody)
}
</call>
<!-- Check the STAFResult is expected class type -->
<if expr='STAFResult.__class__ is not org.python.core.PyDictionary'>
<sequence>
<message log="1" level="'Error'">
'ERROR : Invalid result type (%s), requires org.python.core.PyDictionary.' % STAFResult.__class__
</message>
<throw exception="'STAXException.Results.TestCaseException'">
'Result not a PyDictionary object.'
</throw>
</sequence>
</if>
<call function="'checktestRC'">
{
'returncode' : RC ,
'result' : STAFResult
}
</call>
<if expr="result['statusCode'] == '200'">
<sequence>
<script>
# writing the result file to compare with expected result
httpHeaders = result['headers']
httpContent = result['content']
resultContent = "HTTP1.1 "
resultContent += result['statusCode'] + ' '
resultContent += result['statusMessage'] + '\n'
resultContent += "\n".join(["%s: %s" % (k, v) for k, v in httpHeaders.items()])
resultContent += '\n\n' + httpContent
f=open(runFilePath,'w')
f.write(resultContent)
f.close()
</script>
<message>'Comparing result %s and expected result %s' % (runFilePath, expectedFilePath)</message>
<call function="'runSTAFCommand'">
{ 'name' : 'Compare SOAPResult with expected result',
'location' : STAXServiceMachine,
'service' : 'DSML',
'request' : 'COMPARE FILE',
'arguments' : '%s EXP_FILE %s' %(runFilePath, expectedFilePath)
}
</call>
<if expr="RC != 0">
<!-- list the known issue for the TC -->
<sequence>
<message>"check against test's known issues"</message>
<call function="'runSTAFCommand'">
{ 'name' : 'list known issues for the test',
'location' : STAXServiceMachine,
'service' : 'FS',
'request' : 'LIST DIRECTORY',
'arguments' : '%s/dsml/suites/%s/data NAME %s* EXT issue RECURSE' % (local.data,family,expectedFileName)
}
</call>
<if expr="RC != 0">
<sequence>
<message>
'Failed to get known issues for %s/dsml/suites/%s/data/%s ' % (local.data,family,expectedFileName)
</message>
<return>0</return>
</sequence>
<else>
<try>
<sequence>
<script>
knownTestIssues = STAFResult
</script>
<message >'known Test Issues %s' % knownTestIssues</message>
<if expr="len(knownTestIssues) > 0">
<iterate var="issueFile" in="knownTestIssues">
<sequence>
<script>
# the issue number is the before last element of the '.' splited path
issue=issueFile.split('.')[-2]
issueFilePath = '%s/dsml/suites/%s/data/%s' % (local.data,family,issueFile)
</script>
<call function="'runSTAFCommand'">
{ 'name' : 'check if known issue %s' % issue,
'location' : STAXServiceMachine,
'service' : 'DSML',
'request' : 'COMPARE',
'arguments' : 'FILE %s EXP_FILE %s' %(runFilePath, issueFilePath)
}
</call>
<if expr="RC == 0">
<sequence>
<!-- this is a known issue -->
<call function="'setKnownIssue'">
{ 'issueId' : issue }
</call>
<break/>
</sequence>
</if>
</sequence>
</iterate>
</if>
<if expr="len(genericIssues) > 0">
<iterate var="issueFile" in="genericIssues">
<sequence>
<script>
# the issue number is the before last element of the '.' splited path
issue=issueFile.split('.')[-2]
issueFilePath = '%s/dsml/suites/genericIssues/%s' % (local.data,issueFile)
</script>
<call function="'runSTAFCommand'">
{ 'name' : 'check if known generic issue %s' % issue,
'location' : STAXServiceMachine,
'service' : 'DSML',
'request' : 'COMPARE',
'arguments' : 'FILE %s EXP_FILE %s' %(runFilePath, issueFilePath)
}
</call>
<if expr="RC == 0">
<sequence>
<!-- this is a known issue -->
<call function="'setKnownIssue'">
{ 'issueId' : issue }
</call>
<break/>
</sequence>
</if>
</sequence>
</iterate>
</if>
</sequence>
<catch exception="'...'" typevar="eType" var="eInfo">
<sequence>
<message log="1" level="'fatal'">
'Test case (%s) failed. eType(%s),eInfo(%s)' % (STAXCurrentTestcase,eType,eInfo)
</message>
<tcstatus result="'fail'"/>
</sequence>
</catch>
</try>
</else>
</if>
</sequence>
</if>
<call function="'checktestRC'">
{
'returncode' : RC ,
'result' : STAXResult
}
</call>
</sequence>
<else>
<call function="'checktestRC'">
{
'returncode' : result['statusCode'] ,
'result' : result['statusMessage']
}
</call>
</else>
</if>
</sequence>
<catch exception="'...'" typevar="eType" var="eInfo">
<sequence>
<message log="1" level="'fatal'">
'Test case (%s) failed. eType(%s),eInfo(%s)' % (STAXCurrentTestcase,eType,eInfo)
</message>
<tcstatus result="'fail'"/>
</sequence>
</catch>
<finally>
<call function="'testCase_Postamble'"/>
</finally>
</try>
</sequence>
</testcase>
</iterate>
</sequence>
</iterate>
</sequence>
<finally>
<sequence>
<!-- Test Suite Cleanup -->
<message>'Finally: Global DSML Cleanup.'</message>
<try>
<sequence>
<import machine="STAF_LOCAL_HOSTNAME"
file="'%s/testcases/%s/dsml_cleanup.xml' % (TESTS_DIR,_group)"/>
<call function="'dsml_cleanup'"/>
</sequence>
<catch exception="'STAFException'">
<sequence>
<message log="1" level="'fatal'">'Cleanup of test suite failed.'</message>
</sequence>
</catch>
<finally>
<call function="'testSuite_Postamble'"/>
</finally>
</try>
</sequence>
</finally>
</try>
</block>
</sequence>
</function>
</stax>