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"));
}
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"));
}
Aggregations