org.sape.carbon.services.devtools.junit.launcher
Class TestLauncher

java.lang.Object
  |
  +--org.sape.carbon.services.devtools.junit.launcher.TestLauncher
All Implemented Interfaces:
ActionListener, EventListener, Runnable

public class TestLauncher
extends Object
implements ActionListener, Runnable

Swing Application that will display all Carbon tests to the user and allow the user to turn off selected tests or groups of tests that meet a criteria.

Test grouping is handled through a properties file located in the same directory called "launcher.properties".

Copyright 2003 Sapient

Since:
carbon 2.1
Version:
$Revision: 1.1 $($Author: jdreed $ / $Date: 2003/08/13 02:36:11 $)
Author:
Jordan Reed, August 2003

Nested Class Summary
protected  class TestLauncher.WindowCloser
          Closes the window.
 
Field Summary
private static String ACTION_CHECK_ALL
          Action command indicating the user wishes to check all tests.
private static String ACTION_DONE
          Action command when the user is finished selecting tests.
private static String ACTION_REMOVE_DEPEND
          Action command indicating the user has select to remove one of the dependencies.
protected  JFrame applicationFrame
          The main frame shown to the user.
private static String CARBON_LOGO_LOCATION
          Location of the Carbon logo for the frame icon.
protected  Map checkBoxToClassNameMap
          Map of JCheckBox objects to the String of the Test Class Name they represent.
protected  Map classNameToCheckBoxMap
          Map of Test Class Names to JCheckBoxs that represent them.
private static String DEPEND_PREFIX
          Prefix for depend strings in the properties file.
protected  Map dependButtonMap
          Map of JButtons to the String name of dependencies.
protected  Map dependMap
          Map of Strings containing the name of dependencies to a List of Strings containing the name of the class prefixes that have that dependency.
private static Insets emptyInset
          Cached empty inset to avoid recreation.
private static String EXCLUDE_PREFIX
          Prefix for excluded tests in the properties file.
protected  Set excludedClassNames
          Set of prefixes for classes that should be excluded from testing.
protected  Set inputClassNames
          Set of all test classes found in the system.
private static String JUNIT_LOGO_LOCATION
          Location of the jUnit logo for the pretty button.
private static String PACKAGE_LOCATION
          Base location of this package to load the various resources from.
private static String PROPERTY_FILE_LOCATION
          Location of the 'launcher.properties' file that holds configuration data.
private static String REMOVE_ICON_LOCATION
          Location of the remove icon for the pretty button.
protected  JCheckBox selectAllCheckbox
          The selectAllCheckbox.
static Set selectedClasses
          Static Set of Strings holding the names of the TestClasses the user wishes to execute.
protected  Toolkit toolkit
          Holds the awt toolkit for the system.
private static Insets widthInset
          Cached inset to avoid recreation.
private static Object WINDOW_NOTIFIER
          Used for simple thread concurrency.
 
Constructor Summary
TestLauncher()
          Default constructor initializes all the internal structures.
 
Method Summary
 void actionPerformed(ActionEvent evt)
          Listens for actions events on the various buttons.
protected  void addAllTests()
          Adds all the tests under the "org.sape.carbon" package into the list of tests and then removes the performance classes and excluded classes.
protected  void addDepend(String dependName, String className)
          Adds a class name to the list of classes that match a dependency.
protected  void addExcludedClass(String excludedClassName)
          Adds a single class name to the list of classes to exclude from showing the user.
protected  void addHeaderRows(JPanel testHarnessPanel, GridBagLayout gridBagLayout)
          Add header rows at the top of the testHarnessPanel.
protected  void addRow(JPanel testHarnessPanel, GridBagLayout gridBagLayout, String className)
          Add checkbox rows to testHarnessPanel.
protected  void adjustFrameSize()
          If there are too many test classes the Frame will run off the bottom of the screen.
