Search in sources :

Example 71 with APILifecycleManager

use of org.wso2.carbon.apimgt.core.api.APILifecycleManager in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testDeleteApiWithZeroSubscriptionsException.

@Test(description = "Error occurred while deleting API with zero subscriptions")
public void testDeleteApiWithZeroSubscriptionsException() throws APIManagementException, LifecycleException, SQLException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(0L);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(USER, identityProvider, keyManager, apiDAO, null, apiSubscriptionDAO, null, apiLifecycleManager, labelDao, workflowDAO, null, null, null, gateway);
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    // LifeCycleException
    Mockito.doThrow(LifecycleException.class).when(apiLifecycleManager).removeLifecycle(api.getLifecycleInstanceId());
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    try {
        apiPublisher.deleteAPI(uuid);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while Disassociating the API with Lifecycle id " + uuid);
    }
    // ApiDAOException
    Mockito.doThrow(APIMgtDAOException.class).when(apiDAO).deleteAPI(uuid);
    try {
        apiPublisher.deleteAPI(uuid);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while deleting the API with id " + uuid);
    }
    // GatewayException
    Mockito.doThrow(GatewayException.class).when(gateway).deleteAPI(api);
    try {
        apiPublisher.deleteAPI(uuid);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while deleting API with id - " + uuid + " from gateway");
    }
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) KeyManager(org.wso2.carbon.apimgt.core.api.KeyManager) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 72 with APILifecycleManager

use of org.wso2.carbon.apimgt.core.api.APILifecycleManager in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testDeleteApiWithZeroSubscriptions.

@Test(description = "Delete API with zero Subscriptions")
public void testDeleteApiWithZeroSubscriptions() throws APIManagementException, LifecycleException, SQLException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    List<String> roleIdsOfUser = new ArrayList<>();
    roleIdsOfUser.add(ADMIN_ROLE_ID);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    API api = apiBuilder.build();
    String uuid = api.getId();
    String lifecycleId = api.getLifecycleInstanceId();
    Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(0L);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(ALTERNATIVE_USER, identityProvider, keyManager, apiDAO, null, apiSubscriptionDAO, null, apiLifecycleManager, labelDao, null, null, null, null, gateway);
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    Mockito.when(identityProvider.getIdOfUser(ALTERNATIVE_USER)).thenReturn(USER_ID);
    Mockito.when(identityProvider.getRoleIdsOfUser(USER_ID)).thenReturn(roleIdsOfUser);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    apiPublisher.deleteAPI(uuid);
    Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
    Mockito.verify(apiLifecycleManager, Mockito.times(1)).removeLifecycle(lifecycleId);
    Mockito.verify(apiDAO, Mockito.times(1)).deleteAPI(uuid);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) API(org.wso2.carbon.apimgt.core.models.API) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) KeyManager(org.wso2.carbon.apimgt.core.api.KeyManager) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 73 with APILifecycleManager

use of org.wso2.carbon.apimgt.core.api.APILifecycleManager in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateAPIStatusWhileGettingDBFailure.

@Test(description = "Update api status", expectedExceptions = { APIMgtDAOException.class, APIManagementException.class })
public void testUpdateAPIStatusWhileGettingDBFailure() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    String lifecycleId = api.getLifecycleInstanceId();
    Mockito.when(apiDAO.getAPI(uuid)).thenThrow(new APIMgtDAOException("Couldn't Create connection"));
    Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), uuid, USER, api)).thenReturn(SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId));
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
    apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), Collections.emptyMap());
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 74 with APILifecycleManager

use of org.wso2.carbon.apimgt.core.api.APILifecycleManager in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testRemovePendingLifecycleWorkflowTaskForInvalidAPI.

@Test(description = "Remove api pending lc status change request for an invalid", expectedExceptions = APIManagementException.class)
public void testRemovePendingLifecycleWorkflowTaskForInvalidAPI() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
    String uuid = UUID.randomUUID().toString();
    Mockito.when(apiDAO.getAPI(uuid)).thenThrow(new APIMgtDAOException("API with ID " + uuid + " does not exist", ExceptionCodes.API_NOT_FOUND));
    apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 75 with APILifecycleManager

use of org.wso2.carbon.apimgt.core.api.APILifecycleManager in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testGetAPILifeCycleData.

@Test(description = "Get api lifecycle data")
public void testGetAPILifeCycleData() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    String lifecycleId = api.getLifecycleInstanceId();
    String lcState = api.getLifeCycleStatus();
    LifecycleState bean = new LifecycleState();
    bean.setState(APIStatus.CREATED.getStatus());
    Mockito.when(apiDAO.getAPISummary(uuid)).thenReturn(api);
    Mockito.doReturn(bean).when(apiLifecycleManager).getLifecycleDataForState(lifecycleId, lcState);
    apiPublisher.getAPILifeCycleData(uuid);
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) API(org.wso2.carbon.apimgt.core.models.API) LifecycleState(org.wso2.carbon.lcm.core.impl.LifecycleState) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Aggregations

APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)76 Test (org.testng.annotations.Test)75 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)75 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)73 API (org.wso2.carbon.apimgt.core.models.API)67 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)51 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)34 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)28 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)26 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)22 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)20 HashMap (java.util.HashMap)19 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)19 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)17 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)11 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)10 WorkflowExtensionsConfigBuilder (org.wso2.carbon.apimgt.core.workflow.WorkflowExtensionsConfigBuilder)10 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)7