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 anOfficeTestSupport.- 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 voidaddOfficeFloorEnhancer(java.util.function.Consumer<OfficeFloorBuilder> enhancer)Adds anOfficeFloorenhancer.voidadjustCurrentTimeMillis(long timeInMilliseconds)Move current time forward the input number of milliseconds.voidafterEach()Undertakes the afterEach functionality.voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context)voidassertThreadUsed(java.lang.Thread thread)Ensures theThreadis used.voidbeforeEach()Undertakes the beforeEach functionality.voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context)DependencyMappingBuilderbindManagedObject(java.lang.String bindName, ManagedObjectScope managedObjectScope, ManagedFunctionBuilder<?,?> managedFunctionBuilder)Builds theManagedObjectfor use at the desiredManagedObjectScope.ReflectiveFunctionBuilderconstructFunction(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.ReflectiveGovernanceBuilderconstructGovernance(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.OfficeFloorconstructOfficeFloor()Facade method to create theOfficeFloor.ReflectiveFunctionBuilderconstructStaticFunction(java.lang.Class<?> clazz, java.lang.String methodName)Constructs theReflectiveFunctionBuilderfor 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.longcurrentTimeMillis()Obtains the approximate current time.OfficeBuildergetOfficeBuilder()Obtains theOfficeBuilder.OfficeFloorBuildergetOfficeFloorBuilder()Obtains theOfficeFloorBuilder.java.lang.StringgetOfficeFloorName()Obtains the name of theOfficeFloorcurrently being constructed.java.lang.StringgetOfficeName()Obtains the name of theOfficecurrently being constructed.voidhandleEscalation(java.lang.Throwable escalation)Handles anEscalationfrom anOffice.voidinit(org.junit.jupiter.api.extension.ExtensionContext context)Intialise.OfficeFloorinvokeFunction(java.lang.String functionName, java.lang.Object parameter)Facade method to invokeManagedFunctionof anOffice.OfficeFloorinvokeFunction(java.lang.String functionName, java.lang.Object parameter, int secondsToRun)Facade method to invokeManagedFunctionof anOffice.voidinvokeFunctionAndValidate(java.lang.String functionName, java.lang.Object parameter, java.lang.String... expectedFunctions)Facade method to invoke theManagedFunctionof anOfficeand validate theManagedFunctioninstances invoked.voidrecordReflectiveFunctionMethodInvoked(java.lang.String methodName)Invoked by theReflectiveFunctionBuilderwhen it executes the method.voidsetRecordReflectiveFunctionMethodsInvoked(boolean isRecord)Specifies whether to record the invocations of theReflectiveFunctionBuilderinstances.OfficetriggerFunction(java.lang.String functionName, java.lang.Object parameter, FlowCallback callback)Triggers theManagedFunctionbut does not wait for its completion.voidvalidateNoTopLevelEscalation()Validates that no top level escalation occurred.voidvalidateReflectiveMethodOrder(java.lang.String... methodNames)Validates the order theReflectiveFunctionBuilderinvoked 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 anOfficeFloorenhancer.- Parameters:
enhancer-OfficeFloorenhancer.
-
init
public void init(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.ExceptionDescription copied from interface:TestSupportIntialise.- Specified by:
initin 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:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
java.lang.Exception
-
beforeEach
public void beforeEach() throws java.lang.ExceptionUndertakes 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:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
java.lang.Exception
-
afterEach
public void afterEach() throws java.lang.ExceptionUndertakes the afterEach functionality.- Throws:
java.lang.Exception- If fails.
-
currentTimeMillis
public long currentTimeMillis()
Description copied from interface:MonitorClockObtains the approximate current time.
This is more efficient means to obtain
System.currentTimeMillis()as complete millisecond accuracy is not required.- Specified by:
currentTimeMillisin 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.ThrowableDescription copied from interface:EscalationHandlerHandles anEscalationfrom anOffice.- Specified by:
handleEscalationin interfaceEscalationHandler- Parameters:
escalation-Escalation.- Throws:
java.lang.Throwable- Should failure in handlingEscalation.
-
validateNoTopLevelEscalation
public void validateNoTopLevelEscalation() throws java.lang.ThrowableValidates 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 theOfficeFloorcurrently being constructed.- Returns:
- Name of the
OfficeFloorcurrently being constructed.
-
getOfficeName
public java.lang.String getOfficeName()
Obtains the name of theOfficecurrently being constructed.- Returns:
- Name of the
Officecurrently being constructed.
-
constructFunction
public ReflectiveFunctionBuilder constructFunction(java.lang.Object object, java.lang.String methodName)
Constructs theReflectiveFunctionBuilder.- Parameters:
object-Objectcontaining theMethod.methodName- Name of theMethod.- Returns:
ReflectiveFunctionBuilder.
-
constructStaticFunction
public ReflectiveFunctionBuilder constructStaticFunction(java.lang.Class<?> clazz, java.lang.String methodName)
Constructs theReflectiveFunctionBuilderfor a staticMethod.- Parameters:
clazz-Classcontaining the staticMethod.methodName- Name of theMethod.- Returns:
ReflectiveFunctionBuilder.
-
setRecordReflectiveFunctionMethodsInvoked
public void setRecordReflectiveFunctionMethodsInvoked(boolean isRecord)
Specifies whether to record the invocations of the
ReflectiveFunctionBuilderinstances.This is necessary as stress tests using the
ReflectiveFunctionBuilderwill getOutOfMemoryErrorissues should everyManagedFunctionexecuted be recorded.By default this is
falseto not record.- Parameters:
isRecord-trueto record theManagedFunctioninstances invoked.
-
recordReflectiveFunctionMethodInvoked
public void recordReflectiveFunctionMethodInvoked(java.lang.String methodName)
Invoked by theReflectiveFunctionBuilderwhen it executes the method.- Parameters:
methodName- Name of method being invoked.
-
validateReflectiveMethodOrder
public void validateReflectiveMethodOrder(java.lang.String... methodNames)
Validates the order theReflectiveFunctionBuilderinvoked 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 theThreadis 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:
ManagedFunctionBuilderfor 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:
ManagedFunctionBuilderfor 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-ManagedObjectSourcetype.- Parameters:
managedObjectName- Name of theManagedObject.managedObjectSourceClass-ManagedObjectSourceClass.managingOffice- Name of the managingOffice. May benullto 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-ManagedObjectSourcetype.- Parameters:
managedObjectName- Name of theManagedObject.managedObjectSource-ManagedObjectSourceinstance.managingOffice- Name of the managingOffice. May benullto 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 benullto manually register forManagingOfficeBuilder.- Returns:
ManagedObjectBuilder.
-
bindManagedObject
public DependencyMappingBuilder bindManagedObject(java.lang.String bindName, ManagedObjectScope managedObjectScope, ManagedFunctionBuilder<?,?> managedFunctionBuilder)
Builds theManagedObjectfor use at the desiredManagedObjectScope.- Parameters:
bindName- Name to bind theManagedObjectunder.managedObjectScope-ManagedObjectScopefor theManagedObject.managedFunctionBuilder-ManagedFunctionBuilderif binding toManagedObjectScope.FUNCTION.- Returns:
DependencyMappingBuilderfor the boundManagedObject.
-
constructGovernance
public ReflectiveGovernanceBuilder constructGovernance(java.lang.Object object, java.lang.String governanceName)
Constructs theGovernance.- Parameters:
object-Objectcontaining theMethodinstances 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-TeamSourcetype.- Parameters:
teamName- Name of theTeam.teamSourceClass-TeamSourceclass.- 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 theManagedFunctionbut does not wait for its completion.- Parameters:
functionName- Name of theManagedFunction.parameter- Parameter for theManagedFunction.callback-FlowCallback. May benull.- Returns:
Officecontaining 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 invokeManagedFunctionof anOffice. It will create theOfficeFloorif necessary and times out after 3 seconds if invokedManagedFunctionis not complete.- Parameters:
functionName- Name of theManagedFunctionto invoke.parameter- Parameter.- Returns:
OfficeFloor.- Throws:
java.lang.Exception- If fails to constructOfficeorManagedFunctioninvocation failure.
-
invokeFunctionAndValidate
public void invokeFunctionAndValidate(java.lang.String functionName, java.lang.Object parameter, java.lang.String... expectedFunctions) throws java.lang.ExceptionFacade method to invoke theManagedFunctionof anOfficeand validate theManagedFunctioninstances invoked.- Parameters:
functionName- Name of theManagedFunctionto invoke.parameter- Parameter.expectedFunctions- Names of the expectedManagedFunctioninstances to be invoked in the order specified.- Throws:
java.lang.Exception- If fails to constructOfficeorManagedFunctioninvocation failure.
-
invokeFunction
public OfficeFloor invokeFunction(java.lang.String functionName, java.lang.Object parameter, int secondsToRun) throws java.lang.Exception
- Parameters:
functionName- Name of theManagedFunctionto invoke.parameter- Parameter.secondsToRun- Seconds to run.- Returns:
OfficeFloor.- Throws:
java.lang.Exception- If fails to constructOfficeorManagedFunctioninvocation failure.
-
-