Search in sources :

Example 16 with LifecycleException

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

the class APIPublisherImplTestCase method testAddApiWithDuplicateName.

@Test(description = "Test add api with duplicate name", expectedExceptions = APIManagementException.class)
public void testAddApiWithDuplicateName() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
    Mockito.when(apiDAO.isAPIContextExists("weather")).thenReturn(false);
    Mockito.when(apiDAO.isAPINameExists("WeatherAPI", USER)).thenReturn(true);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(null, apiDAO, null, null, null, apiLifecycleManager, labelDao, null, null, null, null, gateway);
    apiPublisher.addAPI(apiBuilder);
    Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
    Mockito.verify(apiLifecycleManager, Mockito.times(1)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
}
Also used : 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) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 17 with LifecycleException

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

the class APIPublisherImplTestCase method testRemovePendingLifecycleWorkflowTaskForAPI.

@Test(description = "Remove api pending lc status change request")
public void testRemovePendingLifecycleWorkflowTaskForAPI() 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();
    String externalRef = UUID.randomUUID().toString();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(Optional.of(externalRef));
    apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
    Mockito.verify(apiDAO, Mockito.times(1)).updateAPIWorkflowStatus(uuid, APILCWorkflowStatus.APPROVED);
    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) 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 18 with LifecycleException

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

the class APIPublisherImplTestCase method testUpdateCheckListItemException.

@Test(description = "Exception when updating checklist item", expectedExceptions = APIManagementException.class)
public void testUpdateCheckListItemException() 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();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(apiLifecycleManager.checkListItemEvent(lifecycleId, APIStatus.CREATED.getStatus(), APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true)).thenThrow(new LifecycleException("Couldn't get the lifecycle status of api ID " + uuid));
    Map<String, Boolean> checklist = new HashMap<>();
    checklist.put(APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS, true);
    apiPublisher.updateCheckListItem(uuid, APIStatus.CREATED.getStatus(), checklist);
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) LifecycleException(org.wso2.carbon.lcm.core.exception.LifecycleException) HashMap(java.util.HashMap) 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 19 with LifecycleException

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

the class APIPublisherImplTestCase method testDeleteApiWithZeroSubscriptionsAndPendingStateChange.

@Test(description = "Delete API with zero Subscriptions and pending wf state change")
public void testDeleteApiWithZeroSubscriptionsAndPendingStateChange() throws APIManagementException, LifecycleException, SQLException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    builder.workflowStatus(APILCWorkflowStatus.PENDING.toString());
    API api = builder.build();
    String uuid = api.getId();
    String lifecycleId = api.getLifecycleInstanceId();
    Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(0L);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(USER, identityProvider, keyManager, apiDAO, null, apiSubscriptionDAO, null, apiLifecycleManager, null, workflowDAO, null, null, null, gateway);
    String externalRef = UUID.randomUUID().toString();
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(Optional.ofNullable(externalRef));
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    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);
    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) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) 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 20 with LifecycleException

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

the class APIPublisherImplTestCase method testRemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState.

@Test(description = "Remove api pending lc status change request for an api without a pending task", expectedExceptions = APIManagementException.class)
public void testRemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState() 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.APPROVED.toString());
    API api = builder.build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
}
Also used : 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)

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