public void testRemoveNamespace() {
    SailGraph graph = new MemoryStoreSailGraph();
    GremlinScriptContext context = new GremlinScriptContext();
    context
        .getBindings(ScriptContext.ENGINE_SCOPE)
        .put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(graph));

    Function<Object> function = new RemoveNamespaceFunction();
    assertNotNull(graph.getNamespaces().get("rdf"));
    this.stopWatch();
    Atom<Object> atom = function.compute(createUnaryArgs(graph, "rdf"), context);
    printPerformance(
        function.getFunctionName() + " function", 1, "namespace removed", this.stopWatch());
    assertNull(atom.getValue());
    assertNull(graph.getNamespaces().get("rdf"));

    assertNotNull(graph.getNamespaces().get("rdfs"));
    this.stopWatch();
    atom = function.compute(createUnaryArgs("rdfs"), context);
    printPerformance(
        function.getFunctionName() + " function", 1, "namespace removed", this.stopWatch());
    assertTrue(atom.isNull());
    assertNull(graph.getNamespaces().get("rdfs"));

    graph.shutdown();
  }
  public Object invokeFunction(String name, Object... args)
      throws NoSuchMethodException, ScriptException {
    GremlinScriptContext ctx = (GremlinScriptContext) this.getContext();
    int colonIndex = name.indexOf(":");
    Function function;
    try {
      function =
          ctx.getFunctionLibrary()
              .getFunction(name.substring(0, colonIndex), name.substring(colonIndex + 1));
    } catch (RuntimeException e) {
      throw new NoSuchMethodException();
    }

    List<Operation> arguments = new ArrayList<Operation>();
    for (Object arg : args) {
      arguments.add(new UnaryOperation(new Atom(arg)));
    }
    try {
      Atom ret = function.compute(arguments, ctx);
      if (ret.isNull()) return null;
      else return ret.getValue();
    } catch (Exception e) {
      throw new ScriptException(e.getMessage());
    }
  }
 private static GremlinScriptContext convertContext(final ScriptContext context) {
   if (context instanceof GremlinScriptContext) return (GremlinScriptContext) context;
   else {
     GremlinScriptContext context2 = new GremlinScriptContext();
     for (int scope : context.getScopes()) {
       context2.setBindings(context.getBindings(scope), scope);
     }
     return context2;
   }
 }