Skip to content

Commit

Permalink
Merge pull request #613 from catenax-ng/feat/519-integ-test-policy-st…
Browse files Browse the repository at this point in the history
…ore-unhappy-path

Feat/519 Integration Test Policy Store API Unhappy Path
  • Loading branch information
ds-jhartmann authored May 13, 2024
2 parents 60ce165 + f14831b commit cfb13d8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ _**For better traceability add the corresponding GitHub issue number in each cha

## [Unreleased]

### Added

- Integration Test Policy Store API Unhappy Path. #519

### Fixed

- Cleaning up BPNLs without policies. #533
Expand Down
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 Expand Up @@ -184,14 +192,20 @@ public static ValidatableResponse registerPolicyForBpn(

final CreatePolicyRequest createPolicyRequest;
try {

CreatePolicyRequestBuilder builder = CreatePolicyRequest.builder();

if (validUntil != null) {
builder = builder.validUntil(OffsetDateTime.parse(validUntil));
}
createPolicyRequest = builder.businessPartnerNumber(bpn)
.payload(E2ETestHelperForPolicyStoreApi.jsonFromString(objectMapper,
policyJson))
.build();

builder = builder.businessPartnerNumber(bpn);

if (policyJson != null) {
builder = builder.payload(E2ETestHelperForPolicyStoreApi.jsonFromString(objectMapper, policyJson));
}

createPolicyRequest = builder.build();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
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,27 @@ 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);
}

@Given("I want to register a policy")
@Given("I want to update a policy")
public void iWantToRegisterAPolicy() {
Expand Down Expand Up @@ -314,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 cfb13d8

Please sign in to comment.