use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class OAS3Parser method getOASDefinitionForStore.
/**
* Update OAS definition for store
*
* @param product APIProduct
* @param oasDefinition OAS definition
* @param hostsWithSchemes host addresses with protocol mapping
* @return OAS definition
*/
@Override
public String getOASDefinitionForStore(APIProduct product, String oasDefinition, Map<String, String> hostsWithSchemes) {
OpenAPI openAPI = getOpenAPI(oasDefinition);
updateOperations(openAPI);
updateEndpoints(product, hostsWithSchemes, openAPI);
return updateSwaggerSecurityDefinitionForStore(openAPI, new SwaggerData(product), hostsWithSchemes);
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class APIMapperTestCase method testAPIProductToPublisherAPIProductAndBack.
@Test
public void testAPIProductToPublisherAPIProductAndBack() throws GovernanceException, APIManagementException {
PublisherAPIProduct pubAPI = APIProductMapper.INSTANCE.toPublisherApiProduct(product);
Assert.assertEquals("API product uuid does not match", product.getUuid(), pubAPI.getId());
Assert.assertEquals("API product type does not match", product.getType(), pubAPI.getType());
APIProduct mappedProduct = APIProductMapper.INSTANCE.toApiProduct(pubAPI);
Assert.assertEquals("Mapped product uuid does not match", mappedProduct.getUuid(), product.getUuid());
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class RegistryPersistenceUtilTestCase method testcreateAPIProductArtifactContent.
@Test
public void testcreateAPIProductArtifactContent() throws APIPersistenceException, APIManagementException, RegistryException {
APIProduct product = new APIProduct(new APIProductIdentifier("pubuser", "TestAPIProd", "1.0.0"));
GenericArtifact genericArtifact = new GenericArtifactImpl(new QName("", "TestAPIProd", ""), "application/vnd.wso2-api+xml");
List<APICategory> categories = new ArrayList<APICategory>();
APICategory category = new APICategory();
category.setName("testcategory");
categories.add(category);
product.setApiCategories(categories);
Set<Tier> availableTiers = new HashSet<Tier>();
availableTiers.add(new Tier("Unlimited"));
availableTiers.add(new Tier("Gold"));
product.setAvailableTiers(availableTiers);
GenericArtifact retArtifact = RegistryPersistenceUtil.createAPIProductArtifactContent(genericArtifact, product);
Assert.assertEquals("API name does not match", product.getId().getName(), retArtifact.getAttribute("overview_name"));
Assert.assertEquals("API version does not match", product.getId().getVersion(), retArtifact.getAttribute("overview_version"));
Assert.assertEquals("API provider does not match", product.getId().getProviderName(), retArtifact.getAttribute("overview_provider"));
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class ApiMgtDAO method setAPIProductFromDB.
/**
* Get product Id from the product name and the provider.
*
* @param product product identifier
* @throws APIManagementException exception
*/
public void setAPIProductFromDB(APIProduct product) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = product.getId();
String currentApiUuid;
APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(product.getUuid());
if (apiRevision != null && apiRevision.getApiUUID() != null) {
currentApiUuid = apiRevision.getApiUUID();
} else {
currentApiUuid = product.getUuid();
}
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_API_PRODUCT_SQL)) {
prepStmt.setString(1, currentApiUuid);
try (ResultSet rs = prepStmt.executeQuery()) {
if (rs.next()) {
product.setProductId(rs.getInt("API_ID"));
product.setProductLevelPolicy(rs.getString("API_TIER"));
} else {
String msg = "Unable to find the API Product : " + apiProductIdentifier.getName() + "-" + APIUtil.replaceEmailDomainBack(apiProductIdentifier.getProviderName()) + "-" + apiProductIdentifier.getVersion() + " in the database";
throw new APIMgtResourceNotFoundException(msg);
}
}
} catch (SQLException e) {
handleException("Error while locating API Product: " + apiProductIdentifier.getName() + "-" + APIUtil.replaceEmailDomainBack(apiProductIdentifier.getProviderName()) + "-" + apiProductIdentifier.getVersion() + " from the database", e);
}
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class APIProviderImplTest method testDeleteAPIProductWorkflowTask.
@Test
public void testDeleteAPIProductWorkflowTask() throws APIManagementException, WorkflowException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1111);
WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
WorkflowExecutor productStateChangeWorkflowExecutor = Mockito.mock(WorkflowExecutor.class);
Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(productStateChangeWorkflowExecutor);
WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1111), WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(workflowDTO);
APIProductIdentifier identifier = new APIProductIdentifier("admin", "APIProduct", "1.0.0", apiUUID);
apiProvider.deleteWorkflowTask(identifier);
Mockito.verify(apimgtDAO, Mockito.times(1)).getAPIID(apiUUID);
}
Aggregations