Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 053d611

Browse files
authored
Merge pull request #694 from utPLSQL/xmlvalidation
Xmlvalidation
2 parents 16a7632 + 1b3e0bd commit 053d611

5 files changed

Lines changed: 356 additions & 16 deletions

File tree

.travis/lib/xml_validator.jar

9.89 KB
Binary file not shown.

.travis/validate_report_files.sh

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,66 @@
11
#!/usr/bin/env bash
22

3-
echo "validate html"
3+
GL_VALID=1
4+
XSD_DIR="$TRAVIS_BUILD_DIR/.travis/xsd"
5+
XML_JAR_DIR="$TRAVIS_BUILD_DIR/.travis/lib"
6+
#XML Validator
7+
XML_VALIDATOR="$XML_JAR_DIR/xml_validator.jar"
8+
HTML_VALIDATOR_URL="https://validator.w3.org/nu/"
49

510
HTML_FILENAME="coverage.html"
6-
#Exclude existing issue with OL nested in PRE
7-
EXCLUSION_REGEX=".*Element\s.?ol.?\snot\sallowed\sas\schild\sof\selement\s.?pre.*"
8-
HTML_VALIDATOR_URL="https://validator.w3.org/nu/"
9-
VALIDATOR_OUT="gnu"
10-
WARNING_REGEX="info warning:"
11-
ERROR_REGEX="error:"
11+
declare -A XML_FILES
12+
XML_FILES["junit_test_results.xml"]="junit4.xsd"
13+
XML_FILES["tfs_test_results.xml"]="junit_windy.xsd"
14+
15+
function ValidateHtml {
16+
EXCLUSION_REGEX=".*Element\s.?ol.?\snot\sallowed\sas\schild\sof\selement\s.?pre.*"
17+
#HTML Validation API
18+
VALIDATOR_OUT="gnu"
19+
WARNING_REGEX="info warning:"
20+
ERROR_REGEX="error:"
21+
#Validate HTML
22+
HTML_VALIDATION_RESULTS=$(curl -H "Content-Type: text/html; charset=utf-8" --data-binary @$1 "$HTML_VALIDATOR_URL?out=$VALIDATOR_OUT&filterpattern=$EXCLUSION_REGEX")
23+
24+
ERROR_COUNT=$(echo "$HTML_VALIDATION_RESULTS" | grep -c "$ERROR_REGEX")
25+
WARNING_COUNT=$(echo "$HTML_VALIDATION_RESULTS" | grep -c "$WARNING_REGEX")
26+
27+
if [ "$ERROR_COUNT" -gt 0 ]; then
28+
GL_VALID=0
29+
echo ""
30+
echo "******************************"
31+
echo "HTML File is invalid"
32+
echo "There are $ERROR_COUNT errors, $WARNING_COUNT warning in $HTML_FILENAME"
33+
echo "Please see results:"
34+
echo "$HTML_VALIDATION_RESULTS" | grep "$ERROR_REGEX"
35+
fi
36+
}
1237

13-
VALIDATION_RESULTS=$(curl -H "Content-Type: text/html; charset=utf-8" --data-binary @$HTML_FILENAME "$HTML_VALIDATOR_URL?out=$VALIDATOR_OUT&filterpattern=$EXCLUSION_REGEX")
38+
function ValidateXML() {
39+
echo "Validate File $2 against schema $1"
40+
VALIDATION_RESULT=$(java -jar $XML_VALIDATOR -s $1 $2 2>&1)
41+
42+
if [ $? -ne 0 ]; then
43+
GL_VALID=0
44+
echo ""
45+
echo "******************************"
46+
echo "XML is invalid"
47+
echo "Please see results:"
48+
echo "$VALIDATION_RESULT"
49+
fi
50+
}
1451

15-
ERROR_COUNT=`echo "$VALIDATION_RESULTS" | grep -c "$ERROR_REGEX"`
16-
WARNING_COUNT=`echo "$VALIDATION_RESULTS" | grep -c "$WARNING_REGEX"`
52+
ValidateHtml "$HTML_FILENAME"
1753

18-
echo "There are $ERROR_COUNT errors, $WARNING_COUNT warning in $HTML_FILENAME"
54+
for XMLFILE in "${!XML_FILES[@]}"; do
55+
#echo "$XMLFILE" "${XML_FILES[$XMLFILE]}";
56+
ValidateXML "$XSD_DIR/${XML_FILES[$XMLFILE]}" "$XMLFILE"
57+
done
1958

20-
if [ $ERROR_COUNT -gt 0 ]; then
21-
echo "$VALIDATION_RESULTS" | grep "$ERROR_REGEX"
22-
exit 1
59+
if [ $GL_VALID -ne 1 ]; then
60+
echo ""
61+
echo "******************************"
62+
echo "Validation failed please see results above."
63+
exit 1
2364
else
24-
exit 0
65+
exit 0
2566
fi

.travis/xsd/junit4.xsd

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
4+
<xs:element name="failure">
5+
<xs:complexType mixed="true">
6+
<xs:attribute name="type" type="xs:string" use="optional"/>
7+
<xs:attribute name="message" type="xs:string" use="optional"/>
8+
</xs:complexType>
9+
</xs:element>
10+
11+
<xs:element name="error">
12+
<xs:complexType mixed="true">
13+
<xs:attribute name="type" type="xs:string" use="optional"/>
14+
<xs:attribute name="message" type="xs:string" use="optional"/>
15+
</xs:complexType>
16+
</xs:element>
17+
18+
<xs:element name="properties">
19+
<xs:complexType>
20+
<xs:sequence>
21+
<xs:element ref="property" maxOccurs="unbounded"/>
22+
</xs:sequence>
23+
</xs:complexType>
24+
</xs:element>
25+
26+
<xs:element name="property">
27+
<xs:complexType>
28+
<xs:attribute name="name" type="xs:string" use="required"/>
29+
<xs:attribute name="value" type="xs:string" use="required"/>
30+
</xs:complexType>
31+
</xs:element>
32+
33+
<xs:element name="skipped" type="xs:string"/>
34+
<xs:element name="system-err" type="xs:string"/>
35+
<xs:element name="system-out" type="xs:string"/>
36+
37+
<xs:element name="testcase">
38+
<xs:complexType>
39+
<xs:sequence>
40+
<xs:element ref="skipped" minOccurs="0" maxOccurs="1"/>
41+
<xs:element ref="error" minOccurs="0" maxOccurs="unbounded"/>
42+
<xs:element ref="failure" minOccurs="0" maxOccurs="unbounded"/>
43+
<xs:element ref="system-out" minOccurs="0" maxOccurs="unbounded"/>
44+
<xs:element ref="system-err" minOccurs="0" maxOccurs="unbounded"/>
45+
</xs:sequence>
46+
<xs:attribute name="name" type="xs:string" use="required"/>
47+
<xs:attribute name="assertions" type="xs:string" use="optional"/>
48+
<xs:attribute name="time" type="xs:string" use="optional"/>
49+
<xs:attribute name="classname" type="xs:string" use="optional"/>
50+
<xs:attribute name="status" type="xs:string" use="optional"/>
51+
</xs:complexType>
52+
</xs:element>
53+
54+
<xs:element name="testsuite">
55+
<xs:complexType>
56+
<xs:sequence>
57+
<xs:element ref="properties" minOccurs="0" maxOccurs="1"/>
58+
<xs:element ref="testsuite" minOccurs="0" maxOccurs="unbounded"/>
59+
<xs:element ref="testcase" minOccurs="0" maxOccurs="unbounded"/>
60+
<xs:element ref="system-out" minOccurs="0" maxOccurs="1"/>
61+
<xs:element ref="system-err" minOccurs="0" maxOccurs="1"/>
62+
</xs:sequence>
63+
<xs:attribute name="name" type="xs:string" use="required"/>
64+
<xs:attribute name="tests" type="xs:string" use="required"/>
65+
<xs:attribute name="failures" type="xs:string" use="optional"/>
66+
<xs:attribute name="errors" type="xs:string" use="optional"/>
67+
<xs:attribute name="time" type="xs:string" use="optional"/>
68+
<xs:attribute name="disabled" type="xs:string" use="optional"/>
69+
<xs:attribute name="skipped" type="xs:string" use="optional"/>
70+
<xs:attribute name="timestamp" type="xs:string" use="optional"/>
71+
<xs:attribute name="hostname" type="xs:string" use="optional"/>
72+
<xs:attribute name="id" type="xs:string" use="optional"/>
73+
<xs:attribute name="package" type="xs:string" use="optional"/>
74+
</xs:complexType>
75+
</xs:element>
76+
77+
<xs:element name="testsuites">
78+
<xs:complexType>
79+
<xs:sequence>
80+
<xs:element ref="testsuite" minOccurs="0" maxOccurs="unbounded"/>
81+
</xs:sequence>
82+
<xs:attribute name="name" type="xs:string" use="optional"/>
83+
<xs:attribute name="time" type="xs:string" use="optional"/>
84+
<xs:attribute name="tests" type="xs:string" use="optional"/>
85+
<xs:attribute name="failures" type="xs:string" use="optional"/>
86+
<xs:attribute name="disabled" type="xs:string" use="optional"/>
87+
<xs:attribute name="errors" type="xs:string" use="optional"/>
88+
</xs:complexType>
89+
</xs:element>
90+
91+
92+
</xs:schema>

