Search in sources :

Example 6 with ThrottleConditionDTO

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

the class CommonThrottleMappingUtil method fromHeaderConditionToDTO.

/**
 * Converts a Header Condition model object into a DTO
 *
 * @param headerCondition Header Condition model object
 * @return DTO object that was derived from Header Condition model object
 */
public static ThrottleConditionDTO fromHeaderConditionToDTO(HeaderCondition headerCondition) {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.HEADER_CONDITION_TYPE);
    throttleConditionDTO.setHeaderCondition(new HeaderConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(headerCondition, throttleConditionDTO);
    throttleConditionDTO.getHeaderCondition().setHeaderName(headerCondition.getHeaderName());
    throttleConditionDTO.getHeaderCondition().setHeaderValue(headerCondition.getValue());
    return throttleConditionDTO;
}
Also used : ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO) HeaderConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.HeaderConditionDTO)

Example 7 with ThrottleConditionDTO

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

the class CommonThrottleMappingUtilTestCase method fromQueryParamsConditionDtoToQueryParamsConditionModelTest.

@Test(description = "Convert Query param Condition DTO to QueryParamCondition Model object")
public void fromQueryParamsConditionDtoToQueryParamsConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.QUERY_PARAMS_CONDITION_TYPE);
    QueryParameterConditionDTO queryParameterConditionDTO = new QueryParameterConditionDTO();
    queryParameterConditionDTO.setParameterName("testParam");
    queryParameterConditionDTO.setParameterValue("testParamValue");
    throttleConditionDTO.setQueryParameterCondition(queryParameterConditionDTO);
    QueryParameterCondition condition = (QueryParameterCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    assertEquals(condition.getParameter(), "testParam");
    assertEquals(condition.getValue(), "testParamValue");
}
Also used : QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) Test(org.testng.annotations.Test)

Example 8 with ThrottleConditionDTO

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

the class CommonThrottleMappingUtilTestCase method fromHeaderConditionDtoToHeaderConditionModelTest.

@Test(description = "Convert Header Condition DTO to HeaderCondition Model object")
public void fromHeaderConditionDtoToHeaderConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.HEADER_CONDITION_TYPE);
    HeaderConditionDTO headerConditionDTO = new HeaderConditionDTO();
    headerConditionDTO.setHeaderName("testHeader");
    headerConditionDTO.setHeaderValue("testHeaderValue");
    throttleConditionDTO.setHeaderCondition(headerConditionDTO);
    HeaderCondition condition = (HeaderCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    assertEquals(condition.getHeaderName(), "testHeader");
    assertEquals(condition.getValue(), "testHeaderValue");
}
Also used : HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) Test(org.testng.annotations.Test)

Example 9 with ThrottleConditionDTO

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

the class CommonThrottleMappingUtilTestCase method fromIPRangeConditionDtoToIPConditionModelTest.

@Test(description = "Convert IP range IPCondition DTO to IPCondition Model object")
public void fromIPRangeConditionDtoToIPConditionModelTest() throws Exception {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.IP_CONDITION_TYPE);
    IPConditionDTO ipConditionDTO = new IPConditionDTO();
    ipConditionDTO.setIpConditionType(IP_RANGE_TYPE);
    ipConditionDTO.setStartingIP("10.100.0.158");
    ipConditionDTO.setEndingIP("10.100.0.178");
    throttleConditionDTO.setIpCondition(ipConditionDTO);
    IPCondition condition = (IPCondition) CommonThrottleMappingUtil.fromDTOToCondition(throttleConditionDTO);
    Assert.assertNotNull(condition);
    assertEquals(condition.getStartingIP(), "10.100.0.158");
    assertEquals(condition.getEndingIP(), "10.100.0.178");
    assertEquals(condition.getType(), IP_RANGE_TYPE);
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) Test(org.testng.annotations.Test)

Example 10 with ThrottleConditionDTO

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

the class CommonThrottleMappingUtil method fromJWTClaimsConditionToDTO.

/**
 * Converts a JWT Claims Condition model object into a DTO
 *
 * @param condition JWT Claims Condition model object
 * @return DTO object that was derived from JWT Claims Condition model object
 */
public static ThrottleConditionDTO fromJWTClaimsConditionToDTO(JWTClaimsCondition condition) {
    ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
    throttleConditionDTO.setType(PolicyConstants.JWT_CLAIMS_CONDITION_TYPE);
    throttleConditionDTO.setJwtClaimsCondition(new JWTClaimsConditionDTO());
    throttleConditionDTO = updateFieldsFromConditionToDTO(condition, throttleConditionDTO);
    throttleConditionDTO.getJwtClaimsCondition().setClaimUrl(condition.getClaimUrl());
    throttleConditionDTO.getJwtClaimsCondition().setAttribute(condition.getAttribute());
    return throttleConditionDTO;
}
Also used : JWTClaimsConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.JWTClaimsConditionDTO) ThrottleConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)

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