use of org.wso2.carbon.apimgt.impl.dto.ConditionDto 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.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method getQueryParamCondition.
private ConditionDto getQueryParamCondition(boolean invert) {
ConditionDto conditionDto = new ConditionDto();
ConditionDto.QueryParamConditions queryParamConditions = new ConditionDto.QueryParamConditions();
Map map = new HashMap();
map.put("abc", "cde");
map.put("bcd", "xyz");
queryParamConditions.setValues(map);
queryParamConditions.setInvert(invert);
conditionDto.setQueryParameterConditions(queryParamConditions);
return conditionDto;
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto 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.ConditionDto 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));
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method getJWTCondition.
private ConditionDto getJWTCondition(boolean invert) {
ConditionDto conditionDto = new ConditionDto();
ConditionDto.JWTClaimConditions jwtClaimConditions = new ConditionDto.JWTClaimConditions();
Map map = new HashMap();
map.put("http://wso2.org/claims/abc", "cde");
map.put("http://wso2.org/claims/bcd", "xyz");
jwtClaimConditions.setValues(map);
jwtClaimConditions.setInvert(invert);
conditionDto.setJwtClaimConditions(jwtClaimConditions);
return conditionDto;
}
Aggregations