use of org.wso2.carbon.apimgt.core.models.BlockConditions 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.core.models.BlockConditions 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);
}
use of org.wso2.carbon.apimgt.core.models.BlockConditions in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTest method blacklistConditionIdGetTest.
@Test
public void blacklistConditionIdGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
String uuid = UUID.randomUUID().toString();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
BlockConditions conditions = new BlockConditions();
conditions.setUuid(uuid);
Mockito.doReturn(conditions).doThrow(new IllegalArgumentException()).when(adminService).getBlockConditionByUUID(uuid);
Response response = blacklistApiService.blacklistConditionIdGet(uuid, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.core.models.BlockConditions in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetBlockConditions.
@Test(description = "Test getting block conditions")
public void testGetBlockConditions() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
List<BlockConditions> blockConditionsListExpected = new ArrayList<>();
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
blockConditionsListExpected.add(blockConditions);
Mockito.when(policyDAO.getBlockConditions()).thenReturn(blockConditionsListExpected);
List<BlockConditions> blockConditionsListReturned = adminService.getBlockConditions();
Assert.assertEquals(blockConditionsListReturned, blockConditionsListExpected);
// Error path
Mockito.when(policyDAO.getBlockConditions()).thenThrow(APIMgtDAOException.class);
try {
adminService.getBlockConditions();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get list of block conditions.");
}
}
use of org.wso2.carbon.apimgt.core.models.BlockConditions in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeleteBlockConditionByUuid.
@Test(description = "Test deleting block condition by uuid")
public void testDeleteBlockConditionByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
Mockito.when(policyDAO.deleteBlockConditionByUuid(blockConditions.getUuid())).thenReturn(true);
Boolean statusTrue = adminService.deleteBlockConditionByUuid(blockConditions.getUuid());
Assert.assertTrue(statusTrue);
// Error path
// Failure deleting
Mockito.when(policyDAO.deleteBlockConditionByUuid(blockConditions.getUuid())).thenReturn(false);
Boolean statusFalse = adminService.deleteBlockConditionByUuid(blockConditions.getUuid());
Assert.assertFalse(statusFalse);
// Error path
// APIMgtDAOException
Mockito.when(policyDAO.deleteBlockConditionByUuid(blockConditions.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.deleteBlockConditionByUuid(blockConditions.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't delete block condition with UUID: " + blockConditions.getUuid());
}
}
Aggregations