Skip to content

Commit

Permalink
Add integration test for retrieving block conditions by condition typ…
Browse files Browse the repository at this point in the history
…e and exact value
  • Loading branch information
ashanhr committed Sep 19, 2024
1 parent 72377d1 commit 76c3203
Showing 1 changed file with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 76c3203

Please sign in to comment.