Search in sources :

Example 1 with BlockingConditionDTO

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;
}
Also used : BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)

Example 2 with BlockingConditionDTO

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()));
}
Also used : BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO) Test(org.testng.annotations.Test)

Example 3 with BlockingConditionDTO

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");
}
Also used : BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO) Test(org.testng.annotations.Test)

Example 4 with BlockingConditionDTO

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);
}
Also used : BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO) Test(org.testng.annotations.Test)

Example 5 with BlockingConditionDTO

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

Aggregations

BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)13 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)7 Test (org.testng.annotations.Test)5 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO)4 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)2 BlacklistApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl)2 BlockingConditionListDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionListDTO)1 IPConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.IPConditionDTO)1 BlockingConditionListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO)1