Search in sources :

Example 51 with LifeCycle

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

the class ApiDAOImplIT method testChangeLifeCycleStatus.

@Test(description = "Changing the Lifecycle status of a given API")
public void testChangeLifeCycleStatus() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    testAddGetEndpoint();
    API api = SampleTestObjectCreator.createUniqueAPI().build();
    apiDAO.addAPI(api);
    apiDAO.changeLifeCycleStatus(api.getId(), APIStatus.PUBLISHED.getStatus());
    API apiFromDB = apiDAO.getAPI(api.getId());
    Assert.assertEquals(apiFromDB.getLifeCycleStatus(), APIStatus.PUBLISHED.getStatus());
    Assert.assertNotEquals(api.getLifeCycleStatus(), apiFromDB.getLifeCycleStatus());
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 52 with LifeCycle

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

the class APIStoreImplTestCase method testGetAPIWithAllowedLifecycleState.

@Test(description = "Test get API with allowed lifecycle states (Published, Prototyped, Deprecated)")
public void testGetAPIWithAllowedLifecycleState() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Policy policy = new SubscriptionPolicy(UUID, TIER);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
    APIStore apiStore = getApiStoreImpl(apiDAO, Mockito.mock(ApplicationDAO.class), Mockito.mock(APISubscriptionDAO.class), Mockito.mock(WorkflowDAO.class), Mockito.mock(APIGateway.class), policyDAO);
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    String apiId = apiBuilder.getId();
    List<String> allowedStates = new ArrayList<String>() {

        {
            add(APIStatus.PROTOTYPED.getStatus());
            add(APIStatus.PUBLISHED.getStatus());
            add(APIStatus.DEPRECATED.getStatus());
        }
    };
    for (String allowedState : allowedStates) {
        apiBuilder.lifeCycleStatus(allowedState);
        API api = apiBuilder.build();
        Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
        API returnedAPI = apiStore.getAPIbyUUID(apiId);
        Assert.assertEquals(returnedAPI.getLifeCycleStatus(), allowedState);
    }
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ArrayList(java.util.ArrayList) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 53 with LifeCycle

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

the class AppManagerJmeterTestCase method AppManagementTest.

@Test(description = "This test case tests the flow of App Manager mobile-app creation and lifecycle")
public void AppManagementTest() throws AutomationFrameworkException {
    URL url = Thread.currentThread().getContextClassLoader().getResource("jmeter-scripts" + File.separator + "AppManagerTest.jmx");
    JMeterTest script = new JMeterTest(new File(url.getPath()));
    JMeterTestManager manager = new JMeterTestManager();
    log.info("Running app manager mobile creation related test cases using jmeter scripts");
    manager.runTest(script);
}
Also used : JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) File(java.io.File) URL(java.net.URL) JMeterTestManager(org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager) JMeterTest(org.wso2.carbon.automation.extensions.jmeter.JMeterTest) Test(org.testng.annotations.Test)

Example 54 with LifeCycle

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

the class PublisherCommonUtils method getLifecycleStateInformation.

/**
 * Get lifecycle state information of API or API Product
 *
 * @param identifier   Unique identifier of API or API Product
 * @param organization Organization of logged-in user
 * @return LifecycleStateDTO object
 * @throws APIManagementException if there is en error while retrieving the lifecycle state information
 */
public static LifecycleStateDTO getLifecycleStateInformation(Identifier identifier, String organization) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    Map<String, Object> apiLCData = apiProvider.getAPILifeCycleData(identifier.getUUID(), organization);
    if (apiLCData == null) {
        String type;
        if (identifier instanceof APIProductIdentifier) {
            type = APIConstants.API_PRODUCT;
        } else {
            type = APIConstants.API_IDENTIFIER_TYPE;
        }
        throw new APIManagementException("Error while getting lifecycle state for " + type + " with ID " + identifier, ExceptionCodes.from(ExceptionCodes.LIFECYCLE_STATE_INFORMATION_NOT_FOUND, type, identifier.getUUID()));
    } else {
        boolean apiOlderVersionExist = false;
        // check whether other versions of the current API exists
        APIVersionStringComparator comparator = new APIVersionStringComparator();
        Set<String> versions = apiProvider.getAPIVersions(APIUtil.replaceEmailDomain(identifier.getProviderName()), identifier.getName(), organization);
        for (String tempVersion : versions) {
            if (comparator.compare(tempVersion, identifier.getVersion()) < 0) {
                apiOlderVersionExist = true;
                break;
            }
        }
        return APIMappingUtil.fromLifecycleModelToDTO(apiLCData, apiOlderVersionExist);
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) JSONObject(org.json.simple.JSONObject) APIVersionStringComparator(org.wso2.carbon.apimgt.impl.utils.APIVersionStringComparator) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 55 with LifeCycle

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

the class ApiProductsApiServiceImpl method getAPIProductLifecycleHistory.

@Override
public Response getAPIProductLifecycleHistory(String apiProductId, String ifNoneMatch, MessageContext messageContext) {
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        APIProduct product;
        APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(apiProductId);
        if (apiRevision != null && apiRevision.getApiUUID() != null) {
            product = apiProvider.getAPIProductbyUUID(apiRevision.getApiUUID(), organization);
        } else {
            product = apiProvider.getAPIProductbyUUID(apiProductId, organization);
        }
        return Response.ok().entity(PublisherCommonUtils.getLifecycleHistoryDTO(product.getUuid(), apiProvider)).build();
    } catch (APIManagementException e) {
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, e, log);
        } else if (isAuthorizationFailure(e)) {
            RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving the " + "lifecycle history of the API Product with id : " + apiProductId, e, log);
        } else {
            String errorMessage = "Error while retrieving the lifecycle history of  API Product with id : " + apiProductId;
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    }
    return null;
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

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