You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ij...@apache.org on 2011/10/14 12:13:37 UTC
svn commit: r1183275 - in /incubator/jena/Jena2/jena/trunk:
src/main/java/jena/schemagen.java
src/test/java/jena/test/Test_schemagen.java testing/cmd/sg-test-config.rdf
Author: ijd
Date: Fri Oct 14 10:13:37 2011
New Revision: 1183275
URL: http://svn.apache.org/viewvc?rev=1183275&view=rev
Log:
Bug fix: schemagen was not processing the config file correctly, because it was reading the root resource too early. Fixed, and added a test.
Added:
incubator/jena/Jena2/jena/trunk/testing/cmd/sg-test-config.rdf
Modified:
incubator/jena/Jena2/jena/trunk/src/main/java/jena/schemagen.java
incubator/jena/Jena2/jena/trunk/src/test/java/jena/test/Test_schemagen.java
Modified: incubator/jena/Jena2/jena/trunk/src/main/java/jena/schemagen.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/src/main/java/jena/schemagen.java?rev=1183275&r1=1183274&r2=1183275&view=diff
==============================================================================
--- incubator/jena/Jena2/jena/trunk/src/main/java/jena/schemagen.java (original)
+++ incubator/jena/Jena2/jena/trunk/src/main/java/jena/schemagen.java Fri Oct 14 10:13:37 2011
@@ -149,7 +149,7 @@ public class schemagen {
//////////////////////////////////
static {
- setLog4jConfiguration() ;
+ setLog4jConfiguration() ;
}
/* Main entry point. See Javadoc for details of the many command line arguments */
@@ -1565,9 +1565,6 @@ public class schemagen {
configURL = SchemagenUtils.urlCheck( getConfigFileOption() );
}
- // ensure we have a root URI for the configuration model
- determineConfigRoot();
-
// try to read the config URI
try {
FileManager.get().readModel( m_config, configURL );
@@ -1578,6 +1575,9 @@ public class schemagen {
throw new SchemagenException( "Failed to read configuration from URL: " + configURL, e );
}
}
+
+ // ensure we have a root URI for the configuration model
+ determineConfigRoot();
}
/**
Modified: incubator/jena/Jena2/jena/trunk/src/test/java/jena/test/Test_schemagen.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/src/test/java/jena/test/Test_schemagen.java?rev=1183275&r1=1183274&r2=1183275&view=diff
==============================================================================
--- incubator/jena/Jena2/jena/trunk/src/test/java/jena/test/Test_schemagen.java (original)
+++ incubator/jena/Jena2/jena/trunk/src/test/java/jena/test/Test_schemagen.java Fri Oct 14 10:13:37 2011
@@ -539,6 +539,15 @@ public class Test_schemagen
}
+ public void testConfigFile() throws Exception {
+ String SOURCE = PREFIX + "ex:A a owl:Class .";
+ testSchemagenOutput( SOURCE, null,
+ new String[] {"-c", "testing/cmd/sg-test-config.rdf"},
+ new String[] {".*OntClass.*"}, // if config is not processed, we will not get --ontology output
+ new String[] {} );
+
+ }
+
// Internal implementation methods
//////////////////////////////////
@@ -559,10 +568,29 @@ public class Test_schemagen
String[] posPatterns, String[] negPatterns )
throws Exception
{
- sg = (sg == null) ? new SchemaGenAux() : sg;
-
Model m = ModelFactory.createDefaultModel();
m.read( new StringReader( source ), "http://example.com/sg#", "N3" );
+ return testSchemagenOutput( m, sg, args, posPatterns, negPatterns );
+ }
+
+ /**
+ * Test the output from schemagen by saving the output to a string,
+ * then ensuring that every positive regex matches at least one line, and
+ * every negative regex matches at most no lines. Also checks that
+ * compiling the file does not cause any errors.
+ *
+ * @param m Source model to read from
+ * @param sg The schemagen object to test, or null for a default
+ * @param args list of args to pass to SG
+ * @param posPatterns array of regexps that must match at least once in the output
+ * @param negPatterns arrays of regexps that must not match the output
+ * @return The string defining the java class
+ */
+ protected String testSchemagenOutput( Model m, SchemaGenAux sg, String[] args,
+ String[] posPatterns, String[] negPatterns )
+ throws Exception
+ {
+ sg = (sg == null) ? new SchemaGenAux() : sg;
sg.setSource( m );
ByteArrayOutputStream buf = new ByteArrayOutputStream();
Added: incubator/jena/Jena2/jena/trunk/testing/cmd/sg-test-config.rdf
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/testing/cmd/sg-test-config.rdf?rev=1183275&view=auto
==============================================================================
--- incubator/jena/Jena2/jena/trunk/testing/cmd/sg-test-config.rdf (added)
+++ incubator/jena/Jena2/jena/trunk/testing/cmd/sg-test-config.rdf Fri Oct 14 10:13:37 2011
@@ -0,0 +1,23 @@
+<?xml version='1.0'?>
+
+<!DOCTYPE rdf:RDF [
+ <!ENTITY jena 'http://jena.hpl.hp.com/'>
+
+ <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
+ <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
+ <!ENTITY owl 'http://www.w3.org/2002/07/owl#'>
+ <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>
+ <!ENTITY base '&jena;2003/04/schemagen'>
+ <!ENTITY sgen '&base;#'>
+]>
+
+<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:sgen="http://jena.hpl.hp.com/2003/04/schemagen#">
+
+ <sgen:Config>
+ <!-- specifies that the source document uses OWL -->
+ <sgen:owl rdf:datatype="&xsd;boolean">true</sgen:owl>
+ <!-- specifies that we want the generated vocab to use OntClass, OntProperty, etc, not Resource and Property -->
+ <sgen:ontology rdf:datatype="&xsd;boolean">true</sgen:ontology>
+ </sgen:Config>
+</rdf:RDF>
\ No newline at end of file