use of org.wso2.carbon.apimgt.impl.dto.ThrottleProperties in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithComplexCondition.
@Test
public void testGetThrottledInConditionWithComplexCondition() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableHeaderConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty("REST_URL_POSTFIX", "/temperature?abc=cde&bcd=xyz");
Map map = new TreeMap();
map.put("X-Forwarded-For", "127.0.0.1");
map.put("abc", "cde");
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[] { getComplexCondition1() }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getComplexCondition1(), getComplexCondition2() }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
use of org.wso2.carbon.apimgt.impl.dto.ThrottleProperties 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.ThrottleProperties in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithQueryCondition.
@Test
public void testGetThrottledInConditionWithQueryCondition() {
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=cde&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, "condition1");
}
use of org.wso2.carbon.apimgt.impl.dto.ThrottleProperties in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithHeaderConditionInvert.
@Test
public void testGetThrottledInConditionWithHeaderConditionInvert() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableHeaderConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("abc", "cde");
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(true) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getHeaderCondition(true) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "default");
}
use of org.wso2.carbon.apimgt.impl.dto.ThrottleProperties in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithComplexCondition2.
@Test
public void testGetThrottledInConditionWithComplexCondition2() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableHeaderConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("abc", "cde");
map.put("bcd", "xyz");
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[] { getHeaderCondition(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getIPCondition(false), getHeaderCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
Aggregations