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

el_kaboing
05.39.2006 7e3280dfd59ea8775d4c20aa85b18044d545435d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?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
 !
 !      Portions Copyright 2006 Sun Microsystems, Inc.
 ! -->
 
<stax>
 
  <defaultcall function="start_job"/>
 
  <function name="start_job">
 
    <sequence>
 
      <script>
        logdir='%s' % TMPDIR
      </script>
      
      <job name="'Test Job 1'" monitor="1" clearlogs="'Enabled'" logtcstartstop="'Enabled'">
        <job-file>'%s/testcases/runFuncTests.xml' % TESTS_DIR</job-file>
        <job-scriptfiles machine="'%s' % STAF_LOCAL_HOSTNAME">['%s/config/config.py' % TESTS_DIR,'%s/python/security.py' % TESTS_SHARED_DIR]</job-scriptfiles>
        <job-action>
          <log>'Started sub-job %s' % (STAXSubJobID)</log>
        </job-action>
      </job>
 
      <if expr="RC == 0">
        <message>'Sub-job %s completed. Result: %s' % (STAXSubJobID, STAXResult)</message>
      <else>
        <message>'Sub-job %s could not be started. RC: %s Result: %s' % (STAXSubJobID,RC,STAFResult)</message>
      </else>
      </if>
 
      <stafcmd name="'STAF Command: Log Query All'">
        <location>'localhost'</location>
        <service>'log'</service>
        <request>
          'QUERY ALL MACHINE %s LOGNAME STAX_Job_%s' % (STAXServiceMachine,STAXSubJobID)
        </request>
      </stafcmd>
 
      <message>
         'RC=%s, STAFResult= %s' % (RC,STAFResult)
      </message>
 
      <!-- Write Text File for results -->
      <script>
          resultFile= STAFResult
          outfile= '%s/results.txt' % logdir
          txtfh=open(outfile,'w')
      </script>
      
      <iterate var="line" in="resultFile"> 
 
        <script> 
          txtfh.write('%s\n' % line) 
        </script>
      
      </iterate> 
 
      <script> 
        txtfh.close() 
      </script> 
 
      <!-- Write XML File for results -->
      <script>
          import re
          resultFile= STAFResult
          xmlfile= '%s/results.xml' % logdir
          xmlfh=open(xmlfile,'w')
          errorfile= '%s/results.errors' % logdir
          errorfh=open(errorfile,'w')
      </script>
 
      <!-- Build the test case dictionary object -->
      <script>
        testDict={}
        testCaseList=[]
      </script>
 
      <iterate var="element" in="STAFResult"> 
        <script>
          level=element['level']
          message=element['message']
          timestamp=element['timestamp']
 
          startValueDict={}
          stopValueDict={}
          statusValueDict={}
 
          if level == 'Start':
 
            tcpattern=re.compile("(Testcase): (.*)")
            tcmatch = tcpattern.search(message)
 
            if tcmatch:
              tctype=tcmatch.group(1)
              tcname=tcmatch.group(2)
 
              if testDict.has_key(tcname):
 
                for key in testDict[tcname].keys():
                  value=testDict[tcname][key]
                  startValueDict[key]=value
 
              startValueDict['start']=timestamp
              testDict[tcname]=startValueDict
 
              testCaseList.append(tcname)
 
            else:
              errorfh.write('No match element %s.\n' % element)
 
          if level == 'Stop':
 
            tcpattern=re.compile("(Testcase): (.*), ElapsedTime: (.*)")
            tcmatch = tcpattern.search(message)
 
            if tcmatch:
              tctype=tcmatch.group(1)
              tcname=tcmatch.group(2)
              tctime=tcmatch.group(3)
 
              if testDict.has_key(tcname):
 
                for key in testDict[tcname].keys():
                  value=testDict[tcname][key]
                  stopValueDict[key]=value
 
              stopValueDict['stop']=timestamp
              stopValueDict['duration']=tctime
              testDict[tcname]=stopValueDict
 
            else:
              errorfh.write('No match element %s.\n' % element)
 
          if level == 'Status':
 
            tcpattern=re.compile("(Testcase): (.*), Pass: (.*), Fail: (.*), ElapsedTime: (.*), NumStarts: (.*)")
            tcmatch = tcpattern.search(message)
 
            if tcmatch:
              tctype=tcmatch.group(1)
              tcname=tcmatch.group(2)
              tcpass=tcmatch.group(3)
              tcfail=tcmatch.group(4)
              tctime=tcmatch.group(5)
              tcnums=tcmatch.group(6)
 
              if testDict.has_key(tcname):
 
                for key in testDict[tcname].keys():
                  value=testDict[tcname][key]
                  statusValueDict[key]=value
 
              statusValueDict['pass']=tcpass
              statusValueDict['fail']=tcfail
              testDict[tcname]=statusValueDict
 
            else:
              errorfh.write('No match element %s.\n' % element)
 
        </script>
      </iterate>
 
      <!-- XML Report Pre -->
      <script>
        xmlfh.write('&lt;qa&gt;\n')
        xmlfh.write('  &lt;functional-tests&gt;\n')
        xmlfh.write('    &lt;results&gt;\n')
      </script>
 
      <!-- XML Report Results -->
      <script>
        for tcname in testCaseList:
 
          if testDict.has_key(tcname):
 
            if testDict[tcname].has_key('pass'):
              tcpass=testDict[tcname]['pass']
            else:
              tcpass='0'
 
            if testDict[tcname].has_key('fail'):
              tcfail=testDict[tcname]['fail']
            else:
              tcfail='0'
 
            if testDict[tcname].has_key('start'):
              tcstart=testDict[tcname]['start']
            else:
              tcstart='unknown'
 
            if testDict[tcname].has_key('stop'):
              tcstop=testDict[tcname]['stop']
            else:
              tcstop='unknown'
 
            if testDict[tcname].has_key('duration'):
              tcduration=testDict[tcname]['duration']
            else:
              duration='unknown'
 
          else:
            errorfh.write('No key for testcase %s.\n' % tcname)
 
          if int(tcfail) == 0 and int(tcpass) > 0:
            tcresult='pass'
          elif int(tcfail) == 0 and int(tcpass) == 0: 
            tcresult='unknown'
          else:
            tcresult='fail'
 
          xmlfh.write('      &lt;testcase name="%s" result="%s" start="%s" stop="%s" duration="%s"/&gt;\n' % (tcname,tcresult,tcstart,tcstop,tcduration))
      </script> 
 
      <!-- XML Report Post -->
      <script>
        xmlfh.write('    &lt;/results&gt;\n')
        xmlfh.write('  &lt;/functional-tests&gt;\n')
        xmlfh.write('&lt;/qa&gt;\n')
      </script>
 
      <script> 
        xmlfh.close() 
        errorfh.close() 
      </script> 
      
    </sequence>
 
  </function>
 
</stax>