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

Integration test for the fix unable to add API specific policy using YAML format via Publisher REST API #13191

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,70 @@ public void testAPIInvocationAfterAddingNewMultipleOperationPolicies() throws Ex
assertEquals(invokeAPIResponse.getHeaders("TestHeader")[0].getValue(), "TestValue");
}

@Test(groups = {"wso2.am"}, description = "Add API specific operation policy using YAML Policy Definition",
dependsOnMethods = "testAPIInvocationAfterAddingNewMultipleOperationPolicies")
public void testAddAPISpecificOperationPolicyYAML() throws Exception {

HttpResponse addPolicyResponse =
addPolicy(apiId, "customAPISpecificLogPolicyForYAMLPolicyDefinitionTesting.yaml",
"customAPISpecificLogPolicy.j2");
assertNotNull(addPolicyResponse, "Error adding operation policy customAPISpecificLogPolicyYAML");
assertEquals(addPolicyResponse.getResponseCode(), 201, "Response code mismatched");

OperationPolicyDataDTO policyDTO =
new Gson().fromJson(addPolicyResponse.getData(), OperationPolicyDataDTO.class);
String newPolicyId = policyDTO.getId();
assertNotNull(newPolicyId, "Policy Id is null");

Map<String, String> apiSpecificPolicyMap = restAPIPublisher.getAllAPISpecificOperationPolicies(apiId);
Assert.assertNotNull(apiSpecificPolicyMap.get("customAPISpecificLogPolicyYAML"),
"Unable to find the newly added API specific policy");
policyMap.put("customAPISpecificLogPolicyYAML", newPolicyId);
}

@Test(groups = {"wso2.am"}, description = "Delete API specific operation policy created using YAML Policy Definition",
dependsOnMethods = "testAddAPISpecificOperationPolicyYAML")
public void testDeleteAPISpecificOperationPolicyYAML() throws Exception {

int responseCode = deleteOperationPolicy(policyMap.get("customAPISpecificLogPolicyYAML"), apiId);
assertEquals(responseCode, 200);
Map<String, String> updatedAPISpecificPolicyMap = restAPIPublisher.getAllAPISpecificOperationPolicies(apiId);
Assert.assertNull(updatedAPISpecificPolicyMap.get("customAPISpecificLogPolicyYAML"));
policyMap.remove("customAPISpecificLogPolicyYAML");
}

@Test(groups = {"wso2.am"}, description = "Add common operation policy using YAML specification file",
dependsOnMethods = "testDeleteAPISpecificOperationPolicyYAML")
public void testAddNewCommonOperationPolicyYAML() throws Exception {

HttpResponse addPolicyResponse = addPolicy(null,
"customCommonLogPolicyForYAMLPolicyDefinitionTesting.yaml", "customCommonLogPolicy.j2");

assertNotNull(addPolicyResponse, "Error adding operation policy customCommonLogPolicy");
assertEquals(addPolicyResponse.getResponseCode(), 201, "Response code mismatched");

OperationPolicyDataDTO policyDTO =
new Gson().fromJson(addPolicyResponse.getData(), OperationPolicyDataDTO.class);
String newPolicyId = policyDTO.getId();
assertNotNull(newPolicyId, "Policy Id is null");

Map<String, String> updatedCommonPolicyMap = restAPIPublisher.getAllCommonOperationPolicies();
Assert.assertNotNull(updatedCommonPolicyMap.get("customCommonLogPolicyYAML"),
"Unable to find the newly added common policy");
policyMap.put("customCommonLogPolicyYAML", newPolicyId);
}

@Test(groups = {"wso2.am"}, description = "Delete common operation policy created using YAML specification file",
dependsOnMethods = "testAddNewCommonOperationPolicyYAML")
public void testDeleteCommonOperationPolicyYAML() throws Exception {

int responseCode = deleteOperationPolicy(policyMap.get("customCommonLogPolicyYAML"), null);
assertEquals(responseCode, 200);
Map<String, String> updatedCommonPolicyMap = restAPIPublisher.getAllCommonOperationPolicies();
Assert.assertNull(updatedCommonPolicyMap.get("customCommonLogPolicyYAML"));
policyMap.remove("customCommonLogPolicyYAML");
}

@AfterClass(alwaysRun = true)
public void cleanUpArtifacts() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
category: Mediation
name: customAPISpecificLogPolicyYAML
version: v1
displayName: Custom Common Log Policy
description: Using this policy, you can add a custom log message
applicableFlows:
- request
- response
- fault
supportedGateways:
- Synapse
supportedApiTypes:
- HTTP
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
category: Mediation
name: customCommonLogPolicyYAML
version: v1
displayName: Custom Common Log Policy
description: Using this policy, you can add a custom log message
applicableFlows:
- request
- response
- fault
supportedGateways:
- Synapse
supportedApiTypes:
- HTTP
Loading