From 0aa7f05442b8fc8caada4247d095c32f7367ea01 Mon Sep 17 00:00:00 2001 From: Thisal Tennakoon Date: Sun, 26 Mar 2023 20:49:27 +0530 Subject: [PATCH] Integration test for the fix unable to add API specific policy using YAML format via Publisher REST API --- .../OperationPolicyTestCase.java | 64 +++++++++++++++++++ ...gPolicyForYAMLPolicyDefinitionTesting.yaml | 13 ++++ ...gPolicyForYAMLPolicyDefinitionTesting.yaml | 13 ++++ 3 files changed, 90 insertions(+) create mode 100644 modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customAPISpecificLogPolicyForYAMLPolicyDefinitionTesting.yaml create mode 100644 modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customCommonLogPolicyForYAMLPolicyDefinitionTesting.yaml diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/operationPolicy/OperationPolicyTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/operationPolicy/OperationPolicyTestCase.java index e48e7e3c06..27c8603abf 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/operationPolicy/OperationPolicyTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/operationPolicy/OperationPolicyTestCase.java @@ -608,6 +608,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 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 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 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 updatedCommonPolicyMap = restAPIPublisher.getAllCommonOperationPolicies(); + Assert.assertNull(updatedCommonPolicyMap.get("customCommonLogPolicyYAML")); + policyMap.remove("customCommonLogPolicyYAML"); + } + @AfterClass(alwaysRun = true) public void cleanUpArtifacts() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customAPISpecificLogPolicyForYAMLPolicyDefinitionTesting.yaml b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customAPISpecificLogPolicyForYAMLPolicyDefinitionTesting.yaml new file mode 100644 index 0000000000..44a7f5911c --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customAPISpecificLogPolicyForYAMLPolicyDefinitionTesting.yaml @@ -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 \ No newline at end of file diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customCommonLogPolicyForYAMLPolicyDefinitionTesting.yaml b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customCommonLogPolicyForYAMLPolicyDefinitionTesting.yaml new file mode 100644 index 0000000000..4191210acd --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/operationPolicy/customCommonLogPolicyForYAMLPolicyDefinitionTesting.yaml @@ -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 \ No newline at end of file