use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.
the class BlockingConditionMappingUtil method fromBlockingConditionToDTO.
/**
* Converts a single Block Condition model object into REST API DTO object.
*
* @param blockCondition Block condition model object
* @return Block condition DTO object derived from block condition model object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static BlockingConditionDTO fromBlockingConditionToDTO(BlockConditions blockCondition) throws UnsupportedThrottleLimitTypeException {
if (blockCondition.getUuid() == null) {
return null;
}
BlockingConditionDTO dto = new BlockingConditionDTO();
dto.setConditionId(blockCondition.getUuid());
dto.setConditionType(blockCondition.getConditionType());
dto.setStatus(blockCondition.isEnabled());
if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE.equals(blockCondition.getConditionType())) {
dto.setIpCondition(fromBlockConditionToIpConditionDTO(blockCondition));
}
String conditionValue = blockCondition.getConditionValue();
dto.setConditionValue(conditionValue);
return dto;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.
the class MappingUtilTestCase method fromBlockingConditionToDTOTest.
@Test
public void fromBlockingConditionToDTOTest() {
BlockConditions blockCondition = SampleTestObjectCreator.createUniqueBlockConditions(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_IP);
BlockingConditionDTO blockingConditionDTo = MappingUtil.fromBlockingConditionToDTO(blockCondition);
Assert.assertEquals(blockCondition.getUuid(), blockingConditionDTo.getUuid());
Assert.assertEquals(blockCondition.getConditionType(), blockingConditionDTo.getConditionType());
Assert.assertEquals(blockCondition.getConditionValue(), blockingConditionDTo.getConditionValue());
Assert.assertEquals(Boolean.valueOf(blockCondition.isEnabled()), Boolean.valueOf(blockingConditionDTo.getEnabled()));
Assert.assertEquals(Long.valueOf(APIUtils.ipToLong(blockCondition.getConditionValue())), Long.valueOf(blockingConditionDTo.getFixedIp()));
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.
the class BlockingConditionMappingUtilTestCase method fromBlockConditionToIpConditionDTOTest.
@Test(description = "From Blocking Condition to DTO")
public void fromBlockConditionToIpConditionDTOTest() throws Exception {
BlockConditions conditions = new BlockConditions();
conditions.setUuid(UUID.randomUUID().toString());
conditions.setConditionType(BLOCKING_CONDITION_IP_RANGE);
conditions.setStartingIP("12.23.45.3");
conditions.setEndingIP("23.45.2.1");
BlockingConditionDTO dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(conditions);
Assert.assertNotNull(dto);
Assert.assertEquals(dto.getConditionType(), BLOCKING_CONDITION_IP_RANGE);
Assert.assertEquals(dto.getIpCondition().getStartingIP(), "12.23.45.3");
Assert.assertEquals(dto.getIpCondition().getEndingIP(), "23.45.2.1");
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.
the class BlockingConditionMappingUtilTestCase method fromBlockingConditionToDTOTest.
@Test(description = "Convert Blocking Condition to DTO")
public void fromBlockingConditionToDTOTest() throws Exception {
BlockConditions conditions = new BlockConditions();
String uuid = UUID.randomUUID().toString();
conditions.setUuid(uuid);
conditions.setConditionType(BLOCKING_CONDITION_IP_RANGE);
BlockingConditionDTO dto = BlockingConditionMappingUtil.fromBlockingConditionToDTO(conditions);
Assert.assertNotNull(dto);
Assert.assertEquals(uuid, dto.getConditionId());
Assert.assertEquals(dto.getConditionType(), BLOCKING_CONDITION_IP_RANGE);
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO 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());
}
Aggregations