This is an automated email from the ASF dual-hosted git repository.

afs pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit 8ffe509d9153393ddc2d1eb34bf5b1f8eb50eb6b
Author: Andy Seaborne <[email protected]>
AuthorDate: Sun Nov 8 09:46:07 2026 +0000

    Move testing helper afn:context into test code
---
 .../org/apache/jena/sparql/algebra/op/OpExt.java   |  2 +-
 .../jena/sparql/function/library/context.java      | 76 ----------------------
 .../java/org/apache/jena/sparql/util/Context.java  |  3 +-
 .../src/main/java/arq/cmdline/ModContext.java      | 42 ++----------
 .../apache/jena/fuseki/main/TestConfigFile.java    | 67 +++++++++++++++++++
 5 files changed, 74 insertions(+), 116 deletions(-)

diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpExt.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpExt.java
index 06cacd6a30..7ad753ae1e 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpExt.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpExt.java
@@ -48,7 +48,7 @@ public abstract class OpExt extends OpBase
     public abstract Op effectiveOp();
 
     /** Evaluate the op, given a stream of bindings as input
-     *  Throw UnsupportedOperationException if this OpExt is not executeable.
+     *  Throw UnsupportedOperationException if this OpExt is not executable.
      */
     public abstract QueryIterator eval(QueryIterator input, ExecutionContext 
execCxt);
 
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/function/library/context.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/function/library/context.java
deleted file mode 100644
index e565b69a3b..0000000000
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/function/library/context.java
+++ /dev/null
@@ -1,76 +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
- *
- *   https://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.
- *
- *   SPDX-License-Identifier: Apache-2.0
- */
-
-package org.apache.jena.sparql.function.library;
-
-import java.util.List;
-
-import org.apache.jena.atlas.lib.InternalErrorException;
-import org.apache.jena.atlas.lib.Lib;
-import org.apache.jena.graph.Node;
-import org.apache.jena.sparql.expr.ExprEvalException;
-import org.apache.jena.sparql.expr.ExprList;
-import org.apache.jena.sparql.expr.NodeValue;
-import org.apache.jena.sparql.function.FunctionBase;
-import org.apache.jena.sparql.function.FunctionEnv;
-import org.apache.jena.sparql.util.Symbol;
-
-/**
- * Function that returns the value of a context setting.
- */
-public class context extends FunctionBase {
-    // This function exists more for testing context get setup correctly than 
anything else.
-    public context() {}
-
-    @Override
-    public void checkBuild(String uri, ExprList args) {
-        if ( args.size() != 1 )
-            throw new ExprEvalException("Wrong number of arguments");
-    }
-
-    @Override
-    public NodeValue exec(List<NodeValue> args, FunctionEnv env) {
-        NodeValue v = args.get(0);
-        if ( ! v.isString() )
-            throw new ExprEvalException("Not a string: function 
afn:context("+v+")");
-        Symbol symbol = Symbol.create(v.getString());
-        return get(symbol, env);
-    }
-
-    public static NodeValue get(Symbol symbol, FunctionEnv env) {
-        Object obj = env.getContext().get(symbol);
-        if ( obj == null )
-            return NodeValue.nvEmptyString;
-        if ( obj instanceof String )
-            return NodeValue.makeString((String)obj);
-
-        if ( !(obj instanceof Node) )
-            throw new ExprEvalException("Not a Node: " + Lib.className(obj));
-        Node n = (Node)obj;
-        NodeValue nv = NodeValue.makeNode(n);
-        return nv;
-    }
-
-    @Override
-    public NodeValue exec(List<NodeValue> args) {
-        throw new InternalErrorException("afn:context.exec(args) called");
-    }
-}
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
index bc8bdce2f8..18caed04d7 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
@@ -323,8 +323,7 @@ public class Context {
     /**
      * Is the value true or false, either as a Boolean or a string.
      * If undefined, return null.
-     * Exception if not a boolean or a string.
-     *
+     * Throw an exception if the value is not a boolean or a string 
"true"/"false".
      */
     public Boolean getTrueOrFalse(Symbol property) {
         Object x = get(property);
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModContext.java 
b/jena-cmds/src/main/java/arq/cmdline/ModContext.java
index 0a05777cf7..6b430323f2 100644
--- a/jena-cmds/src/main/java/arq/cmdline/ModContext.java
+++ b/jena-cmds/src/main/java/arq/cmdline/ModContext.java
@@ -21,17 +21,12 @@
 
 package arq.cmdline;
 
-import java.io.PrintStream;
-
-import org.apache.jena.atlas.io.IndentedWriter;
 import org.apache.jena.cmd.ArgDecl;
 import org.apache.jena.cmd.CmdArgModule;
 import org.apache.jena.cmd.CmdGeneral;
 import org.apache.jena.cmd.ModBase;
 import org.apache.jena.query.ARQ;
 import org.apache.jena.sparql.util.Context;
-import org.apache.jena.sparql.util.MappingRegistry;
-import org.apache.jena.sparql.util.Symbol;
 import org.apache.jena.sys.JenaSystem;
 
 /** Set Context items */
@@ -41,10 +36,8 @@ public class ModContext extends ModBase
 
     protected final ArgDecl setDecl = new ArgDecl(ArgDecl.HasValue, "set", 
"define", "defn", "def");
 
-    private Context context = new Context();
-
     public ModContext() {}
-    
+
     @Override
     public void registerWith(CmdGeneral cmdLine) {
         cmdLine.getUsage().startCategory("Symbol definition");
@@ -58,38 +51,13 @@ public class ModContext extends ModBase
         if ( cmdLine.getValues(setDecl) == null || 
cmdLine.getValues(setDecl).size() == 0 )
             return;
 
-        for ( String arg : cmdLine.getValues(setDecl) ) {
-            String[] frags = arg.split("=", 2);
-            if ( frags.length != 2 ) {
-                throw new RuntimeException("Can't split '" + arg + "' -- 
looking for '=' to separate name and value");
-            }
+        // Isolate while processing.
+        Context context = new Context();
 
-            String symbolName = frags[0];
-            String value = frags[1];
-
-            // Make it a long name.
-            symbolName = MappingRegistry.mapPrefixName(symbolName);
-            Symbol symbol = Symbol.create(symbolName);
-            context.set(symbol, value);
+        for ( String arg : cmdLine.getValues(setDecl) ) {
+            CmdLib.processArgSet(arg, context);
         }
 
         ARQ.getContext().putAll(context);
     }
-
-    public void verbose() {
-        verbose(System.out);
-    }
-
-    public void verbose(PrintStream stream) {
-        IndentedWriter out = new IndentedWriter(stream);
-        verbose(out);
-        out.flush();
-    }
-
-    public void verbose(IndentedWriter out) {
-        for ( Symbol symbol : context.keys() ) {
-            String value = context.getAsString(symbol);
-            out.println(symbol + " -> " + value);
-        }
-    }
 }
diff --git 
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestConfigFile.java
 
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestConfigFile.java
index 65f1703f93..56dfee7166 100644
--- 
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestConfigFile.java
+++ 
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestConfigFile.java
@@ -26,19 +26,33 @@ import static 
org.apache.jena.fuseki.test.HttpTest.expect404;
 import static org.junit.jupiter.api.Assertions.*;
 
 import java.io.IOException;
+import java.util.List;
 
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
 import org.apache.jena.atlas.io.IO;
+import org.apache.jena.atlas.lib.InternalErrorException;
+import org.apache.jena.atlas.lib.Lib;
 import org.apache.jena.atlas.web.TypedInputStream;
 import org.apache.jena.base.Sys;
 import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
 import org.apache.jena.http.HttpOp;
 import org.apache.jena.query.QueryExecution;
 import org.apache.jena.rdfconnection.RDFConnection;
 import org.apache.jena.rdfconnection.RDFConnectionRemote;
 import org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder;
+import org.apache.jena.sparql.ARQConstants;
 import org.apache.jena.sparql.core.Var;
+import org.apache.jena.sparql.expr.ExprEvalException;
+import org.apache.jena.sparql.expr.ExprList;
+import org.apache.jena.sparql.expr.NodeValue;
+import org.apache.jena.sparql.function.FunctionBase;
+import org.apache.jena.sparql.function.FunctionEnv;
+import org.apache.jena.sparql.function.FunctionRegistry;
+import org.apache.jena.sparql.util.Symbol;
 
 /** Test server configuration by configuration file */
 public class TestConfigFile {
@@ -62,6 +76,17 @@ public class TestConfigFile {
             .build();
     }
 
+    // Register SPARQL extension function.
+    @BeforeAll public static void setup() {
+        FunctionRegistry registry = FunctionRegistry.get();
+        registry.put(ReadContext.uri, uri->new ReadContext());
+    }
+
+    @AfterAll public static void teardown() {
+        FunctionRegistry registry = FunctionRegistry.get();
+        registry.remove(ReadContext.uri);
+    }
+
     @Test public void basic () {
         FusekiServer server = server(0, "basic.ttl");
         server.start();
@@ -407,4 +432,46 @@ public class TestConfigFile {
             .build();
         return server;
     }
+
+    private static class ReadContext extends FunctionBase {
+
+        static String uri = ARQConstants.ARQFunctionLibraryURI+"context";
+
+        // This function exists for testing context get setup correctly.
+        public ReadContext() {}
+
+        @Override
+        public void checkBuild(String uri, ExprList args) {
+            if ( args.size() != 1 )
+                throw new ExprEvalException("Wrong number of arguments");
+        }
+
+        @Override
+        public NodeValue exec(List<NodeValue> args, FunctionEnv env) {
+            NodeValue v = args.get(0);
+            if ( ! v.isString() )
+                throw new ExprEvalException("Not a string: function 
afn:context("+v+")");
+            Symbol symbol = Symbol.create(v.getString());
+            return get(symbol, env);
+        }
+
+        private static NodeValue get(Symbol symbol, FunctionEnv env) {
+            Object obj = env.getContext().get(symbol);
+            if ( obj == null )
+                return NodeValue.nvEmptyString;
+            if ( obj instanceof String )
+                return NodeValue.makeString((String)obj);
+
+            if ( !(obj instanceof Node) )
+                throw new ExprEvalException("Not a Node: " + 
Lib.className(obj));
+            Node n = (Node)obj;
+            NodeValue nv = NodeValue.makeNode(n);
+            return nv;
+        }
+
+        @Override
+        public NodeValue exec(List<NodeValue> args) {
+            throw new InternalErrorException("afn:context.exec(args) called");
+        }
+    }
 }

Reply via email to