use of org.wso2.carbon.registry.api.Registry in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testGetSelfSignupConfigFromRegistry.
@Test
public void testGetSelfSignupConfigFromRegistry() throws Exception {
System.setProperty(CARBON_HOME, "");
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("foo.com");
Mockito.when(privilegedCarbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE)).thenReturn(registry);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(apimConfigService.getSelfSighupConfig("foo.com")).thenReturn("wsdl");
OMElement omElement = Mockito.mock(OMElement.class);
Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement);
PowerMockito.mockStatic(AXIOMUtil.class);
Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class));
PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement);
PowerMockito.mockStatic(PasswordResolverFactory.class);
PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class);
PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver);
UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("foo.com");
Assert.assertNotNull(userRegistrationConfigDTO);
}
use of org.wso2.carbon.registry.api.Registry in project carbon-apimgt by wso2.
the class SequenceUtilsTestCase method testRestToSoapConvertedSequence.
@Test
public void testRestToSoapConvertedSequence() throws Exception {
Resource resource = Mockito.mock(Resource.class);
Mockito.when(userRegistry.resourceExists(RESOURCE_PATH)).thenReturn(false);
Mockito.when(userRegistry.newResource()).thenReturn(resource);
try {
SequenceUtils.saveRestToSoapConvertedSequence(userRegistry, SEQUENCE, HTTP_METHOD, RESOURCE_PATH, RESOURCE_NAME);
Mockito.when(userRegistry.resourceExists(RESOURCE_PATH)).thenReturn(true);
Mockito.when(userRegistry.get(RESOURCE_PATH)).thenReturn(resource);
SequenceUtils.saveRestToSoapConvertedSequence(userRegistry, SEQUENCE, HTTP_METHOD, RESOURCE_PATH, RESOURCE_NAME);
} catch (APIManagementException e) {
Assert.fail("Failed to save the sequence in the registry");
}
}
use of org.wso2.carbon.registry.api.Registry in project carbon-apimgt by wso2.
the class SequenceUtilsTestCase method testUpdateRestToSoapConvertedSequences.
@Test
public void testUpdateRestToSoapConvertedSequences() throws Exception {
String provider = "admin";
String apiName = "test-api";
String version = "1.0.0";
String seqType = "in";
String sequence = "{\"test\":{\"method\":\"post\",\"content\":\"<header></header>\"}}";
Resource resource = Mockito.mock(Resource.class);
PowerMockito.when(MultitenantUtils.getTenantDomain(Mockito.anyString())).thenReturn("carbon.super");
PowerMockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(userRegistry.resourceExists(Mockito.anyString())).thenReturn(true);
Mockito.when(userRegistry.get(Mockito.anyString())).thenReturn(resource);
Mockito.when(tenantManager.getTenantId(Mockito.anyString())).thenReturn(-1);
try {
SequenceUtils.updateRestToSoapConvertedSequences(apiName, version, provider, seqType, sequence);
} catch (APIManagementException e) {
Assert.fail("Failed to update the sequence in the registry");
}
}
use of org.wso2.carbon.registry.api.Registry in project carbon-apimgt by wso2.
the class ExportUtils method exportApiProduct.
/**
* Exports an API Product from API Manager for a given API Product. MMeta information, API Product icon,
* documentation, client certificates and dependent APIs are exported.
*
* @param apiProvider API Provider
* @param apiProductIdentifier API Product Identifier
* @param apiProductDtoToReturn API Product DTO
* @param userName Username
* @param exportFormat Format of output documents. Can be YAML or JSON
* @param preserveStatus Preserve API Product status on export
* @param organization Organization Identifier
* @return
* @throws APIManagementException If an error occurs while getting governance registry
*/
public static File exportApiProduct(APIProvider apiProvider, APIProductIdentifier apiProductIdentifier, APIProductDTO apiProductDtoToReturn, String userName, ExportFormat exportFormat, Boolean preserveStatus, boolean preserveDocs, boolean preserveCredentials, String organization) throws APIManagementException, APIImportExportException {
int tenantId = 0;
// Create temp location for storing API Product data
File exportFolder = CommonUtil.createTempDirectory(apiProductIdentifier);
String exportAPIBasePath = exportFolder.toString();
String archivePath = exportAPIBasePath.concat(File.separator + apiProductIdentifier.getName() + "-" + apiProductIdentifier.getVersion());
tenantId = APIUtil.getTenantId(userName);
CommonUtil.createDirectory(archivePath);
if (preserveDocs) {
addThumbnailToArchive(archivePath, apiProductIdentifier, apiProvider);
addDocumentationToArchive(archivePath, apiProductIdentifier, exportFormat, apiProvider, APIConstants.API_PRODUCT_IDENTIFIER_TYPE);
}
// Set API Product status to created if the status is not preserved
if (!preserveStatus) {
apiProductDtoToReturn.setState(APIProductDTO.StateEnum.CREATED);
}
addGatewayEnvironmentsToArchive(archivePath, apiProductDtoToReturn.getId(), exportFormat, apiProvider);
addAPIProductMetaInformationToArchive(archivePath, apiProductDtoToReturn, exportFormat, apiProvider);
addDependentAPIsToArchive(archivePath, apiProductDtoToReturn, exportFormat, apiProvider, userName, Boolean.TRUE, preserveDocs, preserveCredentials, organization);
// Export mTLS authentication related certificates
if (log.isDebugEnabled()) {
log.debug("Mutual SSL enabled. Exporting client certificates.");
}
addClientCertificatesToArchive(archivePath, apiProductIdentifier, tenantId, apiProvider, exportFormat, organization);
CommonUtil.archiveDirectory(exportAPIBasePath);
FileUtils.deleteQuietly(new File(exportAPIBasePath));
return new File(exportAPIBasePath + APIConstants.ZIP_FILE_EXTENSION);
}
use of org.wso2.carbon.registry.api.Registry in project carbon-apimgt by wso2.
the class ExportUtils method addWSDLtoArchive.
/**
* Retrieve WSDL for the exporting API and store it in the archive directory.
*
* @param archivePath File path to export the WSDL
* @param apiIdentifier ID of the requesting API
* @throws APIImportExportException If an error occurs while retrieving WSDL from the registry or
* storing in the archive directory
*/
public static void addWSDLtoArchive(String archivePath, APIIdentifier apiIdentifier, APIProvider apiProvider) throws APIImportExportException {
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
String wsdlPath = APIConstants.API_WSDL_RESOURCE_LOCATION + apiIdentifier.getProviderName() + "--" + apiIdentifier.getApiName() + apiIdentifier.getVersion() + APIConstants.WSDL_FILE_EXTENSION;
try {
ResourceFile wsdlResource = apiProvider.getWSDL(apiIdentifier.getUUID(), tenantDomain);
if (wsdlResource != null) {
CommonUtil.createDirectory(archivePath + File.separator + "WSDL");
try (InputStream wsdlStream = wsdlResource.getContent();
OutputStream outputStream = new FileOutputStream(archivePath + File.separator + "WSDL" + File.separator + apiIdentifier.getApiName() + "-" + apiIdentifier.getVersion() + APIConstants.WSDL_FILE_EXTENSION)) {
IOUtils.copy(wsdlStream, outputStream);
if (log.isDebugEnabled()) {
log.debug("WSDL file: " + wsdlPath + " retrieved successfully");
}
}
} else if (log.isDebugEnabled()) {
log.debug("WSDL resource does not exists in path: " + wsdlPath + ". Skipping WSDL export.");
}
} catch (IOException | APIManagementException e) {
throw new APIImportExportException("I/O error while writing WSDL: " + wsdlPath + " to file", e);
}
}
Aggregations