Class MockSimulationExtension

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension

    public class MockSimulationExtension
    extends Object
    implements org.junit.jupiter.api.extension.BeforeEachCallback
    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) { }
    • Constructor Detail

      • MockSimulationExtension

        public MockSimulationExtension()
    • Method Detail

      • beforeEach

        public void beforeEach​(org.junit.jupiter.api.extension.ExtensionContext context)
                        throws Exception
        Specified by:
        beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
        Throws:
        Exception