Class ConstructTestSupport

  • All Implemented Interfaces:
    EscalationHandler, MonitorClock, TestSupport, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

    public class ConstructTestSupport
    extends java.lang.Object
    implements TestSupport, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, EscalationHandler, MonitorClock
    Construction testing of an Office TestSupport.
    Author:
    Daniel Sagenschneider
    • Method Detail

      • init

        public void init​(org.junit.jupiter.api.extension.ExtensionContext context)
                  throws java.lang.Exception
        Description copied from interface: TestSupport
        Intialise.
        Specified by:
        init in interface TestSupport
        Parameters:
        context - ExtensionContext.
        Throws:
        java.lang.Exception - If fails to init.
      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
                        throws java.lang.Exception
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
        Throws:
        java.lang.Exception
      • beforeEach

        public void beforeEach()
                        throws java.lang.Exception
        Undertakes the beforeEach functionality.
        Throws:
        java.lang.Exception - If fails.
      • afterEach

        public void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)
                       throws java.lang.Exception
        Specified by:
        afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
        Throws:
        java.lang.Exception
      • afterEach

        public void afterEach()
                       throws java.lang.Exception
        Undertakes the afterEach functionality.
        Throws:
        java.lang.Exception - If fails.
      • currentTimeMillis

        public long currentTimeMillis()
        Description copied from interface: MonitorClock

        Obtains the approximate current time.

        This is more efficient means to obtain System.currentTimeMillis() as complete millisecond accuracy is not required.

        Specified by:
        currentTimeMillis in interface MonitorClock
        Returns:
        Approximate System.currentTimeMillis().
      • adjustCurrentTimeMillis

        public void adjustCurrentTimeMillis​(long timeInMilliseconds)
        Move current time forward the input number of milliseconds.
        Parameters:
        timeInMilliseconds - Milliseconds to move current time forward.
      • validateNoTopLevelEscalation

        public void validateNoTopLevelEscalation()
                                          throws java.lang.Throwable

        Validates that no top level escalation occurred.

        This method will clear the escalation on exit.

        Throws:
        java.lang.Throwable - If top level Escalation.
      • getOfficeFloorName

        public java.lang.String getOfficeFloorName()
        Obtains the name of the OfficeFloor currently being constructed.
        Returns:
        Name of the OfficeFloor currently being constructed.
      • getOfficeName

        public java.lang.String getOfficeName()
        Obtains the name of the Office currently being constructed.
        Returns:
        Name of the Office currently being constructed.
      • setRecordReflectiveFunctionMethodsInvoked

        public void setRecordReflectiveFunctionMethodsInvoked​(boolean isRecord)

        Specifies whether to record the invocations of the ReflectiveFunctionBuilder instances.

        This is necessary as stress tests using the ReflectiveFunctionBuilder will get OutOfMemoryError issues should every ManagedFunction executed be recorded.

        By default this is false to not record.

        Parameters:
        isRecord - true to record the ManagedFunction instances invoked.
      • recordReflectiveFunctionMethodInvoked

        public void recordReflectiveFunctionMethodInvoked​(java.lang.String methodName)
        Invoked by the ReflectiveFunctionBuilder when it executes the method.
        Parameters:
        methodName - Name of method being invoked.
      • assertThreadUsed

        public void assertThreadUsed​(java.lang.Thread thread)
        Ensures the Thread is used.
        Parameters:
        thread - Thread.
      • constructTeam

        public TeamBuilder<?> constructTeam​(java.lang.String teamName,
                                            Team team)
        Facade method to create a Team.
        Parameters:
        teamName - Name of the Team.
        team - Team.
        Returns:
        TeamBuilder.
      • constructTeam

        public <TS extends TeamSourceTeamBuilder<?> constructTeam​(java.lang.String teamName,
                                                                    java.lang.Class<TS> teamSourceClass)
        Facade method to create a Team.
        Type Parameters:
        TS - TeamSource type.
        Parameters:
        teamName - Name of the Team.
        teamSourceClass - TeamSource class.
        Returns:
        TeamBuilder.
      • constructOfficeFloor

        public OfficeFloor constructOfficeFloor()
                                         throws java.lang.Exception
        Facade method to create the OfficeFloor.
        Returns:
        OfficeFloor.
        Throws:
        java.lang.Exception - If fails to construct the OfficeFloor.
      • invokeFunctionAndValidate

        public void invokeFunctionAndValidate​(java.lang.String functionName,
                                              java.lang.Object parameter,
                                              java.lang.String... expectedFunctions)
                                       throws java.lang.Exception
        Facade method to invoke the ManagedFunction of an Office and validate the ManagedFunction instances invoked.
        Parameters:
        functionName - Name of the ManagedFunction to invoke.
        parameter - Parameter.
        expectedFunctions - Names of the expected ManagedFunction instances to be invoked in the order specified.
        Throws:
        java.lang.Exception - If fails to construct Office or ManagedFunction invocation failure.
      • invokeFunction

        public OfficeFloor invokeFunction​(java.lang.String functionName,
                                          java.lang.Object parameter,
                                          int secondsToRun)
                                   throws java.lang.Exception
        Facade method to invoke ManagedFunction of an Office. It will create the OfficeFloor if necessary.
        Parameters:
        functionName - Name of the ManagedFunction to invoke.
        parameter - Parameter.
        secondsToRun - Seconds to run.
        Returns:
        OfficeFloor.
        Throws:
        java.lang.Exception - If fails to construct Office or ManagedFunction invocation failure.