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 1868b7a8e5..1ba52fe3a8 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 @@ -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 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