Search in sources :

Example 1 with BlacklistApiServiceImpl

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);
}
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 2 with BlacklistApiServiceImpl

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);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) BlacklistApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with BlacklistApiServiceImpl

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);
}
Also used : Response(javax.ws.rs.core.Response) BlockingConditionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with BlacklistApiServiceImpl

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);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with BlacklistApiServiceImpl

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);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) BlacklistApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)6 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)5 BlacklistApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl)5 ArrayList (java.util.ArrayList)2 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)2 BlockingConditionDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BlockingConditionDTO)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 BlockingConditionListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.BlockingConditionListDTO)1