Class BMUnit

java.lang.Object
org.jboss.byteman.contrib.bmunit.BMUnit

public class BMUnit extends Object
Byteman Unit test manager class which provides support for loading and unloading scripts. This version assumes loads the agent as needed (unless inhibited -- see below) using System properties to control what hostname and port it uses for the socket. Other system properties can be used to configure operation of the load/unload operations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static HashMap<String,String>
    hash table used to maintain association between test cases and rule files
    private static char
    the file separator character used by the native file system
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static String
    findScript(String dir, String name)
    Tries to find dir/name in the working directory.
    protected static String
    findScript(String dir, String... names)
     
    static String
    getter for the host name used to communicate with the agent
    static String
    getter for the load directory
    static boolean
    getter for the security policy setting
    static int
    getter for the port used to communicate with the agent
    static String
    getter for the resource load directory
    static boolean
    getter for the allowAgentConfigUpdate setting
    static boolean
    getter for the BMUnit verbose setting
    static boolean
    getter for the Byteman debug setting
    static boolean
    getter for the Byteman verbose setting
    static void
    loadScriptFile(Class<?> clazz, String dir)
    loads a script by calling loadScriptFile(clazz, null, dir)
    static void
    loadScriptFile(Class<?> clazz, String testName, String dir)
    loads a script from the load directory using the name of a unit test as the root name for the script file and ".btm" or, failing that, ".txt" for the file extension
    static void
    loadScriptText(Class<?> clazz, String testname, String scriptText)
    loads a script supplied as a text String rather than via a file on disk
    private static String
    normalize(String dir, boolean endWithSeparator)
    transform the supplied directory string if necessary to employ the file separator appropriate to the current file system, including a separator at the end if requested and not present.
    static void
    unloadScriptFile(Class<?> clazz, String testName)
    loads a script from the load directory using the name of a unit test as the root name for the script file and ".btm" or, failing that, ".txt" for the file extension
    static void
    unloadScriptText(Class<?> clazz, String testName)
    unloads a script previously supplied as a text String

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fs

      private static char fs
      the file separator character used by the native file system
    • fileTable

      private static HashMap<String,String> fileTable
      hash table used to maintain association between test cases and rule files
  • Constructor Details

    • BMUnit

      public BMUnit()
  • Method Details

    • isAllowConfigUpdate

      public static boolean isAllowConfigUpdate()
      getter for the allowAgentConfigUpdate setting
      Returns:
      the allowAgentConfigUpdate setting
    • isVerbose

      public static boolean isVerbose()
      getter for the Byteman verbose setting
      Returns:
      the Byteman verbose setting
    • isDebug

      public static boolean isDebug()
      getter for the Byteman debug setting
      Returns:
      the Byteman debug setting
    • isBMUnitVerbose

      public static boolean isBMUnitVerbose()
      getter for the BMUnit verbose setting
      Returns:
      the BMUnit verbose setting
    • getLoadDirectory

      public static String getLoadDirectory()
      getter for the load directory
      Returns:
      the load directory
    • getResourceLoadDirectory

      public static String getResourceLoadDirectory()
      getter for the resource load directory
      Returns:
      the resource load directory
    • normalize

      private static String normalize(String dir, boolean endWithSeparator)
      transform the supplied directory string if necessary to employ the file separator appropriate to the current file system, including a separator at the end if requested and not present. BMUnit assumes that all supplied paths are specified in Unix format i.e. with a '/' separator. So, transformation of '/' to '\' is only performed on Windows systems.
    • getHost

      public static String getHost()
      getter for the host name used to communicate with the agent
      Returns:
      the host name
    • getPort

      public static int getPort()
      getter for the port used to communicate with the agent
      Returns:
      the port
    • getPolicy

      public static boolean getPolicy()
      getter for the security policy setting
      Returns:
      the security policy setting
    • loadScriptFile

      public static void loadScriptFile(Class<?> clazz, String dir) throws Exception
      loads a script by calling loadScriptFile(clazz, null, dir)
      Parameters:
      clazz - the test class
      dir - the directory to load the script from
      Throws:
      Exception - if the script cannot be loaded
    • loadScriptFile

      public static void loadScriptFile(Class<?> clazz, String testName, String dir) throws Exception
      loads a script from the load directory using the name of a unit test as the root name for the script file and ".btm" or, failing that, ".txt" for the file extension
      Parameters:
      clazz - the classname of the unit test
      testName - the name of the unit test method
      dir - the directory in which the scripts are located
      Throws:
      Exception - if the script cannot be loaded
    • unloadScriptFile

      public static void unloadScriptFile(Class<?> clazz, String testName) throws Exception
      loads a script from the load directory using the name of a unit test as the root name for the script file and ".btm" or, failing that, ".txt" for the file extension
      Parameters:
      clazz - the test class
      testName - the test name
      Throws:
      Exception - if the script cannot be unloaded
    • loadScriptText

      public static void loadScriptText(Class<?> clazz, String testname, String scriptText) throws Exception
      loads a script supplied as a text String rather than via a file on disk
      Parameters:
      clazz - the test class
      testname - the test name
      scriptText - the text of the rule or rules contained in the script
      Throws:
      Exception - if the script text cannot be loaded
    • unloadScriptText

      public static void unloadScriptText(Class<?> clazz, String testName) throws Exception
      unloads a script previously supplied as a text String
      Parameters:
      clazz - the test class
      testName - the test name
      Throws:
      Exception - if the script text cannot be unloaded
    • findScript

      protected static String findScript(String dir, String name)
      Tries to find dir/name in the working directory. If not found, tries to add the ".btm", then ".txt" suffixes. If still not found, tries to find the above on the classpath
      Parameters:
      dir - The name of the directory
      name - The file name
      Returns:
      The fully qualified name of the file, or null if not found
    • findScript

      protected static String findScript(String dir, String... names)