Search in sources :

Example 21 with APISubscriptionDAO

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());
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 22 with APISubscriptionDAO

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);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) HashMap(java.util.HashMap) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) LifecycleState(org.wso2.carbon.lcm.core.impl.LifecycleState) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 23 with APISubscriptionDAO

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);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) Test(org.testng.annotations.Test)

Example 24 with APISubscriptionDAO

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);
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 25 with APISubscriptionDAO

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);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Aggregations

APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)59 Test (org.testng.annotations.Test)54 API (org.wso2.carbon.apimgt.core.models.API)30 Application (org.wso2.carbon.apimgt.core.models.Application)24 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)22 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)18 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)18 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)18 BeforeTest (org.testng.annotations.BeforeTest)14 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)14 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)14 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)12 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)11 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)10 SQLException (java.sql.SQLException)8 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)8 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)8 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)6 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)5 SubscriptionValidationData (org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)5