From b68a5183331173f43957162775daf006c2db8772 Mon Sep 17 00:00:00 2001 From: rmsamitha Date: Mon, 15 Jul 2024 13:14:21 +0530 Subject: [PATCH] Unit tests for case insensitive header conditions --- .../apimgt/throttle/policy/deployer/utils/TestUtil.java | 9 +++++++++ .../utils/ThrottlingPolicyTemplateBuilderTest.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/TestUtil.java b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/TestUtil.java index 62b973da1847..97d2b4e17d17 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/TestUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/TestUtil.java @@ -35,6 +35,7 @@ * An Utility class to generate dummy policies. */ public class TestUtil { + public static final String HEADER_CONDITION_HEADER_NAME = "HEADER1"; /** * Generate a dummy API Policy object @@ -75,6 +76,14 @@ public static ApiPolicy getPolicyAPILevel() { condition1.setInverted(false); conditions.add(condition1); + Condition condition2 = new Condition(); + condition2.setConditionType("Header"); + //set the header name in mixed case to test that execution plans are deployed with lower-case header names + condition2.setName(HEADER_CONDITION_HEADER_NAME); + condition2.setValue("test1"); + condition2.setInverted(false); + conditions.add(condition2); + conditionGroup1.setCondition(conditions); QuotaPolicy defaultLimitCondGroup1 = new QuotaPolicy(); diff --git a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlingPolicyTemplateBuilderTest.java b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlingPolicyTemplateBuilderTest.java index a0aa79ff8533..54389c4005ab 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlingPolicyTemplateBuilderTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/test/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlingPolicyTemplateBuilderTest.java @@ -66,6 +66,12 @@ public void testGetThrottlePolicyForAPILevel() throws Exception { String defaultPolicyString = templateBuilder.getThrottlePolicyForAPILevelDefault(policy); Assert.assertNotNull(defaultPolicyString); + + // Test that execution plans are deployed with lower-case header names even though the header condition of the + // policy had the header name in upper-case (or mix-case) + boolean isPolicyStringContainsLowerCasedHeader = + defaultPolicyString.contains(TestUtil.HEADER_CONDITION_HEADER_NAME.toLowerCase()); + Assert.assertTrue(isPolicyStringContainsLowerCasedHeader); } @Test