Overview | Package | Class | Tree | Deprecated | Index | Help
| Hyperic HQ Plugin API v. 4.4.0.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.hyperic.util.unittest.server
Class BaseServerTestCase

    java.lang.Object
      junit.framework.Assert
          junit.framework.TestCase
              org.hyperic.util.unittest.server.BaseServerTestCase

All Implemented Interfaces:
  junit.framework.Test

    public abstract class BaseServerTestCase

extends junit.framework.TestCase

The test case that all server-side unit tests should extend. Before starting the server, the user must set the `hq.unittest.jboss.home` system property to the path where the jboss server that will be used for unit testing resides. That jboss instance must contain a "unittest" configuration created with the `unittest-prepare-jboss` Ant target. The datasource file (`hq-ds.xml`) in the "unittest" configuration must point to the *preexisting* unit testing server database.

In addition, the `hq.unittest.hq.home` system property must be set to the local path where the HQ src resides (.ORG or EE versions depending on the type of unit test). The `hq.unittest.working.dir` system property must be set to the directory where the database dump file containing the initial server state resides (by default in $HQ_HOME/unittest/data).

Finally (and most importantly), the system classloader must be set to the `IsolatingDefaultSystemClassLoader`.

Field Summary
`static java.lang.String` | `HQ_HOME_DIR` The system property specifying the path to the HQ home directory.
`static java.lang.String` | `JBOSS_HOME_DIR` The system property specifying the path to the jboss deployment that will be used for unit testing.
`static java.lang.String` | `JBOSS_UNIT_TEST_CONFIGURATION` The "unittest" configuration that the jboss deployment must have installed and prepared using the Ant "prepare-jboss" target.

Constructor Summary
`BaseServerTestCase(java.lang.String name, boolean restoreDatabase)` Creates an instance.

Method Summary
`protected void` | `deleteSchemaData(java.util.List filenames)` Used to delete data specified by the schema from the unit test database.
`protected void` | `deleteSchemaData(java.lang.String filename)` Used to delete data specified by the schema from the unit test database.
`protected LocalInterfaceRegistry` | `deployHQ()` Deploy the HQ application into the jboss server, starting the jboss server first if necessary.
`protected java.sql.Connection` | `getConnectionToHQDatabase()` Retrieve a connection to the unit test database.
`protected void` | `insertSchemaData(java.util.List filenames)` Used to insert new data into the unit test database.
`protected void` | `insertSchemaData(java.lang.String filename)` Used to insert new data into the unit test database.
`protected void` | `restoreDatabase()` Restore the unit test database to the original state specified by the `test-dbsetup` Ant target.
`void` | `setUp()` Creates the initial unit test database dump file if it doesn't exist already.
`protected void` | `startServer()` Start the jboss server with the "unittest" configuration.
`protected void` | `stopServer()` Stop the jboss server.
`void` | `tearDown()` Delegates to the super class.
`protected void` | `undeployHQ()` Undeploy the HQ or HQEE application from the jboss server.

Methods inherited from class junit.framework.TestCase
`countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString`

