use of org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl 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.rest.api.admin.impl.BlacklistApiServiceImpl 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.rest.api.admin.impl.BlacklistApiServiceImpl 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);
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTestCase method applicationsGetExceptionTestCase.
@Test
public void applicationsGetExceptionTestCase() throws Exception {
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
String message = "Error while retrieving applications.";
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.APPLICATION_INACTIVE);
Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
Response response = blacklistApiService.blacklistGet(null, getRequest());
Assert.assertEquals(response.getStatus(), 400);
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTest method blacklistConditionIdDeleteTest.
@Test
public void blacklistConditionIdDeleteTest() throws NotFoundException, APIManagementException {
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);
Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(adminService).deleteBlockConditionByUuid(uuid);
Response response = blacklistApiService.blacklistConditionIdDelete(uuid, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
Aggregations