use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfNonMatchingIPSpecificCondition.
@Test
public void testApplicabilityOfNonMatchingIPSpecificCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("IPSpecificConditionGroup");
ConditionDTO nonMatchingCondition = new ConditionDTO();
nonMatchingCondition.setConditionType("IPSpecific");
nonMatchingCondition.setConditionValue("10.0.0.1");
ConditionDTO[] conditionDTOS = { nonMatchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(TestUtils.getMessageContext(apiContext, apiVersion), new AuthenticationContext(), conditionGroupDTOS);
Assert.assertNull(matchingConditionGroups.get(0));
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfMatchingHeaderCondition.
@Test
public void testApplicabilityOfMatchingHeaderCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("HeaderConditionGroup");
ConditionDTO matchingCondition = new ConditionDTO();
matchingCondition.setConditionType("Header");
matchingCondition.setConditionName("host");
matchingCondition.setConditionValue("org.wso2.com");
ConditionDTO[] conditionDTOS = { matchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(JWTToken);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("host", "org.wso2.com");
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, map);
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(messageContext, authenticationContext, conditionGroupDTOS);
Assert.assertEquals(matchingConditionGroups.get(0).getConditionGroupId(), "HeaderConditionGroup");
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfInvertedIPRangeCondition.
@Test
public void testApplicabilityOfInvertedIPRangeCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("IPRangeConditionGroup");
// 127.0.0.1 is not in inversion of 127.0.0.0 - 127.0.0.3 IP range
ConditionDTO invertedIPRangeCondition = new ConditionDTO();
invertedIPRangeCondition.setConditionType("IPRange");
invertedIPRangeCondition.setConditionName("127.0.0.0");
invertedIPRangeCondition.setConditionValue("127.0.0.3");
invertedIPRangeCondition.isInverted(true);
ConditionDTO[] conditionDTOS = { invertedIPRangeCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(TestUtils.getMessageContext(apiContext, apiVersion), new AuthenticationContext(), conditionGroupDTOS);
Assert.assertNull(matchingConditionGroups.get(0));
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfMatchingIPRangeCondition.
@Test
public void testApplicabilityOfMatchingIPRangeCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("IPRangeConditionGroup");
ConditionDTO matchingCondition = new ConditionDTO();
matchingCondition.setConditionType("IPRange");
// 127.0.0.1 is in 127.0.0.0 - 127.0.0.2 IP range
matchingCondition.setConditionName("127.0.0.0");
matchingCondition.setConditionValue("127.0.0.2");
ConditionDTO[] conditionDTOS = { matchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(TestUtils.getMessageContext(apiContext, apiVersion), new AuthenticationContext(), conditionGroupDTOS);
Assert.assertEquals(matchingConditionGroups.size(), 1);
Assert.assertEquals(matchingConditionGroups.get(0).getConditionGroupId(), "IPRangeConditionGroup");
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfInvertedQueryParameterTypeCondition.
@Test
public void testApplicabilityOfInvertedQueryParameterTypeCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("QueryParameterTypeConditionGroup");
ConditionDTO nonMatchingCondition = new ConditionDTO();
nonMatchingCondition.setConditionType("QueryParameterType");
nonMatchingCondition.setConditionName("city");
nonMatchingCondition.setConditionValue("colombo");
nonMatchingCondition.isInverted(true);
ConditionDTO[] conditionDTOS = { nonMatchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty("REST_URL_POSTFIX", "/temperature?city=colombo");
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(messageContext, new AuthenticationContext(), conditionGroupDTOS);
Assert.assertNull(matchingConditionGroups.get(0));
}
Aggregations