use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription 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.api.model.webhooks.Subscription 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.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdGetExist.
@Test
public void testSubscriptionsSubscriptionIdGetExist() throws Exception {
printTestMethodName();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
String sub1 = UUID.randomUUID().toString();
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionByUUID(sub1);
Response response = subscriptionsApiService.subscriptionsSubscriptionIdGet(sub1, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Subscription not found"));
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetException.
@Test
public void testSubscriptionsGetException() throws Exception {
printTestMethodName();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String subscriptionId = UUID.randomUUID().toString();
Subscription subscription = SampleTestObjectCreator.createSubscription(subscriptionId);
subscription.setStatus(APIMgtConstants.SubscriptionStatus.REJECTED);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.SUBSCRIPTION_STATE_INVALID)).when(apiPublisher).getSubscriptionByUUID(subscriptionId);
Response response = subscriptionsApiService.subscriptionsUnblockSubscriptionPost(subscriptionId, null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Invalid state change for subscription"));
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class MappingUtil method fromSubscription.
/**
* Converts Subscription to SubscriptionDTO
*
* @param subscription subscription model containg subscription details
* @return SubscriptionDTO containing subscription list
*/
public static SubscriptionDTO fromSubscription(Subscription subscription) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getId());
subscriptionDTO.setSubscriptionStatus(SubscriptionDTO.SubscriptionStatusEnum.fromValue(subscription.getStatus().toString()));
subscriptionDTO.setApplicationInfo(toApplicationDto(subscription.getApplication()));
subscriptionDTO.setPolicy(subscription.getPolicy().getPolicyName());
return subscriptionDTO;
}
Aggregations