Methods inherited from class junit.framework.Assert
`assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### JBOSS_HOME_DIR

    public static final java.lang.String JBOSS_HOME_DIR

  The system property specifying the path to the jboss deployment that will be used for unit testing.

  See Also:
    Constant Field Values

### HQ_HOME_DIR

    public static final java.lang.String HQ_HOME_DIR

  The system property specifying the path to the HQ home directory. The HQ server will be deployed from the HQ home "build" subdirectory.

  See Also:
    Constant Field Values

### JBOSS_UNIT_TEST_CONFIGURATION

    public static final java.lang.String JBOSS_UNIT_TEST_CONFIGURATION

  The "unittest" configuration that the jboss deployment must have installed and prepared using the Ant "prepare-jboss" target.

  See Also:
    Constant Field Values

Constructor Detail

### BaseServerTestCase

    public BaseServerTestCase(java.lang.String name,
                              boolean restoreDatabase)

  Creates an instance.

  Parameters:
    `name` - The test case name.
    `restoreDatabase` - `true` to restore the database before the first unit test in this test case; `false` to not restore the database.
  See Also:
    `restoreDatabase()`

Method Detail

### setUp

    public void setUp()
               throws java.lang.Exception

  Creates the initial unit test database dump file if it doesn't exist already. Also restores the database once before the first unit test in this test case if the constructor parameter is set to `restoreDatabase`. Subclasses should never override this method, only extend it if necessary.

  Overrides:
    `setUp` in class `junit.framework.TestCase`
  Throws:
    `java.lang.Exception`

### tearDown

    public void tearDown()
                  throws java.lang.Exception

  Delegates to the super class.

  Overrides:
    `tearDown` in class `junit.framework.TestCase`
  Throws:
    `java.lang.Exception`
  See Also:
    `TestCase.tearDown()`

### getConnectionToHQDatabase

    protected final java.sql.Connection getConnectionToHQDatabase()
                                                           throws UnitTestDBException

  Retrieve a connection to the unit test database. This connection may be used to verify that a state change has occurred during the unit test.

  Returns:
    The database connection.
  Throws:
    `UnitTestDBException`

### restoreDatabase

    protected final void restoreDatabase()
                                  throws UnitTestDBException

  Restore the unit test database to the original state specified by the `test-dbsetup` Ant target.

  Throws:
    `UnitTestDBException`

### insertSchemaData

    protected final void insertSchemaData(java.lang.String filename)
                                   throws UnitTestDBException

  Used to insert new data into the unit test database. Will either update existing data or insert fresh.

  Parameters:
    `schema` - filename to extract XML data from.
  Throws:
    `UnitTestDBException`

### insertSchemaData

    protected final void insertSchemaData(java.util.List filenames)
                                   throws UnitTestDBException

  Used to insert new data into the unit test database. Will either update existing data or insert fresh.

  Parameters:
    `List` - of schema filenames to extract XML data from.
  Throws:
    `UnitTestDBException`

### deleteSchemaData

    protected final void deleteSchemaData(java.util.List filenames)
                                   throws UnitTestDBException

  Used to delete data specified by the schema from the unit test database.

  Parameters:
    `List` - of schema filenames to extract XML data from.
  Throws:
    `UnitTestDBException`

### deleteSchemaData

    protected final void deleteSchemaData(java.lang.String filename)
                                   throws UnitTestDBException

  Used to delete data specified by the schema from the unit test database.

  Parameters:
    `schema` - filename to extract XML data from.
  Throws:
    `UnitTestDBException`

### startServer

    protected final void startServer()
                              throws java.lang.Exception

  Start the jboss server with the "unittest" configuration.

  Throws:
    `java.lang.Exception`

### deployHQ

    protected final LocalInterfaceRegistry deployHQ()
                                             throws java.lang.Exception

  Deploy the HQ application into the jboss server, starting the jboss server first if necessary.

  Returns:
    The local interface registry for looking up local interfaces for the deployed EJBs.
  Throws:
    `java.lang.Exception`

### undeployHQ

    protected final void undeployHQ()
                             throws java.lang.Exception

  Undeploy the HQ or HQEE application from the jboss server.

  Throws:
    `java.lang.Exception`

### stopServer

    protected final void stopServer()

  Stop the jboss server. This facility is provided for completeness, but if back to back server restarts are performed then unit tests may fail because of server socket binding issues (the jboss server socket factories do not have SO_REUSEADDR set to true). In general, it should be left up to the framework to stop the server once it has been started. If a unit test does not explicitly stop the server, then a shutdown hook stops the server automatically before the unit tests finish executing within their forked vm. If the user must stop the server, then any future server restarts within the same unit test vm should be delayed until the jboss server sockets can move from a TIME_WAIT to CLOSED state.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Hyperic HQ Plugin API v. 4.4.0.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.