Search in sources :

Example 36 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testGetAPILifeCycleDataExceptionWhenRetrievingAPISummary.

@Test(description = "Could not retrieve api summary when Getting api lifecycle data", expectedExceptions = APIManagementException.class)
public void testGetAPILifeCycleDataExceptionWhenRetrievingAPISummary() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    Mockito.when(apiDAO.getAPISummary(API_ID)).thenThrow(new APIMgtDAOException("Couldn't retrieve API Summary for " + API_ID));
    apiPublisher.getAPILifeCycleData(API_ID);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 37 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testCreateNewAPIVersionAndCheckNewApiLifecycleAddFailure.

@Test(description = "Create new  API version with APIID and new API lifecycle add get failed", expectedExceptions = { LifecycleException.class, APIManagementException.class })
public void testCreateNewAPIVersionAndCheckNewApiLifecycleAddFailure() 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);
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenThrow(new LifecycleException(""));
    apiPublisher.createNewAPIVersion(uuid, "2.0.0");
    Mockito.verify(apiDAO, Mockito.times(0)).addAPI(api);
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) LifecycleException(org.wso2.carbon.lcm.core.exception.LifecycleException) 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 38 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testGetLifeCycleEventsExceptionFindingApiSummaryResource.

@Test(description = "Exception finding APISummary Resource when getting lifecycle events list of an API", expectedExceptions = APIManagementException.class)
public void testGetLifeCycleEventsExceptionFindingApiSummaryResource() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    Mockito.when(apiDAO.getAPISummary(API_ID)).thenThrow(new APIMgtDAOException("Couldn't find APISummary Resource for ID " + API_ID));
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    apiPublisher.getLifeCycleEvents(API_ID);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 39 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testGetAPILifeCycleDataForNullAPI.

@Test(description = "Get api lifecycle data for a null api", expectedExceptions = APIManagementException.class)
public void testGetAPILifeCycleDataForNullAPI() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    Mockito.when(apiDAO.getAPISummary(API_ID)).thenThrow(new APIMgtDAOException("API with ID " + API_ID + " does not exist", ExceptionCodes.API_NOT_FOUND));
    apiPublisher.getAPILifeCycleData(API_ID);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 40 with LifeCycle

use of org.wso2.carbon.apimgt.impl.importexport.lifecycle.LifeCycle in project carbon-apimgt by wso2.

the class RestApiUtilTestCase method testGetErrorDTO.

@Test(description = "Testing get Error DTO")
public void testGetErrorDTO() throws Exception {
    ErrorHandler errorHandler = Mockito.mock(ErrorHandler.class);
    when(errorHandler.getErrorCode()).thenReturn((long) 900300);
    when(errorHandler.getErrorMessage()).thenReturn("Lifecycle exception occurred");
    when(errorHandler.getErrorDescription()).thenReturn("Error occurred while changing lifecycle state");
    ErrorDTO errorDTOExpected = new ErrorDTO();
    errorDTOExpected.setCode((long) 900300);
    errorDTOExpected.setMessage("Lifecycle exception occurred");
    errorDTOExpected.setDescription("Error occurred while changing lifecycle state");
    ErrorDTO errorDTO1 = RestApiUtil.getErrorDTO(errorHandler);
    Assert.assertEquals(errorDTO1.getCode(), errorDTOExpected.getCode());
    Assert.assertEquals(errorDTO1.getMessage(), errorDTOExpected.getMessage());
    Assert.assertEquals(errorDTO1.getDescription(), errorDTOExpected.getDescription());
}
Also used : ErrorHandler(org.wso2.carbon.apimgt.core.exception.ErrorHandler) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.testng.annotations.Test)20 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)20 API (org.wso2.carbon.apimgt.core.models.API)20 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)19 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)10 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)10 LifecycleException (org.wso2.carbon.lcm.core.exception.LifecycleException)10 JSONObject (org.json.simple.JSONObject)8 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)8 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)7 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)7 List (java.util.List)6 IOException (java.io.IOException)5 Map (java.util.Map)5 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)4