Search in sources :

Example 71 with WorkflowException

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

the class UserSignUpWSWorkflowExecutorTest method testCompletingUserSignUpWorkflowApprovedByAdmin.

@Test
public void testCompletingUserSignUpWorkflowApprovedByAdmin() throws Exception {
    Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
    roleMap.put(signUpRole, false);
    UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
    userRegistrationConfigDTO.setAdminUserName("admin");
    userRegistrationConfigDTO.setAdminPassword("admin");
    userRegistrationConfigDTO.setRoles(roleMap);
    PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
    PowerMockito.when(SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO)).thenCallRealMethod();
    PowerMockito.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
    Mockito.when(userStoreManager.isExistingUser(testUsername)).thenReturn(true);
    Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
    PowerMockito.doNothing().when(userStoreManager).updateRoleListOfUser(testUsername, null, new String[] { "Internal/" + signUpRole });
    // Set workflow status to be approved
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    try {
        Assert.assertNotNull(userSignUpWSWorkflowExecutor.complete(workflowDTO));
    } catch (WorkflowException e) {
        Assert.fail("Unexpected WorkflowException occurred while completing 'APPROVED' user sign up workflow");
    }
}
Also used : HashMap(java.util.HashMap) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 72 with WorkflowException

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

the class ApplicationRegistrationWSWorkflowExecutorTest method testFailureToExecuteApplicationRegistrationWSWFWhenPreservingWFEntry.

@Test
public void testFailureToExecuteApplicationRegistrationWSWFWhenPreservingWFEntry() throws Exception {
    PowerMockito.doThrow(new APIManagementException("Error while creating Application Registration entry.")).when(apiMgtDAO).createApplicationRegistrationEntry(workflowDTO, false);
    try {
        applicationRegistrationWSWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException has not occurred while executing application registration " + "workflow");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error while creating Application Registration entry.");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with WorkflowException

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

the class SubscriptionCreationSimpleWorkflowExecutorTest method testFailureWhileExecutingSubscriptionCreationWorkFlow.

@Test
public void testFailureWhileExecutingSubscriptionCreationWorkFlow() throws APIManagementException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    try {
        PowerMockito.doThrow(new APIManagementException("Could not complete subscription creation workflow")).when(apiMgtDAO).updateSubscriptionStatus(1, "UNBLOCKED");
        subscriptionCreationSimpleWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException is not thrown when subscription creation simple workflow" + " execution failed");
    } catch (WorkflowException e) {
        Assert.assertTrue(e.getMessage().contains("Could not complete subscription creation workflow"));
    }
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with WorkflowException

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowCompleteExceptionWhenReadingDB.

@Test(expected = WorkflowException.class)
public void testWorkflowCompleteExceptionWhenReadingDB() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    Application app = Mockito.mock(Application.class);
    PowerMockito.doThrow(new APIManagementException("")).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
    PowerMockito.doNothing().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) Application(org.wso2.carbon.apimgt.api.model.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 75 with WorkflowException

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

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowNotAllowedStatus.

@Test
public void testWorkflowNotAllowedStatus() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.REGISTERED);
    Application app = Mockito.mock(Application.class);
    PowerMockito.doReturn(app).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
    applicationCreationWSWorkflowExecutor.complete(workflowDTO);
    // shouldn't update status
    Mockito.verify(apiMgtDAO, Mockito.never()).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_CREATED);
    Mockito.verify(apiMgtDAO, Mockito.never()).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_APPROVED);
    Mockito.verify(apiMgtDAO, Mockito.never()).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_REJECTED);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) Application(org.wso2.carbon.apimgt.api.model.Application) 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