Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#82 Started to add new parameter verifyFailOn
- Loading branch information
Björn Ekryd
committed
Jan 2, 2021
1 parent
0c3181a
commit 1c14976
Showing
10 changed files
with
164 additions
and
9 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
maven-plugin/src/it/verify-fail-on/expected_violation_file.xml
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<sortpom> | ||
<file filename="@POM_PATH@"> | ||
<violation>The xml element <modelVersion> should be placed before <name></violation> | ||
</file> | ||
</sortpom> |
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 @@ | ||
invoker.goals=-e clean verify |
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,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.github.ekryd.sortpom.its</groupId> | ||
<artifactId>default-configuration</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
<name>SortPom Plugin :: ITs :: Default configuration</name> | ||
<description>Test default parameters of the plugin</description> | ||
<url>no-url</url> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.ekryd.sortpom</groupId> | ||
<artifactId>sortpom-maven-plugin</artifactId> | ||
<version>@pom.version@</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>verify</goal> | ||
</goals> | ||
<configuration> | ||
<violationFilename>target/sortpom_reports/violation.xml</violationFilename> | ||
<verifyFail>warn</verifyFail> | ||
<verifyFailOn>lines</verifyFailOn> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,14 @@ | ||
log = new File(basedir, 'build.log') | ||
sorted = new File(basedir, 'pom.xml') | ||
violationFile = new File(basedir, 'target/sortpom_reports/violation.xml') | ||
expected_violationFile = new File(basedir, 'expected_violation_file.xml') | ||
|
||
assert log.exists() | ||
assert log.text.contains('[INFO] Verifying file ' + sorted.absolutePath) | ||
assert log.text.contains('[WARNING] The xml element <modelVersion> should be placed before <name>') | ||
assert log.text.contains('[INFO] Saving violation report to ' + violationFile.absolutePath) | ||
assert log.text.contains('[WARNING] The file ' + sorted.absolutePath + ' is not sorted') | ||
|
||
assert expected_violationFile.text.replaceAll('@POM_PATH@', sorted.absolutePath).tokenize('\n').equals(violationFile.text.replaceAll('\r','').replaceAll('\\\\','').tokenize('\n')) | ||
|
||
return true |
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
19 changes: 19 additions & 0 deletions
19
sorter/src/main/java/sortpom/parameter/VerifyFailOnType.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,19 @@ | ||
package sortpom.parameter; | ||
|
||
import sortpom.exception.FailureException; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum VerifyFailOnType { | ||
XMLELEMENTS, LINES, STRICT; | ||
|
||
static VerifyFailOnType fromString(String verifyFailOn) { | ||
if (verifyFailOn == null) { | ||
throw new FailureException("verifyFailOn must be either xmlElements, lines or strict. Was: null"); | ||
} | ||
return Arrays.stream(VerifyFailOnType.values()) | ||
.filter(e -> e.toString().equalsIgnoreCase(verifyFailOn)) | ||
.findAny() | ||
.orElseThrow(() -> new FailureException("verifyFailOn must be either xmlElements, lines or strict. Was: " + verifyFailOn)); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
sorter/src/test/java/sortpom/parameter/VerifyFailOnTypeTest.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,62 @@ | ||
package sortpom.parameter; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.function.Executable; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import sortpom.exception.FailureException; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsEqual.equalTo; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* | ||
*/ | ||
class VerifyFailOnTypeTest { | ||
@Test | ||
void xmlElementsIgnoreCaseValueIsOk() { | ||
PluginParameters pluginParameters = PluginParameters.builder() | ||
.setVerifyFail("STOP", "XMLElements") | ||
.build(); | ||
|
||
assertEquals(VerifyFailOnType.XMLELEMENTS, pluginParameters.verifyFailOn); | ||
} | ||
|
||
@Test | ||
void linesIgnoreCaseValueIsOk() { | ||
PluginParameters pluginParameters = PluginParameters.builder() | ||
.setVerifyFail("STOP", "liNES") | ||
.build(); | ||
|
||
assertEquals(VerifyFailOnType.LINES, pluginParameters.verifyFailOn); | ||
} | ||
|
||
@Test | ||
void strictIgnoreCaseValueIsOk() { | ||
PluginParameters pluginParameters = PluginParameters.builder() | ||
.setVerifyFail("STOP", "stRIct") | ||
.build(); | ||
|
||
assertEquals(VerifyFailOnType.STRICT, pluginParameters.verifyFailOn); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = "gurka") | ||
void verifyFailFaultyValues(String value) { | ||
|
||
final Executable testMethod = () -> PluginParameters.builder() | ||
.setVerifyFail("STOP", value) | ||
.build(); | ||
|
||
final FailureException thrown = assertThrows(FailureException.class, testMethod); | ||
|
||
assertThat(thrown.getMessage(), is(equalTo("verifyFailOn must be either xmlElements, lines or strict. Was: " + value))); | ||
} | ||
|
||
|
||
} |
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