Search in sources :

Example 1 with IPConditionDTO

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

the class BlockingConditionMappingUtilTestCase method fromBlockingConditionDTOToBlockConditionTest.

@Test(description = "From Blocking Condition DTO to Model")
public void fromBlockingConditionDTOToBlockConditionTest() throws Exception {
    BlockingConditionDTO dto = new BlockingConditionDTO();
    dto.setConditionId(UUID.randomUUID().toString());
    dto.setConditionType(BLOCKING_CONDITION_IP_RANGE);
    IPConditionDTO ipCondition = new IPConditionDTO();
    ipCondition.setStartingIP("12.32.45.3");
    ipCondition.setEndingIP("12.32.45.31");
    dto.setIpCondition(ipCondition);
    dto.setStatus(true);
    BlockConditions conditions = BlockingConditionMappingUtil.fromBlockingConditionDTOToBlockCondition(dto);
    Assert.assertNotNull(conditions);
    Assert.assertEquals(BLOCKING_CONDITION_IP_RANGE, conditions.getConditionType());
    Assert.assertEquals(conditions.getStartingIP(), dto.getIpCondition().getStartingIP());
    Assert.assertEquals(conditions.getEndingIP(), dto.getIpCondition().getEndingIP());
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO) Test(org.testng.annotations.Test)

Example 2 with IPConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.IPConditionDTO 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 3 with IPConditionDTO

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

the class CommonThrottleMappingUtil method fromDTOToIPCondition.

/**
 * Converts a IP Condition DTO object into a model object
 *
 * @param dto             IP Condition DTO object
 * @param invertCondition Invert condition relevant to the DTO
 * @return IP Condition model object derived from DTO
 */
public static IPCondition fromDTOToIPCondition(IPConditionDTO dto, boolean invertCondition) {
    String ipConditionType = mapIPConditionTypeFromDTOToModel(dto.getIpConditionType());
    IPCondition ipCondition = new IPCondition(ipConditionType);
    ipCondition.setConditionEnabled(Boolean.TRUE.toString());
    ipCondition.setInvertCondition(invertCondition);
    ipCondition.setSpecificIP(dto.getSpecificIP());
    ipCondition.setStartingIP(dto.getStartingIP());
    ipCondition.setEndingIP(dto.getEndingIP());
    return ipCondition;
}
Also used : IPCondition(org.wso2.carbon.apimgt.api.model.policy.IPCondition)

Example 4 with IPConditionDTO

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

the class BlockingConditionMappingUtil method fromBlockConditionToIpConditionDTO.

/**
 * Block condition IP range details to IPConditionDTO.
 *
 * @param blockConditions blockCondition to be converted into IPConditionDTO.
 * @return IPConditionDTO Object
 */
private static IPConditionDTO fromBlockConditionToIpConditionDTO(BlockConditions blockConditions) {
    IPConditionDTO ipConditionDTO = new IPConditionDTO();
    ipConditionDTO.setStartingIP(blockConditions.getStartingIP());
    ipConditionDTO.setEndingIP(blockConditions.getEndingIP());
    return ipConditionDTO;
}
Also used : IPConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO)

Example 5 with IPConditionDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.IPConditionDTO 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)

Aggregations

Test (org.testng.annotations.Test)3 IPConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO)3 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)2 IPCondition (org.wso2.carbon.apimgt.api.model.policy.IPCondition)1 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)1 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)1 ThrottleConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleConditionDTO)1 IPConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.IPConditionDTO)1