Search in sources :

Example 6 with BlacklistApiServiceImpl

use of org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl in project carbon-apimgt by wso2.

the class BlacklistApiServiceImplTest method blacklistGetTest.

@Test
public void blacklistGetTest() 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 conditions1 = new BlockConditions();
    conditions1.setUuid(uuid);
    BlockConditions conditions2 = new BlockConditions();
    conditions2.setUuid(UUID.randomUUID().toString());
    List<BlockConditions> list = new ArrayList<>();
    list.add(conditions1);
    list.add(conditions2);
    Mockito.doReturn(list).doThrow(new IllegalArgumentException()).when(adminService).getBlockConditions();
    Response response = blacklistApiService.blacklistGet(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) ArrayList(java.util.ArrayList) BlacklistApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with BlacklistApiServiceImpl

use of org.wso2.carbon.apimgt.rest.api.admin.impl.BlacklistApiServiceImpl in project carbon-apimgt by wso2.

the class BlacklistApiServiceImplTest method blacklistPostTest.

@Test
public void blacklistPostTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    BlockingConditionDTO dto = new BlockingConditionDTO();
    dto.setConditionId(uuid);
    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.mockStatic(BlockingConditionMappingUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    BlockConditions conditions = BlockingConditionMappingUtil.fromBlockingConditionDTOToBlockCondition(dto);
    Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addBlockCondition(conditions);
    Mockito.doReturn(conditions).doThrow(new IllegalArgumentException()).when(adminService).getBlockConditionByUUID(uuid);
    PowerMockito.when(BlockingConditionMappingUtil.fromBlockingConditionDTOToBlockCondition(dto)).thenReturn(conditions);
    Response response = blacklistApiService.blacklistPost(dto, getRequest());
    Assert.assertEquals(201, response.getStatus());
}
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)

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