use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithIPCondition.
@Test
public void testGetThrottledInConditionWithIPCondition() {
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("X-Forwarded-For", "127.0.0.1");
((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[] { getIPCondition(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getIPCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithIPConditionWithDefault.
@Test
public void testGetThrottledInConditionWithIPConditionWithDefault() {
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("X-Forwarded-For", "127.0.0.2");
((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[] { getIPCondition(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getIPCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "default");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithHeaderConditionNegative.
@Test
public void testGetThrottledInConditionWithHeaderConditionNegative() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableHeaderConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("abc", "cd1");
map.put("bcd", "xyz");
((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[] { getHeaderCondition(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getHeaderCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "default");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithIPRangeConditionWithDefault.
@Test
public void testGetThrottledInConditionWithIPRangeConditionWithDefault() {
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("X-Forwarded-For", "192.168.0.5");
((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(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getIpRangeCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testRetrievingEmptyApplicableConditionsWhenConditionsAreNotAvailableInConditionGroup.
@Test
public void testRetrievingEmptyApplicableConditionsWhenConditionsAreNotAvailableInConditionGroup() {
ConditionDTO[] conditionDTOs = new ConditionDTO[0];
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditions(conditionDTOs);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
List<ConditionGroupDTO> conditionGroupDTOList = throttleConditionEvaluator.getApplicableConditions(TestUtils.getMessageContext(apiContext, apiVersion), new AuthenticationContext(), conditionGroupDTOS);
// Should return empty Condition group in the Condition group array
Assert.assertNull(conditionGroupDTOList.get(0));
}
Aggregations