org.jboss.byteman.contrib.bmunit
Class BMUnit

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

public class BMUnit
extends java.lang.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
static java.lang.String AGENT_HOST
          System property specifying the host to be used when starting the agent and when submitting rules to it.
static java.lang.String AGENT_INHIBIT
          System property which inhibits automatic loading of the agent.
static java.lang.String AGENT_PORT
          System property specifying the port to be used when starting the agent and when submitting rules to it.
static java.lang.String LOAD_DIRECTORY
          System property which identifies the directory from which to start searching for rule script.
static java.lang.String VERBOSE
          System property which enables tracing of bmunit activity
 
Constructor Summary
BMUnit()
           
 
Method Summary
protected static java.lang.String findScript(java.lang.String dir, java.lang.String... names)
           
protected static java.lang.String findScript(java.lang.String dir, java.lang.String name)
          Tries to find dir/name in the working directory.
static void loadScriptFile(java.lang.Class<?> clazz, java.lang.String dir)
          loads a script by calling loadScriptFile(clazz, null, dir)
static void loadScriptFile(java.lang.Class<?> clazz, java.lang.String testName, java.lang.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(java.lang.Class<?> clazz, java.lang.String testname, java.lang.String scriptText)
          loads a script supplied as a text String rather than via a file on disk
static void unloadScriptFile(java.lang.Class<?> clazz, java.lang.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(java.lang.Class<?> clazz, java.lang.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 Detail

LOAD_DIRECTORY

public static final java.lang.String LOAD_DIRECTORY
System property which identifies the directory from which to start searching for rule script. If unset the current working directory of the test is used.

See Also:
Constant Field Values

AGENT_PORT

public static final java.lang.String AGENT_PORT
System property specifying the port to be used when starting the agent and when submitting rules to it. You can normally just use the default port.

See Also:
Constant Field Values

AGENT_HOST

public static final java.lang.String AGENT_HOST
System property specifying the host to be used when starting the agent and when submitting rules to it. You can normally just use the default host.

See Also:
Constant Field Values

AGENT_INHIBIT

public static final java.lang.String AGENT_INHIBIT
System property which inhibits automatic loading of the agent. If you set this then you have to load the agent yourself using the Install API or ensure JUnit loads by forking a JVM and passing the necessary -javaagent options on the command line. You may also want to set this if you you have loaded the agent into a remote service in another JVM driven by your unit test.

See Also:
Constant Field Values

VERBOSE

public static final java.lang.String VERBOSE
System property which enables tracing of bmunit activity

See Also:
Constant Field Values
Constructor Detail

BMUnit

public BMUnit()
Method Detail

loadScriptFile

public static void loadScriptFile(java.lang.Class<?> clazz,
                                  java.lang.String dir)
                           throws java.lang.Exception
loads a script by calling loadScriptFile(clazz, null, dir)

Parameters:
clazz - the test class
dir - the directory to load the script from
Throws:
java.lang.Exception

loadScriptFile

public static void loadScriptFile(java.lang.Class<?> clazz,
                                  java.lang.String testName,
                                  java.lang.String dir)
                           throws java.lang.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:
java.lang.Exception

unloadScriptFile

public static void unloadScriptFile(java.lang.Class<?> clazz,
                                    java.lang.String testName)
                             throws java.lang.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:
java.lang.Exception

loadScriptText

public static void loadScriptText(java.lang.Class<?> clazz,
                                  java.lang.String testname,
                                  java.lang.String scriptText)
                           throws java.lang.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:
java.lang.Exception

unloadScriptText

public static void unloadScriptText(java.lang.Class<?> clazz,
                                    java.lang.String testName)
                             throws java.lang.Exception
unloads a script previously supplied as a text String

Parameters:
clazz - the test class
testName - the test name
scriptText - the text of the rule or rules contained in the script
Throws:
java.lang.Exception

findScript

protected static java.lang.String findScript(java.lang.String dir,
                                             java.lang.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 java.lang.String findScript(java.lang.String dir,
                                             java.lang.String... names)


Copyright © 2012. All Rights Reserved.