Search in sources :

Example 81 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteWithLimitedParam.

@Test
public void testWorkflowExecuteWithLimitedParam() throws Exception {
    // application without a callback url
    ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
    Application application = new Application("TestAPP", new Subscriber(null));
    application.setTier("Gold");
    application.setDescription("Description");
    workflowDTO.setApplication(application);
    workflowDTO.setTenantDomain("wso2");
    workflowDTO.setUserName("admin");
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
    ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
    ServiceReferenceHolderMockCreator.initContextService();
    PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
    try {
        Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    }
}
Also used : ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) Application(org.wso2.carbon.apimgt.api.model.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 82 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowRejectException.

@Test(expected = WorkflowException.class)
public void testWorkflowRejectException() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.REJECTED);
    PowerMockito.doThrow(new APIManagementException("")).when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
    applicationCreationWSWorkflowExecutor.complete(workflowDTO);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 83 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowCompleteExceptionWhenUpdatingApplication.

@Test(expected = WorkflowException.class)
public void testWorkflowCompleteExceptionWhenUpdatingApplication() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    PowerMockito.doThrow(new APIManagementException("")).when(apiMgtDAO).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_APPROVED);
    applicationCreationWSWorkflowExecutor.complete(workflowDTO);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 84 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.

the class APIProviderImplTest method testChangeLifeCycleStatusAPIMgtException.

@Test(expected = APIManagementException.class)
public void testChangeLifeCycleStatusAPIMgtException() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, WorkflowException, XMLStreamException {
    APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    prepareForChangeLifeCycleStatus(apiProvider, apimgtDAO, apiId, artifact);
    GovernanceException exception = new GovernanceException(new APIManagementException("APIManagementException:" + "Error while retrieving Life cycle state"));
    Mockito.when(artifact.getLifecycleState()).thenThrow(exception);
    apiProvider.changeLifeCycleStatus(apiId, APIConstants.API_LC_ACTION_DEPRECATE, "org1");
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 85 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.

the class APIProviderImplTest method testChangeLifeCycleStatus_WFAlreadyStarted.

@Test
public void testChangeLifeCycleStatus_WFAlreadyStarted() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, WorkflowException {
    APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    GenericArtifact apiArtifact = Mockito.mock(GenericArtifact.class);
    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.getUUIDFromIdentifier(apiId, "org1")).thenReturn(apiUUID);
    Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1);
    // Workflow has started already
    WorkflowDTO wfDTO = Mockito.mock(WorkflowDTO.class);
    Mockito.when(wfDTO.getStatus()).thenReturn(WorkflowStatus.CREATED);
    Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference("1", WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(wfDTO);
    APIStateChangeResponse response = apiProvider.changeLifeCycleStatus(apiId, APIConstants.API_LC_ACTION_DEPRECATE, "org1");
    Assert.assertNotNull(response);
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)56 Test (org.junit.Test)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)49 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)32 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)25 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)24 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)24 Application (org.wso2.carbon.apimgt.api.model.Application)18 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)17 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)15 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)13 HashMap (java.util.HashMap)12 JSONObject (org.json.simple.JSONObject)12 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)12 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)10 XMLStreamException (javax.xml.stream.XMLStreamException)9 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)9 WorkflowResponse (org.wso2.carbon.apimgt.api.WorkflowResponse)8 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)6