Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixed Defect in Test case for Biceps:R5025 #125

Merged
merged 13 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ public void close() {}
return interactionResult ? ResponseTypes.Result.RESULT_SUCCESS : ResponseTypes.Result.RESULT_FAIL;
}

@Override
public ResponseTypes.Result triggerDescriptorUpdate(final List<String> 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -294,15 +295,19 @@ public ResponseTypes.Result setMetricStatus(

@Override
public ResponseTypes.Result triggerDescriptorUpdate(final String handle) {
return triggerDescriptorUpdate(List.of(handle));
}

belagertem marked this conversation as resolved.
Show resolved Hide resolved
public ResponseTypes.Result triggerDescriptorUpdate(final List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
belagertem marked this conversation as resolved.
Show resolved Hide resolved
*
* @param handles list of descriptor handles to trigger an Update for.
belagertem marked this conversation as resolved.
Show resolved Hide resolved
* @return the result of the manipulation
*/
ResponseTypes.Result triggerDescriptorUpdate(final List<String> handles);

/**
belagertem marked this conversation as resolved.
Show resolved Hide resolved
* Trigger a descriptor update for some descriptor (chosen by the device).
*
* @return the result of the manipulation
*/
ResponseTypes.Result triggerAnyDescriptorUpdate();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

belagertem marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -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<String, String> 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.");
belagertem marked this conversation as resolved.
Show resolved Hide resolved
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<String, String> findFirstDescriptorHandleWithChildren(Injector injector, Logger log) {
belagertem marked this conversation as resolved.
Show resolved Hide resolved
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<MdibEntity> entities = mdibAccess.findEntitiesByType(AbstractDescriptor.class);
for (MdibEntity entity : entities) {
List<String> children = entity.getChildren();
if (children.size() > 0) {
belagertem marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
belagertem marked this conversation as resolved.
Show resolved Hide resolved
*/
public DescriptionChangedPrecondition() {
super(DescriptionChangedPrecondition::preconditionCheck, DescriptionChangedPrecondition::manipulation);
public DescriptionModificationCrtOrDelPrecondition() {
super(DescriptionModificationCrtOrDelPrecondition::preconditionCheck, DescriptionModificationCrtOrDelPrecondition::manipulation);
}

static boolean preconditionCheck(final Injector injector) throws PreconditionException {
Expand All @@ -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.
belagertem marked this conversation as resolved.
Show resolved Hide resolved
*/
public DescriptionModificationAllWithParentChildRelationshipPrecondition() {
super(DescriptionModificationAllWithParentChildRelationshipPrecondition::preconditionCheck, DescriptionModificationAllWithParentChildRelationshipPrecondition::manipulation);
}

static boolean preconditionCheck(final Injector injector) {
return false; // always trigger description changes
belagertem marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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;
belagertem marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* Precondition which checks whether all context descriptors had at least two different context states
* associated, triggering context state associations otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading