Skip to content

Commit

Permalink
fix: changed biceps:R5003 test case (#232)
Browse files Browse the repository at this point in the history
In the mdib representation on the consumer side in sdc-ri, when
processing description modifications, the values
for the MdDescriptionVersion and MdStateVersion are set to the implied
value if the description modification
does not contain any values for them. This is the case if the versions
are missing in the GetMdibResponse,
or generally for DescriptionModificationReports. If the
MdDescriptionVersion or MdStateVersion in the
GetMdibResponse is set to a value other than the implied value, they
would be set to the implied value again in the next
DescriptionModificationReport, which would cause the test to fail. As
the actual values are not communicated via
reports, the check of the MdDescriptionVersion and MdStateVersion has
been removed from the test implementation.

# Checklist

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

* Adherence to coding conventions
  * [x] Pull Request Assignee
  * [x] Reviewer
* Adherence to javadoc conventions
  * [x] Pull Request Assignee
  * [x] Reviewer
* Changelog update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* README update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* config update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* SDCcc executable ran against a test device (if necessary)
  * [x] Pull Request Assignee
  * [x] Reviewer
  • Loading branch information
belagertem authored Jan 22, 2025
1 parent b41c1f0 commit de0e13a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- inconsistent messaging in SDCcc logs ("No problems were found" and "Test run was invalid" one after another.)
- incorrect behavior of the configuration option SDCcc.SummarizeMessageEncodingErrors
- SequenceIds are now ordered by the timestamp of the first message that used them
- test for BICEPS.R5003 does not check MdDescriptionVersion and MdStateVersion anymore (see [PR 232](https://github.com/Draegerwerk/SDCcc/pull/232))

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ void testRequirementR5003() throws IOException, NoTestData {
final var impliedValueMap = new InitialImpliedValue();
final var previousDescriptorVersionMap = new HashMap<String, BigInteger>();
final var previousStateVersionMap = new HashMap<String, BigInteger>();
var previousMdDescriptionVersion = BigInteger.valueOf(-1);
var previousMdStateVersion = BigInteger.valueOf(-1);
var previousMdibVersion = BigInteger.valueOf(-1);

try (final MdibHistorian.HistorianResult history =
Expand Down Expand Up @@ -388,32 +386,11 @@ void testRequirementR5003() throws IOException, NoTestData {
previousStateVersionMap.put(stateHandle, currentStateVersion);
stateVersionsSeen.incrementAndGet();
}
final var currentMdDescriptionVersion =
ImpliedValueUtil.getMdibAccessDescriptionVersion(current);
final var currentMdStateVersion = ImpliedValueUtil.getMdibAccessMdStateVersion(current);
assertTrue(
isNotDecrementedVersion(previousMdDescriptionVersion, currentMdDescriptionVersion),
String.format(
DECREMENTED_VERSION_ERROR_MESSAGE,
"MdDescription",
currentMdibVersion,
previousMdDescriptionVersion,
currentMdDescriptionVersion));
assertTrue(
isNotDecrementedVersion(previousMdStateVersion, currentMdStateVersion),
String.format(
DECREMENTED_VERSION_ERROR_MESSAGE,
"MdState",
currentMdibVersion,
previousMdStateVersion,
currentMdStateVersion));
assertTrue(
isNotDecrementedVersion(previousMdibVersion, currentMdibVersion),
String.format(
"The mdib version has been decremented. It was %s and is now %s.",
previousMdibVersion, currentMdibVersion));
previousMdDescriptionVersion = currentMdDescriptionVersion;
previousMdStateVersion = currentMdStateVersion;
previousMdibVersion = currentMdibVersion;
current = history.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.math.BigInteger;
import java.time.Duration;
import javax.annotation.Nullable;
import org.somda.sdc.biceps.common.access.MdibAccess;
import org.somda.sdc.biceps.model.message.AbstractReport;
import org.somda.sdc.biceps.model.message.DescriptionModificationReport;
import org.somda.sdc.biceps.model.message.DescriptionModificationType;
Expand Down Expand Up @@ -373,17 +372,6 @@ public static BigInteger getDescriptionVersion(final @Nullable MdDescription mdD
return BigInteger.ZERO;
}

/**
* Retrieves the description version of mdib access or the implied value.
*
* @param mdibAccess to retrieve the description version from
* @return the description version
*/
public static BigInteger getMdibAccessDescriptionVersion(final MdibAccess mdibAccess) {
final var descriptionVersion = mdibAccess.getMdDescriptionVersion();
return descriptionVersion != null ? descriptionVersion : BigInteger.ZERO;
}

/**
* Retrieves the language of an mds state or the implied value.
*
Expand Down Expand Up @@ -420,17 +408,6 @@ public static BigInteger getMdStateStateVersion(final @Nullable MdState mdState)
return BigInteger.ZERO;
}

/**
* Retrieves the md state version of mdib access or the implied value.
*
* @param mdibAccess to retrieve the state version from
* @return the state version
*/
public static BigInteger getMdibAccessMdStateVersion(final MdibAccess mdibAccess) {
final var stateVersion = mdibAccess.getMdStateVersion();
return stateVersion != null ? stateVersion : BigInteger.ZERO;
}

/**
* Retrieves the version of a mdib version or the implied value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opentest4j.AssertionFailedError;
import org.somda.sdc.biceps.model.participant.ActivateOperationDescriptor;
import org.somda.sdc.biceps.model.participant.AlertConditionDescriptor;
Expand Down Expand Up @@ -1193,6 +1197,43 @@ public void testRequirementR5003NoTestData() {
assertThrows(NoTestData.class, testClass::testRequirementR5003);
}

/**
* In the mdib representation on the consumer side in sdc-ri, when processing description modifications, the values
* for the MdDescriptionVersion and MdStateVersion are set to the implied value if the description modification
* does not contain any values for them. This is the case if the versions are missing in the GetMdibResponse,
* or generally for DescriptionModificationReports. If the MdDescriptionVersion or MdStateVersion in the
* GetMdibResponse is set to a value other than the implied value, they would be set to the implied value again in the next
* DescriptionModificationReport, which would cause the test to fail. As the actual values are not communicated via
* reports, the check of the MdDescriptionVersion and MdStateVersion has been removed from the test implementation.
* <p>
* This unit test ensures that a decrement of the MdDescriptionVersion or MdStateVersion does not cause the test to
* fail.
* </p>
*
* @param mdDescriptionVersion the MdDescriptionVersion to set
* @param mdStateVersion the MdStateVersion to set
* @throws Exception on any exception
*/
@ParameterizedTest
@MethodSource("provideMdDescriptionVersionAndMdStateVersion")
public void testRequirementR5003TestMdDescriptionVersionAndMdStateVersion(
final @Nullable BigInteger mdDescriptionVersion, final @Nullable BigInteger mdStateVersion)
throws Exception {
final var initial =
buildMdibWithMdDescriptionAndStateVersion(SEQUENCE_ID, mdDescriptionVersion, mdStateVersion);
final var firstUpdate = buildDescriptionModificationReportWithParts(
SEQUENCE_ID,
BigInteger.valueOf(74),
buildDescriptionModificationReportPart(
DescriptionModificationType.UPT,
buildVmd(VMD_HANDLE, BigInteger.ONE, BigInteger.ONE),
buildChannel(CHANNEL_HANDLE, BigInteger.ONE, BigInteger.ONE)));

messageStorageUtil.addInboundSecureHttpMessage(storage, initial);
messageStorageUtil.addInboundSecureHttpMessage(storage, firstUpdate);
assertDoesNotThrow(testClass::testRequirementR5003);
}

/**
* Tests whether versions which are only incremented causes the test to pass.
*
Expand Down Expand Up @@ -1591,7 +1632,7 @@ public void testRequirementR5003BadDecrementStateVersion() throws Exception {
}

Envelope buildMdib(final @Nullable BigInteger vmdVersion, final @Nullable BigInteger mdsVersion) {
return buildMdib(MdibBuilder.DEFAULT_SEQUENCE_ID, vmdVersion, mdsVersion);
return buildMdib(SEQUENCE_ID, vmdVersion, mdsVersion);
}

/*
Expand Down Expand Up @@ -1638,6 +1679,39 @@ Envelope buildMdib(
ActionConstants.getResponseAction(ActionConstants.ACTION_GET_MDIB), getMdibResponse);
}

private static Stream<Arguments> provideMdDescriptionVersionAndMdStateVersion() {
return Stream.of(
Arguments.of(BigInteger.TWO, null),
Arguments.of(null, BigInteger.TWO),
Arguments.of(BigInteger.TWO, BigInteger.TWO));
}

private Envelope buildMdibWithMdDescriptionAndStateVersion(
final String sequenceId,
final @Nullable BigInteger mdDescriptionVersion,
final @Nullable BigInteger mdStateVersion) {
final var mdib = mdibBuilder.buildMinimalMdib(sequenceId);
mdib.getMdDescription().setDescriptionVersion(mdDescriptionVersion);

final var mdState = mdib.getMdState();
mdState.setStateVersion(mdStateVersion);

final var mdsDescriptor = mdib.getMdDescription().getMds().get(0);
mdsDescriptor.setDescriptorVersion(BigInteger.ZERO);

final var vmd = mdibBuilder.buildVmd(VMD_HANDLE);
vmd.getLeft().setDescriptorVersion(BigInteger.ZERO);
vmd.getRight().setDescriptorVersion(BigInteger.ZERO);
mdsDescriptor.getVmd().add(vmd.getLeft());
mdState.getState().add(vmd.getRight());

final var getMdibResponse = messageBuilder.buildGetMdibResponse(mdib.getSequenceId());
getMdibResponse.setMdib(mdib);

return messageBuilder.createSoapMessageWithBody(
ActionConstants.getResponseAction(ActionConstants.ACTION_GET_MDIB), getMdibResponse);
}

Pair<? extends AbstractDescriptor, ? extends AbstractState> buildMds(
final String handle,
@Nullable final BigInteger descriptorVersion,
Expand Down

0 comments on commit de0e13a

Please sign in to comment.