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 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
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor forTestSupport.ConstructTestSupport(ThreadedTestSupport threadedTestSupport, LogTestSupport logTestSupport) Instantiate with required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOfficeFloorEnhancer(Consumer<OfficeFloorBuilder> enhancer) Adds anOfficeFloorenhancer.voidadjustCurrentTimeMillis(long timeInMilliseconds) Move current time forward the input number of milliseconds.voidUndertakes the afterEach functionality.voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidassertThreadUsed(Thread thread) Ensures theThreadis used.voidUndertakes the beforeEach functionality.voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) bindManagedObject(String bindName, ManagedObjectScope managedObjectScope, ManagedFunctionBuilder<?, ?> managedFunctionBuilder) Builds theManagedObjectfor use at the desiredManagedObjectScope.constructFunction(Object object, String methodName) Constructs theReflectiveFunctionBuilder.<O extends Enum<O>,F extends Enum<F>>
ManagedFunctionBuilder<O,F> constructFunction(String functionName, ManagedFunction<O, F> function) Facade method to register aManagedFunction.<O extends Enum<O>,F extends Enum<F>>
ManagedFunctionBuilder<O,F> constructFunction(String functionName, ManagedFunctionFactory<O, F> functionFactory) Facade method to register aManagedFunction.constructGovernance(Object object, String governanceName) Constructs theGovernance.constructManagedObject(Object object, String managedObjectName, String managingOffice) Facade method to register aManagedObject.<D extends Enum<D>,F extends Enum<F>, MS extends ManagedObjectSource<D, F>>
ManagedObjectBuilder<F>constructManagedObject(String managedObjectName, Class<MS> managedObjectSourceClass, String managingOffice) Facade method to register aManagedObject.<D extends Enum<D>,F extends Enum<F>, MS extends ManagedObjectSource<D, F>>
ManagedObjectBuilder<F>constructManagedObject(String managedObjectName, MS managedObjectSource, String managingOffice) Facade method to register aManagedObject.Facade method to create theOfficeFloor.constructStaticFunction(Class<?> clazz, String methodName) Constructs theReflectiveFunctionBuilderfor a staticMethod.<TS extends TeamSource>
TeamBuilder<?>constructTeam(String teamName, Class<TS> teamSourceClass) Facade method to create aTeam.TeamBuilder<?>constructTeam(String teamName, Team team) Facade method to create aTeam.longObtains the approximate current time.Obtains theOfficeBuilder.Obtains theOfficeFloorBuilder.Obtains the name of theOfficeFloorcurrently being constructed.Obtains the name of theOfficecurrently being constructed.voidhandleEscalation(Throwable escalation) Handles anEscalationfrom anOffice.voidinit(org.junit.jupiter.api.extension.ExtensionContext context) Intialise.invokeFunction(String functionName, Object parameter) Facade method to invokeManagedFunctionof anOffice.invokeFunction(String functionName, Object parameter, int secondsToRun) Facade method to invokeManagedFunctionof anOffice.voidinvokeFunctionAndValidate(String functionName, Object parameter, String... expectedFunctions) Facade method to invoke theManagedFunctionof anOfficeand validate theManagedFunctioninstances invoked.voidrecordReflectiveFunctionMethodInvoked(String methodName) Invoked by theReflectiveFunctionBuilderwhen it executes the method.voidsetRecordReflectiveFunctionMethodsInvoked(boolean isRecord) Specifies whether to record the invocations of theReflectiveFunctionBuilderinstances.triggerFunction(String functionName, Object parameter, FlowCallback callback) Triggers theManagedFunctionbut does not wait for its completion.voidValidates that no top level escalation occurred.voidvalidateReflectiveMethodOrder(String... methodNames) Validates the order theReflectiveFunctionBuilderinvoked the methods.
-
Constructor Details
-
ConstructTestSupport
Instantiate with required dependencies.- Parameters:
threadedTestSupport-ThreadedTestSupport.logTestSupport-LogTestSupport.
-
ConstructTestSupport
public ConstructTestSupport()Default constructor forTestSupport.
-
-
Method Details
-
addOfficeFloorEnhancer
Adds anOfficeFloorenhancer.- Parameters:
enhancer-OfficeFloorenhancer.
-
init
Description copied from interface:TestSupportIntialise.- Specified by:
initin interfaceTestSupport- Parameters:
context-ExtensionContext.- Throws:
Exception- If fails to init.
-
beforeEach
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception
-
beforeEach
Undertakes the beforeEach functionality.- Throws:
Exception- If fails.
-
afterEach
- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
Exception
-
afterEach
Undertakes the afterEach functionality.- Throws:
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
Description copied from interface:EscalationHandlerHandles anEscalationfrom anOffice.- Specified by:
handleEscalationin interfaceEscalationHandler- Parameters:
escalation-Escalation.- Throws:
Throwable- Should failure in handlingEscalation.
-
validateNoTopLevelEscalation
Validates that no top level escalation occurred.
This method will clear the escalation on exit.
- Throws:
Throwable- If top levelEscalation.
-
getOfficeFloorBuilder
Obtains theOfficeFloorBuilder.- Returns:
OfficeFloorBuilder.
-
getOfficeBuilder
Obtains theOfficeBuilder.- Returns:
OfficeBuilder.
-
getOfficeFloorName
Obtains the name of theOfficeFloorcurrently being constructed.- Returns:
- Name of the
OfficeFloorcurrently being constructed.
-
getOfficeName
Obtains the name of theOfficecurrently being constructed.- Returns:
- Name of the
Officecurrently being constructed.
-
constructFunction
Constructs theReflectiveFunctionBuilder.- Parameters:
object-Objectcontaining theMethod.methodName- Name of theMethod.- Returns:
ReflectiveFunctionBuilder.
-
constructStaticFunction
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
Invoked by theReflectiveFunctionBuilderwhen it executes the method.- Parameters:
methodName- Name of method being invoked.
-
validateReflectiveMethodOrder
Validates the order theReflectiveFunctionBuilderinvoked the methods.- Parameters:
methodNames- Order that the reflective methods should be invoked.- See Also:
-
assertThreadUsed
Ensures theThreadis used.- Parameters:
thread-Thread.
-
constructFunction
public <O extends Enum<O>,F extends Enum<F>> ManagedFunctionBuilder<O,F> constructFunction(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 Enum<O>,F extends Enum<F>> ManagedFunctionBuilder<O,F> constructFunction(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 Enum<D>,F extends Enum<F>, ManagedObjectBuilder<F> constructManagedObjectMS extends ManagedObjectSource<D, F>> (String managedObjectName, Class<MS> managedObjectSourceClass, 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 Enum<D>,F extends Enum<F>, ManagedObjectBuilder<F> constructManagedObjectMS extends ManagedObjectSource<D, F>> (String managedObjectName, MS managedObjectSource, 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(Object object, String managedObjectName, 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(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
Constructs theGovernance.- Parameters:
object-Objectcontaining theMethodinstances used forGovernance.governanceName- Name of theGovernance.- Returns:
ReflectiveGovernanceBuilder.
-
constructTeam
Facade method to create aTeam.- Parameters:
teamName- Name of theTeam.team-Team.- Returns:
TeamBuilder.
-
constructTeam
public <TS extends TeamSource> TeamBuilder<?> constructTeam(String teamName, Class<TS> teamSourceClass) Facade method to create aTeam.- Type Parameters:
TS-TeamSourcetype.- Parameters:
teamName- Name of theTeam.teamSourceClass-TeamSourceclass.- Returns:
TeamBuilder.
-
constructOfficeFloor
Facade method to create theOfficeFloor.- Returns:
OfficeFloor.- Throws:
Exception- If fails to construct theOfficeFloor.
-
triggerFunction
public Office triggerFunction(String functionName, Object parameter, FlowCallback callback) throws 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:
Exception- If fails to trigger theManagedFunction.
-
invokeFunction
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:
Exception- If fails to constructOfficeorManagedFunctioninvocation failure.
-
invokeFunctionAndValidate
public void invokeFunctionAndValidate(String functionName, Object parameter, String... expectedFunctions) throws Exception Facade 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:
Exception- If fails to constructOfficeorManagedFunctioninvocation failure.
-
invokeFunction
public OfficeFloor invokeFunction(String functionName, Object parameter, int secondsToRun) throws Exception - Parameters:
functionName- Name of theManagedFunctionto invoke.parameter- Parameter.secondsToRun- Seconds to run.- Returns:
OfficeFloor.- Throws:
Exception- If fails to constructOfficeorManagedFunctioninvocation failure.
-