The MockSimulationExtension uses JUnit 5 Extension API to facilitate tests of SimuLizar internals
To enable use of this extension annotate your test class with
@ExtendWith(MockSimulation.class)
By annotating a test method with
@MockSimulation
mocks of the required SimuLizar
internals are created which allow to test i. e. the behavior of model syncers.
In particular, the mocked infrastructure contains:
- Functioning ResourceRegistry, where factory methods
createXXX
return and
register mock implementations
- PCMModelManager providing the pcm instance as global pcm model
- SimuLizarRuntimeState, SimuComModel mocked to provide the above
In a test method, if you want to access a mock, simply add it as a parameter to your test method.
Furthermore, you can similarly get access to a model element. EMF model elements are retrieved
from the ResourceSet by means of filtering by the parameter type. Additionally, it is possible to
filter using dedicated annotations, e.g. by NamedElement::getEntityName() (
Named
) or by
Identifier::getId() (
Identified
).
Example:
@Test
@PCMInstanceFromSupplier(TestModelBase.Empty.class)
@MockSimulation
final void testAddResourceContainer(AbstractSimuLizarRuntimeState runtimeState, ResourceEnvironment environment,
@Named("Container 1") ResourceContainer container) {
}