Search in sources :

Example 6 with PoliciesApiServiceImpl

use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl 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 7 with PoliciesApiServiceImpl

use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl 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)

Example 8 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTest method policiesThrottlingApplicationPolicyIdPutTest.

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

Example 9 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTest method policiesThrottlingCustomGetTest.

@Test
public void policiesThrottlingCustomGetTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    CustomPolicy policy1 = new CustomPolicy(UUID.randomUUID().toString(), "SamplePolicy1");
    CustomPolicy policy2 = new CustomPolicy(UUID.randomUUID().toString(), "SamplePolicy2");
    List<CustomPolicy> policies = new ArrayList<>();
    policies.add(policy1);
    policies.add(policy2);
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getCustomRules();
    Response response = policiesApiService.policiesThrottlingCustomGet(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) ArrayList(java.util.ArrayList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTest method policiesThrottlingSubscriptionPolicyIdGetTest.

@Test
public void policiesThrottlingSubscriptionPolicyIdGetTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    SubscriptionPolicy policy = new SubscriptionPolicy(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).getSubscriptionPolicyByUuid(uuid);
    Response response = policiesApiService.policiesThrottlingSubscriptionIdGet(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) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) PoliciesApiServiceImpl(org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)27 Test (org.junit.Test)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)21 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)20 ArrayList (java.util.ArrayList)6 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)4 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)4 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)4 CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)4 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)4 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 LabelException (org.wso2.carbon.apimgt.core.exception.LabelException)2 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)2 ApplicationThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO)2 CustomRuleDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.CustomRuleDTO)2 SubscriptionThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyDTO)2 Request (org.wso2.msf4j.Request)2 LinkedHashSet (java.util.LinkedHashSet)1