cli method for validatoion walk
This commit is contained in:
@@ -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,69 +0,0 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class TestFileWalker
|
||||
extends SimpleFileVisitor<Path> {
|
||||
protected PathMatcher matcher;
|
||||
protected ZUGFeRDValidator zul;
|
||||
protected int fileCount=1;
|
||||
|
||||
public TestFileWalker() {
|
||||
this.zul = new ZUGFeRDValidator();
|
||||
;
|
||||
matcher = FileSystems.getDefault().getPathMatcher("glob:*.{pdf,xml}");
|
||||
|
||||
}
|
||||
// Print information about
|
||||
// each type of file.
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file,
|
||||
BasicFileAttributes attr) {
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
//get current date time with Date()
|
||||
Date date = new Date();
|
||||
if ((attr!=null)&&(attr.isRegularFile())) {
|
||||
if (matcher.matches(file.getFileName())) {
|
||||
|
||||
System.out.format("\n@%s Testing file %d: %s ", dateFormat.format(date), fileCount++, file);
|
||||
assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status")
|
||||
.asString()
|
||||
.isEqualTo(
|
||||
"valid");
|
||||
|
||||
}
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
// Print each directory visited.
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir,
|
||||
IOException exc) {
|
||||
System.out.format("Directory: %s%n", dir);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
// If there is some error accessing
|
||||
// the file, let the user know.
|
||||
// If you don't override this method
|
||||
// and an error occurs, an IOException
|
||||
// is thrown.
|
||||
@Override
|
||||
public FileVisitResult visitFileFailed(Path file,
|
||||
IOException exc) {
|
||||
System.err.println(exc);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
@@ -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