use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedAPIs.
@Test
public void testGetAllPaginatedAPIs() throws Exception {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
PowerMockito.mockStatic(GovernanceUtils.class);
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(false, true);
UserRegistry userRegistry1 = Mockito.mock(UserRegistry.class);
Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenReturn(userRegistry1);
Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry1);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
GenericArtifact[] genericArtifacts = new GenericArtifact[] { artifact };
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(genericArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// generic artifact null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAPIsWithTag.
@Test
public void testGetAPIsWithTag() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.mockStatic(GovernanceUtils.class);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager(apiConsumer.registry, APIConstants.API_KEY)).thenReturn(artifactManager);
List<GovernanceArtifact> governanceArtifacts = new ArrayList<GovernanceArtifact>();
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
governanceArtifacts.add(artifact);
Mockito.when(GovernanceUtils.findGovernanceArtifacts(Mockito.anyString(), (UserRegistry) Mockito.anyObject(), Mockito.anyString())).thenReturn(governanceArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact)).thenReturn(api);
Mockito.when(artifact.getAttribute("overview_status")).thenReturn("PUBLISHED");
assertNotNull(apiConsumer.getAPIsWithTag("testTag", "testDomain"));
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetTopRatedAPIs.
@Test
public void testGetTopRatedAPIs() throws APIManagementException, RegistryException {
Registry userRegistry = Mockito.mock(Registry.class);
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
GenericArtifact[] genericArtifacts = new GenericArtifact[] { artifact };
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
Mockito.when(artifact.getAttribute(Mockito.anyString())).thenReturn("PUBLISHED");
Mockito.when(artifact.getPath()).thenReturn("testPath");
Mockito.when(userRegistry.getAverageRating("testPath")).thenReturn((float) 20.0);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getAPI(artifact, userRegistry)).thenReturn(api);
assertNotNull(apiConsumer.getTopRatedAPIs(10));
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class APIProviderImpl method changeAPILCCheckListItems.
@Override
public boolean changeAPILCCheckListItems(APIIdentifier apiIdentifier, int checkItem, boolean checkItemValue) throws APIManagementException {
String providerTenantMode = apiIdentifier.getProviderName();
boolean success = false;
boolean isTenantFlowStarted = false;
try {
String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(providerTenantMode));
if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
isTenantFlowStarted = true;
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
}
GenericArtifact apiArtifact = getAPIArtifact(apiIdentifier);
String status = null;
try {
if (apiArtifact != null) {
if (checkItemValue && !apiArtifact.isLCItemChecked(checkItem, APIConstants.API_LIFE_CYCLE)) {
apiArtifact.checkLCItem(checkItem, APIConstants.API_LIFE_CYCLE);
} else if (!checkItemValue && apiArtifact.isLCItemChecked(checkItem, APIConstants.API_LIFE_CYCLE)) {
apiArtifact.uncheckLCItem(checkItem, APIConstants.API_LIFE_CYCLE);
}
success = true;
}
} catch (GovernanceException e) {
handleException("Error while setting registry lifecycle checklist items for the API: " + apiIdentifier.getApiName(), e);
}
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return success;
}
use of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact in project carbon-apimgt by wso2.
the class APIProviderImpl method getProvider.
/**
* get details of provider
*
* @param providerName name of the provider
* @return Provider
* @throws org.wso2.carbon.apimgt.api.APIManagementException if failed to get Provider
*/
@Override
public Provider getProvider(String providerName) throws APIManagementException {
Provider provider = null;
String providerPath = APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.PROVIDERS_PATH + RegistryConstants.PATH_SEPARATOR + providerName;
try {
GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry, APIConstants.PROVIDER_KEY);
if (artifactManager == null) {
String errorMessage = "Failed to retrieve artifact manager when getting provider " + providerName;
log.error(errorMessage);
throw new APIManagementException(errorMessage);
}
Resource providerResource = registry.get(providerPath);
String artifactId = providerResource.getUUID();
if (artifactId == null) {
throw new APIManagementException("artifact it is null");
}
GenericArtifact providerArtifact = artifactManager.getGenericArtifact(artifactId);
provider = APIUtil.getProvider(providerArtifact);
} catch (RegistryException e) {
handleException("Failed to get Provider form : " + providerName, e);
}
return provider;
}
Aggregations