use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO in project carbon-apimgt by wso2.
the class BlacklistApiServiceImpl method blacklistGet.
/**
* Get blacklist conditions.
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response blacklistGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received BlockCondition GET request");
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<BlockConditions> blockConditions = apiMgtAdminService.getBlockConditions();
BlockingConditionListDTO listDTO = BlockingConditionMappingUtil.fromBlockConditionListToListDTO(blockConditions);
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting blacklist ";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO in project carbon-apimgt by wso2.
the class MappingUtilTestCase method fromBlockConditionListToListDTOTest.
@Test
public void fromBlockConditionListToListDTOTest() {
List<BlockConditions> blockConditionsList = new ArrayList<>();
blockConditionsList.add(SampleTestObjectCreator.createUniqueBlockConditions(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE));
blockConditionsList.add(SampleTestObjectCreator.createUniqueBlockConditions(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_API));
blockConditionsList.add(SampleTestObjectCreator.createUniqueBlockConditions(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_IP));
BlockingConditionListDTO blockingConditionDTOList = MappingUtil.fromBlockConditionListToListDTO(blockConditionsList);
Assert.assertEquals(blockingConditionDTOList.getList().size(), blockConditionsList.size());
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO in project carbon-apimgt by wso2.
the class BlockingConditionMappingUtilTestCase method fromBlockConditionListToListDTODTOTest.
@Test(description = "From Blocking Condition List to List DTO")
public void fromBlockConditionListToListDTODTOTest() throws Exception {
List<BlockConditions> blockConditionList = new ArrayList<>();
BlockConditions conditions1 = new BlockConditions();
conditions1.setUuid(UUID.randomUUID().toString());
conditions1.setConditionType(BLOCKING_CONDITION_IP_RANGE);
conditions1.setStartingIP("12.23.45.3");
conditions1.setEndingIP("23.45.2.1");
BlockConditions conditions2 = new BlockConditions();
conditions2.setUuid(UUID.randomUUID().toString());
conditions2.setConditionType("API");
conditions2.setConditionValue("DummyAPI");
blockConditionList.add(conditions1);
blockConditionList.add(conditions2);
BlockingConditionListDTO dto = BlockingConditionMappingUtil.fromBlockConditionListToListDTO(blockConditionList);
Assert.assertNotNull(dto);
Assert.assertEquals(dto.getCount(), (Integer) blockConditionList.size());
Assert.assertEquals(dto.getList().get(0).getIpCondition().getStartingIP(), conditions1.getStartingIP());
Assert.assertEquals(dto.getList().get(0).getIpCondition().getEndingIP(), conditions1.getEndingIP());
Assert.assertEquals(dto.getList().get(0).getConditionType(), conditions1.getConditionType());
Assert.assertEquals(dto.getList().get(0).getConditionId(), conditions1.getUuid());
Assert.assertEquals(dto.getList().get(1).getConditionType(), conditions2.getConditionType());
Assert.assertEquals(dto.getList().get(1).getConditionId(), conditions2.getUuid());
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO 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;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTestCase method blacklistGetTestCase.
@Test
public void blacklistGetTestCase() throws Exception {
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
BlockConditions blockConditionOne = SampleTestObjectCreator.createUniqueBlockConditions("IP_RANGE");
BlockConditions blockConditionTwo = SampleTestObjectCreator.createUniqueBlockConditions("IP");
BlockConditions blockConditionThree = SampleTestObjectCreator.createUniqueBlockConditions("IP_RANGE");
List<BlockConditions> blockConditions = new ArrayList<>();
blockConditions.add(blockConditionOne);
blockConditions.add(blockConditionTwo);
blockConditions.add(blockConditionThree);
Mockito.when(adminService.getBlockConditions()).thenReturn(blockConditions);
Response response = blacklistApiService.blacklistGet(null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
Assert.assertEquals(((BlockingConditionListDTO) response.getEntity()).getList().size(), 3);
}
Aggregations