Package io.openems.edge.common.test
Class AbstractComponentTest<SELF extends AbstractComponentTest<SELF,SUT>,SUT extends OpenemsComponent>
java.lang.Object
io.openems.edge.common.test.AbstractComponentTest<SELF,SUT>
- Direct Known Subclasses:
ComponentTest
,ControllerTest
,ManagedSymmetricEssTest
public abstract class AbstractComponentTest<SELF extends AbstractComponentTest<SELF,SUT>,SUT extends OpenemsComponent>
extends Object
Provides a test framework for OpenEMS Components.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
static class
Defines a Test-Case consisting of given inputs and expected outputs. -
Constructor Summary
ConstructorDescriptionAbstractComponentTest
(SUT sut) Constructs the Component-Test and validates the implemented Channel-IDs. -
Method Summary
Modifier and TypeMethodDescriptionactivate
(AbstractComponentConfig config) Calls the 'activate()' method of the 'system-under-test'.addComponent
(OpenemsComponent component) Adds an availableOpenemsComponent
.addReference
(String memberName, Object object) Adds a OSGi Declarative Services @Reference via java reflection.getSut()
Gets the 'system-under-test', i.e.protected void
handleEvent
(String topic) If the 'system-under-test' is aEventHandler
call theEventHandler.handleEvent(Event)
method.next
(AbstractComponentTest.TestCase testCase) Runs a Test-Case.next
(AbstractComponentTest.TestCase testCase, int executeCount) Run a Test-Case multiple times.protected void
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
event.protected void
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE
event.protected void
This method is executed beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_WRITE
.protected void
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
event.protected void
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE
event.protected void
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_WRITE
event.protected void
This method is executed afterEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
and beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
.protected void
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_EXECUTE_WRITE
event.protected abstract SELF
self()
Gets an instance of the correct subclass of myself.
-
Constructor Details
-
AbstractComponentTest
Constructs the Component-Test and validates the implemented Channel-IDs.- Parameters:
sut
- the 'system-under-test'- Throws:
OpenemsException
- on error
-
-
Method Details
-
getSut
Gets the 'system-under-test', i.e. the testedOpenemsComponent
.- Returns:
- the tested Component
-
self
Gets an instance of the correct subclass of myself.- Returns:
- myself
-
addReference
Adds a OSGi Declarative Services @Reference via java reflection.Can also be used to set any other private field via reflection.
- Parameters:
memberName
- the name of the field or methodobject
- the reference object- Returns:
- itself, to use as a builder
- Throws:
Exception
- on error
-
addComponent
Adds an availableOpenemsComponent
.If the provided Component is a
DummyComponentManager
.- Parameters:
component
- theOpenemsComponent
s- Returns:
- itself, to use as a builder
-
activate
Calls the 'activate()' method of the 'system-under-test'.If 'activate()' changes the configuration, the OSGi behavior is simulated by calling 'deactivate()' and then again 'activate()'
- Parameters:
config
- the configuration- Returns:
- itself, to use as a builder
- Throws:
Exception
- on error
-
next
Runs a Test-Case.- Parameters:
testCase
- The TestCase- Returns:
- itself, to use as a builder
- Throws:
Exception
- on error
-
next
Run a Test-Case multiple times.- Parameters:
testCase
- The TestCaseexecuteCount
- The execution amount of the test case- Returns:
- itself, to use as a builder
- Throws:
Exception
- on error
-
handleEvent
If the 'system-under-test' is aEventHandler
call theEventHandler.handleEvent(Event)
method.- Parameters:
topic
- theEvent
topic- Throws:
Exception
- on error
-
onBeforeProcessImage
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onAfterProcessImage
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onBeforeControllers
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onExecuteControllers
This method is executed afterEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
and beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onAfterControllers
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onBeforeWrite
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_WRITE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onExecuteWrite
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_EXECUTE_WRITE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onAfterWrite
This method is executed beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_WRITE
.- Throws:
OpenemsError.OpenemsNamedException
- on error
-