Class Sandbox

java.lang.Object
org.basex.core.Sandbox

public abstract class Sandbox extends Object
If this class is extended, tests will be run in a sandbox.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Details

  • Constructor Details

    • Sandbox

      public Sandbox()
  • Method Details

    • execute

      protected static String execute(Command cmd)
      Executes a command and returns exceptions into assertion errors.
      Parameters:
      cmd - command to be run
      Returns:
      string result
    • set

      protected static void set(Option<?> option, Object value)
      Sets an option and returns exceptions into assertion errors.
      Parameters:
      option - option to be set
      value - value to be assigned
    • query

      protected static String query(String query)
      Runs a query and returns exceptions into assertion errors.
      Parameters:
      query - query to be evaluated
      Returns:
      string result
    • query

      protected static void query(String query, Object expected)
      Checks if a query yields the specified string.
      Parameters:
      query - query string
      expected - expected result
    • transform

      protected static String transform(String input, String modify, String rtrn)
      Creates a transform expression from a given input, modification and return clause.
      Parameters:
      input - input XML fragment, target of the updating expression
      modify - updating expression, make sure to address all target nodes via the $input variable, i.e. delete node $input/a
      rtrn - return clause
      Returns:
      the query formulated with a transform expression
    • transform

      protected static String transform(String input, String modification)
      Creates a transform expression from a given input and modification clause.
      Parameters:
      input - input XML fragment, target of the updating expression
      modification - updating expression, make sure to address all target nodes via the $input variable, i.e. delete node $input/a
      Returns:
      the query formulated with a transform expression
    • contains

      protected static void contains(String query, String result)
      Checks if a query yields the specified result.
      Parameters:
      query - query string
      result - query result
    • error

      protected static void error(String query, QueryError... error)
      Checks if a query yields the specified error code.
      Parameters:
      query - query string
      error - allowed errors
    • error

      protected static void error(String query, QueryException ex, QueryError... errors)
      Checks if an exception yields one of the specified error codes.
      Parameters:
      query - query
      ex - resulting query exception
      errors - allowed errors
    • serialParams

      protected static String serialParams(String arg)
      Returns serialization parameters.
      Parameters:
      arg - serialization arguments
      Returns:
      parameter string
    • eval

      protected static String eval(String query) throws QueryException, IOException
      Runs a query.
      Parameters:
      query - query string
      Returns:
      result
      Throws:
      QueryException - query exception
      IOException - I/O exception
    • write

      protected static void write(IOFile file, String data)
      Writes a test file.
      Parameters:
      file - file
      data - data to write
    • initSandbox

      public static void initSandbox()
      Creates the sandbox.
    • finishSandbox

      public static void finishSandbox()
      Removes test databases and closes the database context.
    • inline

      protected static void inline(boolean enable)
      Triggers function inlining.
      Parameters:
      enable - flag
    • unroll

      protected static void unroll(boolean enable)
      Triggers function inlining.
      Parameters:
      enable - flag
    • createServer

      public static BaseXServer createServer(String... args) throws IOException
      Creates a new, sandboxed server instance.
      Parameters:
      args - additional arguments
      Returns:
      server instance
      Throws:
      IOException - I/O exception
    • stopServer

      public static void stopServer(BaseXServer server) throws IOException
      Stops a server instance.
      Parameters:
      server - server
      Throws:
      IOException - I/O exception
    • createClient

      public static ClientSession createClient(String... login) throws IOException
      Creates a client instance.
      Parameters:
      login - optional login data
      Returns:
      client instance
      Throws:
      IOException - I/O exception
    • sandbox

      public static IOFile sandbox()
      Returns the sandbox database path.
      Returns:
      database path
    • normNL

      public static String normNL(String result)
      Normalizes newlines in a query result.
      Parameters:
      result - input string
      Returns:
      normalized string