Skip to content

Commit

Permalink
ReportProcessor.processReport() is now only called with ReportTypes t…
Browse files Browse the repository at this point in the history
…hat are supported.
  • Loading branch information
ben-Draeger committed Feb 13, 2024
1 parent 5150208 commit 6f7cb31
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6f7cb31

Please sign in to comment.