use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAllPaginatedAPIs.
@Test
public void testGetAllPaginatedAPIs() throws RegistryException, UserStoreException, APIManagementException, XMLStreamException {
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api1 = new API(apiId1);
api1.setContext("/test");
APIIdentifier apiId2 = new APIIdentifier("admin", "API2", "1.0.0");
API api2 = new API(apiId2);
api2.setContext("/test1");
PaginationContext paginationCtx = Mockito.mock(PaginationContext.class);
PowerMockito.when(PaginationContext.getInstance()).thenReturn(paginationCtx);
Mockito.when(paginationCtx.getLength()).thenReturn(2);
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
ServiceReferenceHolder sh = TestUtils.getServiceReferenceHolder();
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry userReg = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceUserRegistry(CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME, -1234)).thenReturn(userReg);
PowerMockito.when(APIUtil.getArtifactManager(userReg, APIConstants.API_KEY)).thenReturn(artifactManager);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_PUBLISHER_APIS_PER_PAGE)).thenReturn("2");
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tm = Mockito.mock(TenantManager.class);
PowerMockito.when(sh.getRealmService()).thenReturn(realmService);
PowerMockito.when(realmService.getTenantManager()).thenReturn(tm);
PowerMockito.when(tm.getTenantId("carbon.super")).thenReturn(-1234);
GenericArtifact genericArtifact1 = Mockito.mock(GenericArtifact.class);
GenericArtifact genericArtifact2 = Mockito.mock(GenericArtifact.class);
Mockito.when(APIUtil.getAPI(genericArtifact1)).thenReturn(api1);
Mockito.when(APIUtil.getAPI(genericArtifact2)).thenReturn(api2);
List<GovernanceArtifact> governanceArtifacts = new ArrayList<GovernanceArtifact>();
governanceArtifacts.add(genericArtifact1);
governanceArtifacts.add(genericArtifact2);
List<GovernanceArtifact> governanceArtifacts1 = new ArrayList<GovernanceArtifact>();
PowerMockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyMap(), any(Registry.class), Mockito.anyString())).thenReturn(governanceArtifacts, governanceArtifacts1);
Map<String, Object> result = apiProvider.getAllPaginatedAPIs("carbon.super", 0, 10);
List<API> apiList = (List<API>) result.get("apis");
Assert.assertEquals(2, apiList.size());
Assert.assertEquals("API1", apiList.get(0).getId().getApiName());
Assert.assertEquals("API2", apiList.get(1).getId().getApiName());
Assert.assertEquals(2, result.get("totalLength"));
// No APIs available
Map<String, Object> result1 = apiProvider.getAllPaginatedAPIs("carbon.super", 0, 10);
List<API> apiList1 = (List<API>) result1.get("apis");
Assert.assertEquals(0, apiList1.size());
// Registry Exception while retrieving artifacts
Mockito.when(artifactManager.findGenericArtifacts(Matchers.anyMap())).thenThrow(RegistryException.class);
try {
apiProvider.getAllPaginatedAPIs("carbon.super", 0, 10);
} catch (APIManagementException e) {
Assert.assertEquals("Failed to get all APIs", e.getMessage());
}
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class ExportUtils method addDependentAPIsToArchive.
/**
* Retrieve dependent APIs by checking the resources of the API Product and store those in the archive directory.
*
* @param archivePath Temp location to save the API artifacts
* @param apiProductDtoToReturn API Product DTO which the resources should be considered
* @param userName User name of the requester
* @param provider API Product Provider
* @param exportFormat Export format of the API meta data, could be yaml or json
* @param isStatusPreserved Whether API status is preserved while export
* @param organization Organization
* @throws APIImportExportException If an error occurs while creating the directory or extracting the archive
* @throws APIManagementException If an error occurs while retrieving API related resources
*/
public static void addDependentAPIsToArchive(String archivePath, APIProductDTO apiProductDtoToReturn, ExportFormat exportFormat, APIProvider provider, String userName, Boolean isStatusPreserved, boolean preserveDocs, boolean preserveCredentials, String organization) throws APIImportExportException, APIManagementException {
String apisDirectoryPath = archivePath + File.separator + ImportExportConstants.APIS_DIRECTORY;
CommonUtil.createDirectory(apisDirectoryPath);
List<ProductAPIDTO> apisList = apiProductDtoToReturn.getApis();
for (ProductAPIDTO productAPIDTO : apisList) {
String apiProductRequesterDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
API api = provider.getAPIbyUUID(productAPIDTO.getApiId(), apiProductRequesterDomain);
APIDTO apiDtoToReturn = APIMappingUtil.fromAPItoDTO(api, preserveCredentials, null);
File dependentAPI = exportApi(provider, api.getId(), apiDtoToReturn, api, userName, exportFormat, isStatusPreserved, preserveDocs, StringUtils.EMPTY, organization);
CommonUtil.extractArchive(dependentAPI, apisDirectoryPath);
}
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class InMemoryAPIDeployer method retrieveArtifact.
private GatewayAPIDTO retrieveArtifact(String apiId, Set<String> gatewayLabels) throws ArtifactSynchronizerException {
GatewayAPIDTO result;
String labelString = String.join("|", gatewayLabels);
String encodedString = Base64.encodeBase64URLSafeString(labelString.getBytes());
if (artifactRetriever != null) {
try {
String gatewayRuntimeArtifact = artifactRetriever.retrieveArtifact(apiId, encodedString);
if (StringUtils.isNotEmpty(gatewayRuntimeArtifact)) {
result = new Gson().fromJson(gatewayRuntimeArtifact, GatewayAPIDTO.class);
} else {
String msg = "Error retrieving artifacts for API " + apiId + ". Storage returned null";
log.error(msg);
throw new ArtifactSynchronizerException(msg);
}
} catch (ArtifactSynchronizerException e) {
String msg = "Error deploying " + apiId + " in Gateway";
log.error(msg, e);
throw new ArtifactSynchronizerException(msg, e);
}
} else {
String msg = "Artifact retriever not found";
log.error(msg);
throw new ArtifactSynchronizerException(msg);
}
return result;
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class EndPointsApiServiceImpl method getEndpoints.
public Response getEndpoints(String apiName, String version, String tenantDomain, MessageContext messageContext) throws APIManagementException {
tenantDomain = RestApiCommonUtil.getValidateTenantDomain(tenantDomain);
List<String> deployedEndpoints = GatewayUtils.retrieveDeployedEndpoints(apiName, version, tenantDomain);
if (debugEnabled) {
log.debug("Retrieved Artifacts for " + apiName + " from eventhub");
}
EndpointsDTO endpointsDTO = new EndpointsDTO();
endpointsDTO.endpoints(deployedEndpoints);
return Response.ok().entity(endpointsDTO).build();
}
use of org.wso2.ei.dashboard.core.rest.model.Artifacts in project carbon-apimgt by wso2.
the class LocalEntryApiServiceImpl method getLocalEntries.
public Response getLocalEntries(String apiName, String version, String tenantDomain, MessageContext messageContext) throws APIManagementException {
tenantDomain = RestApiCommonUtil.getValidateTenantDomain(tenantDomain);
List<String> deployedLocalEntries = GatewayUtils.retrieveDeployedLocalEntries(apiName, version, tenantDomain);
if (debugEnabled) {
log.debug("Retrieved Artifacts for " + apiName + " from eventhub");
}
LocalEntryDTO localEntryDTO = new LocalEntryDTO();
localEntryDTO.localEntries(deployedLocalEntries);
return Response.ok().entity(localEntryDTO).build();
}
Aggregations