jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1410871 - in /jena/trunk/jena-arq/src/test/java/riotcmd: ./ rdflangtest.java
Date Sun, 18 Nov 2012 11:10:25 GMT
Author: andy
Date: Sun Nov 18 11:10:24 2012
New Revision: 1410871

URL: http://svn.apache.org/viewvc?rev=1410871&view=rev
Log:
Test code for RIOT reader

Added:
    jena/trunk/jena-arq/src/test/java/riotcmd/
    jena/trunk/jena-arq/src/test/java/riotcmd/rdflangtest.java

Added: jena/trunk/jena-arq/src/test/java/riotcmd/rdflangtest.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/riotcmd/rdflangtest.java?rev=1410871&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/test/java/riotcmd/rdflangtest.java (added)
+++ jena/trunk/jena-arq/src/test/java/riotcmd/rdflangtest.java Sun Nov 18 11:10:24 2012
@@ -0,0 +1,210 @@
+/*
+ * 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 riotcmd;
+
+import junit.framework.TestSuite ;
+import org.apache.jena.riot.langsuite.FactoryTestRiot ;
+import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.riot.RIOT ;
+import org.openjena.riot.SysRIOT ;
+import arq.cmd.CmdException ;
+import arq.cmd.TerminationException ;
+import arq.cmdline.ArgDecl ;
+import arq.cmdline.CmdGeneral ;
+import arq.cmdline.ModEngine ;
+import arq.cmdline.ModSymbol ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.n3.IRIResolver ;
+import com.hp.hpl.jena.query.ARQ ;
+import com.hp.hpl.jena.rdf.model.Literal ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.sparql.expr.E_Function ;
+import com.hp.hpl.jena.sparql.expr.NodeValue ;
+import com.hp.hpl.jena.sparql.junit.EarlReport ;
+import com.hp.hpl.jena.sparql.junit.ScriptTestSuiteFactory ;
+import com.hp.hpl.jena.sparql.junit.SimpleTestRunner ;
+import com.hp.hpl.jena.sparql.util.NodeFactory ;
+import com.hp.hpl.jena.sparql.util.Utils ;
+import com.hp.hpl.jena.sparql.vocabulary.DOAP ;
+import com.hp.hpl.jena.sparql.vocabulary.FOAF ;
+import com.hp.hpl.jena.sparql.vocabulary.TestManifest ;
+import com.hp.hpl.jena.vocabulary.DC ;
+import com.hp.hpl.jena.vocabulary.DCTerms ;
+import com.hp.hpl.jena.vocabulary.RDF ;
+import com.hp.hpl.jena.vocabulary.XSD ;
+
+
+/** A program to execute RDF language test suites
+ * 
+ * <pre>
+ * Usage: 
+ *   [--all]
+ *   <i>testManifest</i>
+ *   [ --query <i>query</i> --data <i>data</i> --result <i>result</i>
] -- run one test
+ * </pre>
+ */
+
+public class rdflangtest extends CmdGeneral
+{
+    protected ModSymbol modSymbol       = new ModSymbol() ;
+    protected ArgDecl  strictDecl       = new ArgDecl(ArgDecl.NoValue, "strict") ;
+    protected boolean  cmdStrictMode    = false ; 
+
+    //protected ArgDecl allDecl =    new ArgDecl(ArgDecl.NoValue, "all") ;
+    protected ArgDecl earlDecl          = new ArgDecl(ArgDecl.NoValue, "earl") ;
+    
+    protected boolean createEarlReport = false;
+    
+    public static void main (String... argv)
+    {
+        SysRIOT.wireIntoJena() ;
+        try { new rdflangtest(argv).mainRun() ; }
+        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
+    }
+    
+    public rdflangtest(String[] argv)
+    {
+        super(argv) ;
+        addModule(modSymbol) ;
+        super.add(strictDecl, "--strict", "Operate in strict mode (no extensions of any kind)")
;
+        super.modVersion.addClass(ARQ.class) ;
+        //add(allDecl, "--all", "run all tests") ;
+        getUsage().startCategory("Tests (execute test manifest)") ;
+        getUsage().addUsage("<manifest>", "run the tests specified in the given manifest")
;
+        add(earlDecl, "--earl", "create EARL report") ;
+    }
+    
+    protected ModEngine setModEngine()
+    {
+        return new ModEngine() ;
+    }
+    
+    @Override
+    protected String getCommandName() { return Utils.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" [ --data=<file> --query=<query>
--result=<results> ] | --all | --dawg | <manifest>" ; }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        if ( ! hasPositional() )
+            throw new CmdException("No manifest file") ;
+        createEarlReport = contains(earlDecl) ;
+    }
+    
+    @Override
+    protected void exec()
+    {
+        // Paradoxical naming - the boolean is a visibility flag.
+        BaseTest.setTestLogging() ;
+        
+        if ( contains(strictDecl) )
+        {
+            cmdStrictMode = true ;
+            // Which will apply to reading the manifest!
+            ARQ.setStrictMode() ;
+            RIOT.setStrictMode(true) ;
+        }
+        
+        NodeValue.VerboseWarnings = false ;
+        E_Function.WarnOnUnknownFunction = false ;
+        
+        for ( String fn : getPositional() )
+        {
+            String testfile = IRIResolver.resolveGlobal(fn) ;
+            exec1(testfile) ;
+        }
+    }
+    
+    protected void exec1(String manifest)
+    {
+        if ( createEarlReport )
+            oneManifestEarl(manifest) ;
+        else
+            oneManifest(manifest) ;
+    }
+
+    static void oneManifest(String testManifest)
+    {
+        TestSuite suite = FactoryTestRiot.make(testManifest, null, null) ;
+
+        //junit.textui.TestRunner.run(suite) ;
+        SimpleTestRunner.runAndReport(suite) ;
+    }
+    
+    static void oneManifestEarl(String testManifest)
+    {
+        String name =  "ARQ" ;
+        String releaseName =  "ARQ" ;
+        String version = ARQ.VERSION ;
+        String homepage = "http://jena.apache.org/" ;
+        String systemURI = "http://jena.apache.org/#arq" ;  // Null for bNode.
+        
+        // Include information later.
+        EarlReport report = new EarlReport(systemURI, name, version, homepage) ;
+        ScriptTestSuiteFactory.results = report ;
+        
+        Model model = report.getModel() ;
+        model.setNsPrefix("dawg", TestManifest.getURI()) ;
+        
+        // Update the EARL report. 
+        Resource jena = model.createResource()
+                    .addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/"))
;
+        
+        // ARQ is part fo Jena.
+        Resource arq = report.getSystem()
+                        .addProperty(DCTerms.isPartOf, jena) ;
+        
+        // Andy wrote the test software (updates the thing being tested as well as they are
the same). 
+        Resource who = model.createResource(FOAF.Person)
+                                .addProperty(FOAF.name, "Andy Seaborne")
+                                .addProperty(FOAF.homepage, 
+                                             model.createResource("http://people.apache.org/~andy"))
;
+        
+        Resource reporter = report.getReporter() ;
+        reporter.addProperty(DC.creator, who) ;
+
+        model.setNsPrefix("doap", DOAP.getURI()) ; 
+        model.setNsPrefix("xsd", XSD.getURI()) ;
+        
+        // DAWG specific stuff.
+        Resource system = report.getSystem() ;
+        system.addProperty(RDF.type, DOAP.Project) ;
+        system.addProperty(DOAP.name, name) ;
+        system.addProperty(DOAP.homepage, homepage) ;
+        system.addProperty(DOAP.maintainer, who) ;
+        
+        Resource release = model.createResource(DOAP.Version) ;
+        system.addProperty(DOAP.release, release) ;
+        
+        Node today_node = NodeFactory.todayAsDate() ;
+        Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype())
;
+        release.addProperty(DOAP.created, today) ;
+        release.addProperty(DOAP.name, releaseName) ;      // Again
+        
+        TestSuite suite = ScriptTestSuiteFactory.make(testManifest) ;
+        SimpleTestRunner.runSilent(suite) ;
+        
+        ScriptTestSuiteFactory.results.getModel().write(System.out, "TTL") ;
+        
+    }
+ }



Mime
View raw message