Skip to content

Commit

Permalink
feat(impl): [#519] add test step definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed May 10, 2024
1 parent 8c07fb2 commit d71eb65
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public static String getPolicyTemplate() throws IOException {
return E2ETestHelper.getTemplateFileContent("policy-for-e2e-tests.json");
}

public static String getPolicyTemplateWithoutDefinition() throws IOException {
return E2ETestHelper.getTemplateFileContent("policy-for-e2e-tests-without-definition.json");
}

public static String getPolicyTemplateWithEmptyDefinition() throws IOException {
return E2ETestHelper.getTemplateFileContent("policy-for-e2e-tests-with-empty-definition.json");
}

@SuppressWarnings("unchecked")
public static Map<String, ArrayList<LinkedHashMap<String, ?>>> fetchPoliciesForBpn(
final AuthenticationPropertiesBuilder authenticationPropertiesBuilder, final String bpn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import static org.eclipse.tractusx.irs.cucumber.E2ETestHelperForPolicyStoreApi.fetchPoliciesForBusinessPartnerNumbers;
import static org.eclipse.tractusx.irs.cucumber.E2ETestHelperForPolicyStoreApi.getExpectedBpnToPolicyIdsMapping;
import static org.eclipse.tractusx.irs.cucumber.E2ETestHelperForPolicyStoreApi.getPolicyTemplate;
import static org.eclipse.tractusx.irs.cucumber.E2ETestHelperForPolicyStoreApi.getPolicyTemplateWithEmptyDefinition;
import static org.eclipse.tractusx.irs.cucumber.E2ETestHelperForPolicyStoreApi.getPolicyTemplateWithoutDefinition;
import static org.eclipse.tractusx.irs.cucumber.E2ETestHelperForPolicyStoreApi.registerPolicyForBpn;
import static org.eclipse.tractusx.irs.cucumber.E2ETestHelperForPolicyStoreApi.updatePolicies;

Expand Down Expand Up @@ -233,6 +235,22 @@ public void iRegisterAPolicy(final String policyId, final String bpn, final Stri
validUntil);
}

@When("a policy with policyId {string} WITHOUT definition is registered for BPN {string} and validUntil {string}")
public void iRegisterAPolicyWithoutDefinition(final String policyId, final String bpn, final String validUntil)
throws IOException {
final String policyJson = getPolicyTemplateWithoutDefinition().formatted(policyId);
this.createPoliciesResponse = registerPolicyForBpn(this.authenticationPropertiesBuilder, policyJson, bpn,
validUntil);
}

@When("a policy with policyId {string} WITH EMPTY definition is registered for BPN {string} and validUntil {string}")
public void iRegisterAPolicyWithEmptyDefinition(final String policyId, final String bpn, final String validUntil)
throws IOException {
final String policyJson = getPolicyTemplateWithEmptyDefinition().formatted(policyId);
this.createPoliciesResponse = registerPolicyForBpn(this.authenticationPropertiesBuilder, policyJson, bpn,
validUntil);
}

@When("a policy WITHOUT payload is registered for BPN {string} and validUntil {string}")
public void iRegisterAPolicyWithoutPayload(final String bpn, final String validUntil) {
this.createPoliciesResponse = registerPolicyForBpn(this.authenticationPropertiesBuilder, null, bpn, validUntil);
Expand Down Expand Up @@ -319,6 +337,27 @@ public void theCreatePolicyResponseShouldHaveStatus(final int httpStatus) {
this.createPoliciesResponse.statusCode(httpStatus);
}

@Then("the create policy response should have message containing {string}")
public void theCreatePolicyResponseShouldHaveMessageContaining(final String string) {
final ValidatableResponse validatableResponse = this.createPoliciesResponse;
assertThatResponseHasMessageContaining(validatableResponse, string);
}

@Then("the delete policy response should have message containing {string}")
public void thedeletePolicyResponseShouldHaveMessageContaining(final String string) {
assertThatResponseHasMessageContaining(this.deletePoliciesResponse, string);
}

@Then("the update policy response should have message containing {string}")
public void theUpdatePolicyResponseShouldHaveMessageContaining(final String string) {
assertThatResponseHasMessageContaining(this.updatePoliciesResponse, string);
}

private static void assertThatResponseHasMessageContaining(final ValidatableResponse validatableResponse,
final String string) {
validatableResponse.body("messages", Matchers.hasItem(Matchers.containsString(string)));
}

@Then("the update policy response should have HTTP status {int}")
public void theUpdatePolicyResponseShouldHaveStatus(final int httpStatus) {
this.updatePoliciesResponse.statusCode(httpStatus);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@context": {
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@id": "%s",
"policy": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@context": {
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@id": "%s"
}

0 comments on commit d71eb65

Please sign in to comment.