Skip to content

Commit c4fd4eb

Browse files
author
Bernhard Grünewaldt
committed
basic parser code
1 parent 6313dab commit c4fd4eb

File tree

16 files changed

+768
-24
lines changed

16 files changed

+768
-24
lines changed

DEVELOPMENT.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@
66
mvn package -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
77
java -jar target/java-junit-xml-merger-0.0.1-jar-with-dependencies.jar
88
```
9+
10+
### Testcoverage
11+
12+
[Run OpenClover](http://openclover.org/) with maven:
13+
14+
```bash
15+
mvn clean clover:setup test clover:aggregate clover:clover
16+
```
17+
18+
Now look into `target/site/clover/`

Jenkinsfile

Whitespace-only changes.

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,44 @@
55
----
66
 
77

8+
### Is this for me?
9+
10+
You have multiple XML files that look like this:
11+
12+
```xml
13+
<?xml version="1.0" encoding="UTF-8" ?>
14+
<testsuite tests="23" failures="0" name="foo.BarUnitTest" time="4.20" errors="0" skipped="0">
15+
<!-- foo -->
16+
</testsuite>
17+
```
18+
19+
And you want a single file that looks like this:
20+
21+
```xml
22+
<?xml version="1.0" encoding="UTF-8" ?>
23+
<testsuites name="My Suite" time="6.60" tests="26" failures="0">
24+
<testsuite tests="23" failures="0" name="foo.BarUnitTest" time="4.20" errors="0" skipped="0">
25+
<!-- foo -->
26+
</testsuite>
27+
<testsuite tests="3" failures="0" name="bar.FooUnitTest" time="2.40" errors="0" skipped="0">
28+
<!-- bar -->
29+
</testsuite>
30+
</testsuites>
31+
```
32+
33+
then this is for you
34+
35+
----
36+
&nbsp;
37+
838
### Usage
939

1040
```
1141
java -jar java-junit-xml-merger-0.0.1-jar-with-dependencies.jar \
12-
-i junit-report-1.xml \
13-
-i junit-report-2.xml \
14-
-o junit-all.xml
42+
-i=junit-report-1.xml \
43+
-i=junit-report-2.xml \
44+
-o=junit-all.xml \
45+
-s="My Suite"
1546
```
1647

1748
-----

pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,50 @@
2424
<artifactId>commons-cli</artifactId>
2525
<version>1.4</version>
2626
</dependency>
27+
<dependency>
28+
<groupId>junit</groupId>
29+
<artifactId>junit</artifactId>
30+
<version>4.12</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.openpojo</groupId>
35+
<artifactId>openpojo</artifactId>
36+
<version>0.8.6</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.powermock</groupId>
41+
<artifactId>powermock-module-junit4</artifactId>
42+
<version>${powermock.version}</version>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.powermock</groupId>
47+
<artifactId>powermock-api-mockito</artifactId>
48+
<version>${powermock.version}</version>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.mockito</groupId>
53+
<artifactId>mockito-all</artifactId>
54+
<version>1.10.19</version>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.powermock</groupId>
59+
<artifactId>powermock-api-mockito-common</artifactId>
60+
<version>1.7.0</version>
61+
<scope>test</scope>
62+
</dependency>
2763
</dependencies>
2864
<build>
2965
<plugins>
66+
<plugin>
67+
<groupId>org.openclover</groupId>
68+
<artifactId>clover-maven-plugin</artifactId>
69+
<version>4.2.0</version>
70+
</plugin>
3071
<plugin>
3172
<artifactId>maven-assembly-plugin</artifactId>
3273
<version>3.1.0</version>
@@ -52,4 +93,10 @@
5293
</plugin>
5394
</plugins>
5495
</build>
96+
<properties>
97+
<powermock.version>1.7.0</powermock.version>
98+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
99+
<maven.compiler.source>1.8</maven.compiler.source>
100+
<maven.compiler.target>1.8</maven.compiler.target>
101+
</properties>
55102
</project>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2017 codeclou.io
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package io.codeclou.java.junit.xml.merger;
25+
26+
import io.codeclou.java.junit.xml.merger.model.TestSuite;
27+
import org.apache.commons.cli.*;
28+
import org.w3c.dom.Document;
29+
import org.w3c.dom.Node;
30+
import org.xml.sax.SAXException;
31+
32+
import javax.xml.parsers.DocumentBuilder;
33+
import javax.xml.parsers.DocumentBuilderFactory;
34+
import javax.xml.parsers.ParserConfigurationException;
35+
import java.io.File;
36+
import java.io.IOException;
37+
38+
public class JunitXmlParser {
39+
40+
private CommandLineParser parser = new DefaultParser();
41+
private Options options = new Options();
42+
43+
protected TestSuite parseTestSuite(File filename) throws ParserConfigurationException, SAXException, IOException {
44+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
45+
DocumentBuilder builder = factory.newDocumentBuilder();
46+
Document document = builder.parse(filename);
47+
return transform(document.getFirstChild());
48+
}
49+
50+
public TestSuite transform(Node testSuite) {
51+
TestSuite t = new TestSuite();
52+
t.setTests(Long.valueOf(testSuite.getAttributes().getNamedItem("tests").getNodeValue()));
53+
t.setErrors(Long.valueOf(testSuite.getAttributes().getNamedItem("errors").getNodeValue()));
54+
t.setFailures(Long.valueOf(testSuite.getAttributes().getNamedItem("failures").getNodeValue()));
55+
t.setSkipped(Long.valueOf(testSuite.getAttributes().getNamedItem("skipped").getNodeValue()));
56+
t.setName(testSuite.getAttributes().getNamedItem("name").getNodeValue());
57+
t.setTime(Double.valueOf(testSuite.getAttributes().getNamedItem("time").getNodeValue()));
58+
t.setXml(testSuite);
59+
return t;
60+
}
61+
62+
protected void run(String[] args) throws ParseException {
63+
Option option = new Option("i", "input", true, "input files");
64+
option.setArgs(1000); // allow multiple
65+
options.addOption(option);
66+
options.addOption("o", "output", true, "output file");
67+
CommandLine cmd = this.parser.parse( options, args);
68+
69+
System.out.println("Java Junit Xml Merger");
70+
if(cmd.hasOption("input")) {
71+
System.out.println("input ok");
72+
for (Option o : cmd.getOptions()) {
73+
System.out.println(o.getOpt() + " - " + o.getValue());
74+
}
75+
} else {
76+
System.out.println("input fail");
77+
}
78+
}
79+
}

src/main/java/io/codeclou/java/junit/xml/merger/Merger.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,11 @@
2323
*/
2424
package io.codeclou.java.junit.xml.merger;
2525

26-
import org.apache.commons.cli.*;
27-
2826
public class Merger {
29-
private static CommandLineParser parser = new DefaultParser();
30-
private static Options options = new Options();
31-
32-
33-
public static void main(String [] args) throws ParseException {
34-
Option option = new Option("i", "input", true, "input files");
35-
option.setArgs(1000); // allow multiple
36-
options.addOption(option);
37-
options.addOption("o", "output", true, "output file");
38-
CommandLine cmd = parser.parse( options, args);
3927

40-
System.out.println("Java Junit Xml Merger");
41-
if(cmd.hasOption("input")) {
42-
System.out.println("input ok");
43-
for (Option o : cmd.getOptions()) {
44-
System.out.println(o.getOpt() + " - " + o.getValue());
45-
}
46-
} else {
47-
System.out.println("input fail");
48-
}
28+
public static void main(String [] args) throws Exception {
29+
JunitXmlParser junitXmlParser = new JunitXmlParser();
30+
junitXmlParser.run(args);
4931
}
5032

5133
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2017 codeclou.io
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package io.codeclou.java.junit.xml.merger.model;
25+
26+
import org.w3c.dom.Node;
27+
28+
public class TestSuite {
29+
30+
private Long tests;
31+
private Long failures;
32+
private Long errors;
33+
private Long skipped;
34+
private String name;
35+
private Double time;
36+
37+
private Node xml;
38+
39+
public Long getTests() {
40+
return tests;
41+
}
42+
43+
public void setTests(Long tests) {
44+
this.tests = tests;
45+
}
46+
47+
public Long getFailures() {
48+
return failures;
49+
}
50+
51+
public void setFailures(Long failures) {
52+
this.failures = failures;
53+
}
54+
55+
public Long getErrors() {
56+
return errors;
57+
}
58+
59+
public void setErrors(Long errors) {
60+
this.errors = errors;
61+
}
62+
63+
public Long getSkipped() {
64+
return skipped;
65+
}
66+
67+
public void setSkipped(Long skipped) {
68+
this.skipped = skipped;
69+
}
70+
71+
public String getName() {
72+
return name;
73+
}
74+
75+
public void setName(String name) {
76+
this.name = name;
77+
}
78+
79+
public Double getTime() {
80+
return time;
81+
}
82+
83+
public void setTime(Double time) {
84+
this.time = time;
85+
}
86+
87+
public Node getXml() {
88+
return xml;
89+
}
90+
91+
public void setXml(Node xml) {
92+
this.xml = xml;
93+
}
94+
}

0 commit comments

Comments
 (0)