Search in sources :

Example 26 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 Exception {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    List<Policy> policies = new ArrayList<>();
    policies.add(SampleTestObjectCreator.goldSubscriptionPolicy);
    policies.add(SampleTestObjectCreator.silverSubscriptionPolicy);
    Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(apiPublisher).getAllPoliciesByLevel(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"));
    Response response = policiesApiService.policiesTierLevelGet("subscription", null, null, null, getRequest());
    assertEquals(response.getStatus(), 200);
    assertTrue(response.getEntity().toString().contains("Gold"));
    assertTrue(response.getEntity().toString().contains("Silver"));
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with PoliciesApiServiceImpl

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

the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelGetException.

@Test
public void testPoliciesTierLevelGetException() throws Exception {
    printTestMethodName();
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.POLICY_LEVEL_NOT_SUPPORTED)).when(apiPublisher).getAllPoliciesByLevel(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"));
    Response response = policiesApiService.policiesTierLevelGet("subscription", null, null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("Throttle Policy level invalid"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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