Search in sources :

Example 16 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingCustomRuleIdDeleteTest.

@Test
public void policiesThrottlingCustomRuleIdDeleteTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(adminService).deleteCustomRule(uuid);
    Response response = policiesApiService.policiesThrottlingCustomRuleIdDelete(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) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingCustomRuleIdGetTest.

@Test
public void policiesThrottlingCustomRuleIdGetTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    CustomPolicy policy = new CustomPolicy(uuid, "Policy");
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getCustomRuleByUUID(uuid);
    Response response = policiesApiService.policiesThrottlingCustomRuleIdGet(uuid, null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingAdvancedPolicyIdGetTest.

@Test
public void policiesThrottlingAdvancedPolicyIdGetTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    APIPolicy policy1 = new APIPolicy(uuid, "samplePolicy1");
    policy1.setDescription("Sample Policy");
    policy1.setDeployed(true);
    policy1.setDisplayName("Simple Policy");
    Mockito.doReturn(policy1).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicyByUuid(uuid);
    Response response = policiesApiService.policiesThrottlingAdvancedIdGet(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) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingCustomRuleIdPutTest.

@Test
public void policiesThrottlingCustomRuleIdPutTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    CustomPolicy policy = new CustomPolicy(uuid, "Policy");
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(adminService).updateCustomRule(policy);
    Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getCustomRuleByUUID(uuid);
    CustomRuleDTO dto = CustomPolicyMappingUtil.fromCustomPolicyToDTO(policy);
    Response response = policiesApiService.policiesThrottlingCustomRuleIdPut(uuid, dto, null, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) CustomRuleDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.CustomRuleDTO) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with APIMgtAdminServiceImpl

use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTest method policiesThrottlingAdvancedPolicyIdDeleteTest.

@Test
public void policiesThrottlingAdvancedPolicyIdDeleteTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(adminService).deletePolicyByUuid(uuid, APIMgtAdminService.PolicyLevel.api);
    Response response = policiesApiService.policiesThrottlingAdvancedIdDelete(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) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)67 Response (javax.ws.rs.core.Response)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)65 Test (org.junit.Test)59 Test (org.testng.annotations.Test)58 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)46 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)33 ArrayList (java.util.ArrayList)28 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)20 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)17 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)14 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)13 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)11 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)11 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)10 Label (org.wso2.carbon.apimgt.core.models.Label)10 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)9 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)6 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)6