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());
}
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);
}
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;
}
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;
}
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;
}
Aggregations