use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testCreateNewCompositeApiVersion.
@Test(description = "Create new Composite API version")
public void testCreateNewCompositeApiVersion() throws APIManagementException {
// Add a new Composite API
CompositeAPI.Builder apiBuilder = SampleTestObjectCreator.createUniqueCompositeAPI();
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
IdentityProvider idp = Mockito.mock(IdentityProvider.class);
APIStore apiStore = getApiStoreImpl(idp, null, apiDAO, apiSubscriptionDAO, gatewaySourceGenerator, apiGateway);
apiStore.addCompositeApi(apiBuilder);
CompositeAPI createdAPI = apiBuilder.build();
// Create new API version
String newVersion = java.util.UUID.randomUUID().toString();
Mockito.when(apiDAO.getCompositeAPI(apiBuilder.getId())).thenReturn(createdAPI);
apiStore.createNewCompositeApiVersion(createdAPI.getId(), newVersion);
final ArgumentCaptor<CompositeAPI> captor = ArgumentCaptor.forClass(CompositeAPI.class);
Mockito.verify(apiDAO, Mockito.times(2)).addApplicationAssociatedAPI(captor.capture());
CompositeAPI newAPIVersion = captor.getValue();
Assert.assertEquals(newAPIVersion.getVersion(), newVersion);
Assert.assertNotEquals(newAPIVersion.getId(), createdAPI.getId());
Assert.assertEquals(newAPIVersion.getCopiedFromApiId(), createdAPI.getId());
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIStatusRequireReSubscription.
@Test(description = "Update api status with re-subscriptions")
public void testUpdateAPIStatusRequireReSubscription() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, applicationDAO, apiSubscriptionDAO, apiLifecycleManager, gatewaySourceGenerator, workflowDAO, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
LifecycleState lifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId);
Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleId, lcState)).thenReturn(lifecycleState);
Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api)).thenReturn(lifecycleState);
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lifecycleState(lifecycleState);
apiBuilder.updatedBy(USER);
api = apiBuilder.build();
lifecycleState.setState(APIStatus.PUBLISHED.getStatus());
Map<String, Boolean> checklist = new HashMap<>();
checklist.put(APIMgtConstants.REQUIRE_RE_SUBSCRIPTIONS, true);
apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), checklist);
Mockito.verify(apiLifecycleManager, Mockito.times(1)).executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api);
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAPISubscriptionsOfApi.
@Test(description = "Get api subscriptions of API")
public void testGetAPISubscriptionsOfApi() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiSubscriptionDAO);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(API_CONTEXT, API_VERSION)).thenReturn(new ArrayList<SubscriptionValidationData>());
adminService.getAPISubscriptionsOfApi(API_CONTEXT, API_VERSION);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).getAPISubscriptionsOfAPIForValidation(API_CONTEXT, API_VERSION);
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testDeleteApiWithSubscriptions.
@Test(description = "Delete API with Subscriptions", expectedExceptions = ApiDeleteFailureException.class)
public void testDeleteApiWithSubscriptions() throws LifecycleException, APIManagementException, SQLException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
API api = apiBuilder.build();
String uuid = apiBuilder.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(2L);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiSubscriptionDAO, apiLifecycleManager);
apiPublisher.deleteAPI(uuid);
}
use of org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetAPISubscriptionCountByAPI.
@Test(description = "Exception when getting api subscription count by API", expectedExceptions = APIManagementException.class)
public void testGetAPISubscriptionCountByAPI() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenThrow(new APIMgtDAOException("Couldn't retrieve Subscriptions for API " + uuid));
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiSubscriptionDAO);
apiPublisher.getAPISubscriptionCountByAPI(uuid);
}
Aggregations