Remove duplicated test package org.apache.jena.iri.test Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e89146d8 Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e89146d8 Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e89146d8
Branch: refs/heads/hadoop-rdf Commit: e89146d814968269eacbd146c531266f8c8a4e3a Parents: ecdcd0d Author: Andy Seaborne <[email protected]> Authored: Mon Jan 12 19:09:27 2015 +0000 Committer: Andy Seaborne <[email protected]> Committed: Mon Jan 12 19:09:27 2015 +0000 ---------------------------------------------------------------------- .../org/apache/jena/iri/TestMoreExamples.java | 2 +- .../org/apache/jena/iri/test/Additional.java | 61 - .../org/apache/jena/iri/test/MoreTests.java | 98 - .../org/apache/jena/iri/test/TestCreator.java | 254 - .../apache/jena/iri/test/TestErrorMessages.java | 144 - .../org/apache/jena/iri/test/TestExample.java | 279 - .../org/apache/jena/iri/test/TestMEIri.java | 39 - .../apache/jena/iri/test/TestMERelativize.java | 50 - .../org/apache/jena/iri/test/TestMEResolve.java | 42 - .../org/apache/jena/iri/test/TestMEResult.java | 46 - .../apache/jena/iri/test/TestMoreExamples.java | 264 - .../org/apache/jena/iri/test/TestPackage.java | 36 - .../resources/org/apache/jena/iri/test/test.xml | 9217 ------------------ .../resources/org/apache/jena/iri/test/uris.xml | 463 - 14 files changed, 1 insertion(+), 10994 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/TestMoreExamples.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/TestMoreExamples.java b/jena-iri/src/test/java/org/apache/jena/iri/TestMoreExamples.java index 0db1755..7ae0371 100644 --- a/jena-iri/src/test/java/org/apache/jena/iri/TestMoreExamples.java +++ b/jena-iri/src/test/java/org/apache/jena/iri/TestMoreExamples.java @@ -242,7 +242,7 @@ public class TestMoreExamples extends TestCase implements SAXParserFactory fact = SAXParserFactory.newInstance(); TestSuite result = new TestSuite(); result.setName("More IRI Tests"); - try ( InputStream in = TestCreator.class.getClassLoader().getResourceAsStream("org/apache/jena/iri/test/test.xml") ) { + try ( InputStream in = TestCreator.class.getClassLoader().getResourceAsStream("org/apache/jena/iri/test.xml") ) { fact.newSAXParser().parse(in, new TestReader(result) ); return result; } http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/Additional.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/Additional.java b/jena-iri/src/test/java/org/apache/jena/iri/test/Additional.java deleted file mode 100644 index b1189a6..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/Additional.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test ; - -import java.net.MalformedURLException; - -import junit.framework.JUnit4TestAdapter; - -import org.apache.jena.iri.IRI ; -import org.apache.jena.iri.IRIFactory ; -import org.junit.Assert; -import org.junit.Test; - - -public class Additional -{ - // Test added in response to reports and bugs from 2009. - - static public junit.framework.Test suite() - { - return new JUnit4TestAdapter(Additional.class) ; - } - - @Test public void relDotSlash1() throws MalformedURLException - { - IRIFactory f = IRIFactory.iriImplementation() ; - IRI iri = f.construct("http://a/b/c/dddd;pppp?qqqqq") ; - IRI iri2 = iri.resolve("./") ; - test(iri2, "http://a/b/c/") ; - } - - @Test public void relDotSlash2() throws MalformedURLException - { - IRIFactory f = IRIFactory.iriImplementation() ; - IRI iri = f.construct("http://a/b/c/dddd;pppp?qqqqq") ; - IRI iri2 = iri.resolve("./foo") ; - test(iri2, "http://a/b/c/foo") ; - } - - - private static void test(IRI iri, String iriStr) throws MalformedURLException - { - Assert.assertEquals(iriStr, iri.toASCIIString()) ; - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/MoreTests.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/MoreTests.java b/jena-iri/src/test/java/org/apache/jena/iri/test/MoreTests.java deleted file mode 100644 index bacfbb2..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/MoreTests.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - - -import java.util.Iterator; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.iri.IRI ; -import org.apache.jena.iri.IRIFactory ; -import org.apache.jena.iri.Violation ; - -public class MoreTests extends TestCase { - - static public Test suite() { - TestSuite suite = new TestSuite("Additional IRI Tests"); - - - suite.addTest(new MoreTests("testRelativizeFrag1")); - suite.addTest(new MoreTests("testRelativizeFrag2")); - suite.addTest(new MoreTests("testXPointer")); - suite.addTest(new MoreTests("testNotIDN")); - - return suite; - } - - public MoreTests(String s) { - super(s); - } - - - public void testRelativizeFrag1() { - IRIFactory f = IRIFactory.jenaImplementation(); - IRI base = f.create("http://example.org/somefolder/mybase.rdf"); - IRI frag = f.create("http://example.org#foo"); - IRI rel = base.relativize(frag); - assertEquals(frag,rel); -// System.err.println(rel.toString()); - IRI back = base.resolve(rel); - assertEquals(frag,back); - } - - public void testRelativizeFrag2() { - IRIFactory f = IRIFactory.jenaImplementation(); - IRI base = f.create("http://example.org/somefolder/mybase.rdf"); - IRI frag = f.create("http://example.org/#foo"); - IRI rel = base.relativize(frag); - assertEquals("/#foo",rel.toString()); - IRI back = base.resolve(rel); - assertEquals(frag,back); - } - - public void testXPointer() { - IRIFactory f = IRIFactory.jenaImplementation(); - IRI base = f.create("http://example.org/"); - IRI frag = base.resolve("http://eg.com/test.txt#xpointer(/unit[5])"); - Iterator<Violation> it = frag.violations(false); - assertTrue(it.hasNext()) ; - -// while (it.hasNext()) { -// System.err.println(it.next().getLongMessage()); -// } - - } - public void testNotIDN() { - IRIFactory f = IRIFactory.jenaImplementation(); - IRI base = f.create("http://example.org/"); - IRI frag = base.resolve("outbind://4-00000000C45F478BF9F2A048A7A59DE"+ - "3AE35F7230700D3E3AEE226D20A49A390BCD779EC5D4700"+ - "00003DB3650000D3E3AEE226D20A49A390BCD779EC5D470"+ - "00001182DB0000/www.uconnectevent.org"); - Iterator <Violation>it = frag.violations(false); - assertTrue(it.hasNext()) ; - -// while (it.hasNext()) { -// System.err.println(it.next().getLongMessage()); -// } - - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestCreator.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestCreator.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestCreator.java deleted file mode 100644 index 2217e14..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestCreator.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParserFactory; - -import org.apache.jena.iri.IRI ; -import org.apache.jena.iri.IRIFactory ; -import org.apache.jena.iri.IRIRelativize ; -import org.apache.jena.iri.Violation ; -import org.apache.jena.iri.impl.AbsIRIImpl ; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; - - -final class TestCreator extends DefaultHandler implements IRIRelativize { - - static final int RelativizeFlags = ABSOLUTE|GRANDPARENT|NETWORK|PARENT|CHILD|SAMEDOCUMENT; - public static String substituteStandardEntities(String s) { - s = replace(s, "&", "&"); - s = replace(s, "<", "<"); - s = replace(s, ">", ">"); - s = replace(s, "'", "'"); - s = replace(s, "\t", "	"); - s = replace(s, "\n", "
"); - s = replace(s, "\r", "
"); - return replace(s, "\"", """); - } - - public static String replace( - String s, - String oldString, - String newString) { - String result = ""; - int length = oldString.length(); - int pos = s.indexOf(oldString); - int lastPos = 0; - while (pos >= 0) { - result = result + s.substring(lastPos, pos) + newString; - lastPos = pos + length; - pos = s.indexOf(oldString, lastPos); - } - return result + s.substring(lastPos, s.length()); - } -// static final IRI empty = IRIFactory.defaultFactory().emptyIRI(); - static final Class<?> attSign[] = new Class[] { Attributes.class }; - static final Class<?> nullSign[] = new Class[] { }; - - static PrintWriter out; - static void load() throws SAXException, IOException, ParserConfigurationException { - SAXParserFactory fact = SAXParserFactory.newInstance(); - out = new PrintWriter(new OutputStreamWriter( - new FileOutputStream("src/test/resources/org/apache/jena/iri/test/test.xml"), - "utf-8" - )); - out.println("<UriTests>"); - - try (InputStream in = TestCreator.class.getClassLoader().getResourceAsStream("org/apache/jena/iri/test/uris.xml")) { - fact.newSAXParser().parse(in, new TestCreator()) ; - out.println("</UriTests>") ; - out.close() ; - } - } - - static public void main(String args[]) throws IOException, ParserConfigurationException, SAXException{ - try { - load(); - } catch (SAXParseException e) { - System.err.println(e.getLineNumber()); - System.err.println(e.toString()); - System.err.println(e.getMessage()); - - } - } - - - @Override - public void startElement( - String arg1, - String arg2, - String name, - Attributes att - ) { - try { - this.getClass().getDeclaredMethod(name,attSign) - .invoke(this, att ); - } catch (IllegalArgumentException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | SecurityException e) { - e.printStackTrace(); - } - } - @Override - public void endElement( - String arg1, - String arg2, - String name - ) { - } - - private void uris(Attributes att) { - } - - private void uri(Attributes att) { - String absolute = att.getValue("absolute"); - String base = att.getValue("base"); - String relative = att.getValue("relative"); - - doIt(absolute); - - if (base!=null) { - out.println("<Resolve>"); - IRI b = doIt(base); - IRI r = doIt(relative); - out.println("<Result>"); - IRI result = b.create(r); - doIt(result); - out.println("</Result>"); - IRI rAgain = b.relativize( - result, - RelativizeFlags - ); - if (r.equals(rAgain)) { - out.println("<Relativize same='true'/>"); - } else { - out.println("<Relativize>"); - doIt(rAgain); - out.println("</Relativize>"); - } - - out.println("</Resolve>"); - } - } - - - static String methods[] = { - "getRawHost", - "getRawPath", - "getPort", - "getRawQuery", - "getScheme", - "getRawUserinfo", - "getRawFragment", - "getASCIIHost", - "isRootless", - "toString", - "toDisplayString", -// "hasException", - "isAbsolute", -// "isIRI", -// "isOpaque", -// "isRDFURIReference", - "isRelative", -// "isURIinASCII", -// "isVeryBad", -// "isXSanyURI", - "toASCIIString" - }; - - private void doIt(IRI iri) { - if (iri==null) - return; - for ( String m : methods ) - { - try - { - Object r = IRI.class.getDeclaredMethod( m, nullSign ).invoke( iri, new Object[]{ } ); - if ( r == null ) - { - out.println( "<" + m + - " nullValue='true'/>" ); - } - else - { - out.println( "<" + m + - " value='" + - substituteStandardEntities( r.toString() ) + "'/>" ); - } - - - } - catch ( IllegalArgumentException | NoSuchMethodException | IllegalAccessException | SecurityException e ) - { - e.printStackTrace(); - } - catch ( InvocationTargetException e ) - { - Throwable t = e; - if ( t.getCause() != null ) - { - t = t.getCause(); - } - String s = t.getMessage() != null ? t.getMessage() : t.toString(); - out.println( "<" + m + - " exception='" + - substituteStandardEntities( s ) + "'/>" ); - } - - } - - Iterator<Violation> it = ((AbsIRIImpl)iri).allViolations(); - out.println("<violations>"); - while (it.hasNext()) { - out.print("<violation>"); - out.print((it.next()).codeName()); - out.println("</violation>"); - - } - out.println("</violations>"); - } - - private IRI doIt(String iri) { - if (iri==null) - return null; - IRI rslt = - factory.create(iri); -// empty.create(iri); - out.println("<IRI iri='"+substituteStandardEntities(iri)+"'>"); - doIt(rslt); - out.println("</IRI>"); - return rslt; - } - // TODO set conformance level for this factory - static IRIFactory factory = new IRIFactory(); - static { - factory.setSameSchemeRelativeReferences("file"); - factory.useSchemeSpecificRules("*",true); - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestErrorMessages.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestErrorMessages.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestErrorMessages.java deleted file mode 100644 index 3c84790..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestErrorMessages.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import java.util.Iterator; - -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.iri.IRI ; -import org.apache.jena.iri.IRIFactory ; -import org.apache.jena.iri.Violation ; -import org.apache.jena.iri.ViolationCodes ; -import org.apache.jena.iri.impl.IRIExamples ; -import org.apache.jena.iri.impl.Specification ; -import org.apache.jena.iri.impl.ViolationCodeInfo ; - - -public class TestErrorMessages extends TestCase - implements ViolationCodes { - static { - new ViolationCodes.Initialize(); - } - - - static Specification specs[] = Specification.all - .values().toArray(new Specification[0]); - - - String uri; - - ViolationCodeInfo violation; - - - - boolean good; - - public TestErrorMessages( String uri, ViolationCodeInfo info, boolean good) { - super(escapeAndShorten(uri)); - this.uri = uri; - this.violation = info; - this.good = good; - } - - - - private static String escapeAndShorten(String uri2) { - StringBuilder rslt = new StringBuilder(); - int ln = uri2.length(); - if (ln > 80) - ln = 80; - for (int i = 0; i < ln; i++) { - int ch = uri2.charAt(i); - if (ch > 127 || ch < 32) { - rslt.append("&#"); - rslt.append(ch); - rslt.append(";"); - } else - rslt.append((char) ch); - } - return rslt.toString(); - } - - - - - private void printErrorMessages(Violation v) { - System.err.println(v.getShortMessage()); - - } - - - static public IRIFactory f = IRIFactory.jenaImplementation(); - - @Override - public void runTest() { - IRI iri = f.create(uri); - Iterator<Violation> it = iri.violations(true); - while (it.hasNext()) { - Violation v = it.next(); - printErrorMessages(v); - - } - } - - public static TestSuite suite() { - TestSuite rslt = new TestSuite(); - - rslt.setName("Error messages"); - addAllTestsFromExamples( rslt); - - return rslt; - } - - private static void addAllTestsFromExamples( TestSuite spec) { - for (int i = 0; i < ViolationCodeInfo.all.length; i++) { - addTestsFromExamples(spec, ViolationCodeInfo.all[i]); - } - for ( Specification spec1 : specs ) - { - addExamples( null, spec1, spec ); - } - } - - private static void addTestsFromExamples(TestSuite rslt, ViolationCodeInfo violationCodeInfo) { - - if (violationCodeInfo != null) { - TestSuite ex = new TestSuite(); - ex.setName(violationCodeInfo.getCodeName()); - addExamples(violationCodeInfo, violationCodeInfo, ex); - if (ex.countTestCases()>0) - rslt.addTest(ex); - } - } - - private static void addExamples(ViolationCodeInfo violationCodeInfo, IRIExamples examples, TestSuite ex) { - String e[] = examples.getBadExamples(); - for ( String anE1 : e ) - { - ex.addTest( new TestErrorMessages( anE1, violationCodeInfo, false ) ); - } - e = examples.getGoodExamples(); - for ( String anE : e ) - { - ex.addTest( new TestErrorMessages( anE, violationCodeInfo, true ) ); - } - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestExample.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestExample.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestExample.java deleted file mode 100644 index 49d5b90..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestExample.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import java.util.Iterator; - -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.jena.iri.IRI ; -import org.apache.jena.iri.IRIFactory ; -import org.apache.jena.iri.Violation ; -import org.apache.jena.iri.ViolationCodes ; -import org.apache.jena.iri.impl.Force ; -import org.apache.jena.iri.impl.IRIExamples ; -import org.apache.jena.iri.impl.Specification ; -import org.apache.jena.iri.impl.ViolationCodeInfo ; - - -public class TestExample extends TestCase - implements ViolationCodes { - static { - new ViolationCodes.Initialize(); - } - - // static { - // Iterator it = Specification.iris.values().iterator(); - // while (it.hasNext()) - // System.err.println(it.next().getClass().toString()); - // } - static Specification specs[] = Specification.all - .values().toArray(new Specification[0]); - - static IRIFactory all[][] = new IRIFactory[specs.length][Force.SIZE]; - - - static { - for (int i = 0; i < specs.length; i++) - for (int j = 0; j < Force.SIZE; j++) { - all[i][j] = new IRIFactory(); - all[i][j].dnsViolation(false, false); - all[i][j].mintingViolation(false, false); - all[i][j].shouldViolation(false, false); - all[i][j].securityViolation(false, false); -// all[i][j].schemeViolation(false, false); - switch (j) { - case Force.DNS: - all[i][j].dnsViolation(false, true); - break; - case Force.MINTING: - all[i][j].mintingViolation(false, true); - break; - case Force.MUST: - break; - case Force.SECURITY: - all[i][j].securityViolation(false, true); - break; - case Force.SHOULD: - all[i][j].shouldViolation(false, true); - break; -// case Force.SCHEME_SPECIFIC: -// all[i][j].schemeViolation(false, true); -// all[i][j].useSchemeSpecificRules("*"); -// break; - } - if (specs[i].name().equals("IRI")) { - all[i][j].useSpecificationIRI(false); - - } - if (specs[i].name().equals("URI")) - all[i][j].useSpecificationURI(false); - if (specs[i].name().equals("XLink")) - all[i][j].useSpecificationXLink(false); - if (specs[i].name().equals("RDF")) - all[i][j].useSpecificationRDF(false); - if (specs[i].name().equals("XML")) - all[i][j].useSpecificationXMLSystemID(false); - if (specs[i].name().equals("Schema")) - all[i][j].useSpecificationXMLSchema(false); - - } - } - - String uri; - - ViolationCodeInfo violation; - - int specID; - - boolean good; - - public TestExample(int spec, String uri, ViolationCodeInfo info, boolean good) { - super(escapeAndShorten(uri)); - this.uri = uri; - this.violation = info; - specID = spec; - this.good = good; - } - -// public TestExample(String uri, ViolationCodeInfo info, boolean good) { -// super(escapeAndShorten(uri)); -// this.uri = uri; -// this.violation = info; -// specID = -1; -// } - - private static String escapeAndShorten(String uri2) { - StringBuilder rslt = new StringBuilder(); - int ln = uri2.length(); - if (ln > 80) - ln = 80; - for (int i = 0; i < ln; i++) { - int ch = uri2.charAt(i); - if (ch > 127 || ch < 32) { - rslt.append("&#"); - rslt.append(ch); - rslt.append(";"); - } else - rslt.append((char) ch); - } - return rslt.toString(); - } - - @Override - public void runTest() { - if (specID == -1) - runTestErrorCode(); - else if (violation==null) - runTestJustSpec(); - else - runTestSpec(); - } - - private void runTestJustSpec() { - IRIFactory f = - specs[specID].isSchemeSpec()? - IRIFactory.iriImplementation(): - all[specID][Force.MUST]; - - IRI iri = f.create(uri); - if (iri.hasViolation(false)) { - if (good) fail("Unexpected violation found: "+ - ((iri.violations(false).next())).codeName() - - ); - } else { - if (!good) fail("Expected a violation, none found."); - } - - - } - - - - private void runTestErrorCode() { - IRIFactory f = new IRIFactory(); - f.setIsError(violation.getCode(), true); - - runTest(f, - true, - false, - "Just this error"); - - } - - private void runTestSpec() { - boolean inSpec = violation.appliesTo(specs[specID]); - int force = violation.getForce(); - for (int f = 0; f < Force.SIZE; f++) { - - runTest(all[specID][f], - (force & Force.must)!=0 && inSpec, - (force & (1<<f))!=0 && inSpec, - "Force: " + f + "; spec: " + specs[specID].name()); - } - - } - - private void runTest(IRIFactory f, boolean expectError, - boolean expectWarning, String desc) { - IRI iri = f.create(uri); - boolean implemented = violation.isImplemented(); - expectError = expectError && implemented; - expectWarning = expectWarning && (!expectError) && implemented; - if (good) { - expectError = expectWarning = false; - } - boolean hasError = false; - boolean hasWarning = false; - Iterator<Violation> it = iri.violations(true); - while (it.hasNext()) { - Violation v = it.next(); - if (v.getViolationCode() == violation.getCode()) { - if (v.isError()) { - if (!expectError) - fail("Unexpected error, "+desc); - hasError = true; - } else { - if (!expectWarning) - fail("Unexpected warning, "+desc); - hasWarning = true; - } - break; - } - } - if (expectWarning && !hasWarning) - fail("No warning detected: "+expectError); - if (expectError && !hasError) - fail("No error detected: "+expectError); - } - - public static TestSuite suite() { - TestSuite rslt = new TestSuite(); - - rslt.setName("Examples from documentation"); - for (int sp = 0; sp < specs.length; sp++) { - TestSuite spec = new TestSuite(); - - String specName = specs[sp].name(); - spec.setName(specName); -// if (!specName.equals("http")) -// continue; - if (specs[sp].isIRISpec()) - addAllTestsFromExamples(sp, spec); - - addExamples(sp,null,specs[sp],spec); - if (spec.countTestCases()>0) - rslt.addTest(spec); - } -// if (false) - addAllTestsFromExamples(-1, rslt); - return rslt; - } - - private static void addAllTestsFromExamples(int sp, TestSuite spec) { - for (int i = 0; i < ViolationCodeInfo.all.length; i++) - addTestsFromExamples(spec, sp, ViolationCodeInfo.all[i]); - } - - private static void addTestsFromExamples(TestSuite rslt, int sp, ViolationCodeInfo violationCodeInfo) { - - if (violationCodeInfo != null) { - TestSuite ex = new TestSuite(); - ex.setName(violationCodeInfo.getCodeName()); - addExamples(sp, violationCodeInfo, violationCodeInfo, ex); - if (ex.countTestCases()>0) - rslt.addTest(ex); - } - } - - private static void addExamples(int sp, ViolationCodeInfo violationCodeInfo, IRIExamples examples, TestSuite ex) { - String e[] = examples.getBadExamples(); - for ( String anE1 : e ) - { - ex.addTest( new TestExample( sp, anE1, violationCodeInfo, false ) ); - } - e = examples.getGoodExamples(); - for ( String anE : e ) - { - ex.addTest( new TestExample( sp, anE, violationCodeInfo, true ) ); - } - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEIri.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEIri.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEIri.java deleted file mode 100644 index e6dc82b..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEIri.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import org.apache.jena.iri.IRI ; -import org.xml.sax.Attributes; - - -public class TestMEIri extends TestMoreExamples { - static int count; - - public TestMEIri(Attributes att) { -// super(att.getValue("iri"),att); - super(true? ( //"["+(++count)+"]" + - att.getValue("iri").replaceAll("\n","\\\\n")) :( "iri"+(++count)),att); - } - - @Override - IRI computeIRI() { - return TestCreator.factory.create(att.get("iri")); - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestMERelativize.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMERelativize.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestMERelativize.java deleted file mode 100644 index 7182853..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMERelativize.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import junit.framework.TestSuite; - -import org.apache.jena.iri.IRI ; -import org.xml.sax.Attributes; - - -public class TestMERelativize extends TestMoreExamples { - static int count; - public TestMERelativize(Attributes att, TestSuite suite) { - super("relativize"+ (++count),att,suite); - } - - @Override - IRI computeIRI() { - IRI base = ((TestMoreExamples)parent.testAt(0)).getIRI(); - IRI rel = ((TestMoreExamples)parent.testAt(2)).getIRI(); - return base.relativize(rel, TestCreator.RelativizeFlags); - } - - @Override - public void runTest() { - if (!"true".equals(att.get("same"))) { - super.runTest(); - } else { - assertEquals(computeIRI(), - ((TestMoreExamples)parent.testAt(1)).getIRI()); - } - - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResolve.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResolve.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResolve.java deleted file mode 100644 index bbd3a9e..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResolve.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.xml.sax.Attributes; - - -public class TestMEResolve extends TestSuite { - - public TestMEResolve(Attributes att) { - super(); - } - - void pop() { - setName(((TestCase)testAt(0)).getName() + " " + - ((TestCase)testAt(1)).getName()); - } - -// public void runTest(Test arg0, TestResult arg1) { -// super.runTest(arg0,arg1); -// } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResult.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResult.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResult.java deleted file mode 100644 index 4db38a5..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMEResult.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import junit.framework.TestSuite; - -import org.apache.jena.iri.IRI ; -import org.xml.sax.Attributes; - - -public class TestMEResult extends TestMoreExamples { - static int count; - - public TestMEResult(Attributes att, TestSuite suite) { - super("result"+ (++count),att, suite); - } - - @Override - IRI computeIRI() { - IRI base = ((TestMoreExamples)parent.testAt(0)).getIRI(); - IRI rel = ((TestMoreExamples)parent.testAt(1)).getIRI(); - return base.create(rel); - } - - @Override - public void runTest() { - super.runTest(); - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestMoreExamples.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMoreExamples.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestMoreExamples.java deleted file mode 100644 index 70ee785..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestMoreExamples.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Stack; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParserFactory; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.apache.jena.iri.IRI ; -import org.apache.jena.iri.Violation ; -import org.apache.jena.iri.ViolationCodes ; -import org.apache.jena.iri.impl.AbsIRIImpl ; -import org.apache.jena.iri.impl.PatternCompiler ; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - - -public class TestMoreExamples extends TestCase implements - ViolationCodes { - static class TestReader extends DefaultHandler { - private Stack<Test> stack = new Stack<>(); - - TestReader(TestSuite s) { - stack.push(s); - } - private void push(Test t) { - ((TestSuite)stack.peek()).addTest(t); - stack.push(t); - } - - @Override - public void startElement(String arg1, String arg2, String name, - Attributes att) { - if (name.equals("IRI")) - push(new TestMEIri(att)); - else if (name.equals("Result")) - push(new TestMEResult(att,(TestSuite)stack.peek())); - else if (name.equals("Relativize")) - push(new TestMERelativize(att,(TestSuite)stack.peek())); - else if (name.equals("Resolve")) - push(new TestSuite()); - else if (!name.equals("UriTests")) - add(name, att); - } - - private void add(String name, Attributes att) { - ((TestMoreExamples) stack.peek()).add(name, att); - } - - @Override - public void characters(char ch[], int st, int lg) { - String text = new String(ch,st,lg).trim(); - if (text.length()>0) - ((TestMoreExamples) stack.peek()).add(text); - } - @Override - public void endElement(String arg1, String arg2, String name) { - if (name.equals("Resolve")) { - TestSuite t = (TestSuite) stack.pop(); - t. - setName(((TestCase)t.testAt(0)).getName() + " " + - ((TestCase)t.testAt(1)).getName()); - } else if (name.equals("IRI") || name.equals("Result") - || name.equals("Relativize")) { - stack.pop(); - } - - } - - } - - static Map<String, String> attr2map(Attributes a) { - Map<String, String> rslt = new HashMap<>(); - for (int i = a.getLength()-1;i>=0;i--) - rslt.put(a.getQName(i),a.getValue(i)); - return rslt; - } - Map<String, String> att; - TestSuite parent; - private Map<String, Map<String, String>> methods = new HashMap<>(); - private long violations = 0l; - private IRI iri; - - public TestMoreExamples(String nm, Attributes att) { - this(nm,att,null); - } - - private String savedText = null; - public void add(String text) { - if (savedText!=null) { - text = savedText + text; - savedText = null; -// System.err.println(text); - } - try { - violations |= (1l << PatternCompiler.errorCode(text)); - } - catch (NoSuchFieldException e){ - savedText = text; - } - } - - public TestMoreExamples(String nm, Attributes att, TestSuite suite) { - super(escape(nm)); - this.att = attr2map(att); - this.parent = suite; - } - - private static String escape(String nm) { - StringBuilder rslt = new StringBuilder(); - for (int i=0; i<nm.length();i++) { - char ch = nm.charAt(i); - if (ch>=32 && ch<=126) - rslt.append(ch); - else - rslt.append("\\u"+pad4(Integer.toHexString(ch))); - - } - return rslt.toString(); - } - - private static String pad4(String string) { - switch (string.length()) { - case 0: - return "0000"; - case 1: - return "000"+string; - case 2: - return "00"+string; - case 3: - return "0"+string; - default: - return string; - - } - } - - public TestMoreExamples(String string) { - super(escape(string)); - } - -// static int cnt = 0; - - @Override - public void setUp() throws Exception { -// System.err.println("setUp"+cnt); - super.setUp(); - } - - @Override - public void tearDown() throws Exception { -// System.err.println("tearDown"+cnt++); - super.tearDown(); - } - private void add(String name, Attributes attrs) { - if (name.equals("violation")) - return; - if (name.equals("violations")) - return; - methods.put(name,attr2map(attrs)); - } - - private long getViolations() { - long result = 0l; - Iterator<Violation> it = ((AbsIRIImpl)iri).allViolations(); - while (it.hasNext()) { - result |= (1l<<(it.next()).getViolationCode()); - - } - return result; - } - @Override - public void runTest() { -// System.err.println("runTest"+cnt + " " + getName()); - iri = getIRI(); - - - assertEquals("violations",violations,getViolations()); - - Iterator<Map.Entry<String, Map<String,String>>> it = methods.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry<String, Map<String,String>> ent = it.next(); - String m = ent.getKey(); - Map<String,String> attrs = ent.getValue(); - try { - Object r = IRI.class.getDeclaredMethod(m,TestCreator.nullSign) - .invoke(iri,new Object[]{}); - if (r==null) - assertEquals(attrs.get("nullValue"),"true"); - else - assertEquals(attrs.get("value"),r.toString()); - - } catch (IllegalArgumentException | NoSuchMethodException | IllegalAccessException | SecurityException e) { - e.printStackTrace(); - } - catch (InvocationTargetException e) { - Throwable t = e; - if (t.getCause()!=null) - t= t.getCause(); - String s = t.getMessage()!=null?t.getMessage():t.toString(); - - assertEquals(attrs.get("exception"),s); - } - } - } - - final IRI getIRI() { if (iri==null) iri = computeIRI(); return iri; } - - IRI computeIRI() { - throw new UnsupportedOperationException(); - } - - static TestSuite suitex() throws SAXException, IOException, ParserConfigurationException { - SAXParserFactory fact = SAXParserFactory.newInstance(); - TestSuite result = new TestSuite(); - result.setName("More IRI Tests"); - try (InputStream in = TestCreator.class.getClassLoader().getResourceAsStream("org/apache/jena/iri/test/test.xml")) { - fact.newSAXParser().parse(in,new TestReader(result)); - return result; - } - } - public static TestSuite suite() { - try { - return - suitex(); - - } catch (SAXException | ParserConfigurationException | IOException e) { - e.printStackTrace(); - } -// System.err.println("Yes chris we know"); -// return - TestSuite r2 = new TestSuite("exception-while-building-testsuite"); -// r2.addTest(new TestMoreExamples("testDummy")); - return r2; - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/e89146d8/jena-iri/src/test/java/org/apache/jena/iri/test/TestPackage.java ---------------------------------------------------------------------- diff --git a/jena-iri/src/test/java/org/apache/jena/iri/test/TestPackage.java b/jena-iri/src/test/java/org/apache/jena/iri/test/TestPackage.java deleted file mode 100644 index 5a4bccc..0000000 --- a/jena-iri/src/test/java/org/apache/jena/iri/test/TestPackage.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.iri.test; - -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class TestPackage extends TestCase{ - - public static TestSuite suite() { - TestSuite rslt = new TestSuite(); - - rslt.setName("IRI"); - rslt.addTest(TestExample.suite()); - rslt.addTest(TestMoreExamples.suite()); - rslt.addTest(MoreTests.suite()); - rslt.addTest(Additional.suite()); - return rslt; - } -}
