diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/throttlingpolicy/DenyPolicySearchTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/throttlingpolicy/DenyPolicySearchTestCase.java index ecfc066b3e..117f421305 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/throttlingpolicy/DenyPolicySearchTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/restapi/admin/throttlingpolicy/DenyPolicySearchTestCase.java @@ -116,8 +116,8 @@ public void testAddNewBlockingConditions() throws Exception { blockingCondition2ID = addedBlacklistThrottlingPolicy.getData().getConditionId(); } - @Test(groups = {"wso2.am"}, description = "Test retrieve block conditions by condition type and value", - dependsOnMethods = "testAddNewBlockingConditions") + @Test(groups = { + "wso2.am" }, description = "Test retrieve block conditions by condition type and value", dependsOnMethods = "testAddNewBlockingConditions") public void testGetBlockConditionsByConditionTypeAndValue() throws Exception { // Retrieve blocking condition values that contains /test BlockingConditionListDTO conditionsList = restAPIAdmin.getBlockingConditionsByConditionTypeAndValue( @@ -154,6 +154,80 @@ public void testGetBlockConditionsByConditionTypeAndValue() throws Exception { Assert.assertEquals(countTest2, 1); } + @Test(groups = { + "wso2.am" }, description = "Test retrieve block conditions by condition type and exact value", dependsOnMethods = "testAddNewBlockingConditions") + public void testGetBlockConditionsByConditionTypeAndExactValue() throws Exception { + // Retrieve blocking condition values that exactly matchers with /test + BlockingConditionListDTO conditionsList = restAPIAdmin.getBlockingConditionsByConditionTypeAndValue( + "conditionType:API&conditionValue:\"/test\""); + Assert.assertNotNull(conditionsList); + + int countTest1 = 0; + int countTest2 = 0; + for (BlockingConditionDTO condition : conditionsList.getList()) { + if (apiContextResolver(API1_CONTEXT, API1_VERSION).equals(condition.getConditionValue())) { + countTest1++; + } else if (apiContextResolver(API2_CONTEXT, API2_VERSION).equals(condition.getConditionValue())) { + countTest2++; + } + } + Assert.assertEquals(countTest1, 0); + Assert.assertEquals(countTest2, 0); + + // Retrieve blocking condition values that exactly matches with /test/abc + conditionsList = restAPIAdmin.getBlockingConditionsByConditionTypeAndValue( + "conditionType:API&conditionValue:\"/test/abc\""); + Assert.assertNotNull(conditionsList); + + countTest1 = 0; + countTest2 = 0; + for (BlockingConditionDTO condition : conditionsList.getList()) { + if (apiContextResolver(API1_CONTEXT, API1_VERSION).equals(condition.getConditionValue())) { + countTest1++; + } else if (apiContextResolver(API2_CONTEXT, API2_VERSION).equals(condition.getConditionValue())) { + countTest2++; + } + } + Assert.assertEquals(countTest1, 0); + Assert.assertEquals(countTest2, 0); + + String conditionValue = apiContextResolver(API1_CONTEXT, API1_VERSION); + // Retrieve blocking condition values that exactly matches with /test/1.0.0 + conditionsList = restAPIAdmin.getBlockingConditionsByConditionTypeAndValue( + "conditionType:API&conditionValue:" + conditionValue); + Assert.assertNotNull(conditionsList); + + countTest1 = 0; + countTest2 = 0; + for (BlockingConditionDTO condition : conditionsList.getList()) { + if (apiContextResolver(API1_CONTEXT, API1_VERSION).equals(condition.getConditionValue())) { + countTest1++; + } else if (apiContextResolver(API2_CONTEXT, API2_VERSION).equals(condition.getConditionValue())) { + countTest2++; + } + } + Assert.assertEquals(countTest1, 1); + Assert.assertEquals(countTest2, 0); + + conditionValue = apiContextResolver(API2_CONTEXT, API2_VERSION); + // Retrieve blocking condition values that exactly matches with /test/abc/2.0.0 + conditionsList = restAPIAdmin.getBlockingConditionsByConditionTypeAndValue( + "conditionType:API&conditionValue:" + conditionValue); + Assert.assertNotNull(conditionsList); + + countTest1 = 0; + countTest2 = 0; + for (BlockingConditionDTO condition : conditionsList.getList()) { + if (apiContextResolver(API1_CONTEXT, API1_VERSION).equals(condition.getConditionValue())) { + countTest1++; + } else if (apiContextResolver(API2_CONTEXT, API2_VERSION).equals(condition.getConditionValue())) { + countTest2++; + } + } + Assert.assertEquals(countTest1, 0); + Assert.assertEquals(countTest2, 1); + } + private String apiContextResolver(String context, String version) { if (userMode == TestUserMode.TENANT_ADMIN || userMode == TestUserMode.TENANT_USER) { return "/t/wso2.com/" + context + "/" + version;