Search in sources :

Example 11 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOToJWTClaimsCondition.

/**
 * Converts a JWT Claims Condition DTO object into a model object
 *
 * @param dto JWT Claims Condition DTO object
 * @return JWT Claims Condition model object derived from JWT Claims Condition DTO
 */
public static JWTClaimsCondition fromDTOToJWTClaimsCondition(ThrottleConditionDTO dto) {
    JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
    jwtClaimsCondition = updateFieldsFromDTOToCondition(dto, jwtClaimsCondition);
    jwtClaimsCondition.setAttribute(dto.getJwtClaimsCondition().getAttribute());
    jwtClaimsCondition.setClaimUrl(dto.getJwtClaimsCondition().getClaimUrl());
    return jwtClaimsCondition;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)

Example 12 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromIPConditionToDTO.

/**
 * Converts an IP Condition model object into a DTO
 *
 * @param ipCondition IP Condition model object
 * @return DTO object derived from model object
 */
public static ThrottleConditionDTO fromIPConditionToDTO(IPCondition ipCondition) throws UnsupportedThrottleConditionTypeException {
    String ipConditionType = mapIPConditionTypeFromModelToDTO(ipCondition.getType());
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    throttleConditionDTO.setIpCondition(new IPConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(ipCondition, throttleConditionDTO);
    throttleConditionDTO.getIpCondition().setIpConditionType(ipConditionType);
    throttleConditionDTO.getIpCondition().setSpecificIP(ipCondition.getSpecificIP());
    throttleConditionDTO.getIpCondition().setStartingIP(ipCondition.getStartingIP());
    throttleConditionDTO.getIpCondition().setEndingIP(ipCondition.getEndingIP());
    return throttleConditionDTO;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

Example 13 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtilTestCase method fromJWTConditionDtoToJWTConditionModelTest.

@Test(description = "Convert JWT Condition DTO to JWTCondition Model object")
public void fromJWTConditionDtoToJWTConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.JWT_CLAIMS_CONDITION_TYPE);
    JWTClaimsConditionDTO jwtClaimsConditionDTO = new JWTClaimsConditionDTO();
    jwtClaimsConditionDTO.setAttribute("testAttribute");
    jwtClaimsConditionDTO.setClaimUrl("http://wso2.org/claims");
    throttleConditionDTO.setJwtClaimsCondition(jwtClaimsConditionDTO);
    JWTClaimsCondition condition = (JWTClaimsCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    assertEquals(condition.getAttribute(), "testAttribute");
    assertEquals(condition.getClaimUrl(), "http://wso2.org/claims");
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) Test(org.testng.annotations.Test)

Example 14 with ThrottleConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtilTestCase method fromSpecificIPConditionDtoToIPConditionModelTest.

@Test(description = "Convert IP specific IPCondition DTO to IPCondition Model object")
public void fromSpecificIPConditionDtoToIPConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    IPConditionDTO ipConditionDTO = new IPConditionDTO();
    ipConditionDTO.setIpConditionType(PolicyConstants.IP_SPECIFIC_TYPE);
    ipConditionDTO.setSpecificIP("10.100.0.168");
    throttleConditionDTO.setIpCondition(ipConditionDTO);
    IPCondition condition = (IPCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    Assert.assertNotNull(condition.getCondition());
    assertEquals(condition.getSpecificIP(), "10.100.0.168");
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)5 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)5 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)3 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)2 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)2 QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)2 ConditionalGroupDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ConditionalGroupDTO)1 HeaderConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.HeaderConditionDTO)1 IPConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO)1 JWTClaimsConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.JWTClaimsConditionDTO)1 QueryParameterConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.QueryParameterConditionDTO)1