use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class APIProviderImplTest method prepareForChangeLifeCycleStatus.
/**
* This method can be used when invoking changeLifeCycleStatus()
*/
private void prepareForChangeLifeCycleStatus(APIProviderImplWrapper apiProvider, ApiMgtDAO apimgtDAO, APIIdentifier apiId, GenericArtifact apiArtifact) throws GovernanceException, APIManagementException, FaultGatewaysException, WorkflowException, XMLStreamException {
Mockito.when(APIUtil.getAPIArtifact(apiId, apiProvider.registry)).thenReturn(apiArtifact);
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER)).thenReturn("admin");
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME)).thenReturn("API1");
Mockito.when(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION)).thenReturn("1.0.0");
Mockito.when(apiArtifact.getLifecycleState()).thenReturn("CREATED");
Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1);
// Workflow has not started, this will trigger the executor
WorkflowDTO wfDTO1 = Mockito.mock(WorkflowDTO.class);
Mockito.when(wfDTO1.getStatus()).thenReturn(null);
WorkflowDTO wfDTO2 = Mockito.mock(WorkflowDTO.class);
Mockito.when(wfDTO2.getStatus()).thenReturn(WorkflowStatus.APPROVED);
Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference("1", WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(wfDTO1, wfDTO2);
ServiceReferenceHolder sh = TestUtils.getServiceReferenceHolder();
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
WorkflowProperties workflowProperties = Mockito.mock(WorkflowProperties.class);
Mockito.when(workflowProperties.getWorkflowCallbackAPI()).thenReturn("");
Mockito.when(amConfig.getWorkflowProperties()).thenReturn(workflowProperties);
WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
WorkflowExecutor apiStateWFExecutor = new APIStateChangeSimpleWorkflowExecutor();
Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(apiStateWFExecutor);
Mockito.when(APIUtil.isAnalyticsEnabled()).thenReturn(false);
}
use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testAddFileToDocumentation.
/**
* This method tests adding file to documentation method.
* @throws Exception
*
* @throws GovernanceException Governance Exception.
*/
@Test
public void testAddFileToDocumentation() throws Exception {
String apiUUID = "xxxxxxxx";
String docUUID = "yyyyyyyy";
APIIdentifier identifier = new APIIdentifier("admin-AT-carbon.super", "API1", "1.0.0");
Set<String> environments = new HashSet<String>();
Set<URITemplate> uriTemplates = new HashSet<URITemplate>();
Tier tier = new Tier("Gold");
Map<String, Tier> tiers = new TreeMap<>();
tiers.put("Gold", tier);
URITemplate uriTemplate1 = new URITemplate();
uriTemplate1.setHTTPVerb("POST");
uriTemplate1.setAuthType("Application");
uriTemplate1.setUriTemplate("/add");
uriTemplate1.setThrottlingTier("Gold");
uriTemplates.add(uriTemplate1);
final API api = new API(identifier);
api.setStatus(APIConstants.CREATED);
api.setVisibility("public");
api.setAccessControl("all");
api.setTransports("http,https");
api.setContext("/test");
api.setEnvironments(environments);
api.setUriTemplates(uriTemplates);
api.setOrganization("carbon.super");
List<Documentation> documentationList = getDocumentationList();
final APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, documentationList, null);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
Mockito.when(APIUtil.getTiers(APIConstants.TIER_RESOURCE_TYPE, "carbon.super")).thenReturn(tiers);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getConfigSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PublisherAPI publisherAPI = Mockito.mock(PublisherAPI.class);
PowerMockito.when(apiPersistenceInstance.addAPI(any(Organization.class), any(PublisherAPI.class))).thenReturn(publisherAPI);
apiProvider.addAPI(api);
String fileName = "test.txt";
String contentType = "application/force-download";
Documentation doc = new Documentation(DocumentationType.HOWTO, fileName);
doc.setSourceType(DocumentSourceType.FILE);
PowerMockito.when(APIUtil.getDocumentationFilePath(api.getId(), fileName)).thenReturn("filePath");
InputStream inputStream = Mockito.mock(InputStream.class);
// apiProvider.addFileToDocumentation(api.getId(), doc, fileName, inputStream, contentType);
DocumentationContent content = new DocumentationContent();
ResourceFile resourceFile = new ResourceFile(inputStream, contentType);
content.setResourceFile(resourceFile);
apiProvider.addDocumentationContent(apiUUID, docUUID, "carbon.super", content);
}
use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method getGenericArtifact.
private GenericArtifact getGenericArtifact(String apiName, String provider, String version, String qName) throws GovernanceException {
String id = UUID.randomUUID().toString();
GenericArtifact genericArtifact = new GenericArtifactImpl(id, new QName(qName), "");
genericArtifact.setAttribute(APIConstants.API_OVERVIEW_PROVIDER, provider);
genericArtifact.setAttribute(APIConstants.API_OVERVIEW_NAME, apiName);
genericArtifact.setAttribute(APIConstants.API_OVERVIEW_VERSION, version);
return genericArtifact;
}
use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class AbstractAPIManagerWrapper method getApiForPublishing.
protected API getApiForPublishing(Registry registry, GovernanceArtifact apiArtifact) throws APIManagementException {
try {
APIIdentifier apiIdentifier = new APIIdentifier(apiArtifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER), apiArtifact.getAttribute(APIConstants.API_OVERVIEW_NAME), apiArtifact.getAttribute(APIConstants.API_OVERVIEW_VERSION));
API api = new API(apiIdentifier);
return api;
} catch (GovernanceException e) {
throw new APIManagementException("Error while getting attribute", e);
}
}
use of org.wso2.carbon.governance.api.exception.GovernanceException 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;
}
Aggregations