.travis/xsd/junit_windy.xsd

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
elementFormDefault="qualified"
5+
attributeFormDefault="unqualified">
6+
<xs:annotation>
7+
<xs:documentation xml:lang="en">JUnit test result schema for the Apache Ant JUnit and JUnitReport tasks
8+
Copyright © 2011, Windy Road Technology Pty. Limited
9+
The Apache Ant JUnit XML Schema is distributed under the terms of the Apache License Version 2.0 http://www.apache.org/licenses/
10+
Permission to waive conditions of this license may be requested from Windy Road Support (http://windyroad.org/support).</xs:documentation>
11+
</xs:annotation>
12+
<xs:element name="testsuite" type="testsuite"/>
13+
<xs:simpleType name="ISO8601_DATETIME_PATTERN">
14+
<xs:restriction base="xs:dateTime">
15+
<xs:pattern value="[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}"/>
16+
</xs:restriction>
17+
</xs:simpleType>
18+
<xs:element name="testsuites">
19+
<xs:annotation>
20+
<xs:documentation xml:lang="en">Contains an aggregation of testsuite results</xs:documentation>
21+
</xs:annotation>
22+
<xs:complexType>
23+
<xs:sequence>
24+
<xs:element name="testsuite" minOccurs="0" maxOccurs="unbounded">
25+
<xs:complexType>
26+
<xs:complexContent>
27+
<xs:extension base="testsuite">
28+
<xs:attribute name="package" type="xs:token" use="required">
29+
<xs:annotation>
30+
<xs:documentation xml:lang="en">Derived from testsuite/@name in the non-aggregated documents</xs:documentation>
31+
</xs:annotation>
32+
</xs:attribute>
33+
<xs:attribute name="id" type="xs:int" use="required">
34+
<xs:annotation>
35+
<xs:documentation xml:lang="en">Starts at '0' for the first testsuite and is incremented by 1 for each following testsuite</xs:documentation>
36+
</xs:annotation>
37+
</xs:attribute>
38+
</xs:extension>
39+
</xs:complexContent>
40+
</xs:complexType>
41+
</xs:element>
42+
</xs:sequence>
43+
</xs:complexType>
44+
</xs:element>
45+
<xs:complexType name="testsuite">
46+
<xs:annotation>
47+
<xs:documentation xml:lang="en">Contains the results of exexuting a testsuite</xs:documentation>
48+
</xs:annotation>
49+
<xs:sequence>
50+
<xs:element name="properties">
51+
<xs:annotation>
52+
<xs:documentation xml:lang="en">Properties (e.g., environment settings) set during test execution</xs:documentation>
53+
</xs:annotation>
54+
<xs:complexType>
55+
<xs:sequence>
56+
<xs:element name="property" minOccurs="0" maxOccurs="unbounded">
57+
<xs:complexType>
58+
<xs:attribute name="name" use="required">
59+
<xs:simpleType>
60+
<xs:restriction base="xs:token">
61+
<xs:minLength value="1"/>
62+
</xs:restriction>
63+
</xs:simpleType>
64+
</xs:attribute>
65+
<xs:attribute name="value" type="xs:string" use="required"/>
66+
</xs:complexType>
67+
</xs:element>
68+
</xs:sequence>
69+
</xs:complexType>
70+
</xs:element>
71+
<xs:element name="testcase" minOccurs="0" maxOccurs="unbounded">
72+
<xs:complexType>
73+
<xs:choice minOccurs="0">
74+
<xs:element name="error">
75+
<xs:annotation>
76+
<xs:documentation xml:lang="en">Indicates that the test errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test. Contains as a text node relevant data for the error, e.g., a stack trace</xs:documentation>
77+
</xs:annotation>
78+
<xs:complexType>
79+
<xs:simpleContent>
80+
<xs:extension base="pre-string">
81+
<xs:attribute name="message" type="xs:string">
82+
<xs:annotation>
83+
<xs:documentation xml:lang="en">The error message. e.g., if a java exception is thrown, the return value of getMessage()</xs:documentation>
84+
</xs:annotation>
85+
</xs:attribute>
86+
<xs:attribute name="type" type="xs:string" use="required">
87+
<xs:annotation>
88+
<xs:documentation xml:lang="en">The type of error that occured. e.g., if a java execption is thrown the full class name of the exception.</xs:documentation>
89+
</xs:annotation>
90+
</xs:attribute>
91+
</xs:extension>
92+
</xs:simpleContent>
93+
</xs:complexType>
94+
</xs:element>
95+
<xs:element name="failure">
96+
<xs:annotation>
97+
<xs:documentation xml:lang="en">Indicates that the test failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals. Contains as a text node relevant data for the failure, e.g., a stack trace</xs:documentation>
98+
</xs:annotation>
99+
<xs:complexType>
100+
<xs:simpleContent>
101+
<xs:extension base="pre-string">
102+
<xs:attribute name="message" type="xs:string">
103+
<xs:annotation>
104+
<xs:documentation xml:lang="en">The message specified in the assert</xs:documentation>
105+
</xs:annotation>
106+
</xs:attribute>
107+
<xs:attribute name="type" type="xs:string" use="required">
108+
<xs:annotation>
109+
<xs:documentation xml:lang="en">The type of the assert.</xs:documentation>
110+
</xs:annotation>
111+
</xs:attribute>
112+
</xs:extension>
113+
</xs:simpleContent>
114+
</xs:complexType>
115+
</xs:element>
116+
</xs:choice>
117+
<xs:attribute name="name" type="xs:token" use="required">
118+
<xs:annotation>
119+
<xs:documentation xml:lang="en">Name of the test method</xs:documentation>
120+
</xs:annotation>
121+
</xs:attribute>
122+
<xs:attribute name="classname" type="xs:token" use="required">
123+
<xs:annotation>
124+
<xs:documentation xml:lang="en">Full class name for the class the test method is in.</xs:documentation>
125+
</xs:annotation>
126+
</xs:attribute>
127+
<xs:attribute name="time" type="xs:decimal" use="required">
128+
<xs:annotation>
129+
<xs:documentation xml:lang="en">Time taken (in seconds) to execute the test</xs:documentation>
130+
</xs:annotation>
131+
</xs:attribute>
132+
</xs:complexType>
133+
</xs:element>
134+
<xs:element name="system-out">
135+
<xs:annotation>
136+
<xs:documentation xml:lang="en">Data that was written to standard out while the test was executed</xs:documentation>
137+
</xs:annotation>
138+
<xs:simpleType>
139+
<xs:restriction base="pre-string">
140+
<xs:whiteSpace value="preserve"/>
141+
</xs:restriction>
142+
</xs:simpleType>
143+
</xs:element>
144+
<xs:element name="system-err">
145+
<xs:annotation>
146+
<xs:documentation xml:lang="en">Data that was written to standard error while the test was executed</xs:documentation>
147+
</xs:annotation>
148+
<xs:simpleType>
149+
<xs:restriction base="pre-string">
150+
<xs:whiteSpace value="preserve"/>
151+
</xs:restriction>
152+
</xs:simpleType>
153+
</xs:element>
154+
</xs:sequence>
155+
<xs:attribute name="name" use="required">
156+
<xs:annotation>
157+
<xs:documentation xml:lang="en">Full class name of the test for non-aggregated testsuite documents. Class name without the package for aggregated testsuites documents</xs:documentation>
158+
</xs:annotation>
159+
<xs:simpleType>
160+
<xs:restriction base="xs:token">
161+
<xs:minLength value="1"/>
162+
</xs:restriction>
163+
</xs:simpleType>
164+
</xs:attribute>
165+
<xs:attribute name="timestamp" type="ISO8601_DATETIME_PATTERN" use="required">
166+
<xs:annotation>
167+
<xs:documentation xml:lang="en">when the test was executed. Timezone may not be specified.</xs:documentation>
168+
</xs:annotation>
169+
</xs:attribute>
170+
<xs:attribute name="hostname" use="required">
171+
<xs:annotation>
172+
<xs:documentation xml:lang="en">Host on which the tests were executed. 'localhost' should be used if the hostname cannot be determined.</xs:documentation>
173+
</xs:annotation>
174+
<xs:simpleType>
175+
<xs:restriction base="xs:token">
176+
<xs:minLength value="1"/>
177+
</xs:restriction>
178+
</xs:simpleType>
179+
</xs:attribute>
180+
<xs:attribute name="tests" type="xs:int" use="required">
181+
<xs:annotation>
182+
<xs:documentation xml:lang="en">The total number of tests in the suite</xs:documentation>
183+
</xs:annotation>
184+
</xs:attribute>
185+
<xs:attribute name="failures" type="xs:int" use="required">
186+
<xs:annotation>
187+
<xs:documentation xml:lang="en">The total number of tests in the suite that failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals</xs:documentation>
188+
</xs:annotation>
189+
</xs:attribute>
190+
<xs:attribute name="errors" type="xs:int" use="required">
191+
<xs:annotation>
192+
<xs:documentation xml:lang="en">The total number of tests in the suite that errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test.</xs:documentation>
193+
</xs:annotation>
194+
</xs:attribute>
195+
<xs:attribute name="time" type="xs:decimal" use="required">
196+
<xs:annotation>
197+
<xs:documentation xml:lang="en">Time taken (in seconds) to execute the tests in the suite</xs:documentation>
198+
</xs:annotation>
199+
</xs:attribute>
200+
</xs:complexType>
201+
<xs:simpleType name="pre-string">
202+
<xs:restriction base="xs:string">
203+
<xs:whiteSpace value="preserve"/>
204+
</xs:restriction>
205+
</xs:simpleType>
206+
</xs:schema>

test/install_and_run_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ utPLSQL-cli/bin/utplsql run ${UT3_TESTER}/${UT3_TESTER_PASSWORD}@${CONNECTION_ST
2020
-f=ut_coverage_html_reporter -o=coverage.html \
2121
-f=ut_coveralls_reporter -o=coverage.json \
2222
-f=ut_sonar_test_reporter -o=test_results.xml \
23-
-f=ut_xunit_reporter -o=xunit_test_results.xml \
23+
-f=ut_junit_reporter -o=junit_test_results.xml \
24+
-f=ut_tfs_junit_reporter -o=tfs_test_results.xml \
2425
-scc
2526

2627
status_line_regex="^[0-9]+ tests, ([0-9]+) failed, ([0-9]+) errored.*"

0 commit comments

Comments
 (0)