Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce mdib historian nesting #226

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading