use of org.wso2.carbon.apimgt.api.dto.ConditionDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfNonMatchingIPRangeCondition.
@Test
public void testApplicabilityOfNonMatchingIPRangeCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("IPRangeConditionGroup");
// 127.0.0.1 is not in 10.10.0.1 - 10.10.0.4 IP range
ConditionDTO nonMatchingCondition = new ConditionDTO();
nonMatchingCondition.setConditionType("IPRange");
nonMatchingCondition.setConditionName("10.10.0.1");
nonMatchingCondition.setConditionValue("10.10.0.4");
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.ConditionDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfInvertedIPSpecificCondition.
@Test
public void testApplicabilityOfInvertedIPSpecificCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("IPSpecificConditionGroup");
ConditionDTO invertedIPRangeCondition = new ConditionDTO();
invertedIPRangeCondition.setConditionType("IPSpecific");
invertedIPRangeCondition.setConditionValue("127.0.0.1");
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.ConditionDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithQueryConditionNegativeInvert.
@Test
public void testGetThrottledInConditionWithQueryConditionNegativeInvert() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableQueryParamConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty("REST_URL_POSTFIX", "/temperature?abc=cd&bcd=xyz");
Map<String, List<ConditionDto>> conditionMap = new HashMap<>();
conditionMap.put("condition1", Arrays.asList(new ConditionDto[] { getQueryParamCondition(true) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getQueryParamCondition(true) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
use of org.wso2.carbon.apimgt.api.dto.ConditionDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithIPRangeConditionWithDefaultIpNotInRangeInvert.
@Test
public void testGetThrottledInConditionWithIPRangeConditionWithDefaultIpNotInRangeInvert() {
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("X-Forwarded-For", "192.168.0.12");
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, map);
Map<String, List<ConditionDto>> conditionMap = new HashMap<>();
conditionMap.put("condition1", Arrays.asList(new ConditionDto[] { getIpRangeCondition(true) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getIpRangeCondition(true) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
use of org.wso2.carbon.apimgt.api.dto.ConditionDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithQueryConditionNegative.
@Test
public void testGetThrottledInConditionWithQueryConditionNegative() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableQueryParamConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty("REST_URL_POSTFIX", "/temperature?abc=cd&bcd=xyz");
Map<String, List<ConditionDto>> conditionMap = new HashMap<>();
conditionMap.put("condition1", Arrays.asList(new ConditionDto[] { getQueryParamCondition(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getQueryParamCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "default");
}
Aggregations