use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGet.
@Test
public void testPoliciesTierLevelTierNameGet() throws Exception {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Policy gold = SampleTestObjectCreator.goldSubscriptionPolicy;
Mockito.doReturn(gold).doThrow(new IllegalArgumentException()).when(apiPublisher).getPolicyByName(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"), "Gold");
Response response = policiesApiService.policiesTierLevelTierNameGet("Gold", "subscription", null, null, getRequest());
assertEquals(response.getStatus(), 200);
assertTrue(response.getEntity().toString().contains("Gold"));
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGetException.
@Test
public void testPoliciesTierLevelTierNameGetException() 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).getPolicyByName(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"), "Gold");
Response response = policiesApiService.policiesTierLevelTierNameGet("Gold", "subscription", null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Throttle Policy level invalid"));
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl 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);
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl 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);
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl 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);
}
Aggregations