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());
}
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);
}
}
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);
}
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);
}
}
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;
}
Aggregations