Skip to content
Snippets Groups Projects
Commit a607eae2 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- refactoring, extracted tests for validators in its own testfiles

parent 386342a7
No related branches found
No related tags found
No related merge requests found
Pipeline #4314 passed
...@@ -41,6 +41,8 @@ jarclean: ...@@ -41,6 +41,8 @@ jarclean:
@rm -Rf $(BUILD) @rm -Rf $(BUILD)
test: $(JAR) test: $(JAR)
java -cp ${CLASSPATH}:$(JUNITCLASSPATH) org.junit.runner.JUnitCore org.slub.rosetta.dps.repository.plugin.Validation.TestSLUBValidateDTD;
java -cp ${CLASSPATH}:$(JUNITCLASSPATH) org.junit.runner.JUnitCore org.slub.rosetta.dps.repository.plugin.Validation.TestSLUBValidateRelaxNG;
java -cp ${CLASSPATH}:$(JUNITCLASSPATH) org.junit.runner.JUnitCore org.slub.rosetta.dps.repository.plugin.TestSLUBXmlFormatValidationPlugin java -cp ${CLASSPATH}:$(JUNITCLASSPATH) org.junit.runner.JUnitCore org.slub.rosetta.dps.repository.plugin.TestSLUBXmlFormatValidationPlugin
clean: jarclean clean: jarclean
......
...@@ -3,7 +3,6 @@ package org.slub.rosetta.dps.repository.plugin; ...@@ -3,7 +3,6 @@ package org.slub.rosetta.dps.repository.plugin;
import org.junit.Before; import org.junit.Before;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
import org.slub.rosetta.dps.repository.plugin.Validation.SLUBValidateRelaxNG;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -67,37 +66,6 @@ public class TestSLUBXmlFormatValidationPlugin { ...@@ -67,37 +66,6 @@ public class TestSLUBXmlFormatValidationPlugin {
mock.loadNamespaceSchemaMap(initp.get("schemacatalog")); mock.loadNamespaceSchemaMap(initp.get("schemacatalog"));
} }
@org.junit.Test
public void relaxNG_valid() {
var v = new SLUBValidateRelaxNG();
assertNotNull( "validator relaxNG sucessfully instantiated", v);
var has_exception = false;
var res = false;
try {
var doc = mock.getDocument("resources/test/valid/my_relaxng_test.valid.xml");
res = v.validateAgainst(doc, local2Uri("example_catalog/my_relaxng_test.rng"));
} catch ( Exception e) {
e.printStackTrace();
has_exception = true;
};
assertFalse( has_exception );
assertTrue( res);
}
@org.junit.Test
public void relaxNG_invalid() {
var v = new SLUBValidateRelaxNG();
assertNotNull( "validator relaxNG sucessfully instantiated", v);
var has_exception = false;
var res = false;
try {
var doc = mock.getDocument("resources/test/valid/my_relaxng_test.invalid.xml");
res = v.validateAgainst(doc, new URI("example_catalog/my_relaxng_test.rng"));
} catch ( Exception e) {
has_exception = true;
};
assertFalse( has_exception );
assertFalse( res);
}
@org.junit.Test @org.junit.Test
public void validateFormat() { public void validateFormat() {
System.out.println(); System.out.println();
......
package org.slub.rosetta.dps.repository.plugin.Validation;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.slub.rosetta.dps.repository.plugin.ValidationCatalogResolver;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
/**
* Tests for {@link SLUBValidateDTD}.
*
* @author andreas.romeyke@slub-dresden.de (Andreas Romeyke)
*/
@RunWith(JUnit4.class)
public class TestSLUBValidateDTD {
private final Map<String, String> initp = new HashMap<>();
@Before
public void setUp() {
initp.put("catalog", "/etc/xml/catalog");
initp.put("debug", "true");
}
@org.junit.Test
public void dtd_invalid() {
String[] catalogs = new String[] {
initp.get("catalog")
};
List<String> errors = new ArrayList<>();
ValidationCatalogResolver validationCatalogResolver = new ValidationCatalogResolver(catalogs, errors, true);
var v = new SLUBValidateDTD( validationCatalogResolver );
assertNotNull( "validator relaxNG sucessfully instantiated", v);
var has_exception = false;
Boolean res = false;
try {
var doc = "resources/test/invalid/Svg_example1.invalid.svg";
res = v.validateAgainst(doc);
System.out.println("validating " + doc + " resulting in " + res);
} catch ( Exception e) {
has_exception = true;
};
assertFalse( has_exception );
assertFalse( res);
}
}
package org.slub.rosetta.dps.repository.plugin.Validation;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.slub.rosetta.dps.repository.plugin.SLUBXmlFormatValidationPlugin;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
import static org.junit.Assert.*;
/**
* Tests for {@link SLUBValidateRelaxNG}.
*
* @author andreas.romeyke@slub-dresden.de (Andreas Romeyke)
*/
@RunWith(JUnit4.class)
public class TestSLUBValidateRelaxNG {
private static SLUBXmlFormatValidationPlugin mock;
private Path[] testPaths;
private final Map<String, String> initp = new HashMap<>();
private URI local2Uri(String sUri) {
URI partUri = null;
try {
partUri = new URI(sUri);
File fh = new File("example_catalog/");
String baseStr = "file://" + fh.getAbsoluteFile();
URI baseUri = new URI( baseStr);
return baseUri.resolve(partUri);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
@Before
public void setUp() {
Stream<Path> findFiles;
try {
findFiles = Files.find(Path.of("resources/test/"), 5, ((path, basicFileAttributes) -> Files.isRegularFile(path)));
testPaths = findFiles.toArray(Path[]::new);
} catch (IOException e) {
// do nothing, because nothing found
}
mock = new SLUBXmlFormatValidationPlugin();
initp.put("catalog", "/etc/xml/catalog");
initp.put("schemacatalog", "example_catalog/schema_catalog.xml");
initp.put("debug", "true");
mock.initParams(initp);
}
@org.junit.Test
public void relaxNG_valid() {
var v = new SLUBValidateRelaxNG();
assertNotNull( "validator relaxNG sucessfully instantiated", v);
var has_exception = false;
var res = false;
try {
var doc = mock.getDocument("resources/test/valid/my_relaxng_test.valid.xml");
res = v.validateAgainst(doc, local2Uri("example_catalog/my_relaxng_test.rng"));
} catch ( Exception e) {
e.printStackTrace();
has_exception = true;
};
assertFalse( has_exception );
assertTrue( res);
}
@org.junit.Test
public void relaxNG_invalid() {
var v = new SLUBValidateRelaxNG();
assertNotNull( "validator relaxNG sucessfully instantiated", v);
var has_exception = false;
var res = false;
try {
var doc = mock.getDocument("resources/test/invalid/my_relaxng_test.invalid.xml");
res = v.validateAgainst(doc, new URI("example_catalog/my_relaxng_test.rng"));
} catch ( Exception e) {
System.out.println( "EXCEPTION:" + e.getMessage());
e.printStackTrace();
has_exception = true;
};
assertFalse( has_exception );
assertFalse( res);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment