From dc92869e9ce7e9dd85fb7a28f3a0fbeb002e71be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Thu, 7 Sep 2023 11:26:37 +0200 Subject: [PATCH 01/11] Fixed Defect in Test case for Biceps:R5025 --- .../manipulation/FallbackManipulations.java | 13 +++ .../sdccc/manipulation/GRpcManipulations.java | 11 +- .../sdccc/manipulation/Manipulations.java | 11 +- .../impl/ConditionalPreconditions.java | 82 +++++++++++++- .../InvariantMessageModelAnnexTest.java | 2 +- ...variantParticipantModelVersioningTest.java | 2 +- .../tests/util/ManipulationParameterUtil.java | 11 ++ .../draeger/medical/sdccc/util/Constants.java | 1 + .../impl/ConditionalPreconditionsTest.java | 105 +++++++++++++++++- 9 files changed, 221 insertions(+), 17 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/FallbackManipulations.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/FallbackManipulations.java index b2d178ba..64d8af26 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/FallbackManipulations.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/FallbackManipulations.java @@ -234,6 +234,19 @@ public void close() {} return interactionResult ? ResponseTypes.Result.RESULT_SUCCESS : ResponseTypes.Result.RESULT_FAIL; } + @Override + public ResponseTypes.Result triggerDescriptorUpdate(final List handles) { + final var triggerReportString = "Trigger a descriptor update for handles %s"; + final var interactionMessage = String.format(triggerReportString, String.join(", ", handles)); + final var interactionResult = interactionFactory + .createUserInteraction(new FilterInputStream(System.in) { + @Override + public void close() {} + }) + .displayYesNoUserInteraction(interactionMessage); + return interactionResult ? ResponseTypes.Result.RESULT_SUCCESS : ResponseTypes.Result.RESULT_FAIL; + } + @Override public ResponseTypes.Result triggerAnyDescriptorUpdate() { final var interactionMessage = "Trigger a descriptor update for some descriptor"; diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java index 57283c20..ffbb97eb 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java @@ -41,6 +41,7 @@ import java.util.Optional; import java.util.function.Function; import javax.xml.namespace.QName; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.somda.sdc.biceps.model.participant.AbstractDescriptor; @@ -294,15 +295,19 @@ public ResponseTypes.Result setMetricStatus( @Override public ResponseTypes.Result triggerDescriptorUpdate(final String handle) { + return triggerDescriptorUpdate(List.of(handle)); + } + + public ResponseTypes.Result triggerDescriptorUpdate(final List handles) { final var message = - BasicRequests.BasicHandleRequest.newBuilder().setHandle(handle).build(); + DeviceRequests.TriggerDescriptorUpdateRequest.newBuilder().addAllHandle(handles).build(); return performCallWrapper( v -> deviceStub.triggerDescriptorUpdate(message), - v -> fallback.triggerDescriptorUpdate(handle), + v -> fallback.triggerDescriptorUpdate(handles), BasicResponses.BasicResponse::getResult, BasicResponses.BasicResponse::getResult, - ManipulationParameterUtil.buildHandleManipulationParameterData(handle)); + ManipulationParameterUtil.buildTriggerDescriptorUpdateParameterData(handles)); } @Override diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java index 64fbd73a..df103d67 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java @@ -138,10 +138,19 @@ ResponseTypes.Result setMetricStatus( ResponseTypes.Result triggerDescriptorUpdate(String handle); /** - * Trigger a descriptor update for some descriptor (chosen by the device). + * Trigger a descriptor update for the provided handles (DescriptionModificationReport with one Upt-ReportPart + * for each one of the provided descriptor handles). * + * @param handles list of descriptor handles to trigger an Update for. * @return the result of the manipulation */ + ResponseTypes.Result triggerDescriptorUpdate(final List handles); + + /** + * Trigger a descriptor update for some descriptor (chosen by the device). + * + * @return the result of the manipulation + */ ResponseTypes.Result triggerAnyDescriptorUpdate(); /** diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java index e93e8762..b6bf76e1 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java @@ -34,6 +34,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import javax.xml.namespace.QName; + +import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.somda.sdc.biceps.common.MdibEntity; @@ -186,6 +188,42 @@ private static boolean descriptionUpdateManipulation(final Injector injector) { return ResponseTypes.Result.RESULT_SUCCESS.equals(manipulationResult); } + private static boolean descriptionUpdateWithParentChildRelationshipManipulation(final Injector injector, final Logger log) { + Pair descriptorHandles = findFirstDescriptorHandleWithChildren(injector, log); + if (descriptorHandles == null) { + log.error("Could not trigger a Descriptor Update with Parent Child Relationship as there are no " + + "Descriptors with Children in the Mdib."); + return false; + } + String parentDescriptorHandle = descriptorHandles.getLeft(); + String childDescriptorHandle = descriptorHandles.getRight(); + final var manipulations = injector.getInstance(Manipulations.class); + + final ResponseTypes.Result manipulationResult = manipulations.triggerDescriptorUpdate(List.of(childDescriptorHandle, parentDescriptorHandle)); + + return ResponseTypes.Result.RESULT_SUCCESS.equals(manipulationResult); + } + + private static Pair findFirstDescriptorHandleWithChildren(Injector injector, Logger log) { + final var testClient = injector.getInstance(TestClient.class); + + final var remoteDevice = testClient.getSdcRemoteDevice(); + if (remoteDevice == null) { + log.error("remote device could not be accessed, likely due to a disconnect"); + return null; + } + var mdibAccess = remoteDevice.getMdibAccess(); + + Collection entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class); + for (MdibEntity entity : entities) { + List children = entity.getChildren(); + if (children.size() > 0) { + return Pair.of(entity.getHandle(), children.get(0)); + } + } + return null; + } + private static boolean triggerReportPreconditionCheck( final Injector injector, final Logger log, final QName... reportType) throws PreconditionException { final var messageStorage = injector.getInstance(MessageStorage.class); @@ -461,11 +499,11 @@ static boolean manipulation(final Injector injector) { } // all options exhausted and the goal is still not reached - LOG.error("Unable to find any MdsDescriptors using the GetRemovableDescriptorsOfType() manipulation " + LOG.error("Unable to find any MdsDescriptors using the GetRemovableDescriptorsOfClass() manipulation " + "that can be inserted, updated and removed (at least one for each is required for the test " + "applying this precondition). " + "Please check if the test case applying this precondition is applicable to your device and if the " - + "GetRemovableDescriptorsOfType, InsertDescriptor, RemoveDescriptor, and TriggerDescriptorUpdate " + + "GetRemovableDescriptorsOfClass, InsertDescriptor, RemoveDescriptor, and TriggerDescriptorUpdate " + "manipulations have been implemented correctly."); return false; } @@ -660,15 +698,15 @@ static boolean manipulation(final Injector injector) { * Precondition which checks whether DescriptionModificationReport messages containing an insertion * or deletion have been received, triggering description changes otherwise. */ - public static class DescriptionChangedPrecondition extends SimplePrecondition { + public static class DescriptionModificationCrtOrDelPrecondition extends SimplePrecondition { - private static final Logger LOG = LogManager.getLogger(DescriptionChangedPrecondition.class); + private static final Logger LOG = LogManager.getLogger(DescriptionModificationCrtOrDelPrecondition.class); /** * Creates a description changed precondition check. */ - public DescriptionChangedPrecondition() { - super(DescriptionChangedPrecondition::preconditionCheck, DescriptionChangedPrecondition::manipulation); + public DescriptionModificationCrtOrDelPrecondition() { + super(DescriptionModificationCrtOrDelPrecondition::preconditionCheck, DescriptionModificationCrtOrDelPrecondition::manipulation); } static boolean preconditionCheck(final Injector injector) throws PreconditionException { @@ -688,6 +726,38 @@ static boolean manipulation(final Injector injector) { } } + /** + * Precondition which triggers all possible description changes with parent-child relationships. + */ + public static class DescriptionModificationAllWithParentChildRelationshipPrecondition extends SimplePrecondition { + + private static final Logger LOG = LogManager.getLogger(DescriptionModificationAllWithParentChildRelationshipPrecondition.class); + + /** + * Creates a description changed precondition check. + */ + public DescriptionModificationAllWithParentChildRelationshipPrecondition() { + super(DescriptionModificationAllWithParentChildRelationshipPrecondition::preconditionCheck, DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation); + } + + static boolean preconditionCheck(final Injector injector) { + return false; // always trigger description changes + } + + /** + * Performs the removal, reinsertion and update of all modifiable descriptors in the mdib to trigger reports. + * + * @param injector to analyze mdib on + * @return true if successful, false otherwise + * @throws PreconditionException on errors + */ + static boolean manipulation(final Injector injector) { + boolean result1 = descriptionModificationManipulation(injector, LOG); + boolean result2 = descriptionUpdateWithParentChildRelationshipManipulation(injector, LOG); + return result1 && result2; + } + } + /** * Precondition which checks whether all context descriptors had at least two different context states * associated, triggering context state associations otherwise. diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java index 6416d3b1..79e1391f 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java @@ -332,7 +332,7 @@ void testRequirementR5024() throws NoTestData, IOException { @TestDescription("For every DescriptionModificationReport received from the DUT, and for all parent-child" + " relationships between the elements contained in the report, checks that the reportPart containing" + " the parent comes before the reportPart containing the child.") - @RequirePrecondition(simplePreconditions = ConditionalPreconditions.DescriptionChangedPrecondition.class) + @RequirePrecondition(simplePreconditions = ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.class) void testRequirementR5025() throws NoTestData, IOException { try (final var messages = messageStorage.getInboundMessagesByBodyType(Constants.MSG_DESCRIPTION_MODIFICATION_REPORT)) { 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 a07d948b..314c9851 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 @@ -80,7 +80,7 @@ void setUp() { @TestDescription( "Starting from the initially retrieved mdib, applies every episodic report to the mdib and" + " verifies that descriptor versions are incremented by 1 whenever a child descriptor is added or deleted.") - @RequirePrecondition(simplePreconditions = {ConditionalPreconditions.DescriptionChangedPrecondition.class}) + @RequirePrecondition(simplePreconditions = {ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.class}) void testRequirementR0033() throws NoTestData, IOException { final var mdibHistorian = mdibHistorianFactory.createMdibHistorian( messageStorage, getInjector().getInstance(TestRunObserver.class)); diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/ManipulationParameterUtil.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/ManipulationParameterUtil.java index 1f653ba4..1fd762a8 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/ManipulationParameterUtil.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/util/ManipulationParameterUtil.java @@ -48,6 +48,17 @@ public static ManipulationParameterData buildHandleManipulationParameterData(fin List.of(new ImmutablePair<>(Constants.MANIPULATION_PARAMETER_HANDLE, handle))); } + /** + * Build manipulation parameter data containing the handles that are needed for the manipulation. + * + * @param handles for which manipulation parameter data will be built. + * @return the manipulation parameter data + */ + public static ManipulationParameterData buildTriggerDescriptorUpdateParameterData(final List handles) { + return new ManipulationParameterData( + List.of(new ImmutablePair<>(Constants.MANIPULATION_PARAMETER_HANDLES, String.join(", ", handles)))); + } + /** * Build manipulation parameter data containing the location detail that is needed for the manipulation. * diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/util/Constants.java b/sdccc/src/main/java/com/draeger/medical/sdccc/util/Constants.java index c9308c7c..a29b84ac 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/util/Constants.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/util/Constants.java @@ -222,6 +222,7 @@ public final class Constants { // Manipulation Data for Hibernation public static final String MANIPULATION_PARAMETER_HANDLE = "Handle"; + public static final String MANIPULATION_PARAMETER_HANDLES = "Handles"; public static final String MANIPULATION_PARAMETER_SEQUENCE_ID = "SequenceId"; public static final String MANIPULATION_PARAMETER_LOCATION_DETAIL = "LocationDetail"; public static final String MANIPULATION_PARAMETER_CONTEXT_ASSOCIATION = "ContextAssociation"; diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java index 23662726..d096aa46 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java @@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -282,10 +283,10 @@ protected void configure() { */ @Test @DisplayName("DescriptionChangedPrecondition correctly checks for precondition") - public void testDescriptionModificationPreconditionCheck() + public void testDescriptionModificationCrtOrDelPreconditionCheck() throws PreconditionException, IOException, JAXBException { // no messages - assertFalse(ConditionalPreconditions.DescriptionChangedPrecondition.preconditionCheck(testInjector)); + assertFalse(ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.preconditionCheck(testInjector)); final var reportPart = messageBuilder.buildDescriptionModificationReportReportPart(); reportPart.setModificationType(DescriptionModificationType.CRT); @@ -297,7 +298,7 @@ public void testDescriptionModificationPreconditionCheck() messageStorageUtil.addInboundSecureHttpMessage(storage, message); - assertTrue(ConditionalPreconditions.DescriptionChangedPrecondition.preconditionCheck(testInjector)); + assertTrue(ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.preconditionCheck(testInjector)); } /** @@ -334,7 +335,7 @@ public void testDescriptionModificationManipulation() { } }); - assertTrue(ConditionalPreconditions.DescriptionChangedPrecondition.manipulation(testInjector)); + assertTrue(ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.manipulation(testInjector)); final var insertCaptor = ArgumentCaptor.forClass(String.class); final var removeCaptor = ArgumentCaptor.forClass(String.class); @@ -365,6 +366,100 @@ public void testDescriptionModificationManipulation() { .count()); } + /** + * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition.preconditionCheck + * always returns false. + */ + @Test + @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition preconditionCheck always returns" + + " false to trigger the manipulation.") + public void testDescriptionModificationAllWithParentChildRelationshipPreconditionCheck() + { + // no messages - does not matter as the preconditionCheck should always return false + assertFalse(ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.preconditionCheck(testInjector)); + } + + /** + * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation. + */ + @Test + @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation") + public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulation() { + + final var descriptor1Handle = "superHandle"; + final var descriptor2Handle = "handle;Süper;"; + final var parentDescriptorHandle = "parentHandle"; + final var childDescriptorHandle = "childHandle"; + + final var presenceMap = new HashMap<>(Map.of( + descriptor1Handle, false, + descriptor2Handle, true)); + + when(mockManipulations.getRemovableDescriptorsOfClass()) + .thenReturn(List.of(descriptor1Handle, descriptor2Handle)); + + when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), true); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.removeDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), false); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_SUCCESS); + MdibEntity mockEntity = mock(MdibEntity.class); + when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + when(testClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) + .thenReturn(List.of(mockEntity)); + MdibEntity mockEntity2 = mock(MdibEntity.class); + when(testClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) + .thenAnswer(args -> { + if ( presenceMap.get((String)args.getArgument(0))) { + return Optional.of(mockEntity2); + } else { + return Optional.empty(); + } + }); + + assertTrue(ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.manipulation(testInjector)); + + final var insertCaptor = ArgumentCaptor.forClass(String.class); + final var removeCaptor = ArgumentCaptor.forClass(String.class); + final var handleCaptor = ArgumentCaptor.forClass(List.class); + verify(mockManipulations, times(1)).getRemovableDescriptorsOfClass(); + verify(mockManipulations, times(3)).insertDescriptor(insertCaptor.capture()); + verify(mockManipulations, times(2)).removeDescriptor(removeCaptor.capture()); + verify(mockManipulations, times(1)).triggerDescriptorUpdate(handleCaptor.capture()); + + assertEquals(2, handleCaptor.getAllValues().get(0).size()); + assertEquals(childDescriptorHandle, handleCaptor.getAllValues().get(0).get(0)); + assertEquals(parentDescriptorHandle, handleCaptor.getAllValues().get(0).get(1)); + + assertEquals( + 2, + insertCaptor.getAllValues().stream() + .filter(descriptor1Handle::equals) + .count()); + assertEquals( + 1, + insertCaptor.getAllValues().stream() + .filter(descriptor2Handle::equals) + .count()); + + assertEquals( + 1, + removeCaptor.getAllValues().stream() + .filter(descriptor1Handle::equals) + .count()); + assertEquals( + 1, + removeCaptor.getAllValues().stream() + .filter(descriptor2Handle::equals) + .count()); + } + + /** * Tests whether DescriptionModificationCrtPrecondition correctly checks for precondition. * @@ -640,7 +735,7 @@ public void testDescriptionModificationDelManipulation() { @DisplayName("DescriptionModificationPrecondition throws exception if no removable descriptors are present") void testDescriptionModificationModificationNoDescriptors() { // must fail without any removable descriptors - assertFalse(ConditionalPreconditions.DescriptionChangedPrecondition.manipulation(testInjector)); + assertFalse(ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.manipulation(testInjector)); reset(mockManipulations); } From 6bea5e463faf9396f1f71dcc9ff42c51d15d263b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Thu, 7 Sep 2023 11:45:33 +0200 Subject: [PATCH 02/11] Updated CHANGELOG.md and README.md --- CHANGELOG.md | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e70a83d..2a5f50de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - biceps:R0034_0 does not track changes when reinserting descriptors. - report duplication issue in biceps:C11-C15, biceps:C5, biceps:R5046_0, biceps:B-284_0 as well as biceps:R5003. - biceps:5-4-7 tests confusing changes made by SetComponentActivation manipulations with changes made by SetMetricStatus. +- biceps:5025_0 test case could not be satisfied by devices that do not support inserting and removing descriptors. ## [7.0.1] - 2023-03-17 diff --git a/README.md b/README.md index 1243c9eb..65f0e978 100644 --- a/README.md +++ b/README.md @@ -288,7 +288,7 @@ this case in order to minimize the risk of such an invalid application going unn | C-14 | TriggerReport | | C-15 | TriggerReport | | R5024 | TriggerReport | -| R5025_0 | GetRemovableDescriptorsOfClass, RemoveDescriptor, InsertDescriptor | +| R5025_0 | GetRemovableDescriptorsOfClass, RemoveDescriptor, InsertDescriptor, TriggerDescriptorUpdate | | R5046_0 | GetRemovableDescriptorsOfClass, RemoveDescriptor, InsertDescriptor | | R5051 | GetRemovableDescriptorsOfClass, RemoveDescriptor, InsertDescriptor | | R5052 | TriggerAnyDescriptorUpdate | From 482ac47921f9e110732ecf27b882898afe3a2f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Thu, 7 Sep 2023 15:50:32 +0200 Subject: [PATCH 03/11] Made sure no MdsDescriptor is chosen for the Manipulation. --- .../precondition/impl/ConditionalPreconditions.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java index b6bf76e1..354206ee 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java @@ -216,6 +216,9 @@ private static Pair findFirstDescriptorHandleWithChildren(Inject Collection entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class); for (MdibEntity entity : entities) { + if (entity.getDescriptor() instanceof MdsDescriptor) { + continue; // we are not interested in MdsDescriptors as many Devices do not support modifying them. + } List children = entity.getChildren(); if (children.size() > 0) { return Pair.of(entity.getHandle(), children.get(0)); From 5050003f84e21646423391ff584c4a74dfbcfb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Thu, 7 Sep 2023 18:08:51 +0200 Subject: [PATCH 04/11] Changes proposed by Reviewers. spotless:apply --- .../sdccc/manipulation/GRpcManipulations.java | 7 +-- .../sdccc/manipulation/Manipulations.java | 17 +++---- .../impl/ConditionalPreconditions.java | 49 +++++++++++-------- .../InvariantMessageModelAnnexTest.java | 4 +- ...variantParticipantModelVersioningTest.java | 3 +- .../impl/ConditionalPreconditionsTest.java | 41 +++++++++------- 6 files changed, 67 insertions(+), 54 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java index ffbb97eb..05ce40e9 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/GRpcManipulations.java @@ -41,7 +41,6 @@ import java.util.Optional; import java.util.function.Function; import javax.xml.namespace.QName; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.somda.sdc.biceps.model.participant.AbstractDescriptor; @@ -298,9 +297,11 @@ public ResponseTypes.Result triggerDescriptorUpdate(final String handle) { return triggerDescriptorUpdate(List.of(handle)); } + @Override public ResponseTypes.Result triggerDescriptorUpdate(final List handles) { - final var message = - DeviceRequests.TriggerDescriptorUpdateRequest.newBuilder().addAllHandle(handles).build(); + final var message = DeviceRequests.TriggerDescriptorUpdateRequest.newBuilder() + .addAllHandle(handles) + .build(); return performCallWrapper( v -> deviceStub.triggerDescriptorUpdate(message), diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java index df103d67..639f7e8d 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/Manipulations.java @@ -138,19 +138,18 @@ ResponseTypes.Result setMetricStatus( ResponseTypes.Result triggerDescriptorUpdate(String handle); /** - * Trigger a descriptor update for the provided handles (DescriptionModificationReport with one Upt-ReportPart - * for each one of the provided descriptor handles). + * Trigger a descriptor update for the provided descriptor handles. * - * @param handles list of descriptor handles to trigger an Update for. + * @param handles list of descriptor handles to trigger an update for. * @return the result of the manipulation */ - ResponseTypes.Result triggerDescriptorUpdate(final List handles); + ResponseTypes.Result triggerDescriptorUpdate(List handles); - /** - * Trigger a descriptor update for some descriptor (chosen by the device). - * - * @return the result of the manipulation - */ + /** + * Trigger a descriptor update for some descriptor (chosen by the device). + * + * @return the result of the manipulation + */ ResponseTypes.Result triggerAnyDescriptorUpdate(); /** diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java index 354206ee..6ecae402 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java @@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import javax.xml.namespace.QName; - import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -188,23 +187,26 @@ private static boolean descriptionUpdateManipulation(final Injector injector) { return ResponseTypes.Result.RESULT_SUCCESS.equals(manipulationResult); } - private static boolean descriptionUpdateWithParentChildRelationshipManipulation(final Injector injector, final Logger log) { - Pair descriptorHandles = findFirstDescriptorHandleWithChildren(injector, log); + private static boolean descriptionUpdateWithParentChildRelationshipManipulation( + final Injector injector, final Logger log) { + final Pair descriptorHandles = findFirstDescriptorHandleWithChildren(injector, log); if (descriptorHandles == null) { - log.error("Could not trigger a Descriptor Update with Parent Child Relationship as there are no " + - "Descriptors with Children in the Mdib."); + log.error("Could not trigger a descriptor update with parent child relationship as there are no " + + "descriptors with children in the mdib."); return false; } - String parentDescriptorHandle = descriptorHandles.getLeft(); - String childDescriptorHandle = descriptorHandles.getRight(); + final String parentDescriptorHandle = descriptorHandles.getLeft(); + final String childDescriptorHandle = descriptorHandles.getRight(); final var manipulations = injector.getInstance(Manipulations.class); - final ResponseTypes.Result manipulationResult = manipulations.triggerDescriptorUpdate(List.of(childDescriptorHandle, parentDescriptorHandle)); + final ResponseTypes.Result manipulationResult = + manipulations.triggerDescriptorUpdate(List.of(childDescriptorHandle, parentDescriptorHandle)); return ResponseTypes.Result.RESULT_SUCCESS.equals(manipulationResult); } - private static Pair findFirstDescriptorHandleWithChildren(Injector injector, Logger log) { + private static Pair findFirstDescriptorHandleWithChildren( + final Injector injector, final Logger log) { final var testClient = injector.getInstance(TestClient.class); final var remoteDevice = testClient.getSdcRemoteDevice(); @@ -212,15 +214,15 @@ private static Pair findFirstDescriptorHandleWithChildren(Inject log.error("remote device could not be accessed, likely due to a disconnect"); return null; } - var mdibAccess = remoteDevice.getMdibAccess(); + final var mdibAccess = remoteDevice.getMdibAccess(); - Collection entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class); + final Collection entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class); for (MdibEntity entity : entities) { if (entity.getDescriptor() instanceof MdsDescriptor) { - continue; // we are not interested in MdsDescriptors as many Devices do not support modifying them. + continue; // we are not interested in MdsDescriptors as many Devices do not support modifying them. } - List children = entity.getChildren(); - if (children.size() > 0) { + final List children = entity.getChildren(); + if (!children.isEmpty()) { return Pair.of(entity.getHandle(), children.get(0)); } } @@ -706,10 +708,12 @@ public static class DescriptionModificationCrtOrDelPrecondition extends SimplePr private static final Logger LOG = LogManager.getLogger(DescriptionModificationCrtOrDelPrecondition.class); /** - * Creates a description changed precondition check. + * Creates a description modification crt or del precondition check. */ public DescriptionModificationCrtOrDelPrecondition() { - super(DescriptionModificationCrtOrDelPrecondition::preconditionCheck, DescriptionModificationCrtOrDelPrecondition::manipulation); + super( + DescriptionModificationCrtOrDelPrecondition::preconditionCheck, + DescriptionModificationCrtOrDelPrecondition::manipulation); } static boolean preconditionCheck(final Injector injector) throws PreconditionException { @@ -734,13 +738,16 @@ static boolean manipulation(final Injector injector) { */ public static class DescriptionModificationAllWithParentChildRelationshipPrecondition extends SimplePrecondition { - private static final Logger LOG = LogManager.getLogger(DescriptionModificationAllWithParentChildRelationshipPrecondition.class); + private static final Logger LOG = + LogManager.getLogger(DescriptionModificationAllWithParentChildRelationshipPrecondition.class); /** - * Creates a description changed precondition check. + * Creates a description modification all with parent child relationship precondition check. */ public DescriptionModificationAllWithParentChildRelationshipPrecondition() { - super(DescriptionModificationAllWithParentChildRelationshipPrecondition::preconditionCheck, DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation); + super( + DescriptionModificationAllWithParentChildRelationshipPrecondition::preconditionCheck, + DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation); } static boolean preconditionCheck(final Injector injector) { @@ -755,8 +762,8 @@ static boolean preconditionCheck(final Injector injector) { * @throws PreconditionException on errors */ static boolean manipulation(final Injector injector) { - boolean result1 = descriptionModificationManipulation(injector, LOG); - boolean result2 = descriptionUpdateWithParentChildRelationshipManipulation(injector, LOG); + final boolean result1 = descriptionModificationManipulation(injector, LOG); + final boolean result2 = descriptionUpdateWithParentChildRelationshipManipulation(injector, LOG); return result1 && result2; } } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java index 79e1391f..0ea0eadb 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java @@ -332,7 +332,9 @@ void testRequirementR5024() throws NoTestData, IOException { @TestDescription("For every DescriptionModificationReport received from the DUT, and for all parent-child" + " relationships between the elements contained in the report, checks that the reportPart containing" + " the parent comes before the reportPart containing the child.") - @RequirePrecondition(simplePreconditions = ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.class) + @RequirePrecondition( + simplePreconditions = + ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.class) void testRequirementR5025() throws NoTestData, IOException { try (final var messages = messageStorage.getInboundMessagesByBodyType(Constants.MSG_DESCRIPTION_MODIFICATION_REPORT)) { 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 314c9851..0e8d37c5 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 @@ -80,7 +80,8 @@ void setUp() { @TestDescription( "Starting from the initially retrieved mdib, applies every episodic report to the mdib and" + " verifies that descriptor versions are incremented by 1 whenever a child descriptor is added or deleted.") - @RequirePrecondition(simplePreconditions = {ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.class}) + @RequirePrecondition( + simplePreconditions = {ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.class}) void testRequirementR0033() throws NoTestData, IOException { final var mdibHistorian = mdibHistorianFactory.createMdibHistorian( messageStorage, getInjector().getInstance(TestRunObserver.class)); diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java index d096aa46..4a0944b4 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java @@ -286,7 +286,8 @@ protected void configure() { public void testDescriptionModificationCrtOrDelPreconditionCheck() throws PreconditionException, IOException, JAXBException { // no messages - assertFalse(ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.preconditionCheck(testInjector)); + assertFalse( + ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.preconditionCheck(testInjector)); final var reportPart = messageBuilder.buildDescriptionModificationReportReportPart(); reportPart.setModificationType(DescriptionModificationType.CRT); @@ -298,7 +299,8 @@ public void testDescriptionModificationCrtOrDelPreconditionCheck() messageStorageUtil.addInboundSecureHttpMessage(storage, message); - assertTrue(ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.preconditionCheck(testInjector)); + assertTrue( + ConditionalPreconditions.DescriptionModificationCrtOrDelPrecondition.preconditionCheck(testInjector)); } /** @@ -371,12 +373,13 @@ public void testDescriptionModificationManipulation() { * always returns false. */ @Test - @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition preconditionCheck always returns" + - " false to trigger the manipulation.") - public void testDescriptionModificationAllWithParentChildRelationshipPreconditionCheck() - { + @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition preconditionCheck always returns" + + " false to trigger the manipulation.") + public void testDescriptionModificationAllWithParentChildRelationshipPreconditionCheck() { // no messages - does not matter as the preconditionCheck should always return false - assertFalse(ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.preconditionCheck(testInjector)); + assertFalse( + ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition + .preconditionCheck(testInjector)); } /** @@ -407,22 +410,23 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio return ResponseTypes.Result.RESULT_SUCCESS; }); when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_SUCCESS); - MdibEntity mockEntity = mock(MdibEntity.class); + final MdibEntity mockEntity = mock(MdibEntity.class); when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); when(testClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) .thenReturn(List.of(mockEntity)); - MdibEntity mockEntity2 = mock(MdibEntity.class); - when(testClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) - .thenAnswer(args -> { - if ( presenceMap.get((String)args.getArgument(0))) { - return Optional.of(mockEntity2); - } else { - return Optional.empty(); - } - }); + final MdibEntity mockEntity2 = mock(MdibEntity.class); + when(testClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())).thenAnswer(args -> { + if (presenceMap.get((String) args.getArgument(0))) { + return Optional.of(mockEntity2); + } else { + return Optional.empty(); + } + }); - assertTrue(ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.manipulation(testInjector)); + assertTrue( + ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.manipulation( + testInjector)); final var insertCaptor = ArgumentCaptor.forClass(String.class); final var removeCaptor = ArgumentCaptor.forClass(String.class); @@ -459,7 +463,6 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio .count()); } - /** * Tests whether DescriptionModificationCrtPrecondition correctly checks for precondition. * From 84cc9c80dd233e05e1b699b9974626a1bb3208cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Fri, 8 Sep 2023 10:59:49 +0200 Subject: [PATCH 05/11] Added a note to test case Biceps:R5025. --- .../tests/biceps/invariant/InvariantMessageModelAnnexTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java index 0ea0eadb..b108c8af 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java @@ -332,6 +332,9 @@ void testRequirementR5024() throws NoTestData, IOException { @TestDescription("For every DescriptionModificationReport received from the DUT, and for all parent-child" + " relationships between the elements contained in the report, checks that the reportPart containing" + " the parent comes before the reportPart containing the child.") + // NOTE: for this test case to succeed, the device should support descriptor updates or the list of removable + // descriptors returned by the getRemovableDescriptors() manipulation should include at least one descriptor + // that has child descriptors. @RequirePrecondition( simplePreconditions = ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.class) From 875e0b68320bd7114dd347e88339588e9aecc97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Fri, 8 Sep 2023 15:27:54 +0200 Subject: [PATCH 06/11] Moved DescriptionModificationAllWithParentChildRelationshipPrecondition to ManipulationPreconditions. --- .../impl/ConditionalPreconditions.java | 77 ------- .../impl/ManipulationPreconditions.java | 200 ++++++++++++------ .../InvariantMessageModelAnnexTest.java | 5 +- .../impl/ConditionalPreconditionsTest.java | 95 --------- .../impl/ManipulationPreconditionsTest.java | 93 ++++++++ 5 files changed, 237 insertions(+), 233 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java index 6ecae402..27f1b6b7 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java @@ -187,48 +187,6 @@ private static boolean descriptionUpdateManipulation(final Injector injector) { return ResponseTypes.Result.RESULT_SUCCESS.equals(manipulationResult); } - private static boolean descriptionUpdateWithParentChildRelationshipManipulation( - final Injector injector, final Logger log) { - final Pair descriptorHandles = findFirstDescriptorHandleWithChildren(injector, log); - if (descriptorHandles == null) { - log.error("Could not trigger a descriptor update with parent child relationship as there are no " - + "descriptors with children in the mdib."); - return false; - } - final String parentDescriptorHandle = descriptorHandles.getLeft(); - final String childDescriptorHandle = descriptorHandles.getRight(); - final var manipulations = injector.getInstance(Manipulations.class); - - final ResponseTypes.Result manipulationResult = - manipulations.triggerDescriptorUpdate(List.of(childDescriptorHandle, parentDescriptorHandle)); - - return ResponseTypes.Result.RESULT_SUCCESS.equals(manipulationResult); - } - - private static Pair findFirstDescriptorHandleWithChildren( - final Injector injector, final Logger log) { - final var testClient = injector.getInstance(TestClient.class); - - final var remoteDevice = testClient.getSdcRemoteDevice(); - if (remoteDevice == null) { - log.error("remote device could not be accessed, likely due to a disconnect"); - return null; - } - final var mdibAccess = remoteDevice.getMdibAccess(); - - final Collection entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class); - for (MdibEntity entity : entities) { - if (entity.getDescriptor() instanceof MdsDescriptor) { - continue; // we are not interested in MdsDescriptors as many Devices do not support modifying them. - } - final List children = entity.getChildren(); - if (!children.isEmpty()) { - return Pair.of(entity.getHandle(), children.get(0)); - } - } - return null; - } - private static boolean triggerReportPreconditionCheck( final Injector injector, final Logger log, final QName... reportType) throws PreconditionException { final var messageStorage = injector.getInstance(MessageStorage.class); @@ -733,41 +691,6 @@ static boolean manipulation(final Injector injector) { } } - /** - * Precondition which triggers all possible description changes with parent-child relationships. - */ - public static class DescriptionModificationAllWithParentChildRelationshipPrecondition extends SimplePrecondition { - - private static final Logger LOG = - LogManager.getLogger(DescriptionModificationAllWithParentChildRelationshipPrecondition.class); - - /** - * Creates a description modification all with parent child relationship precondition check. - */ - public DescriptionModificationAllWithParentChildRelationshipPrecondition() { - super( - DescriptionModificationAllWithParentChildRelationshipPrecondition::preconditionCheck, - DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation); - } - - static boolean preconditionCheck(final Injector injector) { - return false; // always trigger description changes - } - - /** - * Performs the removal, reinsertion and update of all modifiable descriptors in the mdib to trigger reports. - * - * @param injector to analyze mdib on - * @return true if successful, false otherwise - * @throws PreconditionException on errors - */ - static boolean manipulation(final Injector injector) { - final boolean result1 = descriptionModificationManipulation(injector, LOG); - final boolean result2 = descriptionUpdateWithParentChildRelationshipManipulation(injector, LOG); - return result1 && result2; - } - } - /** * Precondition which checks whether all context descriptors had at least two different context states * associated, triggering context state associations otherwise. diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java index db31af2e..44447916 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java @@ -10,6 +10,7 @@ import com.draeger.medical.sdccc.configuration.TestSuiteConfig; import com.draeger.medical.sdccc.manipulation.Manipulations; import com.draeger.medical.sdccc.manipulation.precondition.ManipulationPrecondition; +import com.draeger.medical.sdccc.manipulation.precondition.PreconditionException; import com.draeger.medical.sdccc.sdcri.testclient.TestClient; import com.draeger.medical.sdccc.tests.util.ImpliedValueUtil; import com.draeger.medical.sdccc.util.TestRunObserver; @@ -29,6 +30,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; + +import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.somda.sdc.biceps.common.MdibEntity; @@ -38,6 +41,7 @@ import org.somda.sdc.biceps.common.event.ContextStateModificationMessage; import org.somda.sdc.biceps.model.participant.AbstractAlertState; import org.somda.sdc.biceps.model.participant.AbstractContextState; +import org.somda.sdc.biceps.model.participant.AbstractDescriptor; import org.somda.sdc.biceps.model.participant.AbstractDeviceComponentDescriptor; import org.somda.sdc.biceps.model.participant.AbstractDeviceComponentState; import org.somda.sdc.biceps.model.participant.AbstractMetricDescriptor; @@ -55,6 +59,7 @@ 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.MdsDescriptor; import org.somda.sdc.biceps.model.participant.MetricCategory; import org.somda.sdc.biceps.model.participant.PatientContextDescriptor; import org.somda.sdc.biceps.model.participant.PatientContextState; @@ -114,6 +119,114 @@ private static boolean manipulateMetricStatus( return manipulationResults.contains(ResponseTypes.Result.RESULT_SUCCESS); } + private static boolean removeAndReinsertDescriptors(final Injector injector, final Logger log) { + final var manipulations = injector.getInstance(Manipulations.class); + final var testClient = injector.getInstance(TestClient.class); + final var testRunObserver = injector.getInstance(TestRunObserver.class); + + final MdibAccess mdibAccess; + final SdcRemoteDevice remoteDevice; + + remoteDevice = testClient.getSdcRemoteDevice(); + if (remoteDevice == null) { + testRunObserver.invalidateTestRun("Remote device could not be accessed, likely due to a disconnect"); + return false; + } + + mdibAccess = remoteDevice.getMdibAccess(); + + final var modifiableDescriptors = manipulations.getRemovableDescriptorsOfClass(); + if (modifiableDescriptors.isEmpty()) { + log.info("No modifiable descriptors available for manipulation"); + return false; + } + + final var manipulationResults = new HashSet(); + for (String handle : modifiableDescriptors) { + // determine if descriptor is currently present + var descriptorEntity = mdibAccess.getEntity(handle); + log.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); + + // if the descriptor is not present, insert it first + if (descriptorEntity.isEmpty()) { + manipulationResults.add(manipulations.insertDescriptor(handle)); + descriptorEntity = mdibAccess.getEntity(handle); + if (descriptorEntity.isEmpty()) { + manipulationResults.add(ResponseTypes.Result.RESULT_FAIL); + } + log.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); + } + + // remove descriptor + manipulationResults.add(manipulations.removeDescriptor(handle)); + descriptorEntity = mdibAccess.getEntity(handle); + if (descriptorEntity.isPresent()) { + manipulationResults.add(ResponseTypes.Result.RESULT_FAIL); + } + log.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); + + // reinsert descriptor + manipulationResults.add(manipulations.insertDescriptor(handle)); + descriptorEntity = mdibAccess.getEntity(handle); + if (descriptorEntity.isEmpty()) { + manipulationResults.add(ResponseTypes.Result.RESULT_FAIL); + } + log.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); + + if (manipulationResults.contains(ResponseTypes.Result.RESULT_FAIL)) { + testRunObserver.invalidateTestRun(String.format( + "Could not successfully modify descriptor %s, stopping the precondition", handle)); + break; + } + } + + return !manipulationResults.contains(ResponseTypes.Result.RESULT_FAIL) + && !manipulationResults.contains(ResponseTypes.Result.RESULT_NOT_IMPLEMENTED) + && manipulationResults.contains(ResponseTypes.Result.RESULT_SUCCESS); + } + + private static boolean descriptionUpdateWithParentChildRelationshipManipulation( + final Injector injector, final Logger log) { + final Pair descriptorHandles = findFirstDescriptorHandleWithChildren(injector, log); + if (descriptorHandles == null) { + log.error("Could not trigger a descriptor update with parent child relationship as there are no " + + "descriptors with children in the mdib."); + return false; + } + final String parentDescriptorHandle = descriptorHandles.getLeft(); + final String childDescriptorHandle = descriptorHandles.getRight(); + final var manipulations = injector.getInstance(Manipulations.class); + + final ResponseTypes.Result manipulationResult = + manipulations.triggerDescriptorUpdate(List.of(childDescriptorHandle, parentDescriptorHandle)); + + return ResponseTypes.Result.RESULT_SUCCESS.equals(manipulationResult); + } + + private static Pair findFirstDescriptorHandleWithChildren( + final Injector injector, final Logger log) { + final var testClient = injector.getInstance(TestClient.class); + + final var remoteDevice = testClient.getSdcRemoteDevice(); + if (remoteDevice == null) { + log.error("remote device could not be accessed, likely due to a disconnect"); + return null; + } + final var mdibAccess = remoteDevice.getMdibAccess(); + + final Collection entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class); + for (MdibEntity entity : entities) { + if (entity.getDescriptor() instanceof MdsDescriptor) { + continue; // we are not interested in MdsDescriptors as many Devices do not support modifying them. + } + final List children = entity.getChildren(); + if (!children.isEmpty()) { + return Pair.of(entity.getHandle(), children.get(0)); + } + } + return null; + } + /** * Associates two new patients for every available PatientContextDescriptor present in the provider mdib. */ @@ -1607,69 +1720,38 @@ public RemoveAndReinsertDescriptorManipulation() { * @return true if successful, false otherwise */ static boolean manipulation(final Injector injector) { - final var manipulations = injector.getInstance(Manipulations.class); - final var testClient = injector.getInstance(TestClient.class); - final var testRunObserver = injector.getInstance(TestRunObserver.class); - - final MdibAccess mdibAccess; - final SdcRemoteDevice remoteDevice; - - remoteDevice = testClient.getSdcRemoteDevice(); - if (remoteDevice == null) { - testRunObserver.invalidateTestRun("Remote device could not be accessed, likely due to a disconnect"); - return false; - } - - mdibAccess = remoteDevice.getMdibAccess(); - - final var modifiableDescriptors = manipulations.getRemovableDescriptorsOfClass(); - if (modifiableDescriptors.isEmpty()) { - LOG.info("No modifiable descriptors available for manipulation"); - return false; - } - - final var manipulationResults = new HashSet(); - for (String handle : modifiableDescriptors) { - // determine if descriptor is currently present - var descriptorEntity = mdibAccess.getEntity(handle); - LOG.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); - - // if the descriptor is not present, insert it first - if (descriptorEntity.isEmpty()) { - manipulationResults.add(manipulations.insertDescriptor(handle)); - descriptorEntity = mdibAccess.getEntity(handle); - if (descriptorEntity.isEmpty()) { - manipulationResults.add(ResponseTypes.Result.RESULT_FAIL); - } - LOG.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); - } + return removeAndReinsertDescriptors(injector, LOG); + } + } - // remove descriptor - manipulationResults.add(manipulations.removeDescriptor(handle)); - descriptorEntity = mdibAccess.getEntity(handle); - if (descriptorEntity.isPresent()) { - manipulationResults.add(ResponseTypes.Result.RESULT_FAIL); - } - LOG.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); + /** + * Precondition which triggers all possible description changes with parent-child relationships. + */ + public static class DescriptionModificationAllWithParentChildRelationshipPrecondition extends ManipulationPrecondition { - // reinsert descriptor - manipulationResults.add(manipulations.insertDescriptor(handle)); - descriptorEntity = mdibAccess.getEntity(handle); - if (descriptorEntity.isEmpty()) { - manipulationResults.add(ResponseTypes.Result.RESULT_FAIL); - } - LOG.debug("Descriptor {} presence: {}", handle, descriptorEntity.isPresent()); + private static final Logger LOG = + LogManager.getLogger(DescriptionModificationAllWithParentChildRelationshipPrecondition.class); - if (manipulationResults.contains(ResponseTypes.Result.RESULT_FAIL)) { - testRunObserver.invalidateTestRun(String.format( - "Could not successfully modify descriptor %s, stopping the precondition", handle)); - break; - } - } + /** + * Creates a description modification all with parent child relationship precondition check. + */ + public DescriptionModificationAllWithParentChildRelationshipPrecondition() { + super( + DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation); + } - return !manipulationResults.contains(ResponseTypes.Result.RESULT_FAIL) - && !manipulationResults.contains(ResponseTypes.Result.RESULT_NOT_IMPLEMENTED) - && manipulationResults.contains(ResponseTypes.Result.RESULT_SUCCESS); + /** + * Performs the removal, reinsertion and update of all modifiable descriptors in the mdib to trigger reports. + * + * @param injector to analyze mdib on + * @return true if successful, false otherwise + * @throws PreconditionException on errors + */ + static boolean manipulation(final Injector injector) { + final boolean result1 = removeAndReinsertDescriptors(injector, LOG); + final boolean result2 = descriptionUpdateWithParentChildRelationshipManipulation(injector, LOG); + return result1 && result2; } } + } diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java index b108c8af..43e24450 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java @@ -15,6 +15,7 @@ import com.draeger.medical.sdccc.configuration.EnabledTestConfig; import com.draeger.medical.sdccc.manipulation.precondition.impl.ConditionalPreconditions; +import com.draeger.medical.sdccc.manipulation.precondition.impl.ManipulationPreconditions; import com.draeger.medical.sdccc.messages.MessageStorage; import com.draeger.medical.sdccc.messages.mapping.MessageContent; import com.draeger.medical.sdccc.sdcri.testclient.TestClient; @@ -336,8 +337,8 @@ void testRequirementR5024() throws NoTestData, IOException { // descriptors returned by the getRemovableDescriptors() manipulation should include at least one descriptor // that has child descriptors. @RequirePrecondition( - simplePreconditions = - ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.class) + manipulationPreconditions = + ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.class) void testRequirementR5025() throws NoTestData, IOException { try (final var messages = messageStorage.getInboundMessagesByBodyType(Constants.MSG_DESCRIPTION_MODIFICATION_REPORT)) { diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java index 4a0944b4..9ae9a931 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java @@ -368,101 +368,6 @@ public void testDescriptionModificationManipulation() { .count()); } - /** - * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition.preconditionCheck - * always returns false. - */ - @Test - @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition preconditionCheck always returns" - + " false to trigger the manipulation.") - public void testDescriptionModificationAllWithParentChildRelationshipPreconditionCheck() { - // no messages - does not matter as the preconditionCheck should always return false - assertFalse( - ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition - .preconditionCheck(testInjector)); - } - - /** - * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation. - */ - @Test - @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation") - public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulation() { - - final var descriptor1Handle = "superHandle"; - final var descriptor2Handle = "handle;Süper;"; - final var parentDescriptorHandle = "parentHandle"; - final var childDescriptorHandle = "childHandle"; - - final var presenceMap = new HashMap<>(Map.of( - descriptor1Handle, false, - descriptor2Handle, true)); - - when(mockManipulations.getRemovableDescriptorsOfClass()) - .thenReturn(List.of(descriptor1Handle, descriptor2Handle)); - - when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { - presenceMap.put(invocation.getArgument(0), true); - return ResponseTypes.Result.RESULT_SUCCESS; - }); - when(mockManipulations.removeDescriptor(anyString())).thenAnswer((Answer) invocation -> { - presenceMap.put(invocation.getArgument(0), false); - return ResponseTypes.Result.RESULT_SUCCESS; - }); - when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_SUCCESS); - final MdibEntity mockEntity = mock(MdibEntity.class); - when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); - when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); - when(testClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) - .thenReturn(List.of(mockEntity)); - final MdibEntity mockEntity2 = mock(MdibEntity.class); - when(testClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())).thenAnswer(args -> { - if (presenceMap.get((String) args.getArgument(0))) { - return Optional.of(mockEntity2); - } else { - return Optional.empty(); - } - }); - - assertTrue( - ConditionalPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.manipulation( - testInjector)); - - final var insertCaptor = ArgumentCaptor.forClass(String.class); - final var removeCaptor = ArgumentCaptor.forClass(String.class); - final var handleCaptor = ArgumentCaptor.forClass(List.class); - verify(mockManipulations, times(1)).getRemovableDescriptorsOfClass(); - verify(mockManipulations, times(3)).insertDescriptor(insertCaptor.capture()); - verify(mockManipulations, times(2)).removeDescriptor(removeCaptor.capture()); - verify(mockManipulations, times(1)).triggerDescriptorUpdate(handleCaptor.capture()); - - assertEquals(2, handleCaptor.getAllValues().get(0).size()); - assertEquals(childDescriptorHandle, handleCaptor.getAllValues().get(0).get(0)); - assertEquals(parentDescriptorHandle, handleCaptor.getAllValues().get(0).get(1)); - - assertEquals( - 2, - insertCaptor.getAllValues().stream() - .filter(descriptor1Handle::equals) - .count()); - assertEquals( - 1, - insertCaptor.getAllValues().stream() - .filter(descriptor2Handle::equals) - .count()); - - assertEquals( - 1, - removeCaptor.getAllValues().stream() - .filter(descriptor1Handle::equals) - .count()); - assertEquals( - 1, - removeCaptor.getAllValues().stream() - .filter(descriptor2Handle::equals) - .count()); - } - /** * Tests whether DescriptionModificationCrtPrecondition correctly checks for precondition. * diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java index 199b5142..371f3f99 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java @@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; @@ -23,7 +24,10 @@ import static org.mockito.Mockito.when; import com.draeger.medical.sdccc.manipulation.Manipulations; +import com.draeger.medical.sdccc.messages.MessageStorage; import com.draeger.medical.sdccc.sdcri.testclient.TestClient; +import com.draeger.medical.sdccc.sdcri.testclient.TestClientUtil; +import com.draeger.medical.sdccc.tests.InjectorTestBase; import com.draeger.medical.sdccc.tests.test_util.InjectorUtil; import com.draeger.medical.sdccc.util.MdibBuilder; import com.draeger.medical.sdccc.util.TestRunObserver; @@ -32,6 +36,7 @@ import com.google.inject.Injector; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -47,6 +52,7 @@ import org.mockito.Answers; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import org.mockito.stubbing.Answer; import org.somda.sdc.biceps.common.MdibEntity; import org.somda.sdc.biceps.common.access.MdibAccess; import org.somda.sdc.biceps.common.access.MdibAccessObservable; @@ -188,7 +194,11 @@ void setUp() throws IOException { mockMdibAccess = mock(MdibAccess.class, Answers.RETURNS_DEEP_STUBS); mockTestClient = mock(TestClient.class, Answers.RETURNS_DEEP_STUBS); + final var clientInjector = TestClientUtil.createClientInjector(); when(mockTestClient.getSdcRemoteDevice()).thenReturn(mockDevice); + when(mockTestClient.isClientRunning()).thenReturn(true); + when(mockTestClient.getSdcRemoteDevice()).thenReturn(mockDevice); + when(mockTestClient.getInjector()).thenReturn(clientInjector); injector = InjectorUtil.setupInjector(new AbstractModule() { @Override @@ -199,6 +209,7 @@ protected void configure() { } }); + InjectorTestBase.setInjector(injector); testRunObserver = injector.getInstance(TestRunObserver.class); } @@ -1897,4 +1908,86 @@ void testSystemSignalActivationSomeFail() { assertFalse(ManipulationPreconditions.SystemSignalActivationManipulation.manipulation(injector)); } + + /** + * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation. + */ + @Test + @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation") + public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulation() { + + final var descriptor1Handle = "superHandle"; + final var descriptor2Handle = "handle;Süper;"; + final var parentDescriptorHandle = "parentHandle"; + final var childDescriptorHandle = "childHandle"; + + final var presenceMap = new HashMap<>(Map.of( + descriptor1Handle, false, + descriptor2Handle, true)); + + when(mockManipulations.getRemovableDescriptorsOfClass()) + .thenReturn(List.of(descriptor1Handle, descriptor2Handle)); + + when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), true); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.removeDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), false); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_SUCCESS); + final MdibEntity mockEntity = mock(MdibEntity.class); + when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) + .thenReturn(List.of(mockEntity)); + final MdibEntity mockEntity2 = mock(MdibEntity.class); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())).thenAnswer(args -> { + if (presenceMap.get((String) args.getArgument(0))) { + return Optional.of(mockEntity2); + } else { + return Optional.empty(); + } + }); + + assertTrue( + ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.manipulation( + injector)); + + final var insertCaptor = ArgumentCaptor.forClass(String.class); + final var removeCaptor = ArgumentCaptor.forClass(String.class); + final var handleCaptor = ArgumentCaptor.forClass(List.class); + verify(mockManipulations, times(1)).getRemovableDescriptorsOfClass(); + verify(mockManipulations, times(3)).insertDescriptor(insertCaptor.capture()); + verify(mockManipulations, times(2)).removeDescriptor(removeCaptor.capture()); + verify(mockManipulations, times(1)).triggerDescriptorUpdate(handleCaptor.capture()); + + assertEquals(2, handleCaptor.getAllValues().get(0).size()); + assertEquals(childDescriptorHandle, handleCaptor.getAllValues().get(0).get(0)); + assertEquals(parentDescriptorHandle, handleCaptor.getAllValues().get(0).get(1)); + + assertEquals( + 2, + insertCaptor.getAllValues().stream() + .filter(descriptor1Handle::equals) + .count()); + assertEquals( + 1, + insertCaptor.getAllValues().stream() + .filter(descriptor2Handle::equals) + .count()); + + assertEquals( + 1, + removeCaptor.getAllValues().stream() + .filter(descriptor1Handle::equals) + .count()); + assertEquals( + 1, + removeCaptor.getAllValues().stream() + .filter(descriptor2Handle::equals) + .count()); + } + } From 4129807ee40616304406473f30da09fcaa610f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Fri, 8 Sep 2023 17:07:29 +0200 Subject: [PATCH 07/11] Added test cases for DescriptionModificationAllWithParentChildRelationshipPrecondition. --- .../impl/ConditionalPreconditions.java | 1 - .../impl/ManipulationPreconditions.java | 10 +- .../impl/ConditionalPreconditionsTest.java | 1 - .../impl/ManipulationPreconditionsTest.java | 226 +++++++++++++++++- 4 files changed, 220 insertions(+), 18 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java index 27f1b6b7..2494891c 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditions.java @@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import javax.xml.namespace.QName; -import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.somda.sdc.biceps.common.MdibEntity; diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java index 44447916..f3199a0e 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditions.java @@ -30,7 +30,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; - import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -1727,7 +1726,8 @@ static boolean manipulation(final Injector injector) { /** * Precondition which triggers all possible description changes with parent-child relationships. */ - public static class DescriptionModificationAllWithParentChildRelationshipPrecondition extends ManipulationPrecondition { + public static class DescriptionModificationAllWithParentChildRelationshipPrecondition + extends ManipulationPrecondition { private static final Logger LOG = LogManager.getLogger(DescriptionModificationAllWithParentChildRelationshipPrecondition.class); @@ -1736,8 +1736,7 @@ public static class DescriptionModificationAllWithParentChildRelationshipPrecond * Creates a description modification all with parent child relationship precondition check. */ public DescriptionModificationAllWithParentChildRelationshipPrecondition() { - super( - DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation); + super(DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation); } /** @@ -1750,8 +1749,7 @@ public DescriptionModificationAllWithParentChildRelationshipPrecondition() { static boolean manipulation(final Injector injector) { final boolean result1 = removeAndReinsertDescriptors(injector, LOG); final boolean result2 = descriptionUpdateWithParentChildRelationshipManipulation(injector, LOG); - return result1 && result2; + return result1 || result2; } } - } diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java index 9ae9a931..6cbab165 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ConditionalPreconditionsTest.java @@ -11,7 +11,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java index 371f3f99..edd072da 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java @@ -24,7 +24,6 @@ import static org.mockito.Mockito.when; import com.draeger.medical.sdccc.manipulation.Manipulations; -import com.draeger.medical.sdccc.messages.MessageStorage; import com.draeger.medical.sdccc.sdcri.testclient.TestClient; import com.draeger.medical.sdccc.sdcri.testclient.TestClientUtil; import com.draeger.medical.sdccc.tests.InjectorTestBase; @@ -101,7 +100,6 @@ public class ManipulationPreconditionsTest { private static final String ALERT_SYSTEM_CONTEXT_HANDLE2 = "alerthandle2"; private static final String ALERT_CONDITION_HANDLE = "alertconditionhandle"; private static final String ALERT_CONDITION_HANDLE2 = "alertconditionhandle2"; - private static final String ALERT_SIGNAL_HANDLE = "alertSignalHandle"; private static final String AUD_ALERT_SIGNAL_HANDLE = "audAlertSignalHandle"; private static final String OTH_ALERT_SIGNAL_HANDLE = "othAlertSignalHandle"; private static final String TAN_ALERT_SIGNAL_HANDLE = "tanAlertSignalHandle"; @@ -1943,17 +1941,163 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) .thenReturn(List.of(mockEntity)); final MdibEntity mockEntity2 = mock(MdibEntity.class); - when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())).thenAnswer(args -> { - if (presenceMap.get((String) args.getArgument(0))) { - return Optional.of(mockEntity2); - } else { - return Optional.empty(); - } + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) + .thenAnswer(args -> { + if (presenceMap.get((String) args.getArgument(0))) { + return Optional.of(mockEntity2); + } else { + return Optional.empty(); + } + }); + + assertTrue( + ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition + .manipulation(injector)); + + final var insertCaptor = ArgumentCaptor.forClass(String.class); + final var removeCaptor = ArgumentCaptor.forClass(String.class); + final var handleCaptor = ArgumentCaptor.forClass(List.class); + verify(mockManipulations, times(1)).getRemovableDescriptorsOfClass(); + verify(mockManipulations, times(3)).insertDescriptor(insertCaptor.capture()); + verify(mockManipulations, times(2)).removeDescriptor(removeCaptor.capture()); + verify(mockManipulations, times(1)).triggerDescriptorUpdate(handleCaptor.capture()); + + assertEquals(2, handleCaptor.getAllValues().get(0).size()); + assertEquals(childDescriptorHandle, handleCaptor.getAllValues().get(0).get(0)); + assertEquals(parentDescriptorHandle, handleCaptor.getAllValues().get(0).get(1)); + + assertEquals( + 2, + insertCaptor.getAllValues().stream() + .filter(descriptor1Handle::equals) + .count()); + assertEquals( + 1, + insertCaptor.getAllValues().stream() + .filter(descriptor2Handle::equals) + .count()); + + assertEquals( + 1, + removeCaptor.getAllValues().stream() + .filter(descriptor1Handle::equals) + .count()); + assertEquals( + 1, + removeCaptor.getAllValues().stream() + .filter(descriptor2Handle::equals) + .count()); + } + + /** + * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition succeeds even when + * GetRemovableDescriptors failed. + */ + @Test + @DisplayName( + "DescriptionModificationAllWithParentChildRelationshipPrecondition when GetRemovableDescriptors failed.") + public void + testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationGetRemovableDescriptorsFailed() { + + final var descriptor1Handle = "superHandle"; + final var descriptor2Handle = "handle;Süper;"; + final var parentDescriptorHandle = "parentHandle"; + final var childDescriptorHandle = "childHandle"; + + final var presenceMap = new HashMap<>(Map.of( + descriptor1Handle, false, + descriptor2Handle, true)); + + when(mockManipulations.getRemovableDescriptorsOfClass()) + .thenReturn(List.of()); // WHen the Manipulation is NOT_SUPPORTED, an empty List is returned. + + when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), true); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.removeDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), false); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_SUCCESS); + final MdibEntity mockEntity = mock(MdibEntity.class); + when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) + .thenReturn(List.of(mockEntity)); + final MdibEntity mockEntity2 = mock(MdibEntity.class); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) + .thenAnswer(args -> { + if (presenceMap.get((String) args.getArgument(0))) { + return Optional.of(mockEntity2); + } else { + return Optional.empty(); + } + }); + + assertTrue( + ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition + .manipulation(injector)); + + final var handleCaptor = ArgumentCaptor.forClass(List.class); + verify(mockManipulations, times(1)).getRemovableDescriptorsOfClass(); + verify(mockManipulations, times(0)).insertDescriptor(any()); + verify(mockManipulations, times(0)).removeDescriptor(any()); + verify(mockManipulations, times(1)).triggerDescriptorUpdate(handleCaptor.capture()); + + assertEquals(2, handleCaptor.getAllValues().get(0).size()); + assertEquals(childDescriptorHandle, handleCaptor.getAllValues().get(0).get(0)); + assertEquals(parentDescriptorHandle, handleCaptor.getAllValues().get(0).get(1)); + } + + /** + * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition succeeds even though the + * TriggerDescriptorUpdate manipulation failed. + */ + @Test + @DisplayName( + "DescriptionModificationAllWithParentChildRelationshipPrecondition when TriggerDescriptorUpdate Failed") + public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationFailed2() { + + final var descriptor1Handle = "superHandle"; + final var descriptor2Handle = "handle;Süper;"; + final var parentDescriptorHandle = "parentHandle"; + final var childDescriptorHandle = "childHandle"; + + final var presenceMap = new HashMap<>(Map.of( + descriptor1Handle, false, + descriptor2Handle, true)); + + when(mockManipulations.getRemovableDescriptorsOfClass()) + .thenReturn(List.of(descriptor1Handle, descriptor2Handle)); + + when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), true); + return ResponseTypes.Result.RESULT_SUCCESS; }); + when(mockManipulations.removeDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), false); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_FAIL); + final MdibEntity mockEntity = mock(MdibEntity.class); + when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) + .thenReturn(List.of(mockEntity)); + final MdibEntity mockEntity2 = mock(MdibEntity.class); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) + .thenAnswer(args -> { + if (presenceMap.get((String) args.getArgument(0))) { + return Optional.of(mockEntity2); + } else { + return Optional.empty(); + } + }); assertTrue( - ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.manipulation( - injector)); + ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition + .manipulation(injector)); final var insertCaptor = ArgumentCaptor.forClass(String.class); final var removeCaptor = ArgumentCaptor.forClass(String.class); @@ -1990,4 +2134,66 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio .count()); } + /** + * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition fails when both the + * GetRemovableDescriptors manipulation and the TriggerDescriptorUpdate manipulation failed. + */ + @Test + @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition when both GetRemovableDescriptors " + + "and TriggerDescriptorUpdate fail") + public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationFailed3() { + + final var descriptor1Handle = "superHandle"; + final var descriptor2Handle = "handle;Süper;"; + final var parentDescriptorHandle = "parentHandle"; + final var childDescriptorHandle = "childHandle"; + + final var presenceMap = new HashMap<>(Map.of( + descriptor1Handle, false, + descriptor2Handle, true)); + + when(mockManipulations.getRemovableDescriptorsOfClass()) + .thenReturn(List.of()); // When the manipulation returns RESULT_NOT_SUPPORTED, then an empty list + // is returned + + when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), true); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.removeDescriptor(anyString())).thenAnswer((Answer) invocation -> { + presenceMap.put(invocation.getArgument(0), false); + return ResponseTypes.Result.RESULT_SUCCESS; + }); + when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_FAIL); + final MdibEntity mockEntity = mock(MdibEntity.class); + when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) + .thenReturn(List.of(mockEntity)); + final MdibEntity mockEntity2 = mock(MdibEntity.class); + when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) + .thenAnswer(args -> { + if (presenceMap.get((String) args.getArgument(0))) { + return Optional.of(mockEntity2); + } else { + return Optional.empty(); + } + }); + + assertFalse( + ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition + .manipulation(injector)); + + final var insertCaptor = ArgumentCaptor.forClass(String.class); + final var removeCaptor = ArgumentCaptor.forClass(String.class); + final var handleCaptor = ArgumentCaptor.forClass(List.class); + verify(mockManipulations, times(1)).getRemovableDescriptorsOfClass(); + verify(mockManipulations, times(0)).insertDescriptor(insertCaptor.capture()); + verify(mockManipulations, times(0)).removeDescriptor(removeCaptor.capture()); + verify(mockManipulations, times(1)).triggerDescriptorUpdate(handleCaptor.capture()); + + assertEquals(2, handleCaptor.getAllValues().get(0).size()); + assertEquals(childDescriptorHandle, handleCaptor.getAllValues().get(0).get(0)); + assertEquals(parentDescriptorHandle, handleCaptor.getAllValues().get(0).get(1)); + } } From ec6de3a64ff807250f08ff70a0105e88805d4e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Mon, 11 Sep 2023 11:13:56 +0200 Subject: [PATCH 08/11] Use t2iapi SNAPSHOT version. --- sdccc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdccc/pom.xml b/sdccc/pom.xml index 83c1782d..e5d185a0 100644 --- a/sdccc/pom.xml +++ b/sdccc/pom.xml @@ -172,7 +172,7 @@ com.draeger.medical t2iapi - 3.0.0.262 + 3.0.0.296 From a51abd8f7a95d78fbd38c7446653539b4ae39e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Mon, 11 Sep 2023 11:40:11 +0200 Subject: [PATCH 09/11] Changes suggested by reviewers. --- .../impl/ManipulationPreconditionsTest.java | 75 ++++++++----------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java index edd072da..0fcc659d 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java @@ -1907,12 +1907,9 @@ void testSystemSignalActivationSomeFail() { assertFalse(ManipulationPreconditions.SystemSignalActivationManipulation.manipulation(injector)); } - /** - * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation. - */ @Test @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition correctly calls manipulation") - public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulation() { + void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulation() { final var descriptor1Handle = "superHandle"; final var descriptor2Handle = "handle;Süper;"; @@ -1935,16 +1932,16 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio return ResponseTypes.Result.RESULT_SUCCESS; }); when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_SUCCESS); - final MdibEntity mockEntity = mock(MdibEntity.class); - when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); - when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + final MdibEntity mockEntityB2 = mock(MdibEntity.class); + when(mockEntityB2.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntityB2.getChildren()).thenReturn(List.of(childDescriptorHandle)); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) - .thenReturn(List.of(mockEntity)); - final MdibEntity mockEntity2 = mock(MdibEntity.class); + .thenReturn(List.of(mockEntityB2)); + final MdibEntity mockEntityB3 = mock(MdibEntity.class); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) .thenAnswer(args -> { if (presenceMap.get((String) args.getArgument(0))) { - return Optional.of(mockEntity2); + return Optional.of(mockEntityB3); } else { return Optional.empty(); } @@ -1989,14 +1986,10 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio .count()); } - /** - * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition succeeds even when - * GetRemovableDescriptors failed. - */ @Test @DisplayName( "DescriptionModificationAllWithParentChildRelationshipPrecondition when GetRemovableDescriptors failed.") - public void + void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationGetRemovableDescriptorsFailed() { final var descriptor1Handle = "superHandle"; @@ -2009,7 +2002,7 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio descriptor2Handle, true)); when(mockManipulations.getRemovableDescriptorsOfClass()) - .thenReturn(List.of()); // WHen the Manipulation is NOT_SUPPORTED, an empty List is returned. + .thenReturn(List.of()); // When the Manipulation is NOT_SUPPORTED, an empty List is returned. when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { presenceMap.put(invocation.getArgument(0), true); @@ -2020,16 +2013,16 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio return ResponseTypes.Result.RESULT_SUCCESS; }); when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_SUCCESS); - final MdibEntity mockEntity = mock(MdibEntity.class); - when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); - when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + final MdibEntity mockEntityB = mock(MdibEntity.class); + when(mockEntityB.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntityB.getChildren()).thenReturn(List.of(childDescriptorHandle)); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) - .thenReturn(List.of(mockEntity)); - final MdibEntity mockEntity2 = mock(MdibEntity.class); + .thenReturn(List.of(mockEntityB)); + final MdibEntity mockEntityB2 = mock(MdibEntity.class); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) .thenAnswer(args -> { if (presenceMap.get((String) args.getArgument(0))) { - return Optional.of(mockEntity2); + return Optional.of(mockEntityB2); } else { return Optional.empty(); } @@ -2050,14 +2043,10 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio assertEquals(parentDescriptorHandle, handleCaptor.getAllValues().get(0).get(1)); } - /** - * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition succeeds even though the - * TriggerDescriptorUpdate manipulation failed. - */ @Test @DisplayName( - "DescriptionModificationAllWithParentChildRelationshipPrecondition when TriggerDescriptorUpdate Failed") - public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationFailed2() { + "DescriptionModificationAllWithParentChildRelationshipPrecondition when TriggerDescriptorUpdate failed") + void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationFailed2() { final var descriptor1Handle = "superHandle"; final var descriptor2Handle = "handle;Süper;"; @@ -2080,16 +2069,16 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio return ResponseTypes.Result.RESULT_SUCCESS; }); when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_FAIL); - final MdibEntity mockEntity = mock(MdibEntity.class); - when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); - when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + final MdibEntity mockEntityB = mock(MdibEntity.class); + when(mockEntityB.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntityB.getChildren()).thenReturn(List.of(childDescriptorHandle)); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) - .thenReturn(List.of(mockEntity)); - final MdibEntity mockEntity2 = mock(MdibEntity.class); + .thenReturn(List.of(mockEntityB)); + final MdibEntity mockEntityB2 = mock(MdibEntity.class); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) .thenAnswer(args -> { if (presenceMap.get((String) args.getArgument(0))) { - return Optional.of(mockEntity2); + return Optional.of(mockEntityB2); } else { return Optional.empty(); } @@ -2134,14 +2123,10 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio .count()); } - /** - * Tests whether DescriptionModificationAllWithParentChildRelationshipPrecondition fails when both the - * GetRemovableDescriptors manipulation and the TriggerDescriptorUpdate manipulation failed. - */ @Test @DisplayName("DescriptionModificationAllWithParentChildRelationshipPrecondition when both GetRemovableDescriptors " + "and TriggerDescriptorUpdate fail") - public void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationFailed3() { + void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipulationFailed3() { final var descriptor1Handle = "superHandle"; final var descriptor2Handle = "handle;Süper;"; @@ -2165,16 +2150,16 @@ public void testDescriptionModificationAllWithParentChildRelationshipPreconditio return ResponseTypes.Result.RESULT_SUCCESS; }); when(mockManipulations.triggerDescriptorUpdate(anyList())).thenReturn(ResponseTypes.Result.RESULT_FAIL); - final MdibEntity mockEntity = mock(MdibEntity.class); - when(mockEntity.getHandle()).thenReturn(parentDescriptorHandle); - when(mockEntity.getChildren()).thenReturn(List.of(childDescriptorHandle)); + final MdibEntity mockEntityB = mock(MdibEntity.class); + when(mockEntityB.getHandle()).thenReturn(parentDescriptorHandle); + when(mockEntityB.getChildren()).thenReturn(List.of(childDescriptorHandle)); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().findEntitiesByType(any())) - .thenReturn(List.of(mockEntity)); - final MdibEntity mockEntity2 = mock(MdibEntity.class); + .thenReturn(List.of(mockEntityB)); + final MdibEntity mockEntityB2 = mock(MdibEntity.class); when(mockTestClient.getSdcRemoteDevice().getMdibAccess().getEntity(any())) .thenAnswer(args -> { if (presenceMap.get((String) args.getArgument(0))) { - return Optional.of(mockEntity2); + return Optional.of(mockEntityB2); } else { return Optional.empty(); } From 72fd02e0332e1b4b750834301212dfc8f2716884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Mon, 11 Sep 2023 12:00:06 +0200 Subject: [PATCH 10/11] Moved Note to message of NoTestData exception. --- .../biceps/invariant/InvariantMessageModelAnnexTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java index 43e24450..f0a1edb2 100644 --- a/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java +++ b/sdccc/src/main/java/com/draeger/medical/sdccc/tests/biceps/invariant/InvariantMessageModelAnnexTest.java @@ -333,9 +333,6 @@ void testRequirementR5024() throws NoTestData, IOException { @TestDescription("For every DescriptionModificationReport received from the DUT, and for all parent-child" + " relationships between the elements contained in the report, checks that the reportPart containing" + " the parent comes before the reportPart containing the child.") - // NOTE: for this test case to succeed, the device should support descriptor updates or the list of removable - // descriptors returned by the getRemovableDescriptors() manipulation should include at least one descriptor - // that has child descriptors. @RequirePrecondition( manipulationPreconditions = ManipulationPreconditions.DescriptionModificationAllWithParentChildRelationshipPrecondition.class) @@ -359,7 +356,10 @@ void testRequirementR5025() throws NoTestData, IOException { assertTestData( descriptorsSeen.get(), "No DescriptionModificationReports with Parent-Child Relationships between Descriptors " - + " seen during test run, test failed."); + + " seen during test run, test failed." + + " Please make sure that the device either supports descriptor updates or that the list" + + " of removable descriptors returned by the getRemovableDescriptors() manipulation" + + " includes at least one descriptor that has child descriptors."); } } From d2b92e0378d12f14c9090f9d5e96d038738dccf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Engelmann?= Date: Mon, 11 Sep 2023 12:27:09 +0200 Subject: [PATCH 11/11] More changes suggested by reviewers. --- .../precondition/impl/ManipulationPreconditionsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java index 0fcc659d..1da74afb 100644 --- a/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java +++ b/sdccc/src/test/java/com/draeger/medical/sdccc/manipulation/precondition/impl/ManipulationPreconditionsTest.java @@ -2002,7 +2002,7 @@ void testDescriptionModificationAllWithParentChildRelationshipPreconditionManipu descriptor2Handle, true)); when(mockManipulations.getRemovableDescriptorsOfClass()) - .thenReturn(List.of()); // When the Manipulation is NOT_SUPPORTED, an empty List is returned. + .thenReturn(List.of()); // When the manipulation is NOT_SUPPORTED, an empty list is returned. when(mockManipulations.insertDescriptor(anyString())).thenAnswer((Answer) invocation -> { presenceMap.put(invocation.getArgument(0), true);