Search in sources :

Example 1 with WorkflowExecutorFactory

use of org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory in project carbon-apimgt by wso2.

the class APIProviderImplTest method testDeleteAPIProductWorkflowTask.

@Test
public void testDeleteAPIProductWorkflowTask() throws APIManagementException, WorkflowException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1111);
    WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
    Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
    WorkflowExecutor productStateChangeWorkflowExecutor = Mockito.mock(WorkflowExecutor.class);
    Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(productStateChangeWorkflowExecutor);
    WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
    Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1111), WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(workflowDTO);
    APIProductIdentifier identifier = new APIProductIdentifier("admin", "APIProduct", "1.0.0", apiUUID);
    apiProvider.deleteWorkflowTask(identifier);
    Mockito.verify(apimgtDAO, Mockito.times(1)).getAPIID(apiUUID);
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) WorkflowExecutorFactory(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory) APIStateChangeSimpleWorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with WorkflowExecutorFactory

use of org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory in project carbon-apimgt by wso2.

the class APIProviderImplTest method testUpdateAPIforStateChange_ToRetired.

@Test
public void testUpdateAPIforStateChange_ToRetired() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, WorkflowException, APIPersistenceException, XMLStreamException {
    APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
    Set<String> environments = new HashSet<String>();
    environments.add("Production");
    environments.add("Sandbox");
    API api = new API(apiId);
    api.setContext("/test");
    api.setStatus(APIConstants.CREATED);
    api.setAsDefaultVersion(true);
    api.setEnvironments(environments);
    api.setOrganization("carbon.super");
    Mockito.when(apimgtDAO.getPublishedDefaultVersion(apiId)).thenReturn("1.0.0");
    Map<String, String> failedGWEnv = new HashMap<String, String>();
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apiPersistenceInstance, apimgtDAO, scopesDAO, null, null);
    Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
    Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
    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);
    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);
    // Mock Updating API
    Resource apiSourceArtifact = Mockito.mock(Resource.class);
    Mockito.when(apiSourceArtifact.getUUID()).thenReturn("12640983654");
    String apiSourcePath = "path";
    PowerMockito.when(APIUtil.getAPIPath(api.getId())).thenReturn(apiSourcePath);
    PowerMockito.when(apiProvider.registry.get(apiSourcePath)).thenReturn(apiSourceArtifact);
    Mockito.when(artifact.getAttribute(APIConstants.API_OVERVIEW_STATUS)).thenReturn("CREATED");
    Mockito.when(artifactManager.getGenericArtifact(apiSourceArtifact.getUUID())).thenReturn(artifact);
    PowerMockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
    Mockito.when(artifact.getId()).thenReturn("12640983654");
    PowerMockito.when(GovernanceUtils.getArtifactPath(apiProvider.registry, "12640983654")).thenReturn(apiSourcePath);
    Mockito.doNothing().when(artifactManager).updateGenericArtifact(artifact);
    WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
    Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
    boolean status = apiProvider.updateAPIforStateChange(api, APIConstants.CREATED, APIConstants.RETIRED);
    Assert.assertEquals(2, api.getEnvironments().size());
    Assert.assertEquals(true, status);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) WorkflowExecutorFactory(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) RealmService(org.wso2.carbon.user.core.service.RealmService) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with WorkflowExecutorFactory

use of org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory 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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) WorkflowExecutorFactory(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory) APIStateChangeSimpleWorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor) APIStateChangeSimpleWorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor) WorkflowProperties(org.wso2.carbon.apimgt.impl.dto.WorkflowProperties)

Example 4 with WorkflowExecutorFactory

use of org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory in project carbon-apimgt by wso2.

the class APIProviderImplTest method testDeleteWorkflowTask.

@Test
public void testDeleteWorkflowTask() throws APIManagementException, WorkflowException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1111);
    WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
    Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
    WorkflowExecutor apiStateChangeWFExecutor = Mockito.mock(WorkflowExecutor.class);
    Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(apiStateChangeWFExecutor);
    WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
    Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1111), WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(workflowDTO);
    APIIdentifier identifier = new APIIdentifier("admin", "API1", "1.0.0", apiUUID);
    apiProvider.deleteWorkflowTask(identifier);
    Mockito.verify(apimgtDAO, Mockito.times(1)).getAPIID(apiUUID);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) WorkflowExecutorFactory(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory) APIStateChangeSimpleWorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with WorkflowExecutorFactory

use of org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory in project carbon-apimgt by wso2.

the class WorkflowExecutorFactoryTest method init.

@Before
public void init() {
    System.setProperty(CARBON_HOME, "");
    carbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(carbonContext);
    PowerMockito.when(carbonContext.getTenantDomain()).thenReturn(tenantDomain);
    PowerMockito.when(carbonContext.getTenantId()).thenReturn(tenantID);
    cache = Mockito.mock(Cache.class);
    CacheManager cacheManager = Mockito.mock(CacheManager.class);
    PowerMockito.mockStatic(Caching.class);
    Mockito.when(Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)).thenReturn(cacheManager);
    Mockito.when(cacheManager.getCache(APIConstants.WORKFLOW_CACHE_NAME)).thenReturn(cache);
    tenantWorkflowConfigHolder = Mockito.mock(TenantWorkflowConfigHolder.class);
    workflowExecutorFactory = WorkflowExecutorFactory.getInstance();
}
Also used : CacheManager(javax.cache.CacheManager) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Cache(javax.cache.Cache) Before(org.junit.Before)

Aggregations

WorkflowExecutorFactory (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory)5 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)3 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)3 APIStateChangeSimpleWorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor)3 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)3 HashSet (java.util.HashSet)2 QName (javax.xml.namespace.QName)2 API (org.wso2.carbon.apimgt.api.model.API)2 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)2 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)2 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)2 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)2 Resource (org.wso2.carbon.registry.core.Resource)2 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)2 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)2 RealmService (org.wso2.carbon.user.core.service.RealmService)2 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)2