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

Adapt test case for glue:R0036 to replacement requirement glue:R0036_0 #17

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- test for biceps:5-4-7_12_0
- test for biceps:5-4-7_14

### Changed
- updated test case for glue:R0036 to glue:R0036_0

### Fixed
- missing request bodies in glue:R0036 test
- some vulnerabilities due to old dependencies
Expand Down
2 changes: 1 addition & 1 deletion configuration/test_configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ R0011=true
R0012_0_0=true
R0013=true
R0034_0=true
R0036=true
R0036_0=true
R0042_0=true
R0072=true
R0080=true
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public final class EnabledTestConfig {
public static final String GLUE_R0012_0_0 = GLUE + "R0012_0_0";
public static final String GLUE_R0013 = GLUE + "R0013";
public static final String GLUE_R0034_0 = GLUE + "R0034_0";
public static final String GLUE_R0036 = GLUE + "R0036";
public static final String GLUE_R0036_0 = GLUE + "R0036_0";
public static final String GLUE_R0042_0 = GLUE + "R0042_0";
public static final String GLUE_R0072 = GLUE + "R0072";
public static final String GLUE_R0080 = GLUE + "R0080";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.somda.sdc.biceps.model.participant.LocationDetail;
import org.somda.sdc.biceps.model.participant.Mdib;
import org.somda.sdc.biceps.model.participant.MdsDescriptor;
import org.somda.sdc.dpws.CommunicationLog;
import org.somda.sdc.dpws.factory.CommunicationLogFactory;
import org.somda.sdc.dpws.http.HttpServerRegistry;
import org.somda.sdc.dpws.service.HostedServiceProxy;
Expand All @@ -42,6 +43,7 @@
import org.somda.sdc.dpws.soap.RequestResponseClient;
import org.somda.sdc.dpws.soap.SoapMessage;
import org.somda.sdc.dpws.soap.SoapUtil;
import org.somda.sdc.dpws.soap.exception.MalformedSoapMessageException;
import org.somda.sdc.dpws.soap.exception.MarshallingException;
import org.somda.sdc.dpws.soap.exception.SoapFaultException;
import org.somda.sdc.dpws.soap.exception.TransportException;
Expand All @@ -56,11 +58,13 @@
import org.somda.sdc.dpws.soap.wseventing.model.DeliveryType;
import org.somda.sdc.dpws.soap.wseventing.model.FilterType;
import org.somda.sdc.dpws.soap.wseventing.model.Subscribe;
import org.somda.sdc.dpws.soap.wseventing.model.SubscribeResponse;
import org.somda.sdc.glue.common.ActionConstants;
import org.somda.sdc.glue.common.WsdlConstants;

import javax.xml.namespace.QName;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -101,6 +105,7 @@ public class DirectSubscriptionHandlingTest extends InjectorTestBase {
private WsAddressingUtil wsaUtil;
private WsEventingEventSinkFactory eventSinkFactory;
private String adapterAddress;
private CommunicationLog commLog;

@BeforeEach
void setUp() {
Expand All @@ -118,6 +123,9 @@ void setUp() {
this.adapterAddress = getInjector().getInstance(
Key.get(String.class, Names.named(TestSuiteConfig.NETWORK_INTERFACE_ADDRESS))
);
this.commLog = testClient.getInjector().getInstance(CommunicationLogFactory.class)
.createCommunicationLog();

}

@Test
Expand Down Expand Up @@ -174,11 +182,14 @@ private void checkServiceConformance(final QName targetQName) {
}

@Test
@TestIdentifier(EnabledTestConfig.GLUE_R0036)
@TestDescription("Subscribes to all Reports, checks that all Subscriptions are active, then triggers"
+ " an EpisodicContextReport and intentionally fails to receive it. Afterwards, it checks that all"
+ " Subscriptions have been cancelled by the provider.")
void testRequirementR0036() throws InterruptedException {
@TestIdentifier(EnabledTestConfig.GLUE_R0036_0)
@DisplayName("An SDC SERVICE PROVIDER SHALL terminate a subscription if the delivery of one MESSAGE"
+ " related to that subscription failed.")
@TestDescription("Subscribes to all Reports, checks that all Subscriptions are active, then"
+ " triggers an EpisodicContextReport and intentionally fails to receive it. Afterwards,"
+ " it checks that the Subscription to the EpisodicContextReport has been cancelled by"
+ " the provider while all other subscriptions are still active.")
void testRequirementR00360() throws InterruptedException {

// preparation
final LocationContextState locationContext = getOrCreateLocationContextState();
Expand All @@ -205,8 +216,7 @@ void testRequirementR0036() throws InterruptedException {
}
manipulations.setLocationDetail(locationDetail);
});
final List<ReportTestData> reports = List.of(
triggerableReport,
final List<ReportTestData> otherReports = List.of(
new ReportTestData(
WsdlConstants.OPERATION_OPERATION_INVOKED_REPORT,
ActionConstants.ACTION_OPERATION_INVOKED_REPORT,
Expand Down Expand Up @@ -293,14 +303,28 @@ void testRequirementR0036() throws InterruptedException {
// does not need to be triggered in this test.
})
);
final List<ReportTestData> reports = new ArrayList<>();
reports.add(triggerableReport);
reports.addAll(otherReports);

subscribeToAllReports(reports);

checkSubscriptionsAreActive(reports);

triggerReportAndIntentionallyFailReceivingIt(triggerableReport);

checkThatAllSubscriptionsAreCancelled(reports);
checkThatSubscriptionsHaveBeenCancelled(List.of(triggerableReport));
checkThatOtherSubscriptionsHaveNotBeenCancelled(otherReports);
}

private void checkThatOtherSubscriptionsHaveNotBeenCancelled(final List<ReportTestData> reports) {
for (ReportTestData report : reports) {
if (report.getSubscription() != null) {
final Duration status = getSubscriptionStatus(report);
assertNotNull(status, "Subscription for report " + report.getReportName()
+ " has been unexpectedly cancelled.");
}
}
}

private void subscribeToAllReports(final List<ReportTestData> reports) {
Expand Down Expand Up @@ -344,7 +368,8 @@ private void nanoWait(final Object syncPoint, final long duration) throws Interr
syncPoint.wait(millis, (int) nanos);
}

private void checkThatAllSubscriptionsAreCancelled(final List<ReportTestData> reports) throws InterruptedException {
private void checkThatSubscriptionsHaveBeenCancelled(final List<ReportTestData> reports)
throws InterruptedException {
final long timeoutWaitingForCancellations = System.nanoTime() + TIMEOUT_NANOS;
final HashSet<ReportTestData> uncancelledSubscriptions = new HashSet<>(reports);
while (!uncancelledSubscriptions.isEmpty() && System.nanoTime() < timeoutWaitingForCancellations) {
Expand All @@ -360,7 +385,7 @@ private void checkThatAllSubscriptionsAreCancelled(final List<ReportTestData> re
.map(ReportTestData::getReportName)
.collect(Collectors.toList());
fail("Reports " + String.join(", ", subscriptions) + " have not been cancelled by the provider"
+ " although they should have been according to glue:R0036.");
+ " although they should have been according to glue:R0036_0.");
}
}

Expand Down Expand Up @@ -545,12 +570,34 @@ private void subscribeToReportWithTheAbilityToFail(final String baseURI,
soapResponse = requestResponseClient.sendRequestResponse(subscribeRequest);
if (soapResponse.isFault()) {
throw new RuntimeException("Could not subscribe to " + reportName + ".");
} else {
final SubscribeResponse responseBody = soapUtil
.getBody(soapResponse, SubscribeResponse.class)
.orElseThrow(() -> new MalformedSoapMessageException("Cannot read WS-Eventing Subscribe response"));

reportTestData.setSubscription(
new SubscribeResult(determineSubscriptionIdForAction(action), responseBody.getExpires()));
final EventSink eventSink =
eventSinkFactory.createWsEventingEventSink(requestResponseClient, baseURI, commLog);
reportTestData.setEventSink(eventSink);

}
} catch (SoapFaultException | MarshallingException | TransportException | InterceptorException e) {
fail("encountered Exception while subscribing to " + reportName, e);
}
}

/**
* Determine SubscriptionId for a report with the given action.
* This method exists so a test case can override it and set the subscriptionId
* according to its needs.
* @param action the name of the report for which the context suffix should be determined.
* @return the context suffix.
*/
public String determineSubscriptionIdForAction(final String action) {
return UUID.randomUUID().toString();
}

private String getLocalBaseURI() {
return String.format("https://%s:0", this.adapterAddress);
}
Expand Down
Loading