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 java.lang.Object
Provides a test framework for OpenEMS Components.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractComponentTest.ChannelValue
Stores a tuple of ChannelAddress and Object value.static class
AbstractComponentTest.TestCase
Defines a Test-Case consisting of given inputs and expected outputs.
-
Constructor Summary
Constructors Constructor Description AbstractComponentTest(SUT sut)
Constructs the Component-Test and validates the implemented Channel-IDs.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SELF
activate(AbstractComponentConfig config)
Calls the 'activate()' method of the 'system-under-test'.SELF
addComponent(OpenemsComponent component)
Adds an availableOpenemsComponent
.SELF
addReference(java.lang.String memberName, java.lang.Object object)
Adds a OSGi Declarative Services @Reference via java reflection.SUT
getSut()
Gets the 'system-under-test', i.e.protected void
handleEvent(java.lang.String topic)
If the 'system-under-test' is aEventHandler
call theEventHandler.handleEvent(Event)
method.SELF
next(AbstractComponentTest.TestCase testCase)
Runs a Test-Case.protected void
onAfterControllers()
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
event.protected void
onAfterProcessImage()
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE
event.protected void
onAfterWrite()
This method is executed beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_WRITE
.protected void
onBeforeControllers()
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
event.protected void
onBeforeProcessImage()
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE
event.protected void
onBeforeWrite()
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_WRITE
event.protected void
onExecuteControllers()
This method is executed afterEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
and beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
.protected void
onExecuteWrite()
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 Detail
-
AbstractComponentTest
public AbstractComponentTest(SUT sut) throws OpenemsException
Constructs the Component-Test and validates the implemented Channel-IDs.- Parameters:
sut
- the 'system-under-test'- Throws:
OpenemsException
- on error
-
-
Method Detail
-
getSut
public SUT getSut()
Gets the 'system-under-test', i.e. the testedOpenemsComponent
.- Returns:
- the tested Component
-
self
protected abstract SELF self()
Gets an instance of the correct subclass of myself.- Returns:
- myself
-
addReference
public SELF addReference(java.lang.String memberName, java.lang.Object object) throws java.lang.Exception
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:
java.lang.Exception
- on error
-
addComponent
public SELF addComponent(OpenemsComponent component)
Adds an availableOpenemsComponent
.If the provided Component is a
DummyComponentManager
.- Parameters:
component
- theOpenemsComponent
s- Returns:
- itself, to use as a builder
-
activate
public SELF activate(AbstractComponentConfig config) throws java.lang.Exception
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:
java.lang.Exception
- on error
-
next
public SELF next(AbstractComponentTest.TestCase testCase) throws java.lang.Exception
Runs a Test-Case.- Parameters:
testCase
- The TestCase- Returns:
- itself, to use as a builder
- Throws:
java.lang.Exception
- on error
-
handleEvent
protected void handleEvent(java.lang.String topic) throws java.lang.Exception
If the 'system-under-test' is aEventHandler
call theEventHandler.handleEvent(Event)
method.- Parameters:
topic
- theEvent
topic- Throws:
java.lang.Exception
- on error
-
onBeforeProcessImage
protected void onBeforeProcessImage() throws OpenemsError.OpenemsNamedException
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_PROCESS_IMAGE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onAfterProcessImage
protected void onAfterProcessImage() throws OpenemsError.OpenemsNamedException
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_PROCESS_IMAGE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onBeforeControllers
protected void onBeforeControllers() throws OpenemsError.OpenemsNamedException
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onExecuteControllers
protected void onExecuteControllers() throws OpenemsError.OpenemsNamedException
This method is executed afterEdgeEventConstants.TOPIC_CYCLE_BEFORE_CONTROLLERS
and beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onAfterControllers
protected void onAfterControllers() throws OpenemsError.OpenemsNamedException
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_AFTER_CONTROLLERS
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onBeforeWrite
protected void onBeforeWrite() throws OpenemsError.OpenemsNamedException
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_BEFORE_WRITE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onExecuteWrite
protected void onExecuteWrite() throws OpenemsError.OpenemsNamedException
This method is executed before theEdgeEventConstants.TOPIC_CYCLE_EXECUTE_WRITE
event.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
onAfterWrite
protected void onAfterWrite() throws OpenemsError.OpenemsNamedException
This method is executed beforeEdgeEventConstants.TOPIC_CYCLE_AFTER_WRITE
.- Throws:
OpenemsError.OpenemsNamedException
- on error
-
-