diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAlertStateTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAlertStateTest.java index e9d5aed2..aff6e667 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAlertStateTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAlertStateTest.java @@ -76,61 +76,45 @@ void testRequirementR00290() throws NoTestData, IOException { messageStorage, getInjector().getInstance(TestRunObserver.class)); final var presenceOnSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess mdibAccess = history.next(); - - while (mdibAccess != null) { - final var alertConditionStates = mdibAccess.getStatesByType(AlertConditionState.class); - for (var alertConditionState : alertConditionStates) { - final var isPresence = ImpliedValueUtil.isPresence(alertConditionState); - if (isPresence) { - presenceOnSeen.incrementAndGet(); - final var descriptorHandle = alertConditionState.getDescriptorHandle(); - final var alertSystemStateHandle = mdibAccess - .getEntity(descriptorHandle) - .orElseThrow() - .getParent() - .orElseThrow(); - final var alertSystemState = mdibAccess - .getState(alertSystemStateHandle, AlertSystemState.class) - .orElseThrow(); - - assertEquals( - AlertActivation.ON, - alertConditionState.getActivationState(), - String.format( - "AlertConditionState/@Presence is true, for AlertConditionState with handle %s." - + "The AlertConditionState/@Activation state should be 'On' but is '%s'", - descriptorHandle, - alertConditionState - .getActivationState() - .value())); - assertEquals( - AlertActivation.ON, - alertSystemState.getActivationState(), - String.format( - "AlertConditionState/@Presence is true, for AlertConditionState with handle %s." - + " The AlertSystemState/@Activation " - + "state for AlertSystemState with handle %s" - + " should be 'On' but is '%s'", - descriptorHandle, - alertSystemStateHandle, - alertSystemState - .getActivationState() - .value())); - } - } - mdibAccess = history.next(); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); + mdibHistorian.processAllRemoteMdibAccess(mdibAccess -> { + final var alertConditionStates = mdibAccess.getStatesByType(AlertConditionState.class); + for (var alertConditionState : alertConditionStates) { + final var isPresence = ImpliedValueUtil.isPresence(alertConditionState); + if (isPresence) { + presenceOnSeen.incrementAndGet(); + final var descriptorHandle = alertConditionState.getDescriptorHandle(); + final var alertSystemStateHandle = mdibAccess + .getEntity(descriptorHandle) + .orElseThrow() + .getParent() + .orElseThrow(); + final var alertSystemState = mdibAccess + .getState(alertSystemStateHandle, AlertSystemState.class) + .orElseThrow(); + + assertEquals( + AlertActivation.ON, + alertConditionState.getActivationState(), + String.format( + "AlertConditionState/@Presence is true, for AlertConditionState with handle %s." + + "The AlertConditionState/@Activation state should be 'On' but is '%s'", + descriptorHandle, + alertConditionState.getActivationState().value())); + assertEquals( + AlertActivation.ON, + alertSystemState.getActivationState(), + String.format( + "AlertConditionState/@Presence is true, for AlertConditionState with handle %s." + + " The AlertSystemState/@Activation " + + "state for AlertSystemState with handle %s" + + " should be 'On' but is '%s'", + descriptorHandle, + alertSystemStateHandle, + alertSystemState.getActivationState().value())); } - }); - } + } + }); + assertTestData(presenceOnSeen.get(), NO_PRESENCE_TRUE); } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAnnexAlertTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAnnexAlertTest.java index 216bae85..4f2f3d5f 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAnnexAlertTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantAnnexAlertTest.java @@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import com.draeger.medical.sdccc.configuration.EnabledTestConfig; import com.draeger.medical.sdccc.manipulation.precondition.impl.ManipulationPreconditions; @@ -20,7 +19,6 @@ import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; import com.draeger.medical.sdccc.tests.util.ImpliedValueUtil; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.TestRunObserver; @@ -32,10 +30,8 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Stream; 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.participant.AlertActivation; import org.somda.sdc.biceps.model.participant.AlertSignalDescriptor; @@ -44,7 +40,6 @@ import org.somda.sdc.biceps.model.participant.AlertSignalState; import org.somda.sdc.biceps.model.participant.AlertSystemState; import org.somda.sdc.biceps.model.participant.SystemSignalActivation; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * BICEPS Annex B alert tests (B.88 - B.128). @@ -76,64 +71,49 @@ void testRequirementB128() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - RemoteMdibAccess first = history.next(); - - while (first != null) { - final var alertSystemStates = first.getStatesByType(AlertSystemState.class); - - for (var alertSystemState : alertSystemStates) { - final var manifestationAndAlertActivationsMap = - createSystemSignalActivationMap(alertSystemState.getSystemSignalActivation()); - - final var childAlertSignals = - getChildAlertSignals(first, alertSystemState.getDescriptorHandle()); - - for (var manifestationAndState : manifestationAndAlertActivationsMap.entrySet()) { - final var currentActivationStates = manifestationAndState.getValue(); - final var onSeen = new AtomicBoolean(false); - final var allPsd = new AtomicInteger(0); - final var allOff = new AtomicInteger(0); - final var childrenWithSameManifestation = getChildrenWithSameManifestation( - childAlertSignals, manifestationAndState.getKey()); - for (var entry : childrenWithSameManifestation) { - acceptableSequenceSeen.incrementAndGet(); - final var alertSignalActivationState = entry.getActivationState(); - for (var currentActivationState : currentActivationStates) { - verifyAlertSignalActivationState( - currentActivationState, - alertSignalActivationState, - entry.getDescriptorHandle()); - } - - switch (alertSignalActivationState) { - case ON -> onSeen.set(true); - case PSD -> allPsd.incrementAndGet(); - case OFF -> allOff.incrementAndGet(); - default -> {} - } - } - if (onSeen.get()) { - checkActivationState(manifestationAndState.getValue(), AlertActivation.ON); - } else if (!childrenWithSameManifestation.isEmpty() - && allPsd.get() == childrenWithSameManifestation.size()) { - checkActivationState(manifestationAndState.getValue(), AlertActivation.PSD); - } else if (!childrenWithSameManifestation.isEmpty() - && allOff.get() == childrenWithSameManifestation.size()) { - checkActivationState(manifestationAndState.getValue(), AlertActivation.OFF); - } - } + mdibHistorian.processAllRemoteMdibAccess(first -> { + final var alertSystemStates = first.getStatesByType(AlertSystemState.class); + + for (var alertSystemState : alertSystemStates) { + final var manifestationAndAlertActivationsMap = + createSystemSignalActivationMap(alertSystemState.getSystemSignalActivation()); + + final var childAlertSignals = getChildAlertSignals(first, alertSystemState.getDescriptorHandle()); + + for (var manifestationAndState : manifestationAndAlertActivationsMap.entrySet()) { + final var currentActivationStates = manifestationAndState.getValue(); + final var onSeen = new AtomicBoolean(false); + final var allPsd = new AtomicInteger(0); + final var allOff = new AtomicInteger(0); + final var childrenWithSameManifestation = + getChildrenWithSameManifestation(childAlertSignals, manifestationAndState.getKey()); + for (var entry : childrenWithSameManifestation) { + acceptableSequenceSeen.incrementAndGet(); + final var alertSignalActivationState = entry.getActivationState(); + for (var currentActivationState : currentActivationStates) { + verifyAlertSignalActivationState( + currentActivationState, alertSignalActivationState, entry.getDescriptorHandle()); } - first = history.next(); + + switch (alertSignalActivationState) { + case ON -> onSeen.set(true); + case PSD -> allPsd.incrementAndGet(); + case OFF -> allOff.incrementAndGet(); + default -> {} + } + } + if (onSeen.get()) { + checkActivationState(manifestationAndState.getValue(), AlertActivation.ON); + } else if (!childrenWithSameManifestation.isEmpty() + && allPsd.get() == childrenWithSameManifestation.size()) { + checkActivationState(manifestationAndState.getValue(), AlertActivation.PSD); + } else if (!childrenWithSameManifestation.isEmpty() + && allOff.get() == childrenWithSameManifestation.size()) { + checkActivationState(manifestationAndState.getValue(), AlertActivation.OFF); } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); } - }); - } + } + }); assertTestData(acceptableSequenceSeen.get(), "No acceptable sequence seen, test failed"); } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantDeviceComponentStateTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantDeviceComponentStateTest.java index 9663868e..c6c6587e 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantDeviceComponentStateTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantDeviceComponentStateTest.java @@ -8,7 +8,6 @@ package com.draeger.medical.sdccc.tests.biceps.invariant; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; import com.draeger.medical.sdccc.configuration.EnabledTestConfig; import com.draeger.medical.sdccc.manipulation.precondition.impl.ManipulationPreconditions; @@ -19,7 +18,6 @@ import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; import com.draeger.medical.sdccc.tests.util.ImpliedValueUtil; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.TestRunObserver; @@ -27,12 +25,10 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.somda.sdc.biceps.common.MdibEntity; -import org.somda.sdc.biceps.common.storage.PreprocessingException; import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.participant.AbstractAlertDescriptor; import org.somda.sdc.biceps.model.participant.AbstractAlertState; @@ -46,7 +42,6 @@ import org.somda.sdc.biceps.model.participant.AlertActivation; import org.somda.sdc.biceps.model.participant.ComponentActivation; import org.somda.sdc.biceps.model.participant.OperatingMode; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * BICEPS tests for chapter 5.4.6 . @@ -81,94 +76,77 @@ void testRequirementR00250() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess remoteMdibAccess = history.next(); - - while (remoteMdibAccess != null) { - final var entities = - remoteMdibAccess.findEntitiesByType(AbstractDeviceComponentDescriptor.class); - - for (var entity : entities) { - if (ImpliedValueUtil.getComponentActivation( - entity.getFirstState(AbstractDeviceComponentState.class) - .orElseThrow()) - == ComponentActivation.OFF) { - - final var abstractDeviceComponentDescendants = getDescendantsByType( - remoteMdibAccess, entity.getHandle(), AbstractDeviceComponentDescriptor.class); - for (var descendant : abstractDeviceComponentDescendants) { - final var descendantState = descendant - .getFirstState(AbstractDeviceComponentState.class) - .orElseThrow(); - assertEquals( - ComponentActivation.OFF, - ImpliedValueUtil.getComponentActivation(descendantState), - String.format( - "The ComponentActivation OFF was not " - + "set for the descendant with handle %s", - descendantState.getDescriptorHandle())); - } - - final var abstractAlertDescendants = getDescendantsByType( - remoteMdibAccess, entity.getHandle(), AbstractAlertDescriptor.class); - for (var descendant : abstractAlertDescendants) { - final var descendantState = descendant - .getFirstState(AbstractAlertState.class) - .orElseThrow(); - assertEquals( - AlertActivation.OFF, - descendantState.getActivationState(), - String.format( - "The AlertActivation OFF was not " - + "set for the descendant with handle %s", - descendantState.getDescriptorHandle())); - } - - final var abstractMetricDescendants = getDescendantsByType( - remoteMdibAccess, entity.getHandle(), AbstractMetricDescriptor.class); - for (var descendant : abstractMetricDescendants) { - final var descendantState = descendant - .getFirstState(AbstractMetricState.class) - .orElseThrow(); - assertEquals( - ComponentActivation.OFF, - ImpliedValueUtil.getMetricActivation(descendantState), - String.format( - "The ComponentActivation OFF was not " - + "set for the descendant with handle %s", - descendantState.getDescriptorHandle())); - } - - final var abstractOperationDescendants = getDescendantsByType( - remoteMdibAccess, entity.getHandle(), AbstractOperationDescriptor.class); - for (var descendant : abstractOperationDescendants) { - final var descendantState = descendant - .getFirstState(AbstractOperationState.class) - .orElseThrow(); - assertEquals( - OperatingMode.NA, - descendantState.getOperatingMode(), - String.format( - "The OperatingMode NA was not " - + "set for the descendant with handle %s", - descendantState.getDescriptorHandle())); - } - - acceptableSequenceSeen.incrementAndGet(); - } - } - - remoteMdibAccess = history.next(); + mdibHistorian.processAllRemoteMdibAccess(remoteMdibAccess -> { + final var entities = remoteMdibAccess.findEntitiesByType(AbstractDeviceComponentDescriptor.class); + + for (var entity : entities) { + if (ImpliedValueUtil.getComponentActivation(entity.getFirstState(AbstractDeviceComponentState.class) + .orElseThrow()) + == ComponentActivation.OFF) { + + final var abstractDeviceComponentDescendants = getDescendantsByType( + remoteMdibAccess, entity.getHandle(), AbstractDeviceComponentDescriptor.class); + for (var descendant : abstractDeviceComponentDescendants) { + final var descendantState = descendant + .getFirstState(AbstractDeviceComponentState.class) + .orElseThrow(); + assertEquals( + ComponentActivation.OFF, + ImpliedValueUtil.getComponentActivation(descendantState), + String.format( + "The ComponentActivation OFF was not " + + "set for the descendant with handle %s", + descendantState.getDescriptorHandle())); } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); + + final var abstractAlertDescendants = + getDescendantsByType(remoteMdibAccess, entity.getHandle(), AbstractAlertDescriptor.class); + for (var descendant : abstractAlertDescendants) { + final var descendantState = descendant + .getFirstState(AbstractAlertState.class) + .orElseThrow(); + assertEquals( + AlertActivation.OFF, + descendantState.getActivationState(), + String.format( + "The AlertActivation OFF was not " + "set for the descendant with handle %s", + descendantState.getDescriptorHandle())); + } + + final var abstractMetricDescendants = + getDescendantsByType(remoteMdibAccess, entity.getHandle(), AbstractMetricDescriptor.class); + for (var descendant : abstractMetricDescendants) { + final var descendantState = descendant + .getFirstState(AbstractMetricState.class) + .orElseThrow(); + assertEquals( + ComponentActivation.OFF, + ImpliedValueUtil.getMetricActivation(descendantState), + String.format( + "The ComponentActivation OFF was not " + + "set for the descendant with handle %s", + descendantState.getDescriptorHandle())); + } + + final var abstractOperationDescendants = getDescendantsByType( + remoteMdibAccess, entity.getHandle(), AbstractOperationDescriptor.class); + for (var descendant : abstractOperationDescendants) { + final var descendantState = descendant + .getFirstState(AbstractOperationState.class) + .orElseThrow(); + assertEquals( + OperatingMode.NA, + descendantState.getOperatingMode(), + String.format( + "The OperatingMode NA was not " + "set for the descendant with handle %s", + descendantState.getDescriptorHandle())); + } + + acceptableSequenceSeen.incrementAndGet(); } - }); - } + } + }); + assertTestData( acceptableSequenceSeen.get(), "No pm:AbstractDeviceComponentState/@ActivationState had the value OFF."); } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMultiStateTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMultiStateTest.java index e307b31b..74419f67 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMultiStateTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMultiStateTest.java @@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import com.draeger.medical.sdccc.configuration.EnabledTestConfig; import com.draeger.medical.sdccc.manipulation.precondition.impl.ConditionalPreconditions; @@ -20,7 +19,6 @@ import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; import com.draeger.medical.sdccc.tests.util.ImpliedValueUtil; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.TestRunObserver; @@ -37,7 +35,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.somda.sdc.biceps.common.MdibEntity; -import org.somda.sdc.biceps.common.storage.PreprocessingException; import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.participant.AbstractContextDescriptor; import org.somda.sdc.biceps.model.participant.AbstractContextState; @@ -50,7 +47,6 @@ import org.somda.sdc.biceps.model.participant.OperatorContextDescriptor; import org.somda.sdc.biceps.model.participant.PatientContextDescriptor; import org.somda.sdc.biceps.model.participant.WorkflowContextDescriptor; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * BICEPS participant model multistate tests (ch. 5.4.3). @@ -85,45 +81,42 @@ void setUp() { simplePreconditions = {ConditionalPreconditions.AllKindsOfContextStatesAssociatedPrecondition.class}) void testRequirement0097() throws NoTestData, IOException { - final var descriptorHandles = new HashSet(); - final var multiStateHandles = new HashSet(); - final var mdibHistorian = mdibHistorianFactory.createMdibHistorian( messageStorage, getInjector().getInstance(TestRunObserver.class)); final var seenAcceptableSequence = new AtomicBoolean(false); try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - RemoteMdibAccess first = history.next(); - final var seenMultiStatesMap = initMultiStateMap(first, CONTEXT_DESCRIPTOR_CLASSES); - while (first != null) { - final var entities = first.findEntitiesByType(AbstractDescriptor.class); - final var states = first.findContextStatesByType(AbstractContextState.class); - addAllDescriptorHandles(entities, descriptorHandles); - if (states.isEmpty()) { - first = history.next(); - continue; - } - addAllMultiStateHandles(states, multiStateHandles, seenMultiStatesMap); - areMultiStatesHandlesUnique(states); - areHandlesDisjunctive(descriptorHandles, multiStateHandles, first.getMdibVersion()); - first = history.next(); - } - var acceptableSequence = true; - for (var value : seenMultiStatesMap.values()) { - acceptableSequence &= value.size() > 1; - } - - if (acceptableSequence) { - seenAcceptableSequence.set(acceptableSequence); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); + final var descriptorHandles = new HashSet(); + final var multiStateHandles = new HashSet(); + final var seenMultiStatesMap = new HashMap>(); + final var firstAccess = new AtomicBoolean(true); + + mdibHistorian.processRemoteMdibAccessForSequence( + mdibAccess -> { + if (firstAccess.getAndSet(false)) { + seenMultiStatesMap.putAll(initMultiStateMap(mdibAccess, CONTEXT_DESCRIPTOR_CLASSES)); + } + final var entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class); + final var states = mdibAccess.findContextStatesByType(AbstractContextState.class); + addAllDescriptorHandles(entities, descriptorHandles); + if (!states.isEmpty()) { + addAllMultiStateHandles(states, multiStateHandles, seenMultiStatesMap); + areMultiStatesHandlesUnique(states); + areHandlesDisjunctive( + descriptorHandles, multiStateHandles, mdibAccess.getMdibVersion()); + } + }, + sequenceId); + + var acceptableSequence = true; + for (var value : seenMultiStatesMap.values()) { + acceptableSequence &= value.size() > 1; + } + + if (acceptableSequence) { + seenAcceptableSequence.set(true); } - descriptorHandles.clear(); - multiStateHandles.clear(); }); } assertTestData( @@ -161,7 +154,7 @@ private void addAllMultiStateHandles( multiStateHandles.add(state.getHandle()); if (ImpliedValueUtil.getContextAssociation(state) == ContextAssociation.ASSOC) { seenMultiStatesMap - .computeIfAbsent(state.getDescriptorHandle(), stateClass -> new HashSet()) + .computeIfAbsent(state.getDescriptorHandle(), stateClass -> new HashSet<>()) .add(state.getHandle()); } }); diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelAnnexTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelAnnexTest.java index a26951ee..1c11cb66 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelAnnexTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelAnnexTest.java @@ -185,36 +185,24 @@ void testRequirementB402() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - RemoteMdibAccess first = history.next(); - - while (first != null) { - final var vmdEntities = first.findEntitiesByType(VmdDescriptor.class); - for (var vmd : vmdEntities) { - final var descriptor = vmd.getDescriptor(VmdDescriptor.class); - final var state = vmd.getFirstState(VmdState.class); - final var approvedJurisdiction = - descriptor.orElseThrow().getApprovedJurisdictions(); - if (approvedJurisdiction == null) { - acceptableSequenceSeen.incrementAndGet(); - assertNull( - state.orElseThrow().getOperatingJurisdiction(), - String.format( - "OperatingJurisdiction should not be present, because ApprovedJurisdiction is not" - + " present for vmd with handle %s", - descriptor.orElseThrow().getHandle())); - } - } - first = history.next(); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); + mdibHistorian.processAllRemoteMdibAccess(first -> { + final var vmdEntities = first.findEntitiesByType(VmdDescriptor.class); + for (var vmd : vmdEntities) { + final var descriptor = vmd.getDescriptor(VmdDescriptor.class); + final var state = vmd.getFirstState(VmdState.class); + final var approvedJurisdiction = descriptor.orElseThrow().getApprovedJurisdictions(); + if (approvedJurisdiction == null) { + acceptableSequenceSeen.incrementAndGet(); + assertNull( + state.orElseThrow().getOperatingJurisdiction(), + String.format( + "OperatingJurisdiction should not be present, because ApprovedJurisdiction is not" + + " present for vmd with handle %s", + descriptor.orElseThrow().getHandle())); } - }); - } + } + }); + assertTestData( acceptableSequenceSeen.get(), "No vmd descriptor without approved jurisdiction seen," + " during test run, test failed."); diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelContextStateTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelContextStateTest.java index b40f5305..2a0190b3 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelContextStateTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelContextStateTest.java @@ -8,7 +8,6 @@ package com.draeger.medical.sdccc.tests.biceps.invariant; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; import com.draeger.medical.sdccc.configuration.EnabledTestConfig; import com.draeger.medical.sdccc.manipulation.precondition.impl.ManipulationPreconditions; @@ -19,7 +18,6 @@ import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; import com.draeger.medical.sdccc.tests.util.ImpliedValueUtil; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.TestRunObserver; @@ -33,15 +31,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.somda.sdc.biceps.common.MdibEntity; -import org.somda.sdc.biceps.common.storage.PreprocessingException; -import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.participant.AbstractMultiState; import org.somda.sdc.biceps.model.participant.ContextAssociation; import org.somda.sdc.biceps.model.participant.LocationContextDescriptor; import org.somda.sdc.biceps.model.participant.LocationContextState; import org.somda.sdc.biceps.model.participant.PatientContextDescriptor; import org.somda.sdc.biceps.model.participant.PatientContextState; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * BICEPS participant model context state tests (ch. 5.4.4). @@ -75,53 +70,47 @@ void testRequirementR0124() throws NoTestData, IOException { try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { sequenceIds.forEach(sequenceId -> { final var associationCounterMap = HashMultimap.create(); - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess mdibAccess = history.next(); - while (mdibAccess != null) { - - final var patientContextEntities = - mdibAccess.findEntitiesByType(PatientContextDescriptor.class); - - for (MdibEntity patientContextEntity : patientContextEntities) { - - final var associatedPatients = - patientContextEntity.getStates(PatientContextState.class).stream() - .filter(state -> ContextAssociation.ASSOC.equals( - ImpliedValueUtil.getContextAssociation(state))) - .toList(); - - if (!associatedPatients.isEmpty()) { - final var associatedStateHandles = associatedPatients.stream() - .map(AbstractMultiState::getHandle) - .collect(Collectors.toList()); - - assertEquals( - 1, - associatedPatients.size(), - String.format( - "More than one PatientContextState was associated for the" - + " handle %s, associated state handles were %s, mdib version %s", - patientContextEntity.getHandle(), - String.join(", ", associatedStateHandles), - mdibAccess.getMdibVersion())); - - // only add handles if the check above passed - LOG.debug( - "Adding desc {} state {}", - patientContextEntity.getHandle(), - associatedPatients.get(0).getHandle()); - associationCounterMap.put( - patientContextEntity.getHandle(), - associatedPatients.get(0).getHandle()); + mdibHistorian.processRemoteMdibAccessForSequence( + mdibAccess -> { + final var patientContextEntities = + mdibAccess.findEntitiesByType(PatientContextDescriptor.class); + + for (MdibEntity patientContextEntity : patientContextEntities) { + + final var associatedPatients = + patientContextEntity.getStates(PatientContextState.class).stream() + .filter(state -> ContextAssociation.ASSOC.equals( + ImpliedValueUtil.getContextAssociation(state))) + .toList(); + + if (!associatedPatients.isEmpty()) { + final var associatedStateHandles = associatedPatients.stream() + .map(AbstractMultiState::getHandle) + .collect(Collectors.toList()); + + assertEquals( + 1, + associatedPatients.size(), + String.format( + "More than one PatientContextState was associated for the" + + " handle %s, associated state handles were %s, mdib version %s", + patientContextEntity.getHandle(), + String.join(", ", associatedStateHandles), + mdibAccess.getMdibVersion())); + + // only add handles if the check above passed + LOG.debug( + "Adding desc {} state {}", + patientContextEntity.getHandle(), + associatedPatients.get(0).getHandle()); + associationCounterMap.put( + patientContextEntity.getHandle(), + associatedPatients.get(0).getHandle()); + } } - } - mdibAccess = history.next(); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); - } + }, + sequenceId); + // determine if any context descriptor had 2+ associated states final var hadSufficientContexts = associationCounterMap.asMap().values().stream().anyMatch(values -> values.size() >= 2); @@ -160,53 +149,46 @@ void testRequirementR0133() throws NoTestData, IOException { try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { sequenceIds.forEach(sequenceId -> { final var associationCounterMap = HashMultimap.create(); - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess mdibAccess = history.next(); - while (mdibAccess != null) { - - final var locationContextEntities = - mdibAccess.findEntitiesByType(LocationContextDescriptor.class); - - for (MdibEntity locationContextEntity : locationContextEntities) { - - final var associatedLocations = - locationContextEntity.getStates(LocationContextState.class).stream() - .filter(state -> ContextAssociation.ASSOC.equals( - ImpliedValueUtil.getContextAssociation(state))) - .toList(); - - if (!associatedLocations.isEmpty()) { - final var associatedStateHandles = associatedLocations.stream() - .map(AbstractMultiState::getHandle) - .collect(Collectors.toList()); - - assertEquals( - 1, - associatedLocations.size(), - String.format( - "More than one LocationContextState was associated for the" - + " handle %s, associated state handles were %s, mdib version %s", - locationContextEntity.getHandle(), - String.join(", ", associatedStateHandles), - mdibAccess.getMdibVersion())); - - // only add handles if the check above passed - LOG.debug( - "Adding desc {} state {}", - locationContextEntity.getHandle(), - associatedLocations.get(0).getHandle()); - associationCounterMap.put( - locationContextEntity.getHandle(), - associatedLocations.get(0).getHandle()); + mdibHistorian.processRemoteMdibAccessForSequence( + mdibAccess -> { + final var locationContextEntities = + mdibAccess.findEntitiesByType(LocationContextDescriptor.class); + + for (MdibEntity locationContextEntity : locationContextEntities) { + + final var associatedLocations = + locationContextEntity.getStates(LocationContextState.class).stream() + .filter(state -> ContextAssociation.ASSOC.equals( + ImpliedValueUtil.getContextAssociation(state))) + .toList(); + + if (!associatedLocations.isEmpty()) { + final var associatedStateHandles = associatedLocations.stream() + .map(AbstractMultiState::getHandle) + .collect(Collectors.toList()); + + assertEquals( + 1, + associatedLocations.size(), + String.format( + "More than one LocationContextState was associated for the" + + " handle %s, associated state handles were %s, mdib version %s", + locationContextEntity.getHandle(), + String.join(", ", associatedStateHandles), + mdibAccess.getMdibVersion())); + + // only add handles if the check above passed + LOG.debug( + "Adding desc {} state {}", + locationContextEntity.getHandle(), + associatedLocations.get(0).getHandle()); + associationCounterMap.put( + locationContextEntity.getHandle(), + associatedLocations.get(0).getHandle()); + } } - } - mdibAccess = history.next(); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); - } + }, + sequenceId); // determine if any context descriptor had 2+ associated states final var hadSufficientContexts = !associationCounterMap.isEmpty() && associationCounterMap.asMap().values().stream().allMatch(values -> values.size() >= 2); diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelHandleTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelHandleTest.java index e25a2217..deefc023 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelHandleTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelHandleTest.java @@ -22,7 +22,6 @@ import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; import com.draeger.medical.sdccc.tests.util.ImpliedValueUtil; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.Constants; @@ -36,15 +35,12 @@ import java.util.Objects; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Stream; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.somda.sdc.biceps.common.MdibEntity; -import org.somda.sdc.biceps.common.storage.PreprocessingException; -import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.message.DescriptionModificationReport; import org.somda.sdc.biceps.model.message.DescriptionModificationType; import org.somda.sdc.biceps.model.participant.AbstractContextState; @@ -54,7 +50,6 @@ import org.somda.sdc.dpws.soap.SoapMessage; import org.somda.sdc.dpws.soap.SoapUtil; import org.somda.sdc.dpws.soap.exception.MarshallingException; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * BICEPS participant model handle tests (ch. 5.2.2). @@ -93,45 +88,33 @@ void testRequirementR0007() throws NoTestData, IOException { final AtomicInteger handlesSeen = new AtomicInteger(); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - var current = history.next(); - while (current != null) { - final var allEntities = current.findEntitiesByType(AbstractDescriptor.class); - - final List entityHandles = - allEntities.stream().map(MdibEntity::getHandle).toList(); - final HashSet allHandles = new HashSet<>(); - for (var handle : entityHandles) { - assertFalse( - allHandles.contains(handle), - "Handle '" + handle + "' is not unique in mdib version " + current.getMdibVersion() - + "."); - allHandles.add(handle); - } + mdibHistorian.processAllRemoteMdibAccess(current -> { + final var allEntities = current.findEntitiesByType(AbstractDescriptor.class); + + final List entityHandles = + allEntities.stream().map(MdibEntity::getHandle).toList(); + final HashSet allHandles = new HashSet<>(); + for (var handle : entityHandles) { + assertFalse( + allHandles.contains(handle), + "Handle '" + handle + "' is not unique in mdib version " + current.getMdibVersion() + "."); + allHandles.add(handle); + } + + final List contextStates = + current.findContextStatesByType(AbstractContextState.class); + final List contextStateHandles = + contextStates.stream().map(AbstractMultiState::getHandle).toList(); + for (var cSHandle : contextStateHandles) { + assertFalse( + allHandles.contains(cSHandle), + "contextState handle '" + cSHandle + "' is not unique in Mdib version " + + current.getMdibVersion() + "."); + allHandles.add(cSHandle); + } + handlesSeen.addAndGet(allHandles.size()); + }); - final List contextStates = - current.findContextStatesByType(AbstractContextState.class); - final List contextStateHandles = contextStates.stream() - .map(AbstractMultiState::getHandle) - .toList(); - for (var cSHandle : contextStateHandles) { - assertFalse( - allHandles.contains(cSHandle), - "contextState handle '" + cSHandle + "' is not unique in Mdib version " - + current.getMdibVersion() + "."); - allHandles.add(cSHandle); - } - handlesSeen.addAndGet(allHandles.size()); - current = history.next(); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); - } - }); - } assertTestData(handlesSeen.get(), "No Data to perform test on"); } @@ -148,41 +131,30 @@ void testRequirementR0105() throws NoTestData, IOException { final var handlesSeen = new HashSet(); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess first = history.next(); - while (first != null) { - final var mdibVersion = first.getMdibVersion(); - final var allEntities = first.findEntitiesByType(AbstractDescriptor.class); - for (MdibEntity entity : allEntities) { - // descriptor handle - assertTrue( - isWithinPermittedASCIIRange(entity.getHandle()), - String.format( - "Invalid descriptor handle %s found in mdib version %s", - entity.getHandle(), mdibVersion)); - handlesSeen.add(entity.getHandle()); + mdibHistorian.processAllRemoteMdibAccess(first -> { + final var mdibVersion = first.getMdibVersion(); + final var allEntities = first.findEntitiesByType(AbstractDescriptor.class); + for (MdibEntity entity : allEntities) { + // descriptor handle + assertTrue( + isWithinPermittedASCIIRange(entity.getHandle()), + String.format( + "Invalid descriptor handle %s found in mdib version %s", + entity.getHandle(), mdibVersion)); + handlesSeen.add(entity.getHandle()); + + // state handles + entity.doIfMultiState(states -> states.forEach(state -> { + handlesSeen.add(state.getHandle()); + assertTrue( + isWithinPermittedASCIIRange(state.getHandle()), + String.format( + "Invalid multi state handle %s found in mdib version %s", + state.getHandle(), mdibVersion)); + })); + } + }); - // state handles - entity.doIfMultiState(states -> states.forEach(state -> { - handlesSeen.add(state.getHandle()); - assertTrue( - isWithinPermittedASCIIRange(state.getHandle()), - String.format( - "Invalid multi state handle %s found in mdib version %s", - state.getHandle(), mdibVersion)); - })); - } - first = history.next(); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); - } - }); - } assertTestData(handlesSeen, "No Data to perform test on"); } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelMappingTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelMappingTest.java index a9f79fb3..1f260314 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelMappingTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelMappingTest.java @@ -8,7 +8,6 @@ package com.draeger.medical.sdccc.tests.biceps.invariant; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; import com.draeger.medical.sdccc.configuration.EnabledTestConfig; import com.draeger.medical.sdccc.messages.MessageStorage; @@ -16,19 +15,14 @@ import com.draeger.medical.sdccc.tests.InjectorTestBase; import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.TestRunObserver; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Stream; 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.participant.AbstractState; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * BICEPS participant model state mapping tests (ch. 5.4.2). @@ -60,37 +54,24 @@ void testRequirementR0023() throws NoTestData, IOException { final var statesSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { + mdibHistorian.processAllRemoteMdibAccess(first -> { + final var allStates = first.getStatesByType(AbstractState.class); + for (var state : allStates) { + statesSeen.incrementAndGet(); + final var descriptor = + first.getDescriptor(state.getDescriptorHandle()).orElseThrow(); + final var stateName = state.getClass().getSimpleName().replaceAll(STATE_SUFFIX, ""); + assertEquals( + String.format(DESCRIPTOR_SUFFIX, stateName), + descriptor.getClass().getSimpleName(), + String.format( + "Non matching naming scheme for handle: %s." + " State is %s and Descriptor is %s.", + state.getDescriptorHandle(), + state.getClass().getSimpleName(), + descriptor.getClass().getSimpleName())); + } + }); - RemoteMdibAccess first = history.next(); - while (first != null) { - final var allStates = first.getStatesByType(AbstractState.class); - for (var state : allStates) { - statesSeen.incrementAndGet(); - final var descriptor = first.getDescriptor(state.getDescriptorHandle()) - .orElseThrow(); - final var stateName = - state.getClass().getSimpleName().replaceAll(STATE_SUFFIX, ""); - assertEquals( - String.format(DESCRIPTOR_SUFFIX, stateName), - descriptor.getClass().getSimpleName(), - String.format( - "Non matching naming scheme for handle: %s." - + " State is %s and Descriptor is %s.", - state.getDescriptorHandle(), - state.getClass().getSimpleName(), - descriptor.getClass().getSimpleName())); - } - first = history.next(); - } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); - } - }); - } assertTestData(statesSeen.get(), "No Data to perform test on"); } } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelVersioningTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelVersioningTest.java index 983f66e5..d8a03712 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelVersioningTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantParticipantModelVersioningTest.java @@ -91,60 +91,49 @@ void testRequirementR0033() throws NoTestData, IOException { try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { sequenceIds.forEach(sequenceId -> { final var impliedValueMap = new InitialImpliedValue(); - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId); - final MdibHistorian.HistorianResult historyNext = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - // skip the first entry so that history and historyNext are off by one entry - final var skippedElement = historyNext.next(); - assertTestData(skippedElement != null, "Not enough input to compare mdib revisions"); - - RemoteMdibAccess first = history.next(); - RemoteMdibAccess second = historyNext.next(); - while (second != null) { - final var currentDescriptors = first.findEntitiesByType(AbstractDescriptor.class); - for (MdibEntity entity : currentDescriptors) { - final var descriptor = entity.getDescriptor(AbstractDescriptor.class) - .orElseThrow(); - final var nextEntityOpt = second.getEntity(descriptor.getHandle()); - if (nextEntityOpt.isEmpty()) { - continue; - } - final var nextEntity = nextEntityOpt.orElseThrow(); - final var nextDescriptor = nextEntity - .getDescriptor(AbstractDescriptor.class) - .orElseThrow(); + mdibHistorian.processAllConsecutivePairsForSequenceId( + (first, second) -> { + final var currentDescriptors = first.findEntitiesByType(AbstractDescriptor.class); + for (MdibEntity entity : currentDescriptors) { + final var descriptor = entity.getDescriptor(AbstractDescriptor.class) + .orElseThrow(); + final var nextEntityOpt = second.getEntity(descriptor.getHandle()); + if (nextEntityOpt.isEmpty()) { + continue; + } + final var nextEntity = nextEntityOpt.orElseThrow(); + final var nextDescriptor = nextEntity + .getDescriptor(AbstractDescriptor.class) + .orElseThrow(); - // compare children of current and next descriptor one by one - final var childrenChanged = - haveDescriptorChildrenDisOrReappeared(descriptor.getHandle(), first, second); - if (!childrenChanged) { - continue; - } + // compare children of current and next descriptor one by one + final var childrenChanged = + haveDescriptorChildrenDisOrReappeared(descriptor.getHandle(), first, second); - descriptorChanges.incrementAndGet(); - assertTrue( - isIncrementedVersion( - ImpliedValueUtil.getDescriptorVersion(descriptor, impliedValueMap), - ImpliedValueUtil.getDescriptorVersion(nextDescriptor, impliedValueMap)), - "Descriptor version has not changed, but children have." - + " MdibVersions " + first.getMdibVersion() - + " and " + second.getMdibVersion() - + ". Descriptor handle " + descriptor.getHandle() - + ". Old children " + descriptor - + " new children " + nextEntity.getChildren()); - } - first = history.next(); - second = historyNext.next(); - } + if (!childrenChanged) { + continue; + } - } catch (PreprocessingException - | ReportProcessingException - | InitialImpliedValueException - | NoTestData e) { - fail(e); - } + descriptorChanges.incrementAndGet(); + + try { + assertTrue( + isIncrementedVersion( + ImpliedValueUtil.getDescriptorVersion(descriptor, impliedValueMap), + ImpliedValueUtil.getDescriptorVersion( + nextDescriptor, impliedValueMap)), + "Descriptor version has not changed, but children have." + + " MdibVersions " + first.getMdibVersion() + + " and " + second.getMdibVersion() + + ". Descriptor handle " + descriptor.getHandle() + + ". Old children " + descriptor + + " new children " + nextEntity.getChildren()); + } catch (InitialImpliedValueException e) { + fail(e); + } + } + }, + sequenceId); }); } assertTestData(descriptorChanges.get(), "No descriptor changed during the test run."); @@ -170,79 +159,72 @@ void testRequirementR0034() throws NoTestData, IOException { sequenceIds.forEach(sequenceId -> { final var impliedValueMap = new InitialImpliedValue(); final var lastDescriptorMap = new HashMap(); - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId); - final MdibHistorian.HistorianResult historyNext = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - // skip the first entry so that history and historyNext are off by one entry - final var skippedElement = historyNext.next(); - assertTestData(skippedElement != null, "Not enough input to compare mdib revisions"); - - RemoteMdibAccess first = history.next(); - RemoteMdibAccess second = historyNext.next(); - while (second != null) { - final var currentDescriptors = first.findEntitiesByType(AbstractDescriptor.class); - for (MdibEntity entity : currentDescriptors) { - // check if this was previously deleted and returned - final var descriptor = entity.getDescriptor(AbstractDescriptor.class) - .orElseThrow(); - final var oldVersion = lastDescriptorMap.remove(descriptor.getHandle()); - if (oldVersion != null) { - final var descriptorChanged = hasDescriptorChanged(oldVersion, descriptor); - if (descriptorChanged) { - descriptorChanges.incrementAndGet(); + mdibHistorian.processAllConsecutivePairsForSequenceId( + (first, second) -> { + final var currentDescriptors = first.findEntitiesByType(AbstractDescriptor.class); + for (MdibEntity entity : currentDescriptors) { + // check if this was previously deleted and returned + final var descriptor = entity.getDescriptor(AbstractDescriptor.class) + .orElseThrow(); + final var oldVersion = lastDescriptorMap.remove(descriptor.getHandle()); + if (oldVersion != null) { + final var descriptorChanged = hasDescriptorChanged(oldVersion, descriptor); + if (descriptorChanged) { + descriptorChanges.incrementAndGet(); + try { + assertTrue( + isIncrementedVersion( + ImpliedValueUtil.getDescriptorVersion( + oldVersion, impliedValueMap), + ImpliedValueUtil.getDescriptorVersion( + descriptor, impliedValueMap)), + DESCRIPTOR_REINSERTION_PREFIX + + " MdibVersions of insertion " + first.getMdibVersion() + + ". Descriptor handle " + descriptor.getHandle() + + ". Old Descriptor " + oldVersion + + " Inserted Descriptor " + descriptor); + } catch (InitialImpliedValueException e) { + fail(e); + } + } + } + + final var nextEntityOpt = second.getEntity(descriptor.getHandle()); + if (nextEntityOpt.isEmpty()) { + // descriptor was removed, add to storage + lastDescriptorMap.put(descriptor.getHandle(), descriptor); + continue; + } + + final var nextDescriptor = nextEntityOpt + .orElseThrow() + .getDescriptor(AbstractDescriptor.class) + .orElseThrow(); + // compare children of current and next descriptor one by one + final var descriptorChanged = hasDescriptorChanged(descriptor, nextDescriptor); + if (!descriptorChanged) { + continue; + } + + descriptorChanges.incrementAndGet(); + try { assertTrue( isIncrementedVersion( - ImpliedValueUtil.getDescriptorVersion(oldVersion, impliedValueMap), - ImpliedValueUtil.getDescriptorVersion(descriptor, impliedValueMap)), - DESCRIPTOR_REINSERTION_PREFIX - + " MdibVersions of insertion " + first.getMdibVersion() + ImpliedValueUtil.getDescriptorVersion(descriptor, impliedValueMap), + ImpliedValueUtil.getDescriptorVersion( + nextDescriptor, impliedValueMap)), + DESCRIPTOR_UPDATE_PREFIX + + " MdibVersions " + first.getMdibVersion() + + " and " + second.getMdibVersion() + ". Descriptor handle " + descriptor.getHandle() - + ". Old Descriptor " + oldVersion - + " Inserted Descriptor " + descriptor); + + ". Old Descriptor " + descriptor + + " New Descriptor " + nextDescriptor); + } catch (InitialImpliedValueException e) { + fail(e); } } - - final var nextEntityOpt = second.getEntity(descriptor.getHandle()); - if (nextEntityOpt.isEmpty()) { - // descriptor was removed, add to storage - lastDescriptorMap.put(descriptor.getHandle(), descriptor); - continue; - } - - final var nextDescriptor = nextEntityOpt - .orElseThrow() - .getDescriptor(AbstractDescriptor.class) - .orElseThrow(); - // compare children of current and next descriptor one by one - final var descriptorChanged = hasDescriptorChanged(descriptor, nextDescriptor); - if (!descriptorChanged) { - continue; - } - - descriptorChanges.incrementAndGet(); - assertTrue( - isIncrementedVersion( - ImpliedValueUtil.getDescriptorVersion(descriptor, impliedValueMap), - ImpliedValueUtil.getDescriptorVersion(nextDescriptor, impliedValueMap)), - DESCRIPTOR_UPDATE_PREFIX - + " MdibVersions " + first.getMdibVersion() - + " and " + second.getMdibVersion() - + ". Descriptor handle " + descriptor.getHandle() - + ". Old Descriptor " + descriptor - + " New Descriptor " + nextDescriptor); - } - first = history.next(); - second = historyNext.next(); - } - - } catch (PreprocessingException - | ReportProcessingException - | InitialImpliedValueException - | NoTestData e) { - fail(e); - } + }, + sequenceId); }); } assertTestData(descriptorChanges.get(), "No descriptor changed during the test run."); @@ -266,80 +248,71 @@ void testRequirementR0038() throws NoTestData, IOException { sequenceIds.forEach(sequenceId -> { final var impliedValueMap = new InitialImpliedValue(); final var removedStatesMap = new HashMap(); - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId); - final MdibHistorian.HistorianResult historyNext = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - // skip the first entry so that history and historyNext are off by one entry - final var skippedElement = historyNext.next(); - assertTestData(skippedElement != null, "Not enough input to compare mdib revisions"); - - RemoteMdibAccess first = history.next(); - RemoteMdibAccess second = historyNext.next(); - - while (second != null) { - final var states = first.getStatesByType(AbstractState.class); - for (var state : states) { + mdibHistorian.processAllConsecutivePairsForSequenceId( + (first, second) -> { + final var states = first.getStatesByType(AbstractState.class); + for (var state : states) { + + final String stateHandle; + if (state instanceof AbstractMultiState) { + stateHandle = ((AbstractMultiState) state).getHandle(); + } else { + stateHandle = state.getDescriptorHandle(); + } + final Optional nextStateOpt = second.getState(stateHandle); + + if (removedStatesMap.containsKey(stateHandle)) { + final var removedState = removedStatesMap.get(stateHandle); + if (!removedState.equals(state)) { + try { + assertTrue( + isIncrementedVersion( + ImpliedValueUtil.getStateVersion( + removedState, impliedValueMap), + ImpliedValueUtil.getStateVersion(state, impliedValueMap)), + "State version has not been incremented by one, but reinserted state" + + " has changed. MdibVersions " + first.getMdibVersion() + + " and " + second.getMdibVersion() + + ". State handle " + stateHandle + + ". Old State " + removedState + + " New State " + state); + } catch (InitialImpliedValueException e) { + fail(e); + } + } + removedStatesMap.remove(stateHandle); + } - final String stateHandle; - if (state instanceof AbstractMultiState) { - stateHandle = ((AbstractMultiState) state).getHandle(); - } else { - stateHandle = state.getDescriptorHandle(); - } - final Optional nextStateOpt = second.getState(stateHandle); + if (nextStateOpt.isEmpty()) { + // state will be removed + removedStatesMap.put(stateHandle, state); + continue; + } + + final var nextState = nextStateOpt.orElseThrow(); + + if (state.equals(nextState)) { + continue; + } - if (removedStatesMap.containsKey(stateHandle)) { - final var removedState = removedStatesMap.get(stateHandle); - if (!removedState.equals(state)) { + stateChanges.incrementAndGet(); + try { assertTrue( isIncrementedVersion( - ImpliedValueUtil.getStateVersion(removedState, impliedValueMap), - ImpliedValueUtil.getStateVersion(state, impliedValueMap)), - "State version has not been incremented by one, but reinserted state" - + " has changed. MdibVersions " + first.getMdibVersion() + ImpliedValueUtil.getStateVersion(state, impliedValueMap), + ImpliedValueUtil.getStateVersion(nextState, impliedValueMap)), + "State version has not been incremented by one, but state has changed." + + " MdibVersions " + first.getMdibVersion() + " and " + second.getMdibVersion() + ". State handle " + stateHandle - + ". Old State " + removedState - + " New State " + state); + + ". Old State " + state + + " New State " + nextState); + } catch (InitialImpliedValueException e) { + fail(e); } - removedStatesMap.remove(stateHandle); - } - - if (nextStateOpt.isEmpty()) { - // state will be removed - removedStatesMap.put(stateHandle, state); - continue; - } - - final var nextState = nextStateOpt.orElseThrow(); - - if (state.equals(nextState)) { - continue; } - - stateChanges.incrementAndGet(); - assertTrue( - isIncrementedVersion( - ImpliedValueUtil.getStateVersion(state, impliedValueMap), - ImpliedValueUtil.getStateVersion(nextState, impliedValueMap)), - "State version has not been incremented by one, but state has changed." - + " MdibVersions " + first.getMdibVersion() - + " and " + second.getMdibVersion() - + ". State handle " + stateHandle - + ". Old State " + state - + " New State " + nextState); - } - first = history.next(); - second = historyNext.next(); - } - - } catch (PreprocessingException - | ReportProcessingException - | InitialImpliedValueException - | NoTestData e) { - fail(e); - } + }, + sequenceId); removedStatesMap.clear(); }); } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantNonFunctionalQualityAttributesTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantNonFunctionalQualityAttributesTest.java index eedf40bb..b8cec8ba 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantNonFunctionalQualityAttributesTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantNonFunctionalQualityAttributesTest.java @@ -19,7 +19,6 @@ import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; import com.draeger.medical.sdccc.tests.util.ImpliedValueUtil; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.TestRunObserver; @@ -31,8 +30,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; 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.participant.AbstractContextState; import org.somda.sdc.biceps.model.participant.AbstractMetricDescriptor; import org.somda.sdc.biceps.model.participant.AlertConditionState; @@ -49,7 +46,6 @@ import org.somda.sdc.biceps.model.participant.RealTimeSampleArrayMetricState; import org.somda.sdc.biceps.model.participant.StringMetricDescriptor; import org.somda.sdc.biceps.model.participant.StringMetricState; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * Glue Non-functional quality attributes tests (ch. 10). @@ -77,43 +73,29 @@ void testRequirementR0010() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - RemoteMdibAccess remoteMdibAccess = history.next(); - - while (remoteMdibAccess != null) { - final var entities = remoteMdibAccess.findEntitiesByType(MdsDescriptor.class); - - for (var entity : entities) { - acceptableSequenceSeen.incrementAndGet(); - final var children = entity.getChildren(); - final var clockDescriptorSeen = new AtomicBoolean(false); - for (var child : children) { - final var clockOpt = remoteMdibAccess.getDescriptor(child, ClockDescriptor.class); - if (clockOpt.isPresent()) { - clockDescriptorSeen.set(true); - final var clockStateOpt = remoteMdibAccess.getState(child, ClockState.class); - assertTrue( - clockStateOpt.isPresent(), - String.format( - "No clock state present for mds with handle %s.", - entity.getHandle())); - } - } - assertTrue( - clockDescriptorSeen.get(), - String.format( - "No clock descriptor present for mds with handle %s.", entity.getHandle())); - } - remoteMdibAccess = history.next(); + mdibHistorian.processAllRemoteMdibAccess(remoteMdibAccess -> { + final var entities = remoteMdibAccess.findEntitiesByType(MdsDescriptor.class); + + for (var entity : entities) { + acceptableSequenceSeen.incrementAndGet(); + final var children = entity.getChildren(); + final var clockDescriptorSeen = new AtomicBoolean(false); + for (var child : children) { + final var clockOpt = remoteMdibAccess.getDescriptor(child, ClockDescriptor.class); + if (clockOpt.isPresent()) { + clockDescriptorSeen.set(true); + final var clockStateOpt = remoteMdibAccess.getState(child, ClockState.class); + assertTrue( + clockStateOpt.isPresent(), + String.format("No clock state present for mds with handle %s.", entity.getHandle())); } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); } - }); - } + assertTrue( + clockDescriptorSeen.get(), + String.format("No clock descriptor present for mds with handle %s.", entity.getHandle())); + } + }); + assertTestData(acceptableSequenceSeen.get(), "No mds seen during test run, test failed."); } @@ -127,114 +109,95 @@ void testRequirementR0011() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess remoteMdibAccess = history.next(); - - while (remoteMdibAccess != null) { - final var entities = remoteMdibAccess.findEntitiesByType(AbstractMetricDescriptor.class); - - for (var entity : entities) { - - if (entity.getDescriptor(RealTimeSampleArrayMetricDescriptor.class) - .isPresent()) { - final var metricValue = entity.getFirstState(RealTimeSampleArrayMetricState.class) - .orElseThrow() - .getMetricValue(); - - if (metricValue != null - && !metricValue.getSamples().isEmpty()) { - acceptableSequenceSeen.incrementAndGet(); - - assertNotNull( - metricValue.getDeterminationTime(), - String.format( - "No DeterminationTime for the metric with the handle %s " - + "even though it has a non-empty sample attribute.", - entity.getHandle())); - } - } else if (entity.getDescriptor(DistributionSampleArrayMetricDescriptor.class) - .isPresent()) { - final var metricValue = entity.getFirstState(DistributionSampleArrayMetricState.class) - .orElseThrow() - .getMetricValue(); - - if (metricValue != null - && !metricValue.getSamples().isEmpty()) { - acceptableSequenceSeen.incrementAndGet(); - - assertNotNull( - metricValue.getDeterminationTime(), - String.format( - "No DeterminationTime for the metric with the handle %s " - + "even though it has a non-empty sample attribute.", - entity.getHandle())); - } - } else if (entity.getDescriptor(NumericMetricDescriptor.class) - .isPresent()) { - final var metricValue = entity.getFirstState(NumericMetricState.class) - .orElseThrow() - .getMetricValue(); - - if (metricValue != null && metricValue.getValue() != null) { - acceptableSequenceSeen.incrementAndGet(); - - assertNotNull( - metricValue.getDeterminationTime(), - String.format( - "No DeterminationTime for the metric with the handle %s " - + "even though it has a non-empty value attribute.", - entity.getHandle())); - } - } else if (entity.getDescriptor(EnumStringMetricDescriptor.class) - .isPresent()) { - final var metricValue = entity.getFirstState(EnumStringMetricState.class) - .orElseThrow() - .getMetricValue(); + mdibHistorian.processAllRemoteMdibAccess(remoteMdibAccess -> { + final var entities = remoteMdibAccess.findEntitiesByType(AbstractMetricDescriptor.class); - if (metricValue != null && metricValue.getValue() != null) { - acceptableSequenceSeen.incrementAndGet(); + for (var entity : entities) { - assertNotNull( - metricValue.getDeterminationTime(), - String.format( - "No DeterminationTime for the metric with the handle %s " - + "even though it has a non-empty value attribute.", - entity.getHandle())); - } - } else if (entity.getDescriptor(StringMetricDescriptor.class) - .isPresent()) { - final var metricValue = entity.getFirstState(StringMetricState.class) - .orElseThrow() - .getMetricValue(); + if (entity.getDescriptor(RealTimeSampleArrayMetricDescriptor.class) + .isPresent()) { + final var metricValue = entity.getFirstState(RealTimeSampleArrayMetricState.class) + .orElseThrow() + .getMetricValue(); - if (metricValue != null && metricValue.getValue() != null) { - acceptableSequenceSeen.incrementAndGet(); - - assertNotNull( - metricValue.getDeterminationTime(), - String.format( - "No DeterminationTime for the metric with the handle %s " - + "even though it has a non-empty value attribute.", - entity.getHandle())); - } - } else { - fail(String.format( - "Object of type %s is not supported by the test.", - entity.getDescriptorClass())); - } - } + if (metricValue != null && !metricValue.getSamples().isEmpty()) { + acceptableSequenceSeen.incrementAndGet(); - remoteMdibAccess = history.next(); + assertNotNull( + metricValue.getDeterminationTime(), + String.format( + "No DeterminationTime for the metric with the handle %s " + + "even though it has a non-empty sample attribute.", + entity.getHandle())); + } + } else if (entity.getDescriptor(DistributionSampleArrayMetricDescriptor.class) + .isPresent()) { + final var metricValue = entity.getFirstState(DistributionSampleArrayMetricState.class) + .orElseThrow() + .getMetricValue(); + + if (metricValue != null && !metricValue.getSamples().isEmpty()) { + acceptableSequenceSeen.incrementAndGet(); + + assertNotNull( + metricValue.getDeterminationTime(), + String.format( + "No DeterminationTime for the metric with the handle %s " + + "even though it has a non-empty sample attribute.", + entity.getHandle())); + } + } else if (entity.getDescriptor(NumericMetricDescriptor.class).isPresent()) { + final var metricValue = entity.getFirstState(NumericMetricState.class) + .orElseThrow() + .getMetricValue(); + + if (metricValue != null && metricValue.getValue() != null) { + acceptableSequenceSeen.incrementAndGet(); + + assertNotNull( + metricValue.getDeterminationTime(), + String.format( + "No DeterminationTime for the metric with the handle %s " + + "even though it has a non-empty value attribute.", + entity.getHandle())); } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); + } else if (entity.getDescriptor(EnumStringMetricDescriptor.class) + .isPresent()) { + final var metricValue = entity.getFirstState(EnumStringMetricState.class) + .orElseThrow() + .getMetricValue(); + + if (metricValue != null && metricValue.getValue() != null) { + acceptableSequenceSeen.incrementAndGet(); + + assertNotNull( + metricValue.getDeterminationTime(), + String.format( + "No DeterminationTime for the metric with the handle %s " + + "even though it has a non-empty value attribute.", + entity.getHandle())); + } + } else if (entity.getDescriptor(StringMetricDescriptor.class).isPresent()) { + final var metricValue = entity.getFirstState(StringMetricState.class) + .orElseThrow() + .getMetricValue(); + + if (metricValue != null && metricValue.getValue() != null) { + acceptableSequenceSeen.incrementAndGet(); + + assertNotNull( + metricValue.getDeterminationTime(), + String.format( + "No DeterminationTime for the metric with the handle %s " + + "even though it has a non-empty value attribute.", + entity.getHandle())); + } + } else { + fail(String.format("Object of type %s is not supported by the test.", entity.getDescriptorClass())); } - }); - } + } + }); + assertTestData(acceptableSequenceSeen.get(), "No metric with a value has been seen."); } @@ -253,51 +216,41 @@ void testRequirementR001200() throws NoTestData, IOException { try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId); - final MdibHistorian.HistorianResult prevHistory = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - history.next(); // history must be one element ahead of prevHistory - RemoteMdibAccess last = prevHistory.next(); - RemoteMdibAccess current = history.next(); - - while (current != null) { - final var currentAlertConditionStates = current.getStatesByType(AlertConditionState.class); - - for (var currentAlertConditionState : currentAlertConditionStates) { - acceptableSequenceSeen.incrementAndGet(); - final Optional lastAlertConditionState = last.getState( - currentAlertConditionState.getDescriptorHandle(), AlertConditionState.class); - if (lastAlertConditionState.isEmpty()) { - continue; - } + mdibHistorian.processAllConsecutivePairsForSequenceId( + (last, current) -> { + final var currentAlertConditionStates = current.getStatesByType(AlertConditionState.class); - if (ImpliedValueUtil.isPresence(currentAlertConditionState) - != ImpliedValueUtil.isPresence(lastAlertConditionState.orElseThrow())) { - assertNotEquals( - currentAlertConditionState.getDeterminationTime(), - lastAlertConditionState.orElseThrow().getDeterminationTime(), - String.format( - "The AlertConditionState with descriptor handle '%s' has changed " - + "its @Presence attribute from mdibVersion '%s' to mdibVersion '%s', " - + "but its @DeterminationTime was not updated ('%s' in both cases).", - currentAlertConditionState.getDescriptorHandle(), - ImpliedValueUtil.getMdibVersion(last.getMdibVersion()) - .toString(), - ImpliedValueUtil.getMdibVersion(current.getMdibVersion()) - .toString(), - currentAlertConditionState - .getDeterminationTime() - .toString())); - } - } - last = prevHistory.next(); - current = history.next(); - } + for (var currentAlertConditionState : currentAlertConditionStates) { + acceptableSequenceSeen.incrementAndGet(); + final Optional lastAlertConditionState = last.getState( + currentAlertConditionState.getDescriptorHandle(), AlertConditionState.class); + if (lastAlertConditionState.isEmpty()) { + continue; + } - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); - } + if (ImpliedValueUtil.isPresence(currentAlertConditionState) + != ImpliedValueUtil.isPresence(lastAlertConditionState.orElseThrow())) { + assertNotEquals( + currentAlertConditionState.getDeterminationTime(), + lastAlertConditionState + .orElseThrow() + .getDeterminationTime(), + String.format( + "The AlertConditionState with descriptor handle '%s' has changed " + + "its @Presence attribute from mdibVersion '%s' to mdibVersion '%s', " + + "but its @DeterminationTime was not updated ('%s' in both cases).", + currentAlertConditionState.getDescriptorHandle(), + ImpliedValueUtil.getMdibVersion(last.getMdibVersion()) + .toString(), + ImpliedValueUtil.getMdibVersion(current.getMdibVersion()) + .toString(), + currentAlertConditionState + .getDeterminationTime() + .toString())); + } + } + }, + sequenceId); }); } assertTestData(acceptableSequenceSeen.get(), "No AlertConditionState seen during the test run, test failed."); @@ -314,35 +267,22 @@ void testRequirementR0013() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess first = history.next(); - - while (first != null) { - final var contextStates = first.getStatesByType(AbstractContextState.class); - for (var contextState : contextStates) { - final var bindingMdibVersion = contextState.getBindingMdibVersion(); - if (bindingMdibVersion != null) { - final var bindingStartTime = contextState.getBindingStartTime(); - assertNotNull( - bindingStartTime, - String.format( - "The binding start time should not be null for state %s.", - contextState.getHandle())); - acceptableSequenceSeen.incrementAndGet(); - } - } - first = history.next(); - } - - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); + mdibHistorian.processAllRemoteMdibAccess(first -> { + final var contextStates = first.getStatesByType(AbstractContextState.class); + for (var contextState : contextStates) { + final var bindingMdibVersion = contextState.getBindingMdibVersion(); + if (bindingMdibVersion != null) { + final var bindingStartTime = contextState.getBindingStartTime(); + assertNotNull( + bindingStartTime, + String.format( + "The binding start time should not be null for state %s.", + contextState.getHandle())); + acceptableSequenceSeen.incrementAndGet(); } - }); - } + } + }); + assertTestData(acceptableSequenceSeen.get(), "No suitable context states seen, test failed."); } @@ -357,35 +297,21 @@ void testRequirementR0072() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicInteger(0); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { - - RemoteMdibAccess first = history.next(); - - while (first != null) { - final var contextStates = first.getStatesByType(AbstractContextState.class); - for (var contextState : contextStates) { - final var unbindingMdibVersion = contextState.getUnbindingMdibVersion(); - if (unbindingMdibVersion != null) { - final var bindingEndTime = contextState.getBindingEndTime(); - assertNotNull( - bindingEndTime, - String.format( - "The binding end time should not be null for state %s.", - contextState.getHandle())); - acceptableSequenceSeen.incrementAndGet(); - } - } - first = history.next(); - } - - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); + mdibHistorian.processAllRemoteMdibAccess(first -> { + final var contextStates = first.getStatesByType(AbstractContextState.class); + for (var contextState : contextStates) { + final var unbindingMdibVersion = contextState.getUnbindingMdibVersion(); + if (unbindingMdibVersion != null) { + final var bindingEndTime = contextState.getBindingEndTime(); + assertNotNull( + bindingEndTime, + String.format( + "The binding end time should not be null for state %s.", contextState.getHandle())); + acceptableSequenceSeen.incrementAndGet(); } - }); - } + } + }); + assertTestData(acceptableSequenceSeen.get(), "No suitable context states seen, test failed."); } } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantSdcParticipantModelBindingTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantSdcParticipantModelBindingTest.java index 8b9057f9..4e031a7d 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantSdcParticipantModelBindingTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/glue/invariant/InvariantSdcParticipantModelBindingTest.java @@ -8,7 +8,6 @@ package com.draeger.medical.sdccc.tests.glue.invariant; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.fail; import com.draeger.medical.sdccc.configuration.EnabledTestConfig; import com.draeger.medical.sdccc.messages.MessageStorage; @@ -16,26 +15,21 @@ import com.draeger.medical.sdccc.tests.InjectorTestBase; import com.draeger.medical.sdccc.tests.annotations.TestDescription; import com.draeger.medical.sdccc.tests.annotations.TestIdentifier; -import com.draeger.medical.sdccc.tests.util.MdibHistorian; import com.draeger.medical.sdccc.tests.util.NoTestData; import com.draeger.medical.sdccc.tests.util.guice.MdibHistorianFactory; import com.draeger.medical.sdccc.util.TestRunObserver; import java.io.IOException; import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.somda.sdc.biceps.common.MdibEntity; -import org.somda.sdc.biceps.common.storage.PreprocessingException; -import org.somda.sdc.biceps.consumer.access.RemoteMdibAccess; import org.somda.sdc.biceps.model.participant.AbstractComplexDeviceComponentDescriptor; import org.somda.sdc.biceps.model.participant.AbstractDescriptor; import org.somda.sdc.biceps.model.participant.AbstractMetricDescriptor; import org.somda.sdc.biceps.model.participant.AbstractOperationDescriptor; import org.somda.sdc.biceps.model.participant.AlertConditionDescriptor; import org.somda.sdc.biceps.model.participant.ChannelDescriptor; -import org.somda.sdc.glue.consumer.report.ReportProcessingException; /** * Glue Sdc Participant Model Binding tests (ch. 7). @@ -63,47 +57,30 @@ void testRequirementR0080() throws NoTestData, IOException { final var acceptableSequenceSeen = new AtomicBoolean(false); - try (final Stream sequenceIds = mdibHistorian.getKnownSequenceIds()) { - sequenceIds.forEach(sequenceId -> { - try (final MdibHistorian.HistorianResult history = - mdibHistorian.episodicReportBasedHistory(sequenceId)) { + mdibHistorian.processAllRemoteMdibAccess(first -> { + acceptableSequenceSeen.compareAndSet( + false, + checkForTypeAttribute( + first.findEntitiesByType(AbstractComplexDeviceComponentDescriptor.class), + AbstractComplexDeviceComponentDescriptor.class)); + acceptableSequenceSeen.compareAndSet( + false, + checkForTypeAttribute(first.findEntitiesByType(ChannelDescriptor.class), ChannelDescriptor.class)); + acceptableSequenceSeen.compareAndSet( + false, + checkForTypeAttribute( + first.findEntitiesByType(AbstractOperationDescriptor.class), + AbstractOperationDescriptor.class)); + acceptableSequenceSeen.compareAndSet( + false, + checkForTypeAttribute( + first.findEntitiesByType(AlertConditionDescriptor.class), AlertConditionDescriptor.class)); + acceptableSequenceSeen.compareAndSet( + false, + checkForTypeAttribute( + first.findEntitiesByType(AbstractMetricDescriptor.class), AbstractMetricDescriptor.class)); + }); - RemoteMdibAccess first = history.next(); - - while (first != null) { - acceptableSequenceSeen.compareAndSet( - false, - checkForTypeAttribute( - first.findEntitiesByType(AbstractComplexDeviceComponentDescriptor.class), - AbstractComplexDeviceComponentDescriptor.class)); - acceptableSequenceSeen.compareAndSet( - false, - checkForTypeAttribute( - first.findEntitiesByType(ChannelDescriptor.class), ChannelDescriptor.class)); - acceptableSequenceSeen.compareAndSet( - false, - checkForTypeAttribute( - first.findEntitiesByType(AbstractOperationDescriptor.class), - AbstractOperationDescriptor.class)); - acceptableSequenceSeen.compareAndSet( - false, - checkForTypeAttribute( - first.findEntitiesByType(AlertConditionDescriptor.class), - AlertConditionDescriptor.class)); - acceptableSequenceSeen.compareAndSet( - false, - checkForTypeAttribute( - first.findEntitiesByType(AbstractMetricDescriptor.class), - AbstractMetricDescriptor.class)); - - first = history.next(); - } - - } catch (PreprocessingException | ReportProcessingException e) { - fail(e); - } - }); - } assertTestData(acceptableSequenceSeen.get(), "No suitable descriptors seen, test failed."); } 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 0f8623b8..a7c3d053 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 @@ -27,6 +27,8 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.Objects; +import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.stream.Stream; import javax.annotation.Nullable; import javax.xml.namespace.QName; @@ -614,6 +616,91 @@ private RemoteMdibAccess convertToRemoteMdib(final Mdib mdib) throws Preprocessi return mdibStorage; } + /** + * Processes each sequenceId using the provided consumer. + * + * @param sequenceIdConsumer a consumer that processes each sequenceId + */ + public void processSequenceIds(final Consumer sequenceIdConsumer) throws IOException { + try (Stream sequenceIds = this.getKnownSequenceIds()) { + sequenceIds.forEach(sequenceIdConsumer); + } + } + + /** + * Processes each RemoteMdibAccess for a given sequenceId using the provided processor. + * + * @param processor a consumer that processes each RemoteMdibAccess + * @param sequenceId of the sequence to retrieve reports for + */ + public void processRemoteMdibAccessForSequence( + final Consumer processor, final String sequenceId) { + try (HistorianResult history = episodicReportBasedHistory(sequenceId)) { + RemoteMdibAccess mdibAccess; + while ((mdibAccess = history.next()) != null) { + processor.accept(mdibAccess); + } + } catch (PreprocessingException | ReportProcessingException e) { + fail(e); + } + } + + /** + * Processes each RemoteMdibAccess for a given sequenceId using the provided processor. + * + * @param processor a consumer that processes each RemoteMdibAccess + */ + public void processAllRemoteMdibAccess(final Consumer processor) throws IOException { + try (final Stream sequenceIds = this.getKnownSequenceIds()) { + sequenceIds.forEach(sequenceId -> { + processRemoteMdibAccessForSequence(processor, sequenceId); + }); + } + } + + /** + * Processes each RemoteMdibAccess for a given sequenceId using the provided processor. + * + * @param processor a consumer that processes each RemoteMdibAccess + * @param sequenceId of the sequence to retrieve reports for + */ + public void processAllConsecutivePairsForSequenceId( + final BiConsumer processor, final String sequenceId) { + try (final MdibHistorian.HistorianResult history = episodicReportBasedHistory(sequenceId); + final MdibHistorian.HistorianResult historyNext = episodicReportBasedHistory(sequenceId)) { + + // skip the first entry so that history and historyNext are off by one entry + final var skippedElement = historyNext.next(); + if (skippedElement == null) { + throw new NoTestData("Not enough input to compare mdib revisions"); + } + + RemoteMdibAccess first = history.next(); + RemoteMdibAccess second = historyNext.next(); + while (second != null) { + processor.accept(first, second); + first = history.next(); + second = historyNext.next(); + } + } catch (PreprocessingException | ReportProcessingException | NoTestData e) { + fail(e); + } + } + + /** + * Processes each RemoteMdibAccess for a given sequenceId using the provided processor. + * + * @param processor a consumer that processes each RemoteMdibAccess + */ + public void processAllConsecutivePairs(final BiConsumer processor) + throws IOException { + try (final Stream sequenceIds = this.getKnownSequenceIds()) { + sequenceIds.forEach(sequenceId -> { + processAllConsecutivePairsForSequenceId(processor, sequenceId); + }); + } + } + /** * Result container providing a {@linkplain RemoteMdibAccess} on which every incoming report is applied in order of * arrival.