Search in sources :

Example 51 with LifecycleException

use of org.wso2.carbon.lcm.core.exception.LifecycleException in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testTemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState.

@Test(description = "Exception when removing api pending lc status change request for an api", expectedExceptions = APIManagementException.class)
public void testTemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState() 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);
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    builder.workflowStatus(APILCWorkflowStatus.PENDING.toString());
    API api = builder.build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    /*
        Mockito.doThrow(new APIMgtDAOException("Error while executing sql query")).when(workflowDAO)
        .getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
        */
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenThrow(new APIMgtDAOException("Error occurred while changing api lifecycle workflow status"));
    apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
    Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
}
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) 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 52 with LifecycleException

use of org.wso2.carbon.lcm.core.exception.LifecycleException in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateAPIWorkflowStatus.

@Test(description = "Update API Status when its workflow status is pending", expectedExceptions = APIManagementException.class)
public void testUpdateAPIWorkflowStatus() 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);
    API api = SampleTestObjectCreator.createDefaultAPI().workflowStatus(APIMgtConstants.APILCWorkflowStatus.PENDING.toString()).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());
    apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), new HashMap<>());
    Mockito.verify(apiLifecycleManager, Mockito.times(1)).executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) API(org.wso2.carbon.apimgt.core.models.API) LifecycleState(org.wso2.carbon.lcm.core.impl.LifecycleState) 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 53 with LifecycleException

use of org.wso2.carbon.lcm.core.exception.LifecycleException in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testCreateNewAPIVersionWithEmptyVersion.

@Test(description = "Create new  API version with invalid API version")
void testCreateNewAPIVersionWithEmptyVersion() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
    try {
        apiPublisher.createNewAPIVersion(uuid, null);
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("New API version cannot be empty"));
    }
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) 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 54 with LifecycleException

use of org.wso2.carbon.lcm.core.exception.LifecycleException in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateAPIStatus.

@Test(description = "Update api status")
public void testUpdateAPIStatus() 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);
    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());
    apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), new HashMap<>());
    Mockito.verify(apiLifecycleManager, Mockito.times(1)).executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) API(org.wso2.carbon.apimgt.core.models.API) LifecycleState(org.wso2.carbon.lcm.core.impl.LifecycleState) 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 55 with LifecycleException

use of org.wso2.carbon.lcm.core.exception.LifecycleException in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateAPIStatusDeprecatePreviousVersionsAndNotRequireReSubscription.

@Test(description = "Update api status with deprecating previous versions and not require re-subscriptions")
public void testUpdateAPIStatusDeprecatePreviousVersionsAndNotRequireReSubscription() 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 previousApi = SampleTestObjectCreator.createDefaultAPI().build();
    String previousApiUUID = previousApi.getId();
    String lifecycleIdPrevious = previousApi.getLifecycleInstanceId();
    String lcStatePrevious = previousApi.getLifeCycleStatus();
    LifecycleState previousLifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleIdPrevious);
    List<AvailableTransitionBean> list = new ArrayList<>();
    AvailableTransitionBean bean = new AvailableTransitionBean("Deprecate", APIStatus.DEPRECATED.getStatus());
    list.add(bean);
    previousLifecycleState.setAvailableTransitionBeanList(list);
    Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleIdPrevious, lcStatePrevious)).thenReturn(previousLifecycleState);
    Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.PUBLISHED.getStatus(), APIStatus.DEPRECATED.getStatus(), lifecycleIdPrevious, USER, previousApi)).thenReturn(previousLifecycleState);
    previousLifecycleState.setState(APIStatus.DEPRECATED.getStatus());
    API api = SampleTestObjectCreator.createDefaultAPI().copiedFromApiId(previousApiUUID).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);
    lifecycleState.setState(APIStatus.PUBLISHED.getStatus());
    API.APIBuilder apiBuilder = new API.APIBuilder(api);
    apiBuilder.lifecycleState(lifecycleState);
    apiBuilder.updatedBy(USER);
    api = apiBuilder.build();
    Mockito.when(apiDAO.getAPI(previousApiUUID)).thenReturn(previousApi);
    Map<String, Boolean> checklist = new HashMap<>();
    checklist.put(APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    List<Subscription> subscriptions = new ArrayList<>();
    Subscription subscription = new Subscription(previousApiUUID, application, previousApi, new SubscriptionPolicy(TIER));
    subscriptions.add(subscription);
    Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByAPI(previousApiUUID)).thenReturn(subscriptions);
    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 : AvailableTransitionBean(org.wso2.carbon.lcm.core.beans.AvailableTransitionBean) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) 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) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Aggregations

ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)59 Test (org.testng.annotations.Test)58 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)56 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)55 API (org.wso2.carbon.apimgt.core.models.API)54 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)32 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)31 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)21 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)20 HashMap (java.util.HashMap)17 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)15 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)14 LifecycleException (org.wso2.carbon.lcm.core.exception.LifecycleException)14 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)13 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)13 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)11 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)11 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)10 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)8