Search in sources :

Example 11 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTest method policiesThrottlingCustomPostTest.

@Test
public void policiesThrottlingCustomPostTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    CustomRuleDTO dto = new CustomRuleDTO();
    String uuid = UUID.randomUUID().toString();
    dto.setId(uuid);
    CustomPolicy policy = CustomPolicyMappingUtil.fromCustomPolicyDTOToModel(dto);
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.mockStatic(CustomPolicyMappingUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addCustomRule(policy);
    Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getCustomRuleByUUID(uuid);
    PowerMockito.when(CustomPolicyMappingUtil.fromCustomPolicyToDTO(policy)).thenReturn(dto);
    Response response = policiesApiService.policiesThrottlingCustomPost(dto, getRequest());
    Assert.assertEquals(201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) CustomRuleDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.CustomRuleDTO) 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 12 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTest method policiesThrottlingAdvancedPolicyIdPutTest.

@Test
public void policiesThrottlingAdvancedPolicyIdPutTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    String uuid = UUID.randomUUID().toString();
    AdvancedThrottlePolicyDTO dto = new AdvancedThrottlePolicyDTO();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    APIPolicy policy1 = new APIPolicy(uuid, "samplePolicy1");
    Mockito.doReturn(policy1).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicyByUuid(uuid);
    Response response = policiesApiService.policiesThrottlingAdvancedIdPut(uuid, dto, null, null, getRequest());
    Assert.assertEquals(201, response.getStatus());
}
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) AdvancedThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTest method policiesThrottlingAdvancedPostTest.

@Test
public void policiesThrottlingAdvancedPostTest() throws APIManagementException, NotFoundException {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    AdvancedThrottlePolicyDTO dto = new AdvancedThrottlePolicyDTO();
    String uuid = UUID.randomUUID().toString();
    dto.setId(uuid);
    dto.setDisplayName("Sample Policy Display Name");
    dto.setDescription("Simple Description");
    dto.setPolicyName("Simple Policy Name");
    dto.setIsDeployed(true);
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.mockStatic(AdvancedThrottlePolicyMappingUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    APIPolicy policy1 = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyDTOToPolicy(dto);
    Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addApiPolicy(policy1);
    Mockito.doReturn(policy1).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicyByUuid(uuid);
    PowerMockito.when(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyDTOToPolicy(dto)).thenReturn(policy1);
    PowerMockito.when(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToDTO(policy1)).thenReturn(dto);
    Response response = policiesApiService.policiesThrottlingAdvancedPost(dto, getRequest());
    Assert.assertEquals(201, response.getStatus());
}
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) AdvancedThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelGet.

@Test
public void testPoliciesTierLevelGet() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = TestUtil.getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    String tierLevel = APIMgtAdminService.PolicyLevel.api.name();
    List<Policy> tierList = new ArrayList<>();
    Mockito.when(apiStore.getPolicies(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum(tierLevel))).thenReturn(tierList);
    Response response = policiesApiService.policiesTierLevelGet(tierLevel, 10, 0, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTest method policiesThrottlingAdvancedGetTest.

@Test
public void policiesThrottlingAdvancedGetTest() throws APIManagementException, NotFoundException {
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    APIPolicy policy1 = new APIPolicy("samplePolicy1");
    APIPolicy policy2 = new APIPolicy("samplePolicy2");
    List<APIPolicy> policies = new ArrayList<>();
    policies.add(policy1);
    policies.add(policy2);
    Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicies();
    Response response = policiesApiService.policiesThrottlingAdvancedGet(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) ArrayList(java.util.ArrayList) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) 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