Environment configuration methods for the test framework

The framework provides methods to configure the testing environment and return information about it.

Method: assert...

The framework provides static methods that assert whether a particular condition exists. Each method's name begins with the prefix assert followed by the condition tested, as in assertEquals and assertNotZero.

The framework supports all the methods defined by the Assert class in the Java JUnit unit testing framework. The Assert class provides commonly used methods like assertEquals, assertTrue, and assertFalse. For a complete list of supported methods, refer to the JUnit Assert class documentation.

In addition, the framework extends the Assert class methods with methods applicable to testing InsuranceSuite configuration code. Example methods include assertBigDecimalEquals and assertDateEquals. The framework assert methods are defined in the PLAssertions class, which is included in the gw.testharness.v3 package.

The following table groups the methods in the PLAssertions class into general categories. For complete details, refer to the PLAssertions class documentation.

Category Methods
BigDecimal assertBigDecimalEquals, assertBigDecimalNotEquals, assertBigDecimalIsZero, assertBigDecimalIsNotZero
Collection assertEmpty, assertSize, assertCollectionContains, assertCollectionDoesNotContain, CollectionEquals, CollectionSame
Equals assertEquals, assertEqualsIgnoreCase, assertEqualsIgnoreLineEnding, assertEqualsIgnoreWhiteSpace, assertEqualsReplaceAll, assertEqualsUnordered, assertComparesEqual
General purpose assertDateEquals, assertFalseFor, assertTrueWithin, assertGreaterThan, assertZero, assertNotZero
Hashtable assertHashtableContains, assertHashtableContainsKey
Helper assertCollection, assertList, assertSet, assertThat
Iterator assertIteratorEquals, assertIteratorSame
List assertListEquals, assertListSame, findObjectInListUsingComparator
Miscellaneous assertAssignable, assertExceptionThrown, assertExceptionThrownWithMessage
Object assertArrayContains, assertArrayDoesNotContain, assertLength

Method: registerPlugin

registerPlugin<T extends InternalPlugin>(pluginInterface : Class<T>, implementation : T) : void

Call the registerPlugin method to register a replacement plugin implementation to use during the class's testing operations. The method is available only in test classes that extend PCServerTestClassBase.

The pluginInterface argument specifies the plugin to be replaced. The implementation argument references the plugin implementation instance to use during the testing operations.

The original plugin implementation is restored at the completion of the class's tests by the base class implementation of the afterClass method.

class MySampleTest extends PCServerTestClassBase {

  // ... Constructors, other methods, and so on.

  // *** Replacement plugin implementation for testing operations
  class MyReplacementPlugin implements IGenericPlugin {

    // ... Constructors, overrides of plugin methods, and so on.
  }

  // *** Function to test my configuration code
  // The replaced plugin is subsequently restored automatically by the afterClass() method
  function testMyConfigCode() {

    registerPlugin(IGenericPlugin, new MyReplacementPlugin())    // Register replacement plugin for testing operations

    // ... Perform tests here.
  }

  // *** Another test function
  // At the function's completion, restore the original plugin; don't wait until afterClass()
  function testMyConfigCode02() {
    var savedPlugin : IGenericPlugin

    savedPlugin = Plugins.get(IGenericPlugin.class)              // Save original plugin implementation
    registerPlugin(IGenericPlugin, new MyReplacementPlugin())    // Register replacement plugin

    // ... Perform tests here.

    registerPlugin(IGenericPlugin, savedPlugin)                  // Restore original plugin
  }
}

Method: setUpMutableSystemClock

setUpMutableSystemClock() : void

The setUpMutableSystemClock method establishes a temporary system clock available for testing purposes. Test code can adjust the time of the temporary clock without affecting the actual system clock. The method is available only in test classes that extend PCServerTestClassBase.

Call the setUpMutableSystemClock method in the test class's beforeClass method. The temporary clock is initialized to the current system day and time. The original system clock is automatically restored by the base class implementation's afterClass method.

The ChangesCurrentTimeUtil class provides static methods to set and advance the temporary clock. In general, time is advanced to the future. Reversing time to the past can result in unexpected application behavior and is strongly discouraged.

setCurrentTime(test : TestCase, timeInMillis : long) : void
incCurrentTime(test : TestCase, deltaInMillis : long) : void

The setCurrentTime method sets the temporary system clock to a specified time. The incCurrentTime method increments the clock by a specified number of milliseconds.

The test argument references the test class. The timeInMillis argument specifies the time in milliseconds to assign to the clock. The deltaInMillis argument specifies the number of milliseconds to advance the clock.

// Set the temporary system clock to a future date
ChangesCurrentTimeUtil.setCurrentTime(this, mySampleCalendar.getSampleEventDateTime())

// Advance the clock by one day
var ONE_DAY_IN_MILLISECONDS = 1000L*60L*60L*24L
ChangesCurrentTimeUtil.incCurrentTime(this, ONE_DAY_IN_MILLISECONDS)

Property: TestResultsDir

TestResultsDir : File

The TestResultsDir property is a read-only property. This java.io.File object references the directory that stores the test results.