From 6f7cb311f8c2025b28a49846e4fa2a31840dda03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Tue, 13 Feb 2024 18:24:13 +0100 Subject: [PATCH 01/18] ReportProcessor.processReport() is now only called with ReportTypes that are supported. --- CHANGELOG.md | 3 ++ .../sdccc/tests/util/MdibHistorian.java | 31 +++++++++++++--- .../sdccc/tests/util/MdibHistorianTest.java | 35 +++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a4d853e..feb74d5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- ReportWriter.write() could be called with ReportTypes it did not support. + ## [8.0.1] - 2023-09-13 ### Fixed diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index f098a17d..9d799ce4 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -53,8 +53,15 @@ import org.somda.sdc.biceps.consumer.access.RemoteMdibAccessImpl; import org.somda.sdc.biceps.consumer.access.factory.RemoteMdibAccessFactory; import org.somda.sdc.biceps.consumer.preprocessing.DuplicateContextStateHandleHandler; +import org.somda.sdc.biceps.model.message.AbstractAlertReport; +import org.somda.sdc.biceps.model.message.AbstractComponentReport; +import org.somda.sdc.biceps.model.message.AbstractContextReport; +import org.somda.sdc.biceps.model.message.AbstractMetricReport; +import org.somda.sdc.biceps.model.message.AbstractOperationalStateReport; import org.somda.sdc.biceps.model.message.AbstractReport; +import org.somda.sdc.biceps.model.message.DescriptionModificationReport; import org.somda.sdc.biceps.model.message.GetMdibResponse; +import org.somda.sdc.biceps.model.message.WaveformStream; import org.somda.sdc.biceps.model.participant.Mdib; import org.somda.sdc.biceps.model.participant.MdibVersion; import org.somda.sdc.biceps.provider.preprocessing.DuplicateChecker; @@ -535,11 +542,25 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin + " same version has already been applied, and is expected behavior when e.g." + " descriptors update, as both a report for description and state will arrive."); } - LOG.debug( - "Applying report with mdib version {}, type {}", - ImpliedValueUtil.getReportMdibVersion(report), - report.getClass().getSimpleName()); - reportProcessor.processReport(report); + + if (report instanceof WaveformStream || + report instanceof AbstractMetricReport || + report instanceof AbstractAlertReport || + report instanceof AbstractOperationalStateReport || + report instanceof AbstractComponentReport || + report instanceof AbstractContextReport || + report instanceof DescriptionModificationReport + ) { + LOG.debug( + "Applying report with mdib version {}, type {}", + ImpliedValueUtil.getReportMdibVersion(report), + report.getClass().getSimpleName()); + reportProcessor.processReport(report); + } else { + // other reports do not modify the Mdib and hence cannot be passed into + // reportProcessor.processReport(). + // simply ignore them. + } return storage; } diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 19e478d9..ac271440 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -16,6 +16,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.draeger.medical.biceps.model.message.EpisodicContextReport; import com.draeger.medical.biceps.model.participant.AlertActivation; @@ -41,6 +42,7 @@ import jakarta.xml.bind.JAXBException; import java.io.IOException; import java.math.BigInteger; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -50,7 +52,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.somda.sdc.biceps.common.storage.PreprocessingException; +import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.message.AbstractReport; +import org.somda.sdc.biceps.model.message.OperationInvokedReport; +import org.somda.sdc.biceps.model.participant.MdibVersion; import org.somda.sdc.dpws.helper.JaxbMarshalling; import org.somda.sdc.dpws.soap.SoapMarshalling; import org.somda.sdc.glue.common.ActionConstants; @@ -905,6 +910,36 @@ void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportType verify(mockObserver).invalidateTestRun(anyString()); } + /** + * Tests if applyReportOnStorage() can gracefully ignore OperationInvokedReports. + * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception + * in this case. + * @throws ReportProcessingException - when applyReportOnStorage() throws it + * @throws PreprocessingException - when applyReportOnStorage() throws it + */ + @Test + void testApplyReportOnStorageBadCalledWithOperationInvokedReport() throws ReportProcessingException, PreprocessingException { + + // given + BigInteger numericMdibVersion = BigInteger.ZERO; + String sequenceId = "abc"; + final MdibVersion mdibVersion = new MdibVersion(sequenceId, numericMdibVersion); + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + final var report = new OperationInvokedReport(); + final var reportParts = new ArrayList(); + reportParts.add(new OperationInvokedReport.ReportPart()); + report.setReportPart(reportParts); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); + + when(mdibAccess.getMdibVersion()).thenReturn(mdibVersion); + + // when + historianUnderTest.applyReportOnStorage(mdibAccess, report); + } + Envelope buildMdibEnvelope(final String sequenceId, @Nullable final BigInteger mdibVersion) { final var mdib = buildMdib(sequenceId); mdib.setMdibVersion(mdibVersion); From f424d2fb716842d335a6da51078bac5a3711b16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Wed, 14 Feb 2024 09:01:09 +0100 Subject: [PATCH 02/18] Fixed Checkstye warnings, updated licence headers. --- .../medical/sdccc/tests/util/MdibHistorian.java | 5 +++-- .../medical/sdccc/tests/util/MdibHistorianTest.java | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index 9d799ce4..c5a8fa18 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -1,6 +1,6 @@ /* * This Source Code Form is subject to the terms of the MIT License. - * Copyright (c) 2023 Draegerwerk AG & Co. KGaA. + * Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA. * * SPDX-License-Identifier: MIT */ @@ -530,7 +530,7 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin final var reportProcessor = reportProcessorProvider.get(); reportProcessor.startApplyingReportsOnMdib(storage, null); - final var cmp = ImpliedValueUtil.getMdibVersion(storage.getMdibVersion()) + var cmp = ImpliedValueUtil.getMdibVersion(storage.getMdibVersion()) .compareTo(ImpliedValueUtil.getReportMdibVersion(report)); if (cmp > 0) { fail("Cannot apply report older than current storage." @@ -560,6 +560,7 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. + cmp = cmp; // make Checkstyle happy } return storage; } diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index ac271440..1c753944 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -1,6 +1,6 @@ /* * This Source Code Form is subject to the terms of the MIT License. - * Copyright (c) 2023 Draegerwerk AG & Co. KGaA. + * Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA. * * SPDX-License-Identifier: MIT */ @@ -921,18 +921,18 @@ void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportType void testApplyReportOnStorageBadCalledWithOperationInvokedReport() throws ReportProcessingException, PreprocessingException { // given - BigInteger numericMdibVersion = BigInteger.ZERO; - String sequenceId = "abc"; + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; final MdibVersion mdibVersion = new MdibVersion(sequenceId, numericMdibVersion); final var mockObserver = mock(TestRunObserver.class); final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); final var report = new OperationInvokedReport(); - final var reportParts = new ArrayList(); + final var reportParts = new ArrayList(); + final RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); reportParts.add(new OperationInvokedReport.ReportPart()); report.setReportPart(reportParts); report.setMdibVersion(numericMdibVersion); report.setSequenceId(sequenceId); - RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); when(mdibAccess.getMdibVersion()).thenReturn(mdibVersion); From ee8c6f58925ec8538ee70ea743451fa0e0d00e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Wed, 14 Feb 2024 10:01:59 +0100 Subject: [PATCH 03/18] fixed Spotbugs warnings --- .../com/draeger/medical/sdccc/tests/util/MdibHistorian.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index c5a8fa18..a5c4ff23 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -560,7 +560,8 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - cmp = cmp; // make Checkstyle happy + @SuppressWarnings("unused") + var _ignored = 1; // make Checkstyle happy } return storage; } From 16932279211b8c12b4c53ffc7902d06e35d8ecf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Wed, 14 Feb 2024 10:28:36 +0100 Subject: [PATCH 04/18] fixed Checkstyle warnings --- .../com/draeger/medical/sdccc/tests/util/MdibHistorian.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index a5c4ff23..47439962 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -530,7 +530,7 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin final var reportProcessor = reportProcessorProvider.get(); reportProcessor.startApplyingReportsOnMdib(storage, null); - var cmp = ImpliedValueUtil.getMdibVersion(storage.getMdibVersion()) + final var cmp = ImpliedValueUtil.getMdibVersion(storage.getMdibVersion()) .compareTo(ImpliedValueUtil.getReportMdibVersion(report)); if (cmp > 0) { fail("Cannot apply report older than current storage." @@ -561,7 +561,7 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin // reportProcessor.processReport(). // simply ignore them. @SuppressWarnings("unused") - var _ignored = 1; // make Checkstyle happy + final var ignored = 1; // make Checkstyle happy } return storage; } From 47f6a8a611d000d25dec1402bdde0b3fc1ac8b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Wed, 14 Feb 2024 11:02:17 +0100 Subject: [PATCH 05/18] spotless:apply --- .../medical/sdccc/tests/util/MdibHistorian.java | 15 +++++++-------- .../sdccc/tests/util/MdibHistorianTest.java | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index 47439962..4134c8a1 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -543,14 +543,13 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin + " descriptors update, as both a report for description and state will arrive."); } - if (report instanceof WaveformStream || - report instanceof AbstractMetricReport || - report instanceof AbstractAlertReport || - report instanceof AbstractOperationalStateReport || - report instanceof AbstractComponentReport || - report instanceof AbstractContextReport || - report instanceof DescriptionModificationReport - ) { + if (report instanceof WaveformStream + || report instanceof AbstractMetricReport + || report instanceof AbstractAlertReport + || report instanceof AbstractOperationalStateReport + || report instanceof AbstractComponentReport + || report instanceof AbstractContextReport + || report instanceof DescriptionModificationReport) { LOG.debug( "Applying report with mdib version {}, type {}", ImpliedValueUtil.getReportMdibVersion(report), diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 1c753944..0609cf1e 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -918,7 +918,8 @@ void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportType * @throws PreprocessingException - when applyReportOnStorage() throws it */ @Test - void testApplyReportOnStorageBadCalledWithOperationInvokedReport() throws ReportProcessingException, PreprocessingException { + void testApplyReportOnStorageBadCalledWithOperationInvokedReport() + throws ReportProcessingException, PreprocessingException { // given final BigInteger numericMdibVersion = BigInteger.ZERO; From 220a098118234c925a9bf3686926f470dfae743d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Fri, 16 Feb 2024 11:31:17 +0100 Subject: [PATCH 06/18] fixed all 3 calls to ReportProcessor.processReport() in MdibHistorian. --- .../sdccc/tests/util/MdibHistorian.java | 32 +- .../sdccc/tests/util/MdibHistorian2Test.java | 294 ++++++++++++++++++ .../sdccc/tests/util/MdibHistorianTest.java | 118 +++---- 3 files changed, 389 insertions(+), 55 deletions(-) create mode 100644 sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index 4134c8a1..95fb1965 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -260,7 +260,21 @@ private HistorianResult getHistorianResultForEpisodicReportBasedHistory( "Applying report with mdib version {}, type {}", ImpliedValueUtil.getReportMdibVersion(report), report.getClass().getSimpleName()); - reportProcessor.processReport(report); + if (report instanceof WaveformStream + || report instanceof AbstractMetricReport + || report instanceof AbstractAlertReport + || report instanceof AbstractOperationalStateReport + || report instanceof AbstractComponentReport + || report instanceof AbstractContextReport + || report instanceof DescriptionModificationReport) { + reportProcessor.processReport(report); + } else { + // other reports do not modify the Mdib and hence cannot be passed into + // reportProcessor.processReport(). + // simply ignore them. + @SuppressWarnings("unused") + final var ignored = 1; // make Checkstyle happy + } } catch (final Exception e) { fail(e); } @@ -330,7 +344,21 @@ public HistorianResult uniqueEpisodicReportBasedHistoryUntilTimestamp(final Stri "Applying report with mdib version {}, type {}", ImpliedValueUtil.getReportMdibVersion(report), report.getClass().getSimpleName()); - reportProcessor.processReport(report); + if (report instanceof WaveformStream + || report instanceof AbstractMetricReport + || report instanceof AbstractAlertReport + || report instanceof AbstractOperationalStateReport + || report instanceof AbstractComponentReport + || report instanceof AbstractContextReport + || report instanceof DescriptionModificationReport) { + reportProcessor.processReport(report); + } else { + // other reports do not modify the Mdib and hence cannot be passed into + // reportProcessor.processReport(). + // simply ignore them. + @SuppressWarnings("unused") + final var ignored = 1; // make Checkstyle happy + } } catch (final Exception e) { fail(e); } diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java new file mode 100644 index 00000000..63ec9489 --- /dev/null +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java @@ -0,0 +1,294 @@ +/* + * This Source Code Form is subject to the terms of the MIT License. + * Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA. + * + * SPDX-License-Identifier: MIT + */ + +package com.draeger.medical.sdccc.tests.util; + +import static org.mockito.Mockito.mock; + +import com.draeger.medical.biceps.model.message.InvocationError; +import com.draeger.medical.biceps.model.message.InvocationInfo; +import com.draeger.medical.biceps.model.message.InvocationState; +import com.draeger.medical.biceps.model.message.OperationInvokedReport; +import com.draeger.medical.biceps.model.participant.AlertActivation; +import com.draeger.medical.biceps.model.participant.CodedValue; +import com.draeger.medical.biceps.model.participant.InstanceIdentifier; +import com.draeger.medical.biceps.model.participant.Mdib; +import com.draeger.medical.biceps.model.participant.MetricAvailability; +import com.draeger.medical.biceps.model.participant.MetricCategory; +import com.draeger.medical.biceps.model.participant.OperatingMode; +import com.draeger.medical.dpws.soap.model.Envelope; +import com.draeger.medical.sdccc.marshalling.MarshallingUtil; +import com.draeger.medical.sdccc.messages.MessageStorage; +import com.draeger.medical.sdccc.sdcri.testclient.TestClient; +import com.draeger.medical.sdccc.sdcri.testclient.TestClientUtil; +import com.draeger.medical.sdccc.tests.InjectorTestBase; +import com.draeger.medical.sdccc.tests.test_util.InjectorUtil; +import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; +import com.draeger.medical.sdccc.util.MdibBuilder; +import com.draeger.medical.sdccc.util.MessageBuilder; +import com.draeger.medical.sdccc.util.MessageStorageUtil; +import com.draeger.medical.sdccc.util.TestRunObserver; +import com.google.inject.AbstractModule; +import com.google.inject.Injector; +import jakarta.xml.bind.JAXBException; +import java.io.IOException; +import java.math.BigInteger; +import java.util.List; +import javax.annotation.Nullable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.somda.sdc.biceps.common.storage.PreprocessingException; +import org.somda.sdc.dpws.helper.JaxbMarshalling; +import org.somda.sdc.dpws.soap.SoapMarshalling; +import org.somda.sdc.glue.common.ActionConstants; +import org.somda.sdc.glue.consumer.report.ReportProcessingException; + +/** + * Unit tests for those method in {@linkplain MdibHistorian} that + * use models from the com.draeger.medical package. + */ +public class MdibHistorian2Test { + + private static final String VMD_HANDLE = "someVmd"; + private static final String CHANNEL_HANDLE = "someChannel"; + private static final String STRING_METRIC_HANDLE = "theIncredibleStringHandle"; + private static final String ALERT_SYSTEM_HANDLE = "ringDingDong"; + private static final String SYSTEM_CONTEXT_HANDLE = "syswow64"; + private static final String PATIENT_CONTEXT_HANDLE = "PATIENT_ZERO"; + private static final String SCO_HANDLE = "sco_what?"; + private static final String SET_STRING_HANDLE = "sadString"; + + private Injector historianInjector; + private MdibHistorianFactory historianFactory; + private Injector marshallingInjector; + private MessageStorageUtil messageStorageUtil; + private MessageBuilder messageBuilder; + private MessageStorage storage; + private MdibBuilder mdibBuilder; + private SoapMarshalling soapMarshalling; + private JaxbMarshalling jaxbMarshalling; + + @BeforeEach + void setUp() throws IOException { + historianInjector = TestClientUtil.createClientInjector(); + historianFactory = historianInjector.getInstance(MdibHistorianFactory.class); + + marshallingInjector = MarshallingUtil.createMarshallingTestInjector(true); + messageStorageUtil = marshallingInjector.getInstance(MessageStorageUtil.class); + messageBuilder = marshallingInjector.getInstance(MessageBuilder.class); + mdibBuilder = marshallingInjector.getInstance(MdibBuilder.class); + + soapMarshalling = historianInjector.getInstance(SoapMarshalling.class); + soapMarshalling.startAsync().awaitRunning(); + + jaxbMarshalling = historianInjector.getInstance(JaxbMarshalling.class); + jaxbMarshalling.startAsync().awaitRunning(); + + final var mockClient = mock(TestClient.class); + final Injector storageInjector = InjectorUtil.setupInjector(new AbstractModule() { + @Override + protected void configure() { + bind(TestClient.class).toInstance(mockClient); + } + }); + + InjectorTestBase.setInjector(historianInjector); + storage = storageInjector.getInstance(MessageStorage.class); + } + + @AfterEach + void tearDown() { + storage.close(); + soapMarshalling.stopAsync().awaitTerminated(); + jaxbMarshalling.stopAsync().awaitTerminated(); + } + + @Test + void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + + // given + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + final var report = new OperationInvokedReport(); + final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = createOIRReportPart( + createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), + "opTarget", + "opHandle", + createInstanceIdentifier(createCodedValue("33", "JOCS", "2.0"), "rotName", "extName"), + "sourceMds"); + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); + + testEpisodicReportBasedHistory(soapMessage, sequenceId); + } + + @SuppressWarnings({"StatementWithEmptyBody", "EmptyBlock"}) + void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) + throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + + messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); + messageStorageUtil.addInboundSecureHttpMessage(storage, report); + + try (MdibHistorian.HistorianResult historianResult = + historianUnderTest.episodicReportBasedHistory(sequenceId)) { + while (historianResult.next() != null) { + // query all of them + final var ignored = false; // make Checkstyle happy + } + } + } + + @Test + void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationInvokedReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + final var report = new OperationInvokedReport(); + final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = createOIRReportPart( + createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), + "opTarget", + "opHandle", + createInstanceIdentifier(createCodedValue("33", "JOCS", "2.0"), "rotName", "extName"), + "sourceMds"); + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); + + testUniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, soapMessage); + } + + @SuppressWarnings({"StatementWithEmptyBody", "EmptyBlock"}) + private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope report) + throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + + messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); + messageStorageUtil.addInboundSecureHttpMessage(storage, report); + + final long timestamp = System.nanoTime(); + + try (var result = historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { + while (result.next() != null) { + // query them all + final var ignored = false; // make Checkstyle happy + } + } + } + + private static InvocationInfo createInvocationInfo( + final InvocationError error, final InvocationState state, final long transactionId) { + final InvocationInfo info = new InvocationInfo(); + info.setInvocationError(error); + info.setInvocationState(state); + info.setTransactionId(transactionId); + + return info; + } + + private static com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart createOIRReportPart( + final InvocationInfo invocationInfo, + final String opTarget, + final String opHandleRef, + final InstanceIdentifier invocationSource, + final String sourceMds) { + final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = + new com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart(); + part.setInvocationInfo(invocationInfo); + part.setOperationTarget(opTarget); + part.setOperationHandleRef(opHandleRef); + part.setInvocationSource(invocationSource); + part.setSourceMds(sourceMds); + return part; + } + + private static InstanceIdentifier createInstanceIdentifier( + final CodedValue type, final String rootName, final String extensionName) { + final InstanceIdentifier result = new InstanceIdentifier(); + result.setType(type); + result.setRootName(rootName); + result.setExtensionName(extensionName); + return result; + } + + private static CodedValue createCodedValue( + final String code, final String codingSystem, final String codingSystemVersion) { + final CodedValue value = new CodedValue(); + value.setCode(code); + value.setCodingSystem(codingSystem); + value.setCodingSystemVersion(codingSystemVersion); + return value; + } + + Envelope buildMdibEnvelope(final String sequenceId, @Nullable final BigInteger mdibVersion) { + final var mdib = buildMdib(sequenceId); + mdib.setMdibVersion(mdibVersion); + final var report = messageBuilder.buildGetMdibResponse(sequenceId); + report.setMdib(mdib); + return messageBuilder.createSoapMessageWithBody( + ActionConstants.getResponseAction(ActionConstants.ACTION_GET_MDIB), report); + } + + private Mdib buildMdib(final String sequenceId) { + final var mdib = mdibBuilder.buildMinimalMdib(sequenceId); + + final var mdState = mdib.getMdState(); + final var mdsDescriptor = mdib.getMdDescription().getMds().get(0); + mdsDescriptor.setDescriptorVersion(null); + + final var vmd = mdibBuilder.buildVmd(VMD_HANDLE); + vmd.getLeft().setDescriptorVersion(BigInteger.ZERO); + vmd.getRight().setDescriptorVersion(BigInteger.ZERO); + mdsDescriptor.getVmd().add(vmd.getLeft()); + mdState.getState().add(vmd.getRight()); + + final var channel = mdibBuilder.buildChannel(CHANNEL_HANDLE); + vmd.getLeft().getChannel().add(channel.getLeft()); + mdState.getState().add(channel.getRight()); + + final var metric = mdibBuilder.buildStringMetric( + STRING_METRIC_HANDLE, MetricCategory.CLC, MetricAvailability.INTR, mdibBuilder.buildCodedValue("abc")); + channel.getLeft().getMetric().add(metric.getLeft()); + mdState.getState().add(metric.getRight()); + + final var alertSystem = mdibBuilder.buildAlertSystem(ALERT_SYSTEM_HANDLE, AlertActivation.OFF); + mdsDescriptor.setAlertSystem(alertSystem.getLeft()); + mdState.getState().add(alertSystem.getRight()); + + final var systemContext = mdibBuilder.buildSystemContext(SYSTEM_CONTEXT_HANDLE); + + final var operator1 = mdibBuilder.buildOperatorContextDescriptor("opDescriptor1"); + final var operator2 = mdibBuilder.buildOperatorContextDescriptor("opDescriptor2"); + systemContext.getLeft().getOperatorContext().addAll(List.of(operator1, operator2)); + + mdsDescriptor.setSystemContext(systemContext.getLeft()); + mdState.getState().add(systemContext.getRight()); + + final var patientContextDescriptor = mdibBuilder.buildPatientContextDescriptor(PATIENT_CONTEXT_HANDLE); + systemContext.getLeft().setPatientContext(patientContextDescriptor); + + final var sco = mdibBuilder.buildSco(SCO_HANDLE); + mdsDescriptor.setSco(sco.getLeft()); + mdState.getState().add(sco.getRight()); + + final var setString = + mdibBuilder.buildSetStringOperation(SET_STRING_HANDLE, SYSTEM_CONTEXT_HANDLE, OperatingMode.EN); + sco.getLeft().getOperation().add(setString.getLeft()); + mdState.getState().add(setString.getRight()); + return mdib; + } +} diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 0609cf1e..70589249 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -55,6 +55,10 @@ import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.message.AbstractReport; import org.somda.sdc.biceps.model.message.OperationInvokedReport; +import org.somda.sdc.biceps.model.message.SystemErrorReport; +import org.somda.sdc.biceps.model.participant.CodedValue; +import org.somda.sdc.biceps.model.participant.LocalizedText; +import org.somda.sdc.biceps.model.participant.LocalizedTextWidth; import org.somda.sdc.biceps.model.participant.MdibVersion; import org.somda.sdc.dpws.helper.JaxbMarshalling; import org.somda.sdc.dpws.soap.SoapMarshalling; @@ -62,7 +66,8 @@ import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** - * Unit tests for the {@linkplain com.draeger.medical.sdccc.tests.util.MdibHistorian}. + * Unit tests for those methods in {@linkplain com.draeger.medical.sdccc.tests.util.MdibHistorian} + * that use models from the package org.somda.sdc. */ public class MdibHistorianTest { @@ -860,54 +865,27 @@ void testUniqueEpisodicReportBasedHistoryGoodDoNotFilterWhenReportTypeDiffers() } /** - * Tests if uniqueEpisodicReportBasedHistory() invalidates the Test run when encountering 2 reports that - * - have the same MdibVersion, - * - have the same ReportType, but - * - have different Contents. - * @throws JAXBException when these are thrown by the MessageStorage. - * @throws IOException when these are thrown by the MessageStorage. - * @throws ReportProcessingException when these are thrown by uniqueEpisodicReportBasedHistory(). - * @throws PreprocessingException when these are thrown by uniqueEpisodicReportBasedHistory(). + * Tests if applyReportOnStorage() can gracefully ignore OperationInvokedReports. + * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception + * in this case. + * @throws ReportProcessingException - when applyReportOnStorage() throws it + * @throws PreprocessingException - when applyReportOnStorage() throws it */ @Test - void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportTypeButContentDiffers() - throws JAXBException, IOException, ReportProcessingException, PreprocessingException { - final var operator1 = mdibBuilder.buildOperatorContextState("opDescriptor1", "opState1"); - final var operator2 = mdibBuilder.buildOperatorContextState("opDescriptor2", "opState2"); - - final var contextReportMdibVersion = BigInteger.ONE; - final var contextReportStateVersion = BigInteger.TWO; - final var contextReport = buildEpisodicContextReport( - MdibBuilder.DEFAULT_SEQUENCE_ID, contextReportMdibVersion, contextReportStateVersion); - - final var firstMod = - (EpisodicContextReport) contextReport.getBody().getAny().get(0); - firstMod.getReportPart().get(0).getContextState().add(operator1); - firstMod.getReportPart().get(0).getContextState().add(operator2); - - final var contextReport2 = buildEpisodicContextReport( - MdibBuilder.DEFAULT_SEQUENCE_ID, contextReportMdibVersion, contextReportStateVersion); - final var secondMod = - (EpisodicContextReport) contextReport2.getBody().getAny().get(0); - secondMod.getReportPart().get(0).getContextState().add(operator1); - - messageStorageUtil.addInboundSecureHttpMessage( - storage, buildMdibEnvelope(MdibBuilder.DEFAULT_SEQUENCE_ID, BigInteger.ZERO)); - - messageStorageUtil.addInboundSecureHttpMessage(storage, contextReport); - messageStorageUtil.addInboundSecureHttpMessage(storage, contextReport2); // duplicate - - final var mockObserver = mock(TestRunObserver.class); - final var historian = historianFactory.createMdibHistorian(storage, mockObserver); + void testApplyReportOnStorageRegressionCalledWithOperationInvokedReport() + throws ReportProcessingException, PreprocessingException { - try (final var history = historian.uniqueEpisodicReportBasedHistory(MdibBuilder.DEFAULT_SEQUENCE_ID)) { - history.next(); // initial state - history.next(); // state after contextReport - history.next(); // state after contextReport2 - assertNull(history.next()); // no more states as the other reports were filtered out as duplicates - } + // given + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + final var report = new OperationInvokedReport(); + final var reportParts = new ArrayList(); + reportParts.add(new OperationInvokedReport.ReportPart()); + report.setReportPart(reportParts); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); - verify(mockObserver).invalidateTestRun(anyString()); + testApplyReportOnStorage(numericMdibVersion, sequenceId, report); } /** @@ -918,22 +896,56 @@ void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportType * @throws PreprocessingException - when applyReportOnStorage() throws it */ @Test - void testApplyReportOnStorageBadCalledWithOperationInvokedReport() + void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() throws ReportProcessingException, PreprocessingException { // given final BigInteger numericMdibVersion = BigInteger.ZERO; final String sequenceId = "abc"; + final var report = new SystemErrorReport(); + final SystemErrorReport.ReportPart part = new SystemErrorReport.ReportPart(); + part.setErrorCode(createCodedValue("someCode", "someCodingSystem", "1.0")); + final LocalizedText text = + createLocalizedText("someErrorText", "en", "someRef", BigInteger.ZERO, LocalizedTextWidth.M); + part.setErrorInfo(text); + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + + testApplyReportOnStorage(numericMdibVersion, sequenceId, report); + } + + private static LocalizedText createLocalizedText( + final String value, + final String lang, + final String ref, + final BigInteger version, + final LocalizedTextWidth textWidth) { + final LocalizedText text = new LocalizedText(); + text.setLang(lang); + text.setValue(value); + text.setRef(ref); + text.setVersion(version); + text.setTextWidth(textWidth); + return text; + } + + private static CodedValue createCodedValue( + final String code, final String codingSystem, final String codingSystemVersion) { + final CodedValue value = new CodedValue(); + value.setCode(code); + value.setCodingSystem(codingSystem); + value.setCodingSystemVersion(codingSystemVersion); + return value; + } + + private void testApplyReportOnStorage( + final BigInteger numericMdibVersion, final String sequenceId, final AbstractReport report) + throws PreprocessingException, ReportProcessingException { + final RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); final MdibVersion mdibVersion = new MdibVersion(sequenceId, numericMdibVersion); final var mockObserver = mock(TestRunObserver.class); final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); - final var report = new OperationInvokedReport(); - final var reportParts = new ArrayList(); - final RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); - reportParts.add(new OperationInvokedReport.ReportPart()); - report.setReportPart(reportParts); - report.setMdibVersion(numericMdibVersion); - report.setSequenceId(sequenceId); when(mdibAccess.getMdibVersion()).thenReturn(mdibVersion); From 66ffb5d512cd9a5c89f619f049de53ac4f35fec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Fri, 16 Feb 2024 11:31:17 +0100 Subject: [PATCH 07/18] fixed all 3 calls to ReportProcessor.processReport() in MdibHistorian. --- .../sdccc/tests/util/MdibHistorian.java | 32 +- .../sdccc/tests/util/MdibHistorian2Test.java | 294 ++++++++++++++++++ .../sdccc/tests/util/MdibHistorianTest.java | 118 +++---- 3 files changed, 389 insertions(+), 55 deletions(-) create mode 100644 sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index 4134c8a1..95fb1965 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -260,7 +260,21 @@ private HistorianResult getHistorianResultForEpisodicReportBasedHistory( "Applying report with mdib version {}, type {}", ImpliedValueUtil.getReportMdibVersion(report), report.getClass().getSimpleName()); - reportProcessor.processReport(report); + if (report instanceof WaveformStream + || report instanceof AbstractMetricReport + || report instanceof AbstractAlertReport + || report instanceof AbstractOperationalStateReport + || report instanceof AbstractComponentReport + || report instanceof AbstractContextReport + || report instanceof DescriptionModificationReport) { + reportProcessor.processReport(report); + } else { + // other reports do not modify the Mdib and hence cannot be passed into + // reportProcessor.processReport(). + // simply ignore them. + @SuppressWarnings("unused") + final var ignored = 1; // make Checkstyle happy + } } catch (final Exception e) { fail(e); } @@ -330,7 +344,21 @@ public HistorianResult uniqueEpisodicReportBasedHistoryUntilTimestamp(final Stri "Applying report with mdib version {}, type {}", ImpliedValueUtil.getReportMdibVersion(report), report.getClass().getSimpleName()); - reportProcessor.processReport(report); + if (report instanceof WaveformStream + || report instanceof AbstractMetricReport + || report instanceof AbstractAlertReport + || report instanceof AbstractOperationalStateReport + || report instanceof AbstractComponentReport + || report instanceof AbstractContextReport + || report instanceof DescriptionModificationReport) { + reportProcessor.processReport(report); + } else { + // other reports do not modify the Mdib and hence cannot be passed into + // reportProcessor.processReport(). + // simply ignore them. + @SuppressWarnings("unused") + final var ignored = 1; // make Checkstyle happy + } } catch (final Exception e) { fail(e); } diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java new file mode 100644 index 00000000..3718c695 --- /dev/null +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java @@ -0,0 +1,294 @@ +/* + * This Source Code Form is subject to the terms of the MIT License. + * Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA. + * + * SPDX-License-Identifier: MIT + */ + +package com.draeger.medical.sdccc.tests.util; + +import static org.mockito.Mockito.mock; + +import com.draeger.medical.biceps.model.message.InvocationError; +import com.draeger.medical.biceps.model.message.InvocationInfo; +import com.draeger.medical.biceps.model.message.InvocationState; +import com.draeger.medical.biceps.model.message.OperationInvokedReport; +import com.draeger.medical.biceps.model.participant.AlertActivation; +import com.draeger.medical.biceps.model.participant.CodedValue; +import com.draeger.medical.biceps.model.participant.InstanceIdentifier; +import com.draeger.medical.biceps.model.participant.Mdib; +import com.draeger.medical.biceps.model.participant.MetricAvailability; +import com.draeger.medical.biceps.model.participant.MetricCategory; +import com.draeger.medical.biceps.model.participant.OperatingMode; +import com.draeger.medical.dpws.soap.model.Envelope; +import com.draeger.medical.sdccc.marshalling.MarshallingUtil; +import com.draeger.medical.sdccc.messages.MessageStorage; +import com.draeger.medical.sdccc.sdcri.testclient.TestClient; +import com.draeger.medical.sdccc.sdcri.testclient.TestClientUtil; +import com.draeger.medical.sdccc.tests.InjectorTestBase; +import com.draeger.medical.sdccc.tests.test_util.InjectorUtil; +import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; +import com.draeger.medical.sdccc.util.MdibBuilder; +import com.draeger.medical.sdccc.util.MessageBuilder; +import com.draeger.medical.sdccc.util.MessageStorageUtil; +import com.draeger.medical.sdccc.util.TestRunObserver; +import com.google.inject.AbstractModule; +import com.google.inject.Injector; +import jakarta.xml.bind.JAXBException; +import java.io.IOException; +import java.math.BigInteger; +import java.util.List; +import javax.annotation.Nullable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.somda.sdc.biceps.common.storage.PreprocessingException; +import org.somda.sdc.dpws.helper.JaxbMarshalling; +import org.somda.sdc.dpws.soap.SoapMarshalling; +import org.somda.sdc.glue.common.ActionConstants; +import org.somda.sdc.glue.consumer.report.ReportProcessingException; + +/** + * Unit tests for those method in {@linkplain MdibHistorian} that + * use models from the com.draeger.medical package. + */ +public class MdibHistorian2Test { + + private static final String VMD_HANDLE = "someVmd"; + private static final String CHANNEL_HANDLE = "someChannel"; + private static final String STRING_METRIC_HANDLE = "theIncredibleStringHandle"; + private static final String ALERT_SYSTEM_HANDLE = "ringDingDong"; + private static final String SYSTEM_CONTEXT_HANDLE = "syswow64"; + private static final String PATIENT_CONTEXT_HANDLE = "PATIENT_ZERO"; + private static final String SCO_HANDLE = "sco_what?"; + private static final String SET_STRING_HANDLE = "sadString"; + + private Injector historianInjector; + private MdibHistorianFactory historianFactory; + private Injector marshallingInjector; + private MessageStorageUtil messageStorageUtil; + private MessageBuilder messageBuilder; + private MessageStorage storage; + private MdibBuilder mdibBuilder; + private SoapMarshalling soapMarshalling; + private JaxbMarshalling jaxbMarshalling; + + @BeforeEach + void setUp() throws IOException { + historianInjector = TestClientUtil.createClientInjector(); + historianFactory = historianInjector.getInstance(MdibHistorianFactory.class); + + marshallingInjector = MarshallingUtil.createMarshallingTestInjector(true); + messageStorageUtil = marshallingInjector.getInstance(MessageStorageUtil.class); + messageBuilder = marshallingInjector.getInstance(MessageBuilder.class); + mdibBuilder = marshallingInjector.getInstance(MdibBuilder.class); + + soapMarshalling = historianInjector.getInstance(SoapMarshalling.class); + soapMarshalling.startAsync().awaitRunning(); + + jaxbMarshalling = historianInjector.getInstance(JaxbMarshalling.class); + jaxbMarshalling.startAsync().awaitRunning(); + + final var mockClient = mock(TestClient.class); + final Injector storageInjector = InjectorUtil.setupInjector(new AbstractModule() { + @Override + protected void configure() { + bind(TestClient.class).toInstance(mockClient); + } + }); + + InjectorTestBase.setInjector(historianInjector); + storage = storageInjector.getInstance(MessageStorage.class); + } + + @AfterEach + void tearDown() { + storage.close(); + soapMarshalling.stopAsync().awaitTerminated(); + jaxbMarshalling.stopAsync().awaitTerminated(); + } + + @Test + void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + + // given + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + final var report = new OperationInvokedReport(); + final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = createOIRReportPart( + createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), + "opTarget", + "opHandle", + createInstanceIdentifier(createCodedValue("33", "JOCS", "2.0"), "rotName", "extName"), + "sourceMds"); + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); + + testEpisodicReportBasedHistory(soapMessage, sequenceId); + } + + @SuppressWarnings({"EmptyBlock"}) + void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) + throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + + messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); + messageStorageUtil.addInboundSecureHttpMessage(storage, report); + + try (MdibHistorian.HistorianResult historianResult = + historianUnderTest.episodicReportBasedHistory(sequenceId)) { + while (historianResult.next() != null) { + // query all of them + final var ignored = false; // make Checkstyle happy + } + } + } + + @Test + void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationInvokedReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + final var report = new OperationInvokedReport(); + final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = createOIRReportPart( + createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), + "opTarget", + "opHandle", + createInstanceIdentifier(createCodedValue("33", "JOCS", "2.0"), "rotName", "extName"), + "sourceMds"); + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); + + testUniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, soapMessage); + } + + @SuppressWarnings({"EmptyBlock"}) + private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope report) + throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + + messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); + messageStorageUtil.addInboundSecureHttpMessage(storage, report); + + final long timestamp = System.nanoTime(); + + try (var result = historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { + while (result.next() != null) { + // query them all + final var ignored = false; // make Checkstyle happy + } + } + } + + private static InvocationInfo createInvocationInfo( + final InvocationError error, final InvocationState state, final long transactionId) { + final InvocationInfo info = new InvocationInfo(); + info.setInvocationError(error); + info.setInvocationState(state); + info.setTransactionId(transactionId); + + return info; + } + + private static com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart createOIRReportPart( + final InvocationInfo invocationInfo, + final String opTarget, + final String opHandleRef, + final InstanceIdentifier invocationSource, + final String sourceMds) { + final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = + new com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart(); + part.setInvocationInfo(invocationInfo); + part.setOperationTarget(opTarget); + part.setOperationHandleRef(opHandleRef); + part.setInvocationSource(invocationSource); + part.setSourceMds(sourceMds); + return part; + } + + private static InstanceIdentifier createInstanceIdentifier( + final CodedValue type, final String rootName, final String extensionName) { + final InstanceIdentifier result = new InstanceIdentifier(); + result.setType(type); + result.setRootName(rootName); + result.setExtensionName(extensionName); + return result; + } + + private static CodedValue createCodedValue( + final String code, final String codingSystem, final String codingSystemVersion) { + final CodedValue value = new CodedValue(); + value.setCode(code); + value.setCodingSystem(codingSystem); + value.setCodingSystemVersion(codingSystemVersion); + return value; + } + + Envelope buildMdibEnvelope(final String sequenceId, @Nullable final BigInteger mdibVersion) { + final var mdib = buildMdib(sequenceId); + mdib.setMdibVersion(mdibVersion); + final var report = messageBuilder.buildGetMdibResponse(sequenceId); + report.setMdib(mdib); + return messageBuilder.createSoapMessageWithBody( + ActionConstants.getResponseAction(ActionConstants.ACTION_GET_MDIB), report); + } + + private Mdib buildMdib(final String sequenceId) { + final var mdib = mdibBuilder.buildMinimalMdib(sequenceId); + + final var mdState = mdib.getMdState(); + final var mdsDescriptor = mdib.getMdDescription().getMds().get(0); + mdsDescriptor.setDescriptorVersion(null); + + final var vmd = mdibBuilder.buildVmd(VMD_HANDLE); + vmd.getLeft().setDescriptorVersion(BigInteger.ZERO); + vmd.getRight().setDescriptorVersion(BigInteger.ZERO); + mdsDescriptor.getVmd().add(vmd.getLeft()); + mdState.getState().add(vmd.getRight()); + + final var channel = mdibBuilder.buildChannel(CHANNEL_HANDLE); + vmd.getLeft().getChannel().add(channel.getLeft()); + mdState.getState().add(channel.getRight()); + + final var metric = mdibBuilder.buildStringMetric( + STRING_METRIC_HANDLE, MetricCategory.CLC, MetricAvailability.INTR, mdibBuilder.buildCodedValue("abc")); + channel.getLeft().getMetric().add(metric.getLeft()); + mdState.getState().add(metric.getRight()); + + final var alertSystem = mdibBuilder.buildAlertSystem(ALERT_SYSTEM_HANDLE, AlertActivation.OFF); + mdsDescriptor.setAlertSystem(alertSystem.getLeft()); + mdState.getState().add(alertSystem.getRight()); + + final var systemContext = mdibBuilder.buildSystemContext(SYSTEM_CONTEXT_HANDLE); + + final var operator1 = mdibBuilder.buildOperatorContextDescriptor("opDescriptor1"); + final var operator2 = mdibBuilder.buildOperatorContextDescriptor("opDescriptor2"); + systemContext.getLeft().getOperatorContext().addAll(List.of(operator1, operator2)); + + mdsDescriptor.setSystemContext(systemContext.getLeft()); + mdState.getState().add(systemContext.getRight()); + + final var patientContextDescriptor = mdibBuilder.buildPatientContextDescriptor(PATIENT_CONTEXT_HANDLE); + systemContext.getLeft().setPatientContext(patientContextDescriptor); + + final var sco = mdibBuilder.buildSco(SCO_HANDLE); + mdsDescriptor.setSco(sco.getLeft()); + mdState.getState().add(sco.getRight()); + + final var setString = + mdibBuilder.buildSetStringOperation(SET_STRING_HANDLE, SYSTEM_CONTEXT_HANDLE, OperatingMode.EN); + sco.getLeft().getOperation().add(setString.getLeft()); + mdState.getState().add(setString.getRight()); + return mdib; + } +} diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 0609cf1e..70589249 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -55,6 +55,10 @@ import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.message.AbstractReport; import org.somda.sdc.biceps.model.message.OperationInvokedReport; +import org.somda.sdc.biceps.model.message.SystemErrorReport; +import org.somda.sdc.biceps.model.participant.CodedValue; +import org.somda.sdc.biceps.model.participant.LocalizedText; +import org.somda.sdc.biceps.model.participant.LocalizedTextWidth; import org.somda.sdc.biceps.model.participant.MdibVersion; import org.somda.sdc.dpws.helper.JaxbMarshalling; import org.somda.sdc.dpws.soap.SoapMarshalling; @@ -62,7 +66,8 @@ import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** - * Unit tests for the {@linkplain com.draeger.medical.sdccc.tests.util.MdibHistorian}. + * Unit tests for those methods in {@linkplain com.draeger.medical.sdccc.tests.util.MdibHistorian} + * that use models from the package org.somda.sdc. */ public class MdibHistorianTest { @@ -860,54 +865,27 @@ void testUniqueEpisodicReportBasedHistoryGoodDoNotFilterWhenReportTypeDiffers() } /** - * Tests if uniqueEpisodicReportBasedHistory() invalidates the Test run when encountering 2 reports that - * - have the same MdibVersion, - * - have the same ReportType, but - * - have different Contents. - * @throws JAXBException when these are thrown by the MessageStorage. - * @throws IOException when these are thrown by the MessageStorage. - * @throws ReportProcessingException when these are thrown by uniqueEpisodicReportBasedHistory(). - * @throws PreprocessingException when these are thrown by uniqueEpisodicReportBasedHistory(). + * Tests if applyReportOnStorage() can gracefully ignore OperationInvokedReports. + * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception + * in this case. + * @throws ReportProcessingException - when applyReportOnStorage() throws it + * @throws PreprocessingException - when applyReportOnStorage() throws it */ @Test - void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportTypeButContentDiffers() - throws JAXBException, IOException, ReportProcessingException, PreprocessingException { - final var operator1 = mdibBuilder.buildOperatorContextState("opDescriptor1", "opState1"); - final var operator2 = mdibBuilder.buildOperatorContextState("opDescriptor2", "opState2"); - - final var contextReportMdibVersion = BigInteger.ONE; - final var contextReportStateVersion = BigInteger.TWO; - final var contextReport = buildEpisodicContextReport( - MdibBuilder.DEFAULT_SEQUENCE_ID, contextReportMdibVersion, contextReportStateVersion); - - final var firstMod = - (EpisodicContextReport) contextReport.getBody().getAny().get(0); - firstMod.getReportPart().get(0).getContextState().add(operator1); - firstMod.getReportPart().get(0).getContextState().add(operator2); - - final var contextReport2 = buildEpisodicContextReport( - MdibBuilder.DEFAULT_SEQUENCE_ID, contextReportMdibVersion, contextReportStateVersion); - final var secondMod = - (EpisodicContextReport) contextReport2.getBody().getAny().get(0); - secondMod.getReportPart().get(0).getContextState().add(operator1); - - messageStorageUtil.addInboundSecureHttpMessage( - storage, buildMdibEnvelope(MdibBuilder.DEFAULT_SEQUENCE_ID, BigInteger.ZERO)); - - messageStorageUtil.addInboundSecureHttpMessage(storage, contextReport); - messageStorageUtil.addInboundSecureHttpMessage(storage, contextReport2); // duplicate - - final var mockObserver = mock(TestRunObserver.class); - final var historian = historianFactory.createMdibHistorian(storage, mockObserver); + void testApplyReportOnStorageRegressionCalledWithOperationInvokedReport() + throws ReportProcessingException, PreprocessingException { - try (final var history = historian.uniqueEpisodicReportBasedHistory(MdibBuilder.DEFAULT_SEQUENCE_ID)) { - history.next(); // initial state - history.next(); // state after contextReport - history.next(); // state after contextReport2 - assertNull(history.next()); // no more states as the other reports were filtered out as duplicates - } + // given + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + final var report = new OperationInvokedReport(); + final var reportParts = new ArrayList(); + reportParts.add(new OperationInvokedReport.ReportPart()); + report.setReportPart(reportParts); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); - verify(mockObserver).invalidateTestRun(anyString()); + testApplyReportOnStorage(numericMdibVersion, sequenceId, report); } /** @@ -918,22 +896,56 @@ void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportType * @throws PreprocessingException - when applyReportOnStorage() throws it */ @Test - void testApplyReportOnStorageBadCalledWithOperationInvokedReport() + void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() throws ReportProcessingException, PreprocessingException { // given final BigInteger numericMdibVersion = BigInteger.ZERO; final String sequenceId = "abc"; + final var report = new SystemErrorReport(); + final SystemErrorReport.ReportPart part = new SystemErrorReport.ReportPart(); + part.setErrorCode(createCodedValue("someCode", "someCodingSystem", "1.0")); + final LocalizedText text = + createLocalizedText("someErrorText", "en", "someRef", BigInteger.ZERO, LocalizedTextWidth.M); + part.setErrorInfo(text); + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + + testApplyReportOnStorage(numericMdibVersion, sequenceId, report); + } + + private static LocalizedText createLocalizedText( + final String value, + final String lang, + final String ref, + final BigInteger version, + final LocalizedTextWidth textWidth) { + final LocalizedText text = new LocalizedText(); + text.setLang(lang); + text.setValue(value); + text.setRef(ref); + text.setVersion(version); + text.setTextWidth(textWidth); + return text; + } + + private static CodedValue createCodedValue( + final String code, final String codingSystem, final String codingSystemVersion) { + final CodedValue value = new CodedValue(); + value.setCode(code); + value.setCodingSystem(codingSystem); + value.setCodingSystemVersion(codingSystemVersion); + return value; + } + + private void testApplyReportOnStorage( + final BigInteger numericMdibVersion, final String sequenceId, final AbstractReport report) + throws PreprocessingException, ReportProcessingException { + final RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); final MdibVersion mdibVersion = new MdibVersion(sequenceId, numericMdibVersion); final var mockObserver = mock(TestRunObserver.class); final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); - final var report = new OperationInvokedReport(); - final var reportParts = new ArrayList(); - final RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); - reportParts.add(new OperationInvokedReport.ReportPart()); - report.setReportPart(reportParts); - report.setMdibVersion(numericMdibVersion); - report.setSequenceId(sequenceId); when(mdibAccess.getMdibVersion()).thenReturn(mdibVersion); From 600a0ef8d5c110e3ea8060704b298e32f1b2f90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Fri, 16 Feb 2024 16:42:45 +0100 Subject: [PATCH 08/18] Changes suggested by reviewers & Fixes after merge. --- .../medical/sdccc/tests/util/MdibHistorian.java | 12 ++++++------ .../medical/sdccc/tests/util/MdibHistorian2Test.java | 4 ---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index 95fb1965..6b9509bb 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -272,8 +272,8 @@ private HistorianResult getHistorianResultForEpisodicReportBasedHistory( // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - @SuppressWarnings("unused") - final var ignored = 1; // make Checkstyle happy + LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + + "as it is not expected to change the Mdib anyway."); } } catch (final Exception e) { fail(e); @@ -356,8 +356,8 @@ public HistorianResult uniqueEpisodicReportBasedHistoryUntilTimestamp(final Stri // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - @SuppressWarnings("unused") - final var ignored = 1; // make Checkstyle happy + LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + + "as it is not expected to change the Mdib anyway."); } } catch (final Exception e) { fail(e); @@ -587,8 +587,8 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - @SuppressWarnings("unused") - final var ignored = 1; // make Checkstyle happy + LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + + "as it is not expected to change the Mdib anyway."); } return storage; } diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java index 2a16d4d6..3718c695 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java @@ -171,11 +171,7 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationIn testUniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, soapMessage); } -<<<<<<< HEAD @SuppressWarnings({"EmptyBlock"}) -======= - @SuppressWarnings({"StatementWithEmptyBody", "EmptyBlock"}) ->>>>>>> 220a098118234c925a9bf3686926f470dfae743d private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope report) throws ReportProcessingException, PreprocessingException, JAXBException, IOException { final var mockObserver = mock(TestRunObserver.class); From ea4a090988883367ee8f32490034dbce0c0e43cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Mon, 19 Feb 2024 09:15:16 +0100 Subject: [PATCH 09/18] spotless:apply & removed unused method --- .../sdccc/tests/util/MdibHistorian.java | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index 6b9509bb..db4c317e 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -272,8 +272,8 @@ private HistorianResult getHistorianResultForEpisodicReportBasedHistory( // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + - "as it is not expected to change the Mdib anyway."); + LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + + "as it is not expected to change the Mdib anyway."); } } catch (final Exception e) { fail(e); @@ -356,8 +356,8 @@ public HistorianResult uniqueEpisodicReportBasedHistoryUntilTimestamp(final Stri // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + - "as it is not expected to change the Mdib anyway."); + LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + + "as it is not expected to change the Mdib anyway."); } } catch (final Exception e) { fail(e); @@ -514,35 +514,6 @@ public Stream getAllReportsWithLowerMdibVersion( } } - // TODO javadoc and maybe instead of getting all reports with lowertimestamp get the storage directly. So dont apply - // every report manually but provide a result - public Stream getAllReportsWithLowerTimestamp( - final String sequenceId, - @Nullable final BigInteger minimumMdibVersion, - final long maximumTimestamp, - final QName... bodyTypes) { - try { - final var messages = - messageStorage.getInboundMessagesByTimestampAndBodyType(sequenceId, maximumTimestamp, bodyTypes); - - var iter = messages.getStream() - .sequential() // the stateful filter operation below is not thread-safe - .map(this::unmarshallReportKeepUUID); - if (minimumMdibVersion != null) { - iter = iter.filter(it -> - ImpliedValueUtil.getReportMdibVersion(it.getLeft()).compareTo(minimumMdibVersion) >= 1); - } - return filterReportDuplicates(iter).map(Pair::getLeft); - } catch (IOException e) { - final var errorMessage = "Error while trying to retrieve reports from storage"; - LOG.error("{}: {}", errorMessage, e.getMessage()); - LOG.debug("{}", errorMessage, e); - fail(e); - // unreachable, silence warnings - throw new RuntimeException(e); - } - } - /** * Applies a report on a stored mdib. * @@ -587,8 +558,8 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + - "as it is not expected to change the Mdib anyway."); + LOG.debug("ignoring report of type " + report.getClass().getSimpleName() + + "as it is not expected to change the Mdib anyway."); } return storage; } From c9bcf347c0fcf7ca9f7c524e0fad12c7f6aea7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Mon, 19 Feb 2024 16:32:59 +0100 Subject: [PATCH 10/18] changes proposed by reviewers. --- .../sdccc/tests/util/MdibHistorian.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java index db4c317e..fd37156e 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/MdibHistorian.java @@ -256,10 +256,6 @@ private HistorianResult getHistorianResultForEpisodicReportBasedHistory( + " same version has already been applied, and is expected behavior when e.g." + " descriptors update, as both a report for description and state will arrive."); } - LOG.debug( - "Applying report with mdib version {}, type {}", - ImpliedValueUtil.getReportMdibVersion(report), - report.getClass().getSimpleName()); if (report instanceof WaveformStream || report instanceof AbstractMetricReport || report instanceof AbstractAlertReport @@ -267,13 +263,20 @@ private HistorianResult getHistorianResultForEpisodicReportBasedHistory( || report instanceof AbstractComponentReport || report instanceof AbstractContextReport || report instanceof DescriptionModificationReport) { + LOG.debug( + "Applying report with mdib version {}, type {}", + ImpliedValueUtil.getReportMdibVersion(report), + report.getClass().getSimpleName()); reportProcessor.processReport(report); } else { // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - LOG.debug("ignoring report of type " + report.getClass().getSimpleName() - + "as it is not expected to change the Mdib anyway."); + LOG.debug( + "Ignoring report of type {} with MdibVersion {} as it is not expected to " + + "change the Mdib anyway.", + report.getClass().getSimpleName(), + ImpliedValueUtil.getReportMdibVersion(report)); } } catch (final Exception e) { fail(e); @@ -351,13 +354,20 @@ public HistorianResult uniqueEpisodicReportBasedHistoryUntilTimestamp(final Stri || report instanceof AbstractComponentReport || report instanceof AbstractContextReport || report instanceof DescriptionModificationReport) { + LOG.debug( + "Applying report with mdib version {}, type {}", + ImpliedValueUtil.getReportMdibVersion(report), + report.getClass().getSimpleName()); reportProcessor.processReport(report); } else { // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - LOG.debug("ignoring report of type " + report.getClass().getSimpleName() - + "as it is not expected to change the Mdib anyway."); + LOG.debug( + "Ignoring report of type {} with MdibVersion {} as it is not expected to " + + "change the Mdib anyway.", + report.getClass().getSimpleName(), + ImpliedValueUtil.getReportMdibVersion(report)); } } catch (final Exception e) { fail(e); @@ -558,8 +568,11 @@ public RemoteMdibAccess applyReportOnStorage(final RemoteMdibAccess storage, fin // other reports do not modify the Mdib and hence cannot be passed into // reportProcessor.processReport(). // simply ignore them. - LOG.debug("ignoring report of type " + report.getClass().getSimpleName() - + "as it is not expected to change the Mdib anyway."); + LOG.debug( + "Ignoring report of type {} with MdibVersion {} as it is not expected to " + + "change the Mdib anyway.", + report.getClass().getSimpleName(), + ImpliedValueUtil.getReportMdibVersion(report)); } return storage; } From aace5abdb896a9ebe89b8d50ed6de96fff13c244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Mon, 19 Feb 2024 17:17:22 +0100 Subject: [PATCH 11/18] removed unnecessary uses of fully-qualified class names. --- .../medical/sdccc/tests/util/MdibHistorian2Test.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java index 3718c695..2e0bc78c 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java @@ -116,7 +116,7 @@ void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() final BigInteger numericMdibVersion = BigInteger.ZERO; final String sequenceId = "abc"; final var report = new OperationInvokedReport(); - final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = createOIRReportPart( + final OperationInvokedReport.ReportPart part = createOIRReportPart( createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), "opTarget", "opHandle", @@ -156,7 +156,7 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationIn final BigInteger numericMdibVersion = BigInteger.ZERO; final String sequenceId = "abc"; final var report = new OperationInvokedReport(); - final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = createOIRReportPart( + final OperationInvokedReport.ReportPart part = createOIRReportPart( createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), "opTarget", "opHandle", @@ -200,14 +200,14 @@ private static InvocationInfo createInvocationInfo( return info; } - private static com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart createOIRReportPart( + private static OperationInvokedReport.ReportPart createOIRReportPart( final InvocationInfo invocationInfo, final String opTarget, final String opHandleRef, final InstanceIdentifier invocationSource, final String sourceMds) { - final com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart part = - new com.draeger.medical.biceps.model.message.OperationInvokedReport.ReportPart(); + final OperationInvokedReport.ReportPart part = + new OperationInvokedReport.ReportPart(); part.setInvocationInfo(invocationInfo); part.setOperationTarget(opTarget); part.setOperationHandleRef(opHandleRef); From 65dcb45d4e34f5e906e3f1508bc74304d2738a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Tue, 20 Feb 2024 17:08:28 +0100 Subject: [PATCH 12/18] merged two unit test classes for MdibHistorian into one. --- .../sdccc/tests/util/MdibHistorian2Test.java | 294 ------------------ .../sdccc/tests/util/MdibHistorianTest.java | 118 ++++++- 2 files changed, 116 insertions(+), 296 deletions(-) delete mode 100644 sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java deleted file mode 100644 index 2e0bc78c..00000000 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorian2Test.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the MIT License. - * Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA. - * - * SPDX-License-Identifier: MIT - */ - -package com.draeger.medical.sdccc.tests.util; - -import static org.mockito.Mockito.mock; - -import com.draeger.medical.biceps.model.message.InvocationError; -import com.draeger.medical.biceps.model.message.InvocationInfo; -import com.draeger.medical.biceps.model.message.InvocationState; -import com.draeger.medical.biceps.model.message.OperationInvokedReport; -import com.draeger.medical.biceps.model.participant.AlertActivation; -import com.draeger.medical.biceps.model.participant.CodedValue; -import com.draeger.medical.biceps.model.participant.InstanceIdentifier; -import com.draeger.medical.biceps.model.participant.Mdib; -import com.draeger.medical.biceps.model.participant.MetricAvailability; -import com.draeger.medical.biceps.model.participant.MetricCategory; -import com.draeger.medical.biceps.model.participant.OperatingMode; -import com.draeger.medical.dpws.soap.model.Envelope; -import com.draeger.medical.sdccc.marshalling.MarshallingUtil; -import com.draeger.medical.sdccc.messages.MessageStorage; -import com.draeger.medical.sdccc.sdcri.testclient.TestClient; -import com.draeger.medical.sdccc.sdcri.testclient.TestClientUtil; -import com.draeger.medical.sdccc.tests.InjectorTestBase; -import com.draeger.medical.sdccc.tests.test_util.InjectorUtil; -import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; -import com.draeger.medical.sdccc.util.MdibBuilder; -import com.draeger.medical.sdccc.util.MessageBuilder; -import com.draeger.medical.sdccc.util.MessageStorageUtil; -import com.draeger.medical.sdccc.util.TestRunObserver; -import com.google.inject.AbstractModule; -import com.google.inject.Injector; -import jakarta.xml.bind.JAXBException; -import java.io.IOException; -import java.math.BigInteger; -import java.util.List; -import javax.annotation.Nullable; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.somda.sdc.biceps.common.storage.PreprocessingException; -import org.somda.sdc.dpws.helper.JaxbMarshalling; -import org.somda.sdc.dpws.soap.SoapMarshalling; -import org.somda.sdc.glue.common.ActionConstants; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; - -/** - * Unit tests for those method in {@linkplain MdibHistorian} that - * use models from the com.draeger.medical package. - */ -public class MdibHistorian2Test { - - private static final String VMD_HANDLE = "someVmd"; - private static final String CHANNEL_HANDLE = "someChannel"; - private static final String STRING_METRIC_HANDLE = "theIncredibleStringHandle"; - private static final String ALERT_SYSTEM_HANDLE = "ringDingDong"; - private static final String SYSTEM_CONTEXT_HANDLE = "syswow64"; - private static final String PATIENT_CONTEXT_HANDLE = "PATIENT_ZERO"; - private static final String SCO_HANDLE = "sco_what?"; - private static final String SET_STRING_HANDLE = "sadString"; - - private Injector historianInjector; - private MdibHistorianFactory historianFactory; - private Injector marshallingInjector; - private MessageStorageUtil messageStorageUtil; - private MessageBuilder messageBuilder; - private MessageStorage storage; - private MdibBuilder mdibBuilder; - private SoapMarshalling soapMarshalling; - private JaxbMarshalling jaxbMarshalling; - - @BeforeEach - void setUp() throws IOException { - historianInjector = TestClientUtil.createClientInjector(); - historianFactory = historianInjector.getInstance(MdibHistorianFactory.class); - - marshallingInjector = MarshallingUtil.createMarshallingTestInjector(true); - messageStorageUtil = marshallingInjector.getInstance(MessageStorageUtil.class); - messageBuilder = marshallingInjector.getInstance(MessageBuilder.class); - mdibBuilder = marshallingInjector.getInstance(MdibBuilder.class); - - soapMarshalling = historianInjector.getInstance(SoapMarshalling.class); - soapMarshalling.startAsync().awaitRunning(); - - jaxbMarshalling = historianInjector.getInstance(JaxbMarshalling.class); - jaxbMarshalling.startAsync().awaitRunning(); - - final var mockClient = mock(TestClient.class); - final Injector storageInjector = InjectorUtil.setupInjector(new AbstractModule() { - @Override - protected void configure() { - bind(TestClient.class).toInstance(mockClient); - } - }); - - InjectorTestBase.setInjector(historianInjector); - storage = storageInjector.getInstance(MessageStorage.class); - } - - @AfterEach - void tearDown() { - storage.close(); - soapMarshalling.stopAsync().awaitTerminated(); - jaxbMarshalling.stopAsync().awaitTerminated(); - } - - @Test - void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() - throws ReportProcessingException, JAXBException, PreprocessingException, IOException { - - // given - final BigInteger numericMdibVersion = BigInteger.ZERO; - final String sequenceId = "abc"; - final var report = new OperationInvokedReport(); - final OperationInvokedReport.ReportPart part = createOIRReportPart( - createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), - "opTarget", - "opHandle", - createInstanceIdentifier(createCodedValue("33", "JOCS", "2.0"), "rotName", "extName"), - "sourceMds"); - report.getReportPart().add(part); - report.setMdibVersion(numericMdibVersion); - report.setSequenceId(sequenceId); - final Envelope soapMessage = - messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); - - testEpisodicReportBasedHistory(soapMessage, sequenceId); - } - - @SuppressWarnings({"EmptyBlock"}) - void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) - throws ReportProcessingException, PreprocessingException, JAXBException, IOException { - final var mockObserver = mock(TestRunObserver.class); - final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); - - messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); - messageStorageUtil.addInboundSecureHttpMessage(storage, report); - - try (MdibHistorian.HistorianResult historianResult = - historianUnderTest.episodicReportBasedHistory(sequenceId)) { - while (historianResult.next() != null) { - // query all of them - final var ignored = false; // make Checkstyle happy - } - } - } - - @Test - void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationInvokedReport() - throws ReportProcessingException, JAXBException, PreprocessingException, IOException { - - final BigInteger numericMdibVersion = BigInteger.ZERO; - final String sequenceId = "abc"; - final var report = new OperationInvokedReport(); - final OperationInvokedReport.ReportPart part = createOIRReportPart( - createInvocationInfo(InvocationError.OTH, InvocationState.FAIL, 123), - "opTarget", - "opHandle", - createInstanceIdentifier(createCodedValue("33", "JOCS", "2.0"), "rotName", "extName"), - "sourceMds"); - report.getReportPart().add(part); - report.setMdibVersion(numericMdibVersion); - report.setSequenceId(sequenceId); - final Envelope soapMessage = - messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); - - testUniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, soapMessage); - } - - @SuppressWarnings({"EmptyBlock"}) - private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope report) - throws ReportProcessingException, PreprocessingException, JAXBException, IOException { - final var mockObserver = mock(TestRunObserver.class); - final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); - - messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); - messageStorageUtil.addInboundSecureHttpMessage(storage, report); - - final long timestamp = System.nanoTime(); - - try (var result = historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { - while (result.next() != null) { - // query them all - final var ignored = false; // make Checkstyle happy - } - } - } - - private static InvocationInfo createInvocationInfo( - final InvocationError error, final InvocationState state, final long transactionId) { - final InvocationInfo info = new InvocationInfo(); - info.setInvocationError(error); - info.setInvocationState(state); - info.setTransactionId(transactionId); - - return info; - } - - private static OperationInvokedReport.ReportPart createOIRReportPart( - final InvocationInfo invocationInfo, - final String opTarget, - final String opHandleRef, - final InstanceIdentifier invocationSource, - final String sourceMds) { - final OperationInvokedReport.ReportPart part = - new OperationInvokedReport.ReportPart(); - part.setInvocationInfo(invocationInfo); - part.setOperationTarget(opTarget); - part.setOperationHandleRef(opHandleRef); - part.setInvocationSource(invocationSource); - part.setSourceMds(sourceMds); - return part; - } - - private static InstanceIdentifier createInstanceIdentifier( - final CodedValue type, final String rootName, final String extensionName) { - final InstanceIdentifier result = new InstanceIdentifier(); - result.setType(type); - result.setRootName(rootName); - result.setExtensionName(extensionName); - return result; - } - - private static CodedValue createCodedValue( - final String code, final String codingSystem, final String codingSystemVersion) { - final CodedValue value = new CodedValue(); - value.setCode(code); - value.setCodingSystem(codingSystem); - value.setCodingSystemVersion(codingSystemVersion); - return value; - } - - Envelope buildMdibEnvelope(final String sequenceId, @Nullable final BigInteger mdibVersion) { - final var mdib = buildMdib(sequenceId); - mdib.setMdibVersion(mdibVersion); - final var report = messageBuilder.buildGetMdibResponse(sequenceId); - report.setMdib(mdib); - return messageBuilder.createSoapMessageWithBody( - ActionConstants.getResponseAction(ActionConstants.ACTION_GET_MDIB), report); - } - - private Mdib buildMdib(final String sequenceId) { - final var mdib = mdibBuilder.buildMinimalMdib(sequenceId); - - final var mdState = mdib.getMdState(); - final var mdsDescriptor = mdib.getMdDescription().getMds().get(0); - mdsDescriptor.setDescriptorVersion(null); - - final var vmd = mdibBuilder.buildVmd(VMD_HANDLE); - vmd.getLeft().setDescriptorVersion(BigInteger.ZERO); - vmd.getRight().setDescriptorVersion(BigInteger.ZERO); - mdsDescriptor.getVmd().add(vmd.getLeft()); - mdState.getState().add(vmd.getRight()); - - final var channel = mdibBuilder.buildChannel(CHANNEL_HANDLE); - vmd.getLeft().getChannel().add(channel.getLeft()); - mdState.getState().add(channel.getRight()); - - final var metric = mdibBuilder.buildStringMetric( - STRING_METRIC_HANDLE, MetricCategory.CLC, MetricAvailability.INTR, mdibBuilder.buildCodedValue("abc")); - channel.getLeft().getMetric().add(metric.getLeft()); - mdState.getState().add(metric.getRight()); - - final var alertSystem = mdibBuilder.buildAlertSystem(ALERT_SYSTEM_HANDLE, AlertActivation.OFF); - mdsDescriptor.setAlertSystem(alertSystem.getLeft()); - mdState.getState().add(alertSystem.getRight()); - - final var systemContext = mdibBuilder.buildSystemContext(SYSTEM_CONTEXT_HANDLE); - - final var operator1 = mdibBuilder.buildOperatorContextDescriptor("opDescriptor1"); - final var operator2 = mdibBuilder.buildOperatorContextDescriptor("opDescriptor2"); - systemContext.getLeft().getOperatorContext().addAll(List.of(operator1, operator2)); - - mdsDescriptor.setSystemContext(systemContext.getLeft()); - mdState.getState().add(systemContext.getRight()); - - final var patientContextDescriptor = mdibBuilder.buildPatientContextDescriptor(PATIENT_CONTEXT_HANDLE); - systemContext.getLeft().setPatientContext(patientContextDescriptor); - - final var sco = mdibBuilder.buildSco(SCO_HANDLE); - mdsDescriptor.setSco(sco.getLeft()); - mdState.getState().add(sco.getRight()); - - final var setString = - mdibBuilder.buildSetStringOperation(SET_STRING_HANDLE, SYSTEM_CONTEXT_HANDLE, OperatingMode.EN); - sco.getLeft().getOperation().add(setString.getLeft()); - mdState.getState().add(setString.getRight()); - return mdib; - } -} diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 70589249..7b661b81 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.when; import com.draeger.medical.biceps.model.message.EpisodicContextReport; +import com.draeger.medical.biceps.model.message.ObjectFactory; import com.draeger.medical.biceps.model.participant.AlertActivation; import com.draeger.medical.biceps.model.participant.Mdib; import com.draeger.medical.biceps.model.participant.MetricAvailability; @@ -66,8 +67,7 @@ import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** - * Unit tests for those methods in {@linkplain com.draeger.medical.sdccc.tests.util.MdibHistorian} - * that use models from the package org.somda.sdc. + * Unit tests for {@linkplain com.draeger.medical.sdccc.tests.util.MdibHistorian}. */ public class MdibHistorianTest { @@ -915,6 +915,120 @@ void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() testApplyReportOnStorage(numericMdibVersion, sequenceId, report); } + @Test + void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationInvokedReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + + final var messageObjectFactory = new ObjectFactory(); + final var participantObjectFactory = new com.draeger.medical.biceps.model.participant.ObjectFactory(); + + final var report = messageObjectFactory.createOperationInvokedReport(); + final var part = messageObjectFactory.createOperationInvokedReportReportPart(); + final var invInfo = messageObjectFactory.createInvocationInfo(); + invInfo.setInvocationError(com.draeger.medical.biceps.model.message.InvocationError.OTH); + invInfo.setInvocationState(com.draeger.medical.biceps.model.message.InvocationState.FAIL); + invInfo.setTransactionId(123); + part.setInvocationInfo(invInfo); + part.setOperationTarget("opTarget"); + part.setOperationHandleRef("opHandle"); + + final var invSrc = participantObjectFactory.createInstanceIdentifier(); + final var type = participantObjectFactory.createCodedValue(); + type.setCode("33"); + type.setCodingSystem("JOCS"); + type.setCodingSystemVersion("2.0"); + invSrc.setType(type); + invSrc.setRootName("rootName"); + invSrc.setExtensionName("extName"); + part.setInvocationSource(invSrc); + part.setSourceMds("sourceMds"); + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); + + testUniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, soapMessage); + } + + @Test + void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + + // given + final var messageObjectFactory = new ObjectFactory(); + final var participantObjectFactory = new com.draeger.medical.biceps.model.participant.ObjectFactory(); + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; + final var report = messageObjectFactory.createOperationInvokedReport(); + final var part = messageObjectFactory.createOperationInvokedReportReportPart(); + final var invSrc = participantObjectFactory.createInstanceIdentifier(); + invSrc.setRootName("rootName"); + invSrc.setExtensionName("extName"); + final var type = participantObjectFactory.createCodedValue(); + type.setCode("33"); + type.setCodingSystem("JOCS"); + type.setCodingSystemVersion("2.0"); + invSrc.setType(type); + part.setInvocationSource(invSrc); + final var invInfo = messageObjectFactory.createInvocationInfo(); + invInfo.setTransactionId(123); + invInfo.setInvocationError(com.draeger.medical.biceps.model.message.InvocationError.OTH); + invInfo.setInvocationState(com.draeger.medical.biceps.model.message.InvocationState.FAIL); + part.setInvocationInfo(invInfo); + part.setOperationTarget("opTarget"); + part.setOperationHandleRef("opHandle"); + part.setSourceMds("sourceMds"); + + report.getReportPart().add(part); + report.setMdibVersion(numericMdibVersion); + report.setSequenceId(sequenceId); + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); + + testEpisodicReportBasedHistory(soapMessage, sequenceId); + } + + @SuppressWarnings({"EmptyBlock"}) + void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) + throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + + messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); + messageStorageUtil.addInboundSecureHttpMessage(storage, report); + + try (MdibHistorian.HistorianResult historianResult = + historianUnderTest.episodicReportBasedHistory(sequenceId)) { + while (historianResult.next() != null) { + // query all of them + final var ignored = false; // make Checkstyle happy + } + } + } + + @SuppressWarnings({"EmptyBlock"}) + private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope report) + throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + + messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); + messageStorageUtil.addInboundSecureHttpMessage(storage, report); + + final long timestamp = System.nanoTime(); + + try (var result = historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { + while (result.next() != null) { + // query them all + final var ignored = false; // make Checkstyle happy + } + } + } + private static LocalizedText createLocalizedText( final String value, final String lang, From 62328416ba642e5575b18217c3efeb3981be9ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Wed, 21 Feb 2024 11:24:04 +0100 Subject: [PATCH 13/18] re-added unit test that was unintentionally removed. --- .../sdccc/tests/util/MdibHistorianTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 7b661b81..275fa01b 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -864,6 +864,57 @@ void testUniqueEpisodicReportBasedHistoryGoodDoNotFilterWhenReportTypeDiffers() } } + /** + * Tests if uniqueEpisodicReportBasedHistory() invalidates the Test run when encountering 2 reports that + * - have the same MdibVersion, + * - have the same ReportType, but + * - have different Contents. + * @throws JAXBException when these are thrown by the MessageStorage. + * @throws IOException when these are thrown by the MessageStorage. + * @throws ReportProcessingException when these are thrown by uniqueEpisodicReportBasedHistory(). + * @throws PreprocessingException when these are thrown by uniqueEpisodicReportBasedHistory(). + */ + @Test + void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportTypeButContentDiffers() + throws JAXBException, IOException, ReportProcessingException, PreprocessingException { + final var operator1 = mdibBuilder.buildOperatorContextState("opDescriptor1", "opState1"); + final var operator2 = mdibBuilder.buildOperatorContextState("opDescriptor2", "opState2"); + + final var contextReportMdibVersion = BigInteger.ONE; + final var contextReportStateVersion = BigInteger.TWO; + final var contextReport = buildEpisodicContextReport( + MdibBuilder.DEFAULT_SEQUENCE_ID, contextReportMdibVersion, contextReportStateVersion); + + final var firstMod = + (EpisodicContextReport) contextReport.getBody().getAny().get(0); + firstMod.getReportPart().get(0).getContextState().add(operator1); + firstMod.getReportPart().get(0).getContextState().add(operator2); + + final var contextReport2 = buildEpisodicContextReport( + MdibBuilder.DEFAULT_SEQUENCE_ID, contextReportMdibVersion, contextReportStateVersion); + final var secondMod = + (EpisodicContextReport) contextReport2.getBody().getAny().get(0); + secondMod.getReportPart().get(0).getContextState().add(operator1); + + messageStorageUtil.addInboundSecureHttpMessage( + storage, buildMdibEnvelope(MdibBuilder.DEFAULT_SEQUENCE_ID, BigInteger.ZERO)); + + messageStorageUtil.addInboundSecureHttpMessage(storage, contextReport); + messageStorageUtil.addInboundSecureHttpMessage(storage, contextReport2); // duplicate + + final var mockObserver = mock(TestRunObserver.class); + final var historian = historianFactory.createMdibHistorian(storage, mockObserver); + + try (final var history = historian.uniqueEpisodicReportBasedHistory(MdibBuilder.DEFAULT_SEQUENCE_ID)) { + history.next(); // initial state + history.next(); // state after contextReport + history.next(); // state after contextReport2 + assertNull(history.next()); // no more states as the other reports were filtered out as duplicates + } + + verify(mockObserver).invalidateTestRun(anyString()); + } + /** * Tests if applyReportOnStorage() can gracefully ignore OperationInvokedReports. * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception From ee64b6d414871ddf321dbc815cafebfdc8698162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Wed, 21 Feb 2024 14:22:55 +0100 Subject: [PATCH 14/18] changes proposed by reviewers. --- .../sdccc/tests/util/MdibHistorianTest.java | 179 +++++++++++++----- 1 file changed, 128 insertions(+), 51 deletions(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 275fa01b..e3b31864 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -19,7 +19,8 @@ import static org.mockito.Mockito.when; import com.draeger.medical.biceps.model.message.EpisodicContextReport; -import com.draeger.medical.biceps.model.message.ObjectFactory; +import com.draeger.medical.biceps.model.message.InvocationError; +import com.draeger.medical.biceps.model.message.InvocationState; import com.draeger.medical.biceps.model.participant.AlertActivation; import com.draeger.medical.biceps.model.participant.Mdib; import com.draeger.medical.biceps.model.participant.MetricAvailability; @@ -81,9 +82,7 @@ public class MdibHistorianTest { private static final String SCO_HANDLE = "sco_what?"; private static final String SET_STRING_HANDLE = "sadString"; - private Injector historianInjector; private MdibHistorianFactory historianFactory; - private Injector marshallingInjector; private MessageStorageUtil messageStorageUtil; private MessageBuilder messageBuilder; private MessageStorage storage; @@ -93,10 +92,10 @@ public class MdibHistorianTest { @BeforeEach void setUp() throws IOException { - historianInjector = TestClientUtil.createClientInjector(); + final Injector historianInjector = TestClientUtil.createClientInjector(); historianFactory = historianInjector.getInstance(MdibHistorianFactory.class); - marshallingInjector = MarshallingUtil.createMarshallingTestInjector(true); + final Injector marshallingInjector = MarshallingUtil.createMarshallingTestInjector(true); messageStorageUtil = marshallingInjector.getInstance(MessageStorageUtil.class); messageBuilder = marshallingInjector.getInstance(MessageBuilder.class); mdibBuilder = marshallingInjector.getInstance(MdibBuilder.class); @@ -940,7 +939,7 @@ void testApplyReportOnStorageRegressionCalledWithOperationInvokedReport() } /** - * Tests if applyReportOnStorage() can gracefully ignore OperationInvokedReports. + * Tests if applyReportOnStorage() can gracefully ignore SystemErrorReports. * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception * in this case. * @throws ReportProcessingException - when applyReportOnStorage() throws it @@ -966,6 +965,15 @@ void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() testApplyReportOnStorage(numericMdibVersion, sequenceId, report); } + /** + * Tests if uniqueEpisodicReportBasedHistoryUntilTimestamp() gracefully ignores OperationInvokedReports. + * NOTE: this is a regression test as uniqueEpisodicReportBasedHistoryUntilTimestamp() failed in this case + * before. + * @throws ReportProcessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() + * @throws JAXBException - when thrown by the MessageStorage + * @throws PreprocessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() + * @throws IOException - when thrown by the MessageStorage + */ @Test void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationInvokedReport() throws ReportProcessingException, JAXBException, PreprocessingException, IOException { @@ -973,22 +981,16 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationIn final BigInteger numericMdibVersion = BigInteger.ZERO; final String sequenceId = "abc"; - final var messageObjectFactory = new ObjectFactory(); - final var participantObjectFactory = new com.draeger.medical.biceps.model.participant.ObjectFactory(); - - final var report = messageObjectFactory.createOperationInvokedReport(); - final var part = messageObjectFactory.createOperationInvokedReportReportPart(); - final var invInfo = messageObjectFactory.createInvocationInfo(); - invInfo.setInvocationError(com.draeger.medical.biceps.model.message.InvocationError.OTH); - invInfo.setInvocationState(com.draeger.medical.biceps.model.message.InvocationState.FAIL); - invInfo.setTransactionId(123); + final var report = messageBuilder.buildOperationInvokedReport(sequenceId); + final var part = messageBuilder.buildOperationInvokedReportReportPart(); + final var invInfo = messageBuilder.buildInvocationInfo(123, InvocationState.FAIL); + invInfo.setInvocationError(InvocationError.OTH); part.setInvocationInfo(invInfo); part.setOperationTarget("opTarget"); part.setOperationHandleRef("opHandle"); - final var invSrc = participantObjectFactory.createInstanceIdentifier(); - final var type = participantObjectFactory.createCodedValue(); - type.setCode("33"); + final var invSrc = mdibBuilder.buildInstanceIdentifier(); + final var type = mdibBuilder.buildCodedValue("33"); type.setCodingSystem("JOCS"); type.setCodingSystemVersion("2.0"); invSrc.setType(type); @@ -1005,30 +1007,82 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationIn testUniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, soapMessage); } + /** + * Tests if uniqueEpisodicReportBasedHistoryUntilTimestamp() gracefully ignores SystemErrorReports. + * NOTE: this is a regression test as uniqueEpisodicReportBasedHistoryUntilTimestamp() failed in this case + * before. + * @throws ReportProcessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() + * @throws JAXBException - when thrown by the MessageStorage + * @throws PreprocessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() + * @throws IOException - when thrown by the MessageStorage + */ + @Test + void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithSystemErrorReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + + final String sequenceId = "abc"; + + final var part = messageBuilder.buildSystemErrorReportReportPart(mdibBuilder.buildCodedValue("97")); + final var report = messageBuilder.buildSystemErrorReport(sequenceId, List.of(part)); + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_SYSTEM_ERROR_REPORT, report); + + testUniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, soapMessage); + } + + private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope soapMessage) + throws IOException, JAXBException, ReportProcessingException, PreprocessingException { + // given + final var mockObserver = mock(TestRunObserver.class); + final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + + messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); + messageStorageUtil.addInboundSecureHttpMessage(storage, soapMessage); + + final long timestamp = System.nanoTime(); + + // when + try (var result = historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { + // then + RemoteMdibAccess lastMdib = null; + RemoteMdibAccess mdib = result.next(); + while (mdib != null) { + if (lastMdib != null) { + assertEquals(lastMdib, mdib); // nothing changed + } + lastMdib = mdib; + mdib = result.next(); + } + } + } + + /** + * Tests if episodicReportBasedHistory() gracefully ignores OperationInvokedReports. + * NOTE: this is a regression test as episodicReportBasedHistory() failed in this case before. + * @throws ReportProcessingException - when thrown by episodicReportBasedHistory() + * @throws JAXBException - when thrown by the MessageStorage + * @throws PreprocessingException - when thrown by episodicReportBasedHistory() + * @throws IOException - when thrown by the MessageStorage + */ @Test void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() throws ReportProcessingException, JAXBException, PreprocessingException, IOException { // given - final var messageObjectFactory = new ObjectFactory(); - final var participantObjectFactory = new com.draeger.medical.biceps.model.participant.ObjectFactory(); final BigInteger numericMdibVersion = BigInteger.ZERO; final String sequenceId = "abc"; - final var report = messageObjectFactory.createOperationInvokedReport(); - final var part = messageObjectFactory.createOperationInvokedReportReportPart(); - final var invSrc = participantObjectFactory.createInstanceIdentifier(); + final var report = messageBuilder.buildOperationInvokedReport(sequenceId); + final var part = messageBuilder.buildOperationInvokedReportReportPart(); + final var invSrc = mdibBuilder.buildInstanceIdentifier(); invSrc.setRootName("rootName"); invSrc.setExtensionName("extName"); - final var type = participantObjectFactory.createCodedValue(); - type.setCode("33"); + final var type = mdibBuilder.buildCodedValue("33"); type.setCodingSystem("JOCS"); type.setCodingSystemVersion("2.0"); invSrc.setType(type); part.setInvocationSource(invSrc); - final var invInfo = messageObjectFactory.createInvocationInfo(); - invInfo.setTransactionId(123); - invInfo.setInvocationError(com.draeger.medical.biceps.model.message.InvocationError.OTH); - invInfo.setInvocationState(com.draeger.medical.biceps.model.message.InvocationState.FAIL); + final var invInfo = messageBuilder.buildInvocationInfo(123, InvocationState.FAIL); + invInfo.setInvocationError(InvocationError.OTH); part.setInvocationInfo(invInfo); part.setOperationTarget("opTarget"); part.setOperationHandleRef("opHandle"); @@ -1036,46 +1090,69 @@ void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() report.getReportPart().add(part); report.setMdibVersion(numericMdibVersion); - report.setSequenceId(sequenceId); final Envelope soapMessage = messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); testEpisodicReportBasedHistory(soapMessage, sequenceId); } - @SuppressWarnings({"EmptyBlock"}) - void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) - throws ReportProcessingException, PreprocessingException, JAXBException, IOException { - final var mockObserver = mock(TestRunObserver.class); - final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); + /** + * Tests if episodicReportBasedHistory() gracefully ignores SystemErrorReports. + * NOTE: this is a regression test as episodicReportBasedHistory() failed in this case before. + * @throws ReportProcessingException - when thrown by episodicReportBasedHistory() + * @throws JAXBException - when thrown by the MessageStorage + * @throws PreprocessingException - when thrown by episodicReportBasedHistory() + * @throws IOException - when thrown by the MessageStorage + */ + @Test + void testEpisodicReportBasedHistoryRegressionWithSystemErrorReport() + throws ReportProcessingException, JAXBException, PreprocessingException, IOException { - messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); - messageStorageUtil.addInboundSecureHttpMessage(storage, report); + // given + final BigInteger numericMdibVersion = BigInteger.ZERO; + final String sequenceId = "abc"; - try (MdibHistorian.HistorianResult historianResult = - historianUnderTest.episodicReportBasedHistory(sequenceId)) { - while (historianResult.next() != null) { - // query all of them - final var ignored = false; // make Checkstyle happy - } - } + final var part = messageBuilder.buildSystemErrorReportReportPart(mdibBuilder.buildCodedValue("97")); + final var report = messageBuilder.buildSystemErrorReport(sequenceId, List.of(part)); + report.setMdibVersion(numericMdibVersion); + + final Envelope soapMessage = + messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); + + testEpisodicReportBasedHistory(soapMessage, sequenceId); } + /** + * Tests if episodicReportBasedHistory() gracefully ignores a given report. + * @param report - the report to ignore + * @param sequenceId - the sequenceId of the report + * @throws ReportProcessingException - when thrown by episodicReportBasedHistory() + * @throws JAXBException - when thrown by the MessageStorage + * @throws PreprocessingException - when thrown by episodicReportBasedHistory() + * @throws IOException - when thrown by the MessageStorage + */ @SuppressWarnings({"EmptyBlock"}) - private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope report) + void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + // given final var mockObserver = mock(TestRunObserver.class); final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); messageStorageUtil.addInboundSecureHttpMessage(storage, report); - final long timestamp = System.nanoTime(); - - try (var result = historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { - while (result.next() != null) { - // query them all - final var ignored = false; // make Checkstyle happy + // when + try (MdibHistorian.HistorianResult historianResult = + historianUnderTest.episodicReportBasedHistory(sequenceId)) { + // then + RemoteMdibAccess lastMdib = null; + RemoteMdibAccess mdib = historianResult.next(); + while (mdib != null) { + if (lastMdib != null) { + assertEquals(lastMdib, mdib); // nothing changed + } + lastMdib = mdib; + mdib = historianResult.next(); } } } From 0e080930f3851369f8428d9d49c6bbffc96471cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Wed, 21 Feb 2024 14:30:11 +0100 Subject: [PATCH 15/18] changes proposed by reviewers. --- .../com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index e3b31864..dcdc08d0 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -1131,7 +1131,6 @@ void testEpisodicReportBasedHistoryRegressionWithSystemErrorReport() * @throws PreprocessingException - when thrown by episodicReportBasedHistory() * @throws IOException - when thrown by the MessageStorage */ - @SuppressWarnings({"EmptyBlock"}) void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) throws ReportProcessingException, PreprocessingException, JAXBException, IOException { // given From 5483f7a5c7a0885fc60db95047b72ff7da54fa36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Thu, 22 Feb 2024 09:53:32 +0100 Subject: [PATCH 16/18] changes proposed by reviewers. --- .../sdccc/tests/util/MdibHistorianTest.java | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index dcdc08d0..9c1be56a 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -7,6 +7,7 @@ package com.draeger.medical.sdccc.tests.util; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -1000,7 +1001,6 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationIn part.setSourceMds("sourceMds"); report.getReportPart().add(part); report.setMdibVersion(numericMdibVersion); - report.setSequenceId(sequenceId); final Envelope soapMessage = messageBuilder.createSoapMessageWithBody(ActionConstants.ACTION_OPERATION_INVOKED_REPORT, report); @@ -1041,19 +1041,22 @@ private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String seq final long timestamp = System.nanoTime(); - // when - try (var result = historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { - // then - RemoteMdibAccess lastMdib = null; - RemoteMdibAccess mdib = result.next(); - while (mdib != null) { - if (lastMdib != null) { - assertEquals(lastMdib, mdib); // nothing changed + // when & then + assertDoesNotThrow(() -> { + try (var result = + historianUnderTest.uniqueEpisodicReportBasedHistoryUntilTimestamp(sequenceId, timestamp)) { + // then + RemoteMdibAccess lastMdib = null; + RemoteMdibAccess mdib = result.next(); + while (mdib != null) { + if (lastMdib != null) { + assertEquals(lastMdib, mdib); // nothing changed + } + lastMdib = mdib; + mdib = result.next(); } - lastMdib = mdib; - mdib = result.next(); } - } + }); } /** @@ -1140,20 +1143,22 @@ void testEpisodicReportBasedHistory(final Envelope report, final String sequence messageStorageUtil.addInboundSecureHttpMessage(storage, buildMdibEnvelope(sequenceId, BigInteger.ZERO)); messageStorageUtil.addInboundSecureHttpMessage(storage, report); - // when - try (MdibHistorian.HistorianResult historianResult = - historianUnderTest.episodicReportBasedHistory(sequenceId)) { - // then - RemoteMdibAccess lastMdib = null; - RemoteMdibAccess mdib = historianResult.next(); - while (mdib != null) { - if (lastMdib != null) { - assertEquals(lastMdib, mdib); // nothing changed + // when & then + assertDoesNotThrow(() -> { + try (MdibHistorian.HistorianResult historianResult = + historianUnderTest.episodicReportBasedHistory(sequenceId)) { + // then + RemoteMdibAccess lastMdib = null; + RemoteMdibAccess mdib = historianResult.next(); + while (mdib != null) { + if (lastMdib != null) { + assertEquals(lastMdib, mdib); // nothing changed + } + lastMdib = mdib; + mdib = historianResult.next(); } - lastMdib = mdib; - mdib = historianResult.next(); } - } + }); } private static LocalizedText createLocalizedText( @@ -1190,8 +1195,8 @@ private void testApplyReportOnStorage( when(mdibAccess.getMdibVersion()).thenReturn(mdibVersion); - // when - historianUnderTest.applyReportOnStorage(mdibAccess, report); + // when & then + assertDoesNotThrow(() -> historianUnderTest.applyReportOnStorage(mdibAccess, report)); } Envelope buildMdibEnvelope(final String sequenceId, @Nullable final BigInteger mdibVersion) { From d4e4a3f7d31aa3903aa357e66a0b92741a97ac8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Thu, 22 Feb 2024 10:01:05 +0100 Subject: [PATCH 17/18] fixed warnings. --- .../sdccc/tests/util/MdibHistorianTest.java | 37 +++++-------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 9c1be56a..48adc983 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -919,12 +919,9 @@ void testUniqueEpisodicReportBasedHistoryFailInvalidateTestRunWhenSameReportType * Tests if applyReportOnStorage() can gracefully ignore OperationInvokedReports. * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception * in this case. - * @throws ReportProcessingException - when applyReportOnStorage() throws it - * @throws PreprocessingException - when applyReportOnStorage() throws it */ @Test - void testApplyReportOnStorageRegressionCalledWithOperationInvokedReport() - throws ReportProcessingException, PreprocessingException { + void testApplyReportOnStorageRegressionCalledWithOperationInvokedReport() { // given final BigInteger numericMdibVersion = BigInteger.ZERO; @@ -943,12 +940,9 @@ void testApplyReportOnStorageRegressionCalledWithOperationInvokedReport() * Tests if applyReportOnStorage() can gracefully ignore SystemErrorReports. * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception * in this case. - * @throws ReportProcessingException - when applyReportOnStorage() throws it - * @throws PreprocessingException - when applyReportOnStorage() throws it */ @Test - void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() - throws ReportProcessingException, PreprocessingException { + void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() { // given final BigInteger numericMdibVersion = BigInteger.ZERO; @@ -970,14 +964,12 @@ void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() * Tests if uniqueEpisodicReportBasedHistoryUntilTimestamp() gracefully ignores OperationInvokedReports. * NOTE: this is a regression test as uniqueEpisodicReportBasedHistoryUntilTimestamp() failed in this case * before. - * @throws ReportProcessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() * @throws JAXBException - when thrown by the MessageStorage - * @throws PreprocessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() * @throws IOException - when thrown by the MessageStorage */ @Test void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationInvokedReport() - throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + throws JAXBException, IOException { final BigInteger numericMdibVersion = BigInteger.ZERO; final String sequenceId = "abc"; @@ -1011,14 +1003,12 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationIn * Tests if uniqueEpisodicReportBasedHistoryUntilTimestamp() gracefully ignores SystemErrorReports. * NOTE: this is a regression test as uniqueEpisodicReportBasedHistoryUntilTimestamp() failed in this case * before. - * @throws ReportProcessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() * @throws JAXBException - when thrown by the MessageStorage - * @throws PreprocessingException - when thrown by uniqueEpisodicReportBasedHistoryUntilTimestamp() * @throws IOException - when thrown by the MessageStorage */ @Test void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithSystemErrorReport() - throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + throws JAXBException, IOException { final String sequenceId = "abc"; @@ -1031,7 +1021,7 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithSystemError } private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String sequenceId, final Envelope soapMessage) - throws IOException, JAXBException, ReportProcessingException, PreprocessingException { + throws IOException, JAXBException { // given final var mockObserver = mock(TestRunObserver.class); final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); @@ -1062,14 +1052,11 @@ private void testUniqueEpisodicReportBasedHistoryUntilTimestamp(final String seq /** * Tests if episodicReportBasedHistory() gracefully ignores OperationInvokedReports. * NOTE: this is a regression test as episodicReportBasedHistory() failed in this case before. - * @throws ReportProcessingException - when thrown by episodicReportBasedHistory() * @throws JAXBException - when thrown by the MessageStorage - * @throws PreprocessingException - when thrown by episodicReportBasedHistory() * @throws IOException - when thrown by the MessageStorage */ @Test - void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() - throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() throws JAXBException, IOException { // given final BigInteger numericMdibVersion = BigInteger.ZERO; @@ -1102,14 +1089,11 @@ void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() /** * Tests if episodicReportBasedHistory() gracefully ignores SystemErrorReports. * NOTE: this is a regression test as episodicReportBasedHistory() failed in this case before. - * @throws ReportProcessingException - when thrown by episodicReportBasedHistory() * @throws JAXBException - when thrown by the MessageStorage - * @throws PreprocessingException - when thrown by episodicReportBasedHistory() * @throws IOException - when thrown by the MessageStorage */ @Test - void testEpisodicReportBasedHistoryRegressionWithSystemErrorReport() - throws ReportProcessingException, JAXBException, PreprocessingException, IOException { + void testEpisodicReportBasedHistoryRegressionWithSystemErrorReport() throws JAXBException, IOException { // given final BigInteger numericMdibVersion = BigInteger.ZERO; @@ -1129,13 +1113,11 @@ void testEpisodicReportBasedHistoryRegressionWithSystemErrorReport() * Tests if episodicReportBasedHistory() gracefully ignores a given report. * @param report - the report to ignore * @param sequenceId - the sequenceId of the report - * @throws ReportProcessingException - when thrown by episodicReportBasedHistory() * @throws JAXBException - when thrown by the MessageStorage - * @throws PreprocessingException - when thrown by episodicReportBasedHistory() * @throws IOException - when thrown by the MessageStorage */ void testEpisodicReportBasedHistory(final Envelope report, final String sequenceId) - throws ReportProcessingException, PreprocessingException, JAXBException, IOException { + throws JAXBException, IOException { // given final var mockObserver = mock(TestRunObserver.class); final var historianUnderTest = historianFactory.createMdibHistorian(storage, mockObserver); @@ -1186,8 +1168,7 @@ private static CodedValue createCodedValue( } private void testApplyReportOnStorage( - final BigInteger numericMdibVersion, final String sequenceId, final AbstractReport report) - throws PreprocessingException, ReportProcessingException { + final BigInteger numericMdibVersion, final String sequenceId, final AbstractReport report) { final RemoteMdibAccess mdibAccess = mock(RemoteMdibAccess.class); final MdibVersion mdibVersion = new MdibVersion(sequenceId, numericMdibVersion); final var mockObserver = mock(TestRunObserver.class); From b250f287254d2340fbae9ff6887657e53e593c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Thu, 22 Feb 2024 12:59:24 +0100 Subject: [PATCH 18/18] removed incorrect Notes. --- .../draeger/medical/sdccc/tests/util/MdibHistorianTest.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java index 48adc983..c6bde651 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/tests/util/MdibHistorianTest.java @@ -938,8 +938,6 @@ void testApplyReportOnStorageRegressionCalledWithOperationInvokedReport() { /** * Tests if applyReportOnStorage() can gracefully ignore SystemErrorReports. - * NOTE: this is a regression test: before it was fixed, applyReportOnStorage() did fail with an Exception - * in this case. */ @Test void testApplyReportOnStorageRegressionCalledWithSystemErrorReport() { @@ -1001,8 +999,6 @@ void testUniqueEpisodicReportBasedHistoryUntilTimestampRegressionWithOperationIn /** * Tests if uniqueEpisodicReportBasedHistoryUntilTimestamp() gracefully ignores SystemErrorReports. - * NOTE: this is a regression test as uniqueEpisodicReportBasedHistoryUntilTimestamp() failed in this case - * before. * @throws JAXBException - when thrown by the MessageStorage * @throws IOException - when thrown by the MessageStorage */ @@ -1088,7 +1084,6 @@ void testEpisodicReportBasedHistoryRegressionWithOperationInvokedReport() throws /** * Tests if episodicReportBasedHistory() gracefully ignores SystemErrorReports. - * NOTE: this is a regression test as episodicReportBasedHistory() failed in this case before. * @throws JAXBException - when thrown by the MessageStorage * @throws IOException - when thrown by the MessageStorage */