use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method getResponse.
private Response getResponse(String apiContext, String apiVersion) throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
Mockito.when(apiMgtAdminService.getAPISubscriptions(LIMIT)).thenReturn(createSubscriptionValidationDataList());
return subscriptionsApiService.subscriptionsGet(apiContext, apiVersion, LIMIT, null, getRequest());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetfromAPI.
@Test
public void testSubscriptionsGetfromAPI() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String apiId = UUID.randomUUID().toString();
String subsID1 = UUID.randomUUID().toString();
String subsID2 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
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);
List<Subscription> subscriptionList = new ArrayList<>();
subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID1));
subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID2));
Mockito.when(apiStore.getSubscriptionsByAPI(apiId)).thenReturn(subscriptionList);
Response response = subscriptionsApiService.subscriptionsGet(apiId, null, null, 0, 10, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdDelete.
@Test
public void testSubscriptionsSubscriptionIdDelete() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String subsID1 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
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);
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
Mockito.when(apiStore.deleteAPISubscription(subsID1)).thenReturn(workflowResponse);
Response response = subscriptionsApiService.subscriptionsSubscriptionIdDelete(subsID1, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsPost.
@Test
public void testSubscriptionsPost() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
String subsID1 = UUID.randomUUID().toString();
String subsID2 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
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);
Application application = SampleTestObjectCreator.createDefaultApplication();
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
Mockito.when(apiStore.getApplicationByUuid(applicationId)).thenReturn(application);
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
SubscriptionDTO subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(SampleTestObjectCreator.createSubscription(subsID1));
Response response = subscriptionsApiService.subscriptionsPost(subscriptionDTO, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.SubscriptionsApiService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetfromApplication.
@Test
public void testSubscriptionsGetfromApplication() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String subsID1 = UUID.randomUUID().toString();
String subsID2 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
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);
Application application = SampleTestObjectCreator.createDefaultApplication();
List<Subscription> subscriptionList = new ArrayList<>();
subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID1));
subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID2));
Mockito.when(apiStore.getApplicationByUuid(applicationId)).thenReturn(application);
Mockito.when(apiStore.getAPISubscriptionsByApplication(application, ApiType.STANDARD)).thenReturn(subscriptionList);
Response response = subscriptionsApiService.subscriptionsGet(null, applicationId, ApiType.STANDARD.toString(), 0, 10, null, request);
Assert.assertEquals(200, response.getStatus());
}
Aggregations