Package io.openems.edge.common.test
Class AbstractComponentTest.TestCase
java.lang.Object
io.openems.edge.common.test.AbstractComponentTest.TestCase
- Enclosing class:
- AbstractComponentTest<SELF extends AbstractComponentTest<SELF,
SUT>, SUT extends OpenemsComponent>
Defines a Test-Case consisting of given inputs and expected outputs.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyInputs
(Map<String, OpenemsComponent> components) Applies the values for input channels.void
Applies the time leap to the clock.input
(ChannelAddress address, Object value) Adds an input value for a Channel.onAfterControllersCallbacks
(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
event.onAfterProcessImage
(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE
event.onAfterWriteCallbacks
(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_AFTER_WRITE
event.Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
event.onBeforeProcessImage
(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE
event.onBeforeWriteCallbacks
(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_BEFORE_WRITE
event.Adds a Callback that is called afterEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
and beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
.onExecuteWriteCallbacks
(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_EXECUTE_WRITE
event.output
(ChannelAddress address, Object value) Adds an expected output value for a Channel.timeleap
(TimeLeapClock clock, long amountToAdd, TemporalUnit unit) Adds a simulated timeleap, i.e.protected void
validateOutputs
(Map<String, OpenemsComponent> components) Validates the output values.
-
Constructor Details
-
TestCase
public TestCase() -
TestCase
Create a TestCase with a description.- Parameters:
description
- the description
-
-
Method Details
-
input
Adds an input value for a Channel.- Parameters:
address
- theChannelAddress
value
- the valueObject
- Returns:
- myself
-
output
Adds an expected output value for a Channel.- Parameters:
address
- theChannelAddress
value
- the valueObject
- Returns:
- myself
-
timeleap
public AbstractComponentTest.TestCase timeleap(TimeLeapClock clock, long amountToAdd, TemporalUnit unit) Adds a simulated timeleap, i.e. simulates that a given amount of time passed.- Parameters:
clock
- the activeTimeLeapClock
, i.e. provided to the system-under-test by aClockProvider
likeComponentManager
.amountToAdd
- the amount that should be simulatedunit
- theTemporalUnit
of the amount, e.g. using theChronoUnit
enum- Returns:
- myself
-
onBeforeProcessImage
Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE
event.- Parameters:
callback
- the callback- Returns:
- myself
-
onAfterProcessImage
Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE
event.- Parameters:
callback
- the callback- Returns:
- myself
-
onBeforeControllersCallbacks
public AbstractComponentTest.TestCase onBeforeControllersCallbacks(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
event.- Parameters:
callback
- the callback- Returns:
- myself
-
onExecuteControllersCallbacks
public AbstractComponentTest.TestCase onExecuteControllersCallbacks(ThrowingRunnable<Exception> callback) Adds a Callback that is called afterEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
and beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
. events.- Parameters:
callback
- the callback- Returns:
- myself
-
onAfterControllersCallbacks
public AbstractComponentTest.TestCase onAfterControllersCallbacks(ThrowingRunnable<Exception> callback) Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
event.- Parameters:
callback
- the callback- Returns:
- myself
-
onBeforeWriteCallbacks
Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_BEFORE_WRITE
event.- Parameters:
callback
- the callback- Returns:
- myself
-
onExecuteWriteCallbacks
Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_EXECUTE_WRITE
event.- Parameters:
callback
- the callback- Returns:
- myself
-
onAfterWriteCallbacks
Adds a Callback that is called onEdgeEventConstants.TOPIC_CYCLE_AFTER_WRITE
event.- Parameters:
callback
- the callback- Returns:
- myself
-
applyTimeLeap
public void applyTimeLeap()Applies the time leap to the clock. -
applyInputs
protected void applyInputs(Map<String, OpenemsComponent> components) throws IllegalArgumentException, OpenemsError.OpenemsNamedExceptionApplies the values for input channels.- Parameters:
components
- Referenced components- Throws:
OpenemsError.OpenemsNamedException
- on errorIllegalArgumentException
- on error
-
validateOutputs
Validates the output values.- Parameters:
components
- Referenced components- Throws:
Exception
- on validation failure
-