cli method for validatoion walk
This commit is contained in:
@@ -53,6 +53,21 @@
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- for directory validation: -->
|
||||
<dependency>
|
||||
<groupId>org.xmlunit</groupId>
|
||||
<artifactId>xmlunit-core</artifactId>
|
||||
<version>2.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xmlunit</groupId>
|
||||
<artifactId>xmlunit-assertj</artifactId>
|
||||
<version>2.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- /directory validation: -->
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
|
||||
0
Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java
Executable file → Normal file
0
Mustang-CLI/src/main/java/org/mustangproject/commandline/FileChecker.java
Executable file → Normal file
0
Mustang-CLI/src/main/java/org/mustangproject/commandline/FileTraverser.java
Executable file → Normal file
0
Mustang-CLI/src/main/java/org/mustangproject/commandline/FileTraverser.java
Executable file → Normal file
@@ -324,6 +324,10 @@ public class Main {
|
||||
|
||||
optionsRecognized=performValidate(sourceName);
|
||||
|
||||
} else if ((action!=null)&&(action.equals("validateExpectValid"))) {
|
||||
|
||||
optionsRecognized=performValidateExpect(true, directoryName);
|
||||
|
||||
} else {
|
||||
// no argument or argument unknown
|
||||
printUsage();
|
||||
@@ -354,6 +358,20 @@ public class Main {
|
||||
return optionsRecognized;
|
||||
}
|
||||
|
||||
private static boolean performValidateExpect(boolean valid, String dirName) {
|
||||
ValidatorFileWalker zfWalk = new ValidatorFileWalker();
|
||||
Path startingDir = Paths.get(dirName);
|
||||
try {
|
||||
Files.walkFileTree(startingDir, zfWalk);
|
||||
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException {
|
||||
|
||||
// Get params from user if not already defined
|
||||
|
||||
0
Mustang-CLI/src/main/java/org/mustangproject/commandline/StatRun.java
Executable file → Normal file
0
Mustang-CLI/src/main/java/org/mustangproject/commandline/StatRun.java
Executable file → Normal file
@@ -1,6 +1,6 @@
|
||||
package org.mustangproject.validator;
|
||||
package org.mustangproject.commandline;
|
||||
|
||||
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
@@ -12,14 +12,23 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xmlunit.builder.Input;
|
||||
import org.xmlunit.xpath.JAXPXPathEngine;
|
||||
import org.xmlunit.xpath.XPathEngine;
|
||||
import org.mustangproject.validator.ZUGFeRDValidator;
|
||||
|
||||
public class TestFileWalker
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
|
||||
public class ValidatorFileWalker
|
||||
extends SimpleFileVisitor<Path> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ValidatorFileWalker.class.getCanonicalName()); // log
|
||||
protected PathMatcher matcher;
|
||||
protected ZUGFeRDValidator zul;
|
||||
protected int fileCount=1;
|
||||
|
||||
public TestFileWalker() {
|
||||
public ValidatorFileWalker() {
|
||||
this.zul = new ZUGFeRDValidator();
|
||||
;
|
||||
matcher = FileSystems.getDefault().getPathMatcher("glob:*.{pdf,xml}");
|
||||
@@ -36,7 +45,7 @@ public class TestFileWalker
|
||||
if ((attr!=null)&&(attr.isRegularFile())) {
|
||||
if (matcher.matches(file.getFileName())) {
|
||||
|
||||
System.out.format("\n@%s Testing file %d: %s ", dateFormat.format(date), fileCount++, file);
|
||||
LOGGER.info(String.format("\n@%s Testing file %d: %s ", dateFormat.format(date), fileCount++, file));
|
||||
assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status")
|
||||
.asString()
|
||||
.isEqualTo(
|
||||
@@ -51,7 +60,7 @@ public class TestFileWalker
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir,
|
||||
IOException exc) {
|
||||
System.out.format("Directory: %s%n", dir);
|
||||
LOGGER.info("\nDirectory: %s%n", dir);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@@ -63,7 +72,7 @@ public class TestFileWalker
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file,
|
||||
IOException exc) {
|
||||
System.err.println(exc);
|
||||
LOGGER.error(exc.getMessage(),exc);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xmlunit.xpath.JAXPXPathEngine;
|
||||
import org.xmlunit.xpath.XPathEngine;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PathTest extends TestCase {
|
||||
|
||||
TestFileWalker zfWalk;
|
||||
|
||||
@Before
|
||||
public void beforeEachTestMethod() {
|
||||
System.out.println("Invoked before each test method");
|
||||
TestFileWalker zfWalk = new TestFileWalker();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfficialSamples() {
|
||||
// ignored for the
|
||||
// time being
|
||||
Path startingDir = Paths.get(System.getProperty("user.dir") + "/../../Release/Beispiele/");
|
||||
TestFileWalker zfWalk = new TestFileWalker();
|
||||
try {
|
||||
Files.walkFileTree(startingDir, zfWalk);
|
||||
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
// XPathEngine xpath = new JAXPXPathEngine();
|
||||
// File tempFile = getResourceAsFile("invalidV2.xml");
|
||||
//https://stackoverflow.com/questions/16245914/execute-an-external-jar -> http://docs.oracle.com/javase/tutorial/deployment/jar/jarclassloader.html
|
||||
|
||||
/**
|
||||
* assertThat(content).valueByXPath("count(//error)") .asInt()
|
||||
* .isGreaterThan(1); //2 errors are OK because there is a known bug
|
||||
*
|
||||
*
|
||||
* assertThat(content).valueByXPath("//error[@type=\"4\"]") .asString()
|
||||
* .contains( "In Deutschland sind die Profile MINIMUM und BASIC WL nur als
|
||||
* Buchungshilfe (TypeCode: 751) zugelassen.");
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFacturX() {
|
||||
TestFileWalker zfWalk = new TestFileWalker();
|
||||
Path startingDir = Paths.get(System.getProperty("user.dir") + "/../../foreign_samples/fx/");
|
||||
try {
|
||||
Files.walkFileTree(startingDir, zfWalk);
|
||||
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
// XPathEngine xpath = new JAXPXPathEngine();
|
||||
// File tempFile = getResourceAsFile("invalidV2.xml");
|
||||
//https://stackoverflow.com/questions/16245914/execute-an-external-jar -> http://docs.oracle.com/javase/tutorial/deployment/jar/jarclassloader.html
|
||||
|
||||
/**
|
||||
* assertThat(content).valueByXPath("count(//error)") .asInt()
|
||||
* .isGreaterThan(1); //2 errors are OK because there is a known bug
|
||||
*
|
||||
*
|
||||
* assertThat(content).valueByXPath("//error[@type=\"4\"]") .asString()
|
||||
* .contains( "In Deutschland sind die Profile MINIMUM und BASIC WL nur als
|
||||
* Buchungshilfe (TypeCode: 751) zugelassen.");
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTestFiles() {
|
||||
// ignored for the
|
||||
// time being
|
||||
/*https://www.xoev.de/sixcms/media.php/13/XRechnung_Kompakt.pdf "Problem
|
||||
–
|
||||
Nur positive Beispiele als Testgrundlage
|
||||
•
|
||||
Negative Beispiele sind sehr wichtig!"*/
|
||||
/* Path startingDir = Paths.get(System.getProperty("user.dir") + "/testfiles/toPass/");
|
||||
try {
|
||||
Files.walkFileTree(startingDir, zfWalk);
|
||||
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
*/
|
||||
// XPathEngine xpath = new JAXPXPathEngine();
|
||||
// File tempFile = getResourceAsFile("invalidV2.xml");
|
||||
//https://stackoverflow.com/questions/16245914/execute-an-external-jar -> http://docs.oracle.com/javase/tutorial/deployment/jar/jarclassloader.html
|
||||
|
||||
/**
|
||||
* assertThat(content).valueByXPath("count(//error)") .asInt()
|
||||
* .isGreaterThan(1); //2 errors are OK because there is a known bug
|
||||
*
|
||||
*
|
||||
* assertThat(content).valueByXPath("//error[@type=\"4\"]") .asString()
|
||||
* .contains( "In Deutschland sind die Profile MINIMUM und BASIC WL nur als
|
||||
* Buchungshilfe (TypeCode: 751) zugelassen.");
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
import java.io.File;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
Reference in New Issue
Block a user