use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class RegistryPersistenceImplTestCase method testUpdateAPIProduct.
@Test
public void testUpdateAPIProduct() throws APIPersistenceException, RegistryException, APIManagementException {
PublisherAPIProduct publisherAPI = new PublisherAPIProduct();
publisherAPI.setDescription("Modified description");
APIProduct api = APIProductMapper.INSTANCE.toApiProduct(publisherAPI);
Registry registry = Mockito.mock(UserRegistry.class);
Resource resource = new ResourceImpl();
Mockito.when(registry.get(anyString())).thenReturn(resource);
Tag[] tags = new Tag[0];
Mockito.when(registry.getTags(anyString())).thenReturn(tags);
GenericArtifact existArtifact = PersistenceHelper.getSampleAPIProductArtifact();
String apiUUID = existArtifact.getId();
PowerMockito.mockStatic(RegistryPersistenceUtil.class);
GenericArtifactManager manager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
Mockito.when(manager.getGenericArtifact(apiUUID)).thenReturn(existArtifact);
Mockito.doNothing().when(manager).updateGenericArtifact(existArtifact);
PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
GenericArtifact updatedArtifact = PersistenceHelper.getSampleAPIProductArtifact();
updatedArtifact.setAttribute(APIConstants.API_OVERVIEW_DESCRIPTION, api.getDescription());
PowerMockito.when(RegistryPersistenceUtil.createAPIProductArtifactContent(any(GenericArtifact.class), any(APIProduct.class))).thenReturn(updatedArtifact);
Organization org = new Organization(SUPER_TENANT_DOMAIN);
APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, existArtifact);
PublisherAPIProduct updatedAPI = apiPersistenceInstance.updateAPIProduct(org, publisherAPI);
Assert.assertEquals("Updated API description does not match", "Modified description", updatedAPI.getDescription());
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class RegistryPersistenceUtilTestCase method testAPIProductGet.
@Test
public void testAPIProductGet() throws GovernanceException, APIManagementException {
GenericArtifact artifact = PersistenceHelper.getSampleAPIProductArtifact();
APIProduct apiProduct = RegistryPersistenceUtil.getAPIProduct(artifact, registry);
Assert.assertEquals("Attibute overview_type does not match", artifact.getAttribute("overview_type"), apiProduct.getType());
Assert.assertEquals("API product id does not match", artifact.getId(), apiProduct.getUuid());
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class APIUtils method extractEndpointURLs.
/**
* Extracts the API environment details with access url for each endpoint
*
* @param apiProduct API object
* @param tenantDomain Tenant domain of the API
* @return the API environment details
* @throws APIManagementException error while extracting the information
*/
public static List<APIEndpointURLsDTO> extractEndpointURLs(APIProduct apiProduct, String tenantDomain) throws APIManagementException {
List<APIEndpointURLsDTO> apiEndpointsList = new ArrayList<>();
String organization = apiProduct.getOrganization();
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
Set<String> environmentsPublishedByAPI = new HashSet<>(apiProduct.getEnvironments());
environmentsPublishedByAPI.remove("none");
Set<String> apiTransports = new HashSet<>(Arrays.asList(apiProduct.getTransports().split(",")));
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
for (String environmentName : environmentsPublishedByAPI) {
Environment environment = environments.get(environmentName);
if (environment != null) {
APIURLsDTO apiURLsDTO = new APIURLsDTO();
String[] gwEndpoints = null;
gwEndpoints = environment.getApiGatewayEndpoint().split(",");
Map<String, String> domains = new HashMap<>();
if (tenantDomain != null) {
domains = apiConsumer.getTenantDomainMappings(tenantDomain, APIConstants.API_DOMAIN_MAPPINGS_GATEWAY);
}
String customGatewayUrl = null;
if (domains != null) {
customGatewayUrl = domains.get(APIConstants.CUSTOM_URL);
}
for (String gwEndpoint : gwEndpoints) {
StringBuilder endpointBuilder = new StringBuilder(gwEndpoint);
if (customGatewayUrl != null) {
int index = endpointBuilder.indexOf("//");
endpointBuilder.replace(index + 2, endpointBuilder.length(), customGatewayUrl);
endpointBuilder.append(apiProduct.getContext().replace("/t/" + tenantDomain, ""));
} else {
endpointBuilder.append(apiProduct.getContext());
}
if (gwEndpoint.contains("http:") && apiTransports.contains("http")) {
apiURLsDTO.setHttp(endpointBuilder.toString());
} else if (gwEndpoint.contains("https:") && apiTransports.contains("https")) {
apiURLsDTO.setHttps(endpointBuilder.toString());
}
}
APIEndpointURLsDTO apiEndpointURLsDTO = new APIEndpointURLsDTO();
apiEndpointURLsDTO.setUrLs(apiURLsDTO);
apiEndpointURLsDTO.setEnvironmentName(environment.getName());
apiEndpointURLsDTO.setEnvironmentType(environment.getType());
apiEndpointsList.add(apiEndpointURLsDTO);
}
}
return apiEndpointsList;
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class ImportUtils method isTierAvailable.
/**
* Check whether a target Tier is available to subscribe
*
* @param targetTierName Target Tier Name
* @param apiTypeWrapper - {@link ApiTypeWrapper}
* @return true, if the target tier is available
*/
private static boolean isTierAvailable(String targetTierName, ApiTypeWrapper apiTypeWrapper) {
Set<Tier> availableTiers;
API api = null;
APIProduct apiProduct = null;
if (!apiTypeWrapper.isAPIProduct()) {
api = apiTypeWrapper.getApi();
availableTiers = api.getAvailableTiers();
} else {
apiProduct = apiTypeWrapper.getApiProduct();
availableTiers = apiProduct.getAvailableTiers();
}
for (Tier tier : availableTiers) {
if (StringUtils.equals(tier.getName(), targetTierName)) {
return true;
}
}
if (!apiTypeWrapper.isAPIProduct()) {
log.error("Tier:" + targetTierName + " is not available for API " + api.getId().getApiName() + "-" + api.getId().getVersion());
} else {
log.error("Tier:" + targetTierName + " is not available for API Product " + apiProduct.getId().getName() + "-" + apiProduct.getId().getVersion());
}
return false;
}
use of org.wso2.carbon.apimgt.api.model.APIProduct in project carbon-apimgt by wso2.
the class OAS2Parser method getOASDefinitionForStore.
/**
* Update OAS definition for store
*
* @param product APIProduct
* @param oasDefinition OAS definition
* @param hostsWithSchemes host addresses with protocol mapping
* @return OAS definition
* @throws APIManagementException throws if an error occurred
*/
@Override
public String getOASDefinitionForStore(APIProduct product, String oasDefinition, Map<String, String> hostsWithSchemes) throws APIManagementException {
Swagger swagger = getSwagger(oasDefinition);
updateOperations(swagger);
updateEndpoints(product, hostsWithSchemes, swagger);
return updateSwaggerSecurityDefinitionForStore(swagger, new SwaggerData(product), hostsWithSchemes);
}
Aggregations