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] 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);