diff --git a/CHANGELOG.md b/CHANGELOG.md index 59f20e76..7d62054d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- the collected data is now flushed after each precondition - moved test case specific parameter into separate file test_parameter.toml - sdc-ri version to 6.0.0-SNAPSHOT diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistry.kt b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistry.kt index f60e3751..bd8b245b 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistry.kt +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistry.kt @@ -6,6 +6,7 @@ */ package com.draeger.medical.sdccc.manipulation.precondition +import com.draeger.medical.sdccc.messages.MessageStorage import com.google.inject.Inject import com.google.inject.Injector import com.google.inject.Singleton @@ -101,6 +102,8 @@ class PreconditionRegistry @Inject internal constructor(private val injector: In for (precondition in preconditions) { logger.info { "Running precondition ${precondition.javaClass.simpleName}" } precondition.verifyPrecondition(injector) + // flush data after each precondition to ensure that each precondition has most current data + injector.getInstance(MessageStorage::class.java).flush() } } diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistryTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistryTest.java index 26a16fb2..3160bdb0 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistryTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/PreconditionRegistryTest.java @@ -15,7 +15,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import com.draeger.medical.sdccc.messages.MessageStorage; import com.google.inject.Injector; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -29,8 +31,16 @@ */ public class PreconditionRegistryTest { + private PreconditionRegistry registry; + @BeforeEach void setUp() { + final var mockInjector = mock(Injector.class); + final var messageStorageMock = mock(MessageStorage.class); + when(mockInjector.getInstance(MessageStorage.class)).thenReturn(messageStorageMock); + + registry = new PreconditionRegistry(mockInjector); + PreconditionUtil.MockPrecondition.reset(); PreconditionUtil.MockManipulation.reset(); } @@ -43,9 +53,6 @@ void setUp() { @Test @DisplayName("Tests registering a complex interaction and whether it's prompted for") public void testPreconditionInteractionRegistrationAndPrompt() throws Exception { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final var preconditionWasCalled = new AtomicBoolean(false); PreconditionUtil.MockPrecondition.setIsPreconditionMet(injector -> { preconditionWasCalled.set(true); @@ -74,9 +81,6 @@ public void testPreconditionInteractionRegistrationAndPrompt() throws Exception @Test @DisplayName("Tests whether registering the same complex interaction thrice only prompts for it once") public void testPreconditionInteractionRegisteredOnlyOnce() throws Exception { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final var preconditionWasCalled = new AtomicInteger(0); PreconditionUtil.MockPrecondition.setIsPreconditionMet(injector -> { preconditionWasCalled.incrementAndGet(); @@ -98,9 +102,6 @@ public void testPreconditionInteractionRegisteredOnlyOnce() throws Exception { @Test @DisplayName("Tests whether an exception during registration causes a RuntimeException and stops the test run") public void testPreconditionInteractionRegistrationException() { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final var mockInteractionWasCalled = new AtomicInteger(0); PreconditionUtil.MockPrecondition.setAfterConstructorCall(() -> { mockInteractionWasCalled.incrementAndGet(); @@ -121,9 +122,6 @@ public void testPreconditionInteractionRegistrationException() { @Test @DisplayName("Tests registering a manipulation and whether it's prompted for") public void testManipulationInteractionRegistrationAndPrompt() throws Exception { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final var manipulationWasCalled = new AtomicBoolean(false); PreconditionUtil.MockManipulation.setManipulationCall(injector -> { manipulationWasCalled.set(true); @@ -144,9 +142,6 @@ public void testManipulationInteractionRegistrationAndPrompt() throws Exception @Test @DisplayName("Tests whether registering the same manipulation thrice only prompts for it once") public void testManipulationInteractionRegisteredOnlyOnce() throws Exception { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final var manipulationWasCalled = new AtomicInteger(0); PreconditionUtil.MockManipulation.setManipulationCall(injector -> { manipulationWasCalled.incrementAndGet(); @@ -167,9 +162,6 @@ public void testManipulationInteractionRegisteredOnlyOnce() throws Exception { @Test @DisplayName("Tests whether an exception during registration causes a RuntimeException and stops the test run") public void testManipulationInteractionRegistrationException() { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final var mockInteractionWasCalled = new AtomicInteger(0); PreconditionUtil.MockManipulation.setAfterConstructorCall(() -> { mockInteractionWasCalled.incrementAndGet(); @@ -184,9 +176,6 @@ public void testManipulationInteractionRegistrationException() { @Test void testRegisteringObservingPreconditions() throws Exception { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final KClass> mockPreconditionFactory = mock(KClass.class); final var mockFactory = mock(ObservingPreconditionFactory.class); @@ -211,9 +200,6 @@ void testRegisteringObservingPreconditions() throws Exception { @Test void testRegisteringObservingPreconditionsFailsWhenNoObjectInstanceAvailable() { - final var mockInjector = mock(Injector.class); - final var registry = new PreconditionRegistry(mockInjector); - final KClass> mockPreconditionFactory = mock(KClass.class); final var mockFactory = mock(ObservingPreconditionFactory.class);