Package net.officefloor.frame.test
Class ConstructTestSupport
- java.lang.Object
-
- net.officefloor.frame.test.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 anOffice
TestSupport
.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description ConstructTestSupport()
Default constructor forTestSupport
.ConstructTestSupport(ThreadedTestSupport threadedTestSupport, LogTestSupport logTestSupport)
Instantiate with required dependencies.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOfficeFloorEnhancer(java.util.function.Consumer<OfficeFloorBuilder> enhancer)
Adds anOfficeFloor
enhancer.void
adjustCurrentTimeMillis(long timeInMilliseconds)
Move current time forward the input number of milliseconds.void
afterEach()
Undertakes the afterEach functionality.void
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
void
assertThreadUsed(java.lang.Thread thread)
Ensures theThread
is used.void
beforeEach()
Undertakes the beforeEach functionality.void
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
DependencyMappingBuilder
bindManagedObject(java.lang.String bindName, ManagedObjectScope managedObjectScope, ManagedFunctionBuilder<?,?> managedFunctionBuilder)
Builds theManagedObject
for use at the desiredManagedObjectScope
.ReflectiveFunctionBuilder
constructFunction(java.lang.Object object, java.lang.String methodName)
Constructs theReflectiveFunctionBuilder
.<O extends java.lang.Enum<O>,F extends java.lang.Enum<F>>
ManagedFunctionBuilder<O,F>constructFunction(java.lang.String functionName, ManagedFunction<O,F> function)
Facade method to register aManagedFunction
.<O extends java.lang.Enum<O>,F extends java.lang.Enum<F>>
ManagedFunctionBuilder<O,F>constructFunction(java.lang.String functionName, ManagedFunctionFactory<O,F> functionFactory)
Facade method to register aManagedFunction
.ReflectiveGovernanceBuilder
constructGovernance(java.lang.Object object, java.lang.String governanceName)
Constructs theGovernance
.ManagedObjectBuilder<?>
constructManagedObject(java.lang.Object object, java.lang.String managedObjectName, java.lang.String managingOffice)
Facade method to register aManagedObject
.<D extends java.lang.Enum<D>,F extends java.lang.Enum<F>,MS extends ManagedObjectSource<D,F>>
ManagedObjectBuilder<F>constructManagedObject(java.lang.String managedObjectName, java.lang.Class<MS> managedObjectSourceClass, java.lang.String managingOffice)
Facade method to register aManagedObject
.<D extends java.lang.Enum<D>,F extends java.lang.Enum<F>,MS extends ManagedObjectSource<D,F>>
ManagedObjectBuilder<F>constructManagedObject(java.lang.String managedObjectName, MS managedObjectSource, java.lang.String managingOffice)
Facade method to register aManagedObject
.OfficeFloor
constructOfficeFloor()
Facade method to create theOfficeFloor
.ReflectiveFunctionBuilder
constructStaticFunction(java.lang.Class<?> clazz, java.lang.String methodName)
Constructs theReflectiveFunctionBuilder
for a staticMethod
.<TS extends TeamSource>
TeamBuilder<?>constructTeam(java.lang.String teamName, java.lang.Class<TS> teamSourceClass)
Facade method to create aTeam
.TeamBuilder<?>
constructTeam(java.lang.String teamName, Team team)
Facade method to create aTeam
.long
currentTimeMillis()
Obtains the approximate current time.OfficeBuilder
getOfficeBuilder()
Obtains theOfficeBuilder
.OfficeFloorBuilder
getOfficeFloorBuilder()
Obtains theOfficeFloorBuilder
.java.lang.String
getOfficeFloorName()
Obtains the name of theOfficeFloor
currently being constructed.java.lang.String
getOfficeName()
Obtains the name of theOffice
currently being constructed.void
handleEscalation(java.lang.Throwable escalation)
Handles anEscalation
from anOffice
.void
init(org.junit.jupiter.api.extension.ExtensionContext context)
Intialise.OfficeFloor
invokeFunction(java.lang.String functionName, java.lang.Object parameter)
Facade method to invokeManagedFunction
of anOffice
.OfficeFloor
invokeFunction(java.lang.String functionName, java.lang.Object parameter, int secondsToRun)
Facade method to invokeManagedFunction
of anOffice
.void
invokeFunctionAndValidate(java.lang.String functionName, java.lang.Object parameter, java.lang.String... expectedFunctions)
Facade method to invoke theManagedFunction
of anOffice
and validate theManagedFunction
instances invoked.void
recordReflectiveFunctionMethodInvoked(java.lang.String methodName)
Invoked by theReflectiveFunctionBuilder
when it executes the method.void
setRecordReflectiveFunctionMethodsInvoked(boolean isRecord)
Specifies whether to record the invocations of theReflectiveFunctionBuilder
instances.Office
triggerFunction(java.lang.String functionName, java.lang.Object parameter, FlowCallback callback)
Triggers theManagedFunction
but does not wait for its completion.void
validateNoTopLevelEscalation()
Validates that no top level escalation occurred.void
validateReflectiveMethodOrder(java.lang.String... methodNames)
Validates the order theReflectiveFunctionBuilder
invoked the methods.
-
-
-
Constructor Detail
-
ConstructTestSupport
public ConstructTestSupport(ThreadedTestSupport threadedTestSupport, LogTestSupport logTestSupport)
Instantiate with required dependencies.- Parameters:
threadedTestSupport
-ThreadedTestSupport
.logTestSupport
-LogTestSupport
.
-
ConstructTestSupport
public ConstructTestSupport()
Default constructor forTestSupport
.
-
-
Method Detail
-
addOfficeFloorEnhancer
public void addOfficeFloorEnhancer(java.util.function.Consumer<OfficeFloorBuilder> enhancer)
Adds anOfficeFloor
enhancer.- Parameters:
enhancer
-OfficeFloor
enhancer.
-
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 interfaceTestSupport
- 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 interfaceorg.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 interfaceorg.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 interfaceMonitorClock
- 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.
-
handleEscalation
public void handleEscalation(java.lang.Throwable escalation) throws java.lang.Throwable
Description copied from interface:EscalationHandler
Handles anEscalation
from anOffice
.- Specified by:
handleEscalation
in interfaceEscalationHandler
- Parameters:
escalation
-Escalation
.- Throws:
java.lang.Throwable
- Should failure in handlingEscalation
.
-
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 levelEscalation
.
-
getOfficeFloorBuilder
public OfficeFloorBuilder getOfficeFloorBuilder()
Obtains theOfficeFloorBuilder
.- Returns:
OfficeFloorBuilder
.
-
getOfficeBuilder
public OfficeBuilder getOfficeBuilder()
Obtains theOfficeBuilder
.- Returns:
OfficeBuilder
.
-
getOfficeFloorName
public java.lang.String getOfficeFloorName()
Obtains the name of theOfficeFloor
currently being constructed.- Returns:
- Name of the
OfficeFloor
currently being constructed.
-
getOfficeName
public java.lang.String getOfficeName()
Obtains the name of theOffice
currently being constructed.- Returns:
- Name of the
Office
currently being constructed.
-
constructFunction
public ReflectiveFunctionBuilder constructFunction(java.lang.Object object, java.lang.String methodName)
Constructs theReflectiveFunctionBuilder
.- Parameters:
object
-Object
containing theMethod
.methodName
- Name of theMethod
.- Returns:
ReflectiveFunctionBuilder
.
-
constructStaticFunction
public ReflectiveFunctionBuilder constructStaticFunction(java.lang.Class<?> clazz, java.lang.String methodName)
Constructs theReflectiveFunctionBuilder
for a staticMethod
.- Parameters:
clazz
-Class
containing the staticMethod
.methodName
- Name of theMethod
.- Returns:
ReflectiveFunctionBuilder
.
-
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 getOutOfMemoryError
issues should everyManagedFunction
executed be recorded.By default this is
false
to not record.- Parameters:
isRecord
-true
to record theManagedFunction
instances invoked.
-
recordReflectiveFunctionMethodInvoked
public void recordReflectiveFunctionMethodInvoked(java.lang.String methodName)
Invoked by theReflectiveFunctionBuilder
when it executes the method.- Parameters:
methodName
- Name of method being invoked.
-
validateReflectiveMethodOrder
public void validateReflectiveMethodOrder(java.lang.String... methodNames)
Validates the order theReflectiveFunctionBuilder
invoked the methods.- Parameters:
methodNames
- Order that the reflective methods should be invoked.- See Also:
setRecordReflectiveFunctionMethodsInvoked(boolean)
-
assertThreadUsed
public void assertThreadUsed(java.lang.Thread thread)
Ensures theThread
is used.- Parameters:
thread
-Thread
.
-
constructFunction
public <O extends java.lang.Enum<O>,F extends java.lang.Enum<F>> ManagedFunctionBuilder<O,F> constructFunction(java.lang.String functionName, ManagedFunctionFactory<O,F> functionFactory)
Facade method to register aManagedFunction
.- Type Parameters:
O
- Dependency key type.F
- Flow key type.- Parameters:
functionName
- Name of theManagedFunction
.functionFactory
-ManagedFunctionFactory
.- Returns:
ManagedFunctionBuilder
for theManagedFunction
.
-
constructFunction
public <O extends java.lang.Enum<O>,F extends java.lang.Enum<F>> ManagedFunctionBuilder<O,F> constructFunction(java.lang.String functionName, ManagedFunction<O,F> function)
Facade method to register aManagedFunction
.- Type Parameters:
O
- Dependency key type.F
- Flow key type.- Parameters:
functionName
- Name of theManagedFunction
.function
-ManagedFunction
.- Returns:
ManagedFunctionBuilder
for theManagedFunction
.
-
constructManagedObject
public <D extends java.lang.Enum<D>,F extends java.lang.Enum<F>,MS extends ManagedObjectSource<D,F>> ManagedObjectBuilder<F> constructManagedObject(java.lang.String managedObjectName, java.lang.Class<MS> managedObjectSourceClass, java.lang.String managingOffice)
Facade method to register aManagedObject
.- Type Parameters:
D
- Dependency key type.F
- Flow key type.MS
-ManagedObjectSource
type.- Parameters:
managedObjectName
- Name of theManagedObject
.managedObjectSourceClass
-ManagedObjectSource
Class
.managingOffice
- Name of the managingOffice
. May benull
to manually register forManagingOfficeBuilder
.- Returns:
ManagedObjectBuilder
.
-
constructManagedObject
public <D extends java.lang.Enum<D>,F extends java.lang.Enum<F>,MS extends ManagedObjectSource<D,F>> ManagedObjectBuilder<F> constructManagedObject(java.lang.String managedObjectName, MS managedObjectSource, java.lang.String managingOffice)
Facade method to register aManagedObject
.- Type Parameters:
D
- Dependency key type.F
- Flow key type.MS
-ManagedObjectSource
type.- Parameters:
managedObjectName
- Name of theManagedObject
.managedObjectSource
-ManagedObjectSource
instance.managingOffice
- Name of the managingOffice
. May benull
to manually register forManagingOfficeBuilder
.- Returns:
ManagedObjectBuilder
.
-
constructManagedObject
public ManagedObjectBuilder<?> constructManagedObject(java.lang.Object object, java.lang.String managedObjectName, java.lang.String managingOffice)
Facade method to register aManagedObject
.- Parameters:
object
- Object for theManagedObject
.managedObjectName
- Name of theManagedObject
.managingOffice
- Name of the mananagingOffice
. May benull
to manually register forManagingOfficeBuilder
.- Returns:
ManagedObjectBuilder
.
-
bindManagedObject
public DependencyMappingBuilder bindManagedObject(java.lang.String bindName, ManagedObjectScope managedObjectScope, ManagedFunctionBuilder<?,?> managedFunctionBuilder)
Builds theManagedObject
for use at the desiredManagedObjectScope
.- Parameters:
bindName
- Name to bind theManagedObject
under.managedObjectScope
-ManagedObjectScope
for theManagedObject
.managedFunctionBuilder
-ManagedFunctionBuilder
if binding toManagedObjectScope.FUNCTION
.- Returns:
DependencyMappingBuilder
for the boundManagedObject
.
-
constructGovernance
public ReflectiveGovernanceBuilder constructGovernance(java.lang.Object object, java.lang.String governanceName)
Constructs theGovernance
.- Parameters:
object
-Object
containing theMethod
instances used forGovernance
.governanceName
- Name of theGovernance
.- Returns:
ReflectiveGovernanceBuilder
.
-
constructTeam
public TeamBuilder<?> constructTeam(java.lang.String teamName, Team team)
Facade method to create aTeam
.- Parameters:
teamName
- Name of theTeam
.team
-Team
.- Returns:
TeamBuilder
.
-
constructTeam
public <TS extends TeamSource> TeamBuilder<?> constructTeam(java.lang.String teamName, java.lang.Class<TS> teamSourceClass)
Facade method to create aTeam
.- Type Parameters:
TS
-TeamSource
type.- Parameters:
teamName
- Name of theTeam
.teamSourceClass
-TeamSource
class.- Returns:
TeamBuilder
.
-
constructOfficeFloor
public OfficeFloor constructOfficeFloor() throws java.lang.Exception
Facade method to create theOfficeFloor
.- Returns:
OfficeFloor
.- Throws:
java.lang.Exception
- If fails to construct theOfficeFloor
.
-
triggerFunction
public Office triggerFunction(java.lang.String functionName, java.lang.Object parameter, FlowCallback callback) throws java.lang.Exception
Triggers theManagedFunction
but does not wait for its completion.- Parameters:
functionName
- Name of theManagedFunction
.parameter
- Parameter for theManagedFunction
.callback
-FlowCallback
. May benull
.- Returns:
Office
containing theManagedFunction
.- Throws:
java.lang.Exception
- If fails to trigger theManagedFunction
.
-
invokeFunction
public OfficeFloor invokeFunction(java.lang.String functionName, java.lang.Object parameter) throws java.lang.Exception
Facade method to invokeManagedFunction
of anOffice
. It will create theOfficeFloor
if necessary and times out after 3 seconds if invokedManagedFunction
is not complete.- Parameters:
functionName
- Name of theManagedFunction
to invoke.parameter
- Parameter.- Returns:
OfficeFloor
.- Throws:
java.lang.Exception
- If fails to constructOffice
orManagedFunction
invocation failure.
-
invokeFunctionAndValidate
public void invokeFunctionAndValidate(java.lang.String functionName, java.lang.Object parameter, java.lang.String... expectedFunctions) throws java.lang.Exception
Facade method to invoke theManagedFunction
of anOffice
and validate theManagedFunction
instances invoked.- Parameters:
functionName
- Name of theManagedFunction
to invoke.parameter
- Parameter.expectedFunctions
- Names of the expectedManagedFunction
instances to be invoked in the order specified.- Throws:
java.lang.Exception
- If fails to constructOffice
orManagedFunction
invocation failure.
-
invokeFunction
public OfficeFloor invokeFunction(java.lang.String functionName, java.lang.Object parameter, int secondsToRun) throws java.lang.Exception
- Parameters:
functionName
- Name of theManagedFunction
to invoke.parameter
- Parameter.secondsToRun
- Seconds to run.- Returns:
OfficeFloor
.- Throws:
java.lang.Exception
- If fails to constructOffice
orManagedFunction
invocation failure.
-
-