Skip to content

Commit

Permalink
Reduce mdib historian nesting (#226)
Browse files Browse the repository at this point in the history
// Reduces the nesting in Test Cases by providing a consumer in
MdibHistorian

# Checklist

The following aspects have been respected by the author of this pull
request, confirmed by both pull request assignee **and** reviewer:

* Adherence to coding conventions
  * [x] Pull Request Assignee
  * [x] Reviewer
* Adherence to javadoc conventions
  * [x] Pull Request Assignee
  * [x] Reviewer
* Changelog update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* README update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* config update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* SDCcc executable ran against a test device (if necessary)
  * [x] Pull Request Assignee
  * [x] Reviewer
  • Loading branch information
midttuna authored Jan 9, 2025
1 parent aa9e024 commit 4a510e5
Show file tree
Hide file tree
Showing 13 changed files with 1,035 additions and 1,309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,61 +76,45 @@ void testRequirementR00290() throws NoTestData, IOException {
messageStorage, getInjector().getInstance(TestRunObserver.class));

final var presenceOnSeen = new AtomicInteger(0);
try (final Stream<String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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).
Expand Down Expand Up @@ -76,64 +71,49 @@ void testRequirementB128() throws NoTestData, IOException {

final var acceptableSequenceSeen = new AtomicInteger(0);

try (final Stream<String> 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");
}
Expand Down
Loading

0 comments on commit 4a510e5

Please sign in to comment.