Search in sources :

Example 6 with BlockingConditionDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.

the class BlacklistApiServiceImplTest method blacklistConditionIdPutTest.

@Test
public void blacklistConditionIdPutTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    BlockingConditionDTO dto = new BlockingConditionDTO();
    dto.setConditionId(UUID.randomUUID().toString());
    dto.setStatus(true);
    dto.setConditionType(BLOCKING_CONDITIONS_IP);
    dto.setConditionValue("12.32.45.3");
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    BlockConditions conditions = BlockingConditionMappingUtil.fromBlockingConditionDTOToBlockCondition(dto);
    Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(adminService).updateBlockConditionStateByUUID(uuid, true);
    Mockito.doReturn(conditions).doThrow(new IllegalArgumentException()).when(adminService).getBlockConditionByUUID(uuid);
    Response response = blacklistApiService.blacklistConditionIdPut(uuid, dto, null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO) BlacklistApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with BlockingConditionDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.

the class MappingUtil method fromBlockConditionListToListDTO.

/**
 * Converts a List of Block Condition in to REST API LIST DTO Object.
 *
 * @param blockConditionList A List of Block Conditions
 * @return REST API List DTO object derived from Block Condition list
 */
public static BlockingConditionListDTO fromBlockConditionListToListDTO(List<BlockConditions> blockConditionList) {
    BlockingConditionListDTO listDTO = new BlockingConditionListDTO();
    List<BlockingConditionDTO> blockingConditionDTOList = new ArrayList<>();
    if (blockConditionList != null) {
        for (BlockConditions blockCondition : blockConditionList) {
            BlockingConditionDTO dto = fromBlockingConditionToDTO(blockCondition);
            blockingConditionDTOList.add(dto);
        }
    }
    listDTO.setCount(blockingConditionDTOList.size());
    listDTO.setList(blockingConditionDTOList);
    return listDTO;
}
Also used : BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ArrayList(java.util.ArrayList) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO)

Example 8 with BlockingConditionDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.

the class MappingUtil 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
 */
public static BlockingConditionDTO fromBlockingConditionToDTO(BlockConditions blockCondition) {
    if (blockCondition.getUuid() == null) {
        return null;
    }
    BlockingConditionDTO dto = new BlockingConditionDTO();
    dto.setUuid(blockCondition.getUuid());
    dto.setConditionType(blockCondition.getConditionType());
    dto.setEnabled(blockCondition.isEnabled());
    if (blockCondition.getConditionType().equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE)) {
        dto.setStartingIP(APIUtils.ipToLong(blockCondition.getStartingIP()));
        dto.setEndingIP(APIUtils.ipToLong(blockCondition.getEndingIP()));
    }
    String conditionValue = blockCondition.getConditionValue();
    if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_IP.equals(blockCondition.getConditionType())) {
        dto.setFixedIp(APIUtils.ipToLong(conditionValue));
    }
    dto.setConditionValue(conditionValue);
    return dto;
}
Also used : BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO)

Example 9 with BlockingConditionDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.

the class BlockingConditionMappingUtil method fromBlockConditionListToListDTO.

/**
 * Converts a List of Block Condition in to REST API LIST DTO Object.
 *
 * @param blockConditionList A List of Block Conditions
 * @return REST API List DTO object derived from Block Condition list
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static BlockingConditionListDTO fromBlockConditionListToListDTO(List<BlockConditions> blockConditionList) throws UnsupportedThrottleLimitTypeException {
    BlockingConditionListDTO listDTO = new BlockingConditionListDTO();
    List<BlockingConditionDTO> blockingConditionDTOList = new ArrayList<>();
    if (blockConditionList != null) {
        for (BlockConditions blockCondition : blockConditionList) {
            BlockingConditionDTO dto = fromBlockingConditionToDTO(blockCondition);
            blockingConditionDTOList.add(dto);
        }
    }
    listDTO.setCount(blockingConditionDTOList.size());
    listDTO.setList(blockingConditionDTOList);
    return listDTO;
}
Also used : BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionListDTO) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ArrayList(java.util.ArrayList) BlockingConditionDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)

Example 10 with BlockingConditionDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionDTO in project carbon-apimgt by wso2.

the class BlockingConditionMappingUtil method fromBlockingConditionDTOToBlockCondition.

/**
 * Convert BlockingConditionDTO to BlockCondition.
 *
 * @param blockingConditionDTO blockindConditionDTO to be converted
 * @return BlockCondition Object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static BlockConditions fromBlockingConditionDTOToBlockCondition(BlockingConditionDTO blockingConditionDTO) throws UnsupportedThrottleLimitTypeException {
    BlockConditions blockConditions = new BlockConditions();
    blockConditions.setUuid(blockingConditionDTO.getConditionId());
    blockConditions.setConditionType(blockingConditionDTO.getConditionType());
    blockConditions.setConditionValue(blockingConditionDTO.getConditionValue());
    blockConditions.setEnabled(blockingConditionDTO.getStatus());
    if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE.equals(blockConditions.getConditionType())) {
        blockConditions.setStartingIP(blockingConditionDTO.getIpCondition().getStartingIP());
        blockConditions.setEndingIP(blockingConditionDTO.getIpCondition().getEndingIP());
    }
    return blockConditions;
}
Also used : BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions)

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