protected  void closeAndReturn()
          Populates the selectedClasses field based on the checkboxes, closes the frame, and calls notifyAll on the WINDOW_NOTIFIER.
protected  JPanel createButtonPanel()
          Creates the panel of buttons across the top of the display that the user can use to execute jUnit or turn-off dependency groups.
protected  JPanel createTestHarnessPanel()
          Creates the panel listing all of the located tests with checkboxes next to each to turn it on or off.
 void getUserInput()
          This is the main method to build the frame and show it to the user.
protected  void loadPropertiesFile()
          Loads and parses the properties file from the classpath.
static void main(String[] args)
          Executes the main program.
 void run()
          Allows this class to be run as a thread.
 void runAsThread()
          Runs the input in it's own thread and will return once the user has finished selecting and closed the window.
protected  void setAllCheckboxes(boolean checkboxState)
          Cycles through all the checkboxes and sets the state.
protected  void setDependsCheckboxes(String dependName, boolean checkboxState)
          Sets all the checkboxes under a given depends key.
 void setInputClassNames(Set inputClassNames)
          Sets the name of the classes to display to the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

selectedClasses

public static Set selectedClasses
Static Set of Strings holding the names of the TestClasses the user wishes to execute. After the main window is complete this object can be queried by the jUnit framework from inside the same JVM.


WINDOW_NOTIFIER

private static final Object WINDOW_NOTIFIER
Used for simple thread concurrency. The main window will call notify() on this when the user has finished processing.


emptyInset

private static final Insets emptyInset
Cached empty inset to avoid recreation.


widthInset

private static final Insets widthInset
Cached inset to avoid recreation.


PACKAGE_LOCATION

private static final String PACKAGE_LOCATION
Base location of this package to load the various resources from.

See Also:
Constant Field Values

PROPERTY_FILE_LOCATION

private static final String PROPERTY_FILE_LOCATION
Location of the 'launcher.properties' file that holds configuration data.

See Also:
Constant Field Values

JUNIT_LOGO_LOCATION

private static final String JUNIT_LOGO_LOCATION
Location of the jUnit logo for the pretty button.

See Also:
Constant Field Values

REMOVE_ICON_LOCATION

private static final String REMOVE_ICON_LOCATION
Location of the remove icon for the pretty button.

See Also:
Constant Field Values

CARBON_LOGO_LOCATION

private static final String CARBON_LOGO_LOCATION
Location of the Carbon logo for the frame icon.

See Also:
Constant Field Values

EXCLUDE_PREFIX

private static final String EXCLUDE_PREFIX
Prefix for excluded tests in the properties file.

See Also:
Constant Field Values

DEPEND_PREFIX

private static final String DEPEND_PREFIX
Prefix for depend strings in the properties file.

See Also:
Constant Field Values

ACTION_DONE

private static final String ACTION_DONE
Action command when the user is finished selecting tests.

See Also:
Constant Field Values

ACTION_CHECK_ALL

private static final String ACTION_CHECK_ALL
Action command indicating the user wishes to check all tests.

See Also:
Constant Field Values

ACTION_REMOVE_DEPEND

private static final String ACTION_REMOVE_DEPEND
Action command indicating the user has select to remove one of the dependencies.

See Also:
Constant Field Values

toolkit

protected Toolkit toolkit
Holds the awt toolkit for the system.


applicationFrame

protected JFrame applicationFrame
The main frame shown to the user.


selectAllCheckbox

protected JCheckBox selectAllCheckbox
The selectAllCheckbox. This is stored so it can be constantly kept checked.


checkBoxToClassNameMap

protected Map checkBoxToClassNameMap
Map of JCheckBox objects to the String of the Test Class Name they represent.


classNameToCheckBoxMap

protected Map classNameToCheckBoxMap
Map of Test Class Names to JCheckBoxs that represent them.


inputClassNames

protected Set inputClassNames
Set of all test classes found in the system.


excludedClassNames

protected Set excludedClassNames
Set of prefixes for classes that should be excluded from testing.


dependMap

protected Map dependMap
Map of Strings containing the name of dependencies to a List of Strings containing the name of the class prefixes that have that dependency.


dependButtonMap

protected Map dependButtonMap
Map of JButtons to the String name of dependencies. This is used to determine which dependcy button the user has clicked on.

Constructor Detail

TestLauncher

public TestLauncher()
Default constructor initializes all the internal structures.

Method Detail

main

public static void main(String[] args)
Executes the main program.

Parameters:
args - ignored

loadPropertiesFile

protected void loadPropertiesFile()
Loads and parses the properties file from the classpath.

After execution the excludedClassNames and dependMap objects will be initialzed.


addExcludedClass

protected void addExcludedClass(String excludedClassName)
Adds a single class name to the list of classes to exclude from showing the user.

Parameters:
excludedClassName - class name to exclude

addDepend

protected void addDepend(String dependName,
                         String className)
Adds a class name to the list of classes that match a dependency.

Parameters:
dependName - the name of the dependency to add the class to
className - the name of the class to add

addAllTests

protected void addAllTests()
Adds all the tests under the "org.sape.carbon" package into the list of tests and then removes the performance classes and excluded classes.


setInputClassNames

public void setInputClassNames(Set inputClassNames)
Sets the name of the classes to display to the user. This makes a defensive copy of the Set passed in.

Parameters:
inputClassNames - A set of Strings representing the classes to show to the user

run

public void run()
Allows this class to be run as a thread.

Specified by:
run in interface Runnable

runAsThread

public void runAsThread()
Runs the input in it's own thread and will return once the user has finished selecting and closed the window.


getUserInput

public void getUserInput()
This is the main method to build the frame and show it to the user. The method will exit the moment the frame is up and displayed. If you wish to have your thread pause until the user selects input call the runAsThread method instead.


adjustFrameSize

protected void adjustFrameSize()
If there are too many test classes the Frame will run off the bottom of the screen. This will adjust the window size to be more reasonable if needed.


createButtonPanel

protected JPanel createButtonPanel()
Creates the panel of buttons across the top of the display that the user can use to execute jUnit or turn-off dependency groups.

Returns:
the button panel

createTestHarnessPanel

protected JPanel createTestHarnessPanel()
Creates the panel listing all of the located tests with checkboxes next to each to turn it on or off.

Returns:
the test harness panel

addHeaderRows

protected void addHeaderRows(JPanel testHarnessPanel,
                             GridBagLayout gridBagLayout)
Add header rows at the top of the testHarnessPanel.

The only header row is a checkbox that will activate all other checkboxes in the panel.

Parameters:
testHarnessPanel - the panel to add the row to
gridBagLayout - the layout manager

addRow

protected void addRow(JPanel testHarnessPanel,
                      GridBagLayout gridBagLayout,
                      String className)
Add checkbox rows to testHarnessPanel.

Parameters:
testHarnessPanel - the panel to add the row to
gridBagLayout - the layout manager
className - the name of the class to add a checkbox for

setAllCheckboxes

protected void setAllCheckboxes(boolean checkboxState)
Cycles through all the checkboxes and sets the state.

Parameters:
checkboxState - the state to set all checkboxes to

setDependsCheckboxes

protected void setDependsCheckboxes(String dependName,
                                    boolean checkboxState)
Sets all the checkboxes under a given depends key.

Parameters:
dependName - the name of the depend checkboxes to set.
checkboxState - the state of the checkboxes to set

closeAndReturn

protected void closeAndReturn()
Populates the selectedClasses field based on the checkboxes, closes the frame, and calls notifyAll on the WINDOW_NOTIFIER.


actionPerformed

public void actionPerformed(ActionEvent evt)
Listens for actions events on the various buttons.

Specified by:
actionPerformed in interface ActionListener
Parameters:
evt - the event being performed.


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.