-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* log * refactor: move model to separate project so can use in other projects to parse test xml * refactor: move model to separate project so can use in other projects to parse test xml * add test * refactor * tests passing after refactor * add utils for parsing result from surefire xml dir * add result test * support absolute paths * refactor Co-authored-by: eric.r.driggs <[email protected]>
- Loading branch information
1 parent
ed12a3c
commit c8eb358
Showing
111 changed files
with
2,209 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
springBootVersion = 2.4.5 | ||
springDependencyVersion = 1.0.10.RELEASE | ||
springDependencyVersion = 1.0.10.RELEASE | ||
lombokVersion = 1.18.20 | ||
jakartaVersion = '2.3.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
buildscript { | ||
ext { | ||
jakartaVersion = '2.3.3' | ||
lombokVersion = '1.18.20' | ||
jacksonVersion = '2.13.2' | ||
junitVersion = '5.7.1' | ||
} | ||
} | ||
|
||
plugins { | ||
id 'java' | ||
id 'groovy' | ||
id 'idea' | ||
} | ||
|
||
configurations { | ||
compileOnly { | ||
extendsFrom annotationProcessor | ||
} | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
//Lombok | ||
implementation "org.projectlombok:lombok:${lombokVersion}" | ||
annotationProcessor "org.projectlombok:lombok:${lombokVersion}" | ||
|
||
//JSON | ||
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" | ||
|
||
//XML | ||
compile "jakarta.xml.bind:jakarta.xml.bind-api:${jakartaVersion}" | ||
runtime "com.sun.xml.bind:jaxb-impl:${jakartaVersion}" | ||
|
||
//Mapping | ||
implementation 'org.modelmapper:modelmapper:2.3.0' | ||
|
||
//Test | ||
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" | ||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This file is generated by the 'io.freefair.lombok' Gradle plugin | ||
config.stopBubbling = true | ||
lombok.addLombokGeneratedAnnotation = true | ||
lombok.accessors.chain = true | ||
lombok.equalsAndHashCode.callSuper = call |
64 changes: 64 additions & 0 deletions
64
reportcard-model/src/main/java/com/ericdriggs/file/FileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.ericdriggs.file; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class FileUtils { | ||
|
||
public static String absolutePathFromRelativePath (String relativePath) { | ||
return Path.of(Path.of("").toString(), relativePath).toAbsolutePath().toString(); | ||
} | ||
|
||
public static String regexForExtension (String fileNameExtension) { | ||
return ".*[.]" + fileNameExtension; | ||
} | ||
|
||
public static List<String> fileContentsFromPathAndRegex(String absolutePath, String fileNameRegex) { | ||
List<String> absolutePaths = filePathsForPathAndRegex(absolutePath, fileNameRegex); | ||
return fileContentsFromPaths(absolutePaths); | ||
} | ||
|
||
|
||
public static List<String> fileContentsFromPaths(List<String> absolutePaths) { | ||
List<String> fileContents = new ArrayList<>(); | ||
for ( String absolutePath : absolutePaths) { | ||
fileContents.add(stringFromPath(absolutePath)); | ||
} | ||
return fileContents; | ||
} | ||
|
||
|
||
@SneakyThrows(IOException.class) | ||
public static List<String> filePathsForPathAndRegex(String absolutePath, String fileNameRegex) { | ||
Path dirPath = Path.of(absolutePath); | ||
|
||
//not recursive | ||
final int maxDepth = 1; | ||
|
||
try (Stream<Path> walk = Files.find( | ||
dirPath, | ||
maxDepth, | ||
(path, basicFileAttributes) -> path.toFile().getName().matches(fileNameRegex))) { | ||
|
||
List<String> result = walk.filter(Files::isRegularFile) | ||
.map(x -> x.toAbsolutePath().toString()) | ||
.collect(Collectors.toList()); | ||
return result; | ||
} | ||
} | ||
|
||
@SneakyThrows(IOException.class) | ||
public static String stringFromPath(String absolutePath) { | ||
return Files.readString(Path.of(absolutePath)); | ||
} | ||
|
||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
reportcard-model/src/main/java/com/ericdriggs/reportcard/model/ResultParserUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.ericdriggs.reportcard.model; | ||
|
||
import com.ericdriggs.reportcard.model.converter.surefire.SurefireConvertersUtil; | ||
import com.ericdriggs.reportcard.xml.surefire.SurefireParserUtil; | ||
import com.ericdriggs.reportcard.xml.surefire.Testsuite; | ||
|
||
import java.util.List; | ||
|
||
public enum ResultParserUtil { | ||
|
||
;//static methods only | ||
private static final String XML_EXTENSION_REGEX = ".*[.]xml"; | ||
|
||
public static TestResult fromSurefirePath(String absolutePath) { | ||
return fromSurefirePathAndRegex(absolutePath, XML_EXTENSION_REGEX); | ||
} | ||
|
||
|
||
public static TestResult fromSurefirePathAndRegex(String absolutePath, String fileNameRegex) { | ||
List<Testsuite> testsuites = SurefireParserUtil.parseTestSuitesFromPathAndRegex(absolutePath, fileNameRegex); | ||
return SurefireConvertersUtil.doFromSurefireToModelTestResult(testsuites); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
reportcard-model/src/main/java/com/ericdriggs/reportcard/model/TestStatusType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.ericdriggs.reportcard.model; | ||
|
||
import com.ericdriggs.reportcard.xml.ResultCount; | ||
|
||
public enum TestStatusType { | ||
SUCCESS(new ResultCount().setTests(1).setSuccesses(1)), | ||
SKIPPED(new ResultCount().setTests(1).setSkipped(1)), | ||
FAILURE(new ResultCount().setTests(1).setFailures(1)), | ||
ERROR(new ResultCount().setTests(1).setErrors(1)); | ||
|
||
private ResultCount resultCount; | ||
|
||
TestStatusType(ResultCount resultCount) { | ||
this.resultCount = resultCount; | ||
} | ||
|
||
public ResultCount getResultCount() { | ||
return resultCount; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
reportcard-model/src/main/java/com/ericdriggs/reportcard/model/TestSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.ericdriggs.reportcard.model; | ||
|
||
import com.ericdriggs.reportcard.xml.ResultCount; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TestSuite extends com.ericdriggs.reportcard.pojos.TestSuite { | ||
private List<TestCase> testCases = new ArrayList<>(); | ||
|
||
public List<TestCase> getTestCases() { | ||
return testCases; | ||
} | ||
|
||
public TestSuite setTestCases( List<TestCase> testCases) { | ||
this.testCases = testCases; | ||
return this; | ||
} | ||
|
||
|
||
public ResultCount getResultCount() { | ||
ResultCount resultCount = new ResultCount(); | ||
for(TestCase testCase : testCases) { | ||
resultCount.add(testCase.getResultCount()); | ||
} | ||
return resultCount; | ||
} | ||
|
||
public static ResultCount getResultCount(List<TestSuite> testSuites) { | ||
ResultCount resultCount = new ResultCount(); | ||
for (TestSuite testSuite : testSuites) { | ||
resultCount.add(testSuite.getResultCount()); | ||
} | ||
return resultCount; | ||
} | ||
} |
Oops, something went wrong.