Search in sources :

Example 76 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowReject.

@Test
public void testWorkflowReject() throws APIManagementException, WorkflowException {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    workflowDTO.setStatus(WorkflowStatus.REJECTED);
    Application app = Mockito.mock(Application.class);
    PowerMockito.doReturn(app).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
    PowerMockito.doNothing().when(apiMgtDAO).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_REJECTED);
    applicationCreationWSWorkflowExecutor.complete(workflowDTO);
    Mockito.verify(apiMgtDAO, Mockito.times(1)).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)

Example 77 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowCompleteExceptionWhenStatusUpdateFailed.

@Test(expected = WorkflowException.class)
public void testWorkflowCompleteExceptionWhenStatusUpdateFailed() 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);
    // application is not in DB for the given id
    PowerMockito.doReturn(app).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
    PowerMockito.doThrow(new APIManagementException("Error occurred when updating the status of the Application " + "creation process")).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 78 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteFailWhenMessageProcessingFailed.

@Test
public void testWorkflowExecuteFailWhenMessageProcessingFailed() throws Exception {
    ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(new XMLStreamException("Error " + "converting String to OMElement"));
    Application application = new Application("TestAPP", new Subscriber(null));
    application.setTier("Gold");
    application.setCallbackUrl("www.wso2.com");
    application.setDescription("Description");
    workflowDTO.setApplication(application);
    workflowDTO.setTenantDomain("wso2");
    workflowDTO.setUserName("admin");
    workflowDTO.setCallbackUrl("http://localhost:8280/workflow-callback");
    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 {
        applicationCreationWSWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error converting String to OMElement");
    }
}
Also used : ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) XMLStreamException(javax.xml.stream.XMLStreamException) 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 79 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteWithDifferentMediatype.

@Test
public void testWorkflowExecuteWithDifferentMediatype() throws Exception {
    ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
    Application application = new Application("TestAPP", new Subscriber(null));
    application.setTier("Gold");
    application.setCallbackUrl("www.wso2.com");
    application.setDescription("Description");
    workflowDTO.setApplication(application);
    workflowDTO.setTenantDomain("wso2");
    workflowDTO.setUserName("admin");
    workflowDTO.setCallbackUrl("http://localhost:8280/workflow-callback");
    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);
    applicationCreationWSWorkflowExecutor.setContentType("application/xml");
    try {
        // shouldn't fail.
        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 80 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowCleanupTaskExceptionWhenMessageProcessingFailed.

@Test(expected = WorkflowException.class)
public void testWorkflowCleanupTaskExceptionWhenMessageProcessingFailed() throws Exception {
    WorkflowDTO workflowDTO = new WorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
    ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
    ServiceReferenceHolderMockCreator.initContextService();
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(new XMLStreamException("Error " + "converting String to OMElement"));
    applicationCreationWSWorkflowExecutor.cleanUpPendingTask(workflowDTO.getExternalWorkflowReference());
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) XMLStreamException(javax.xml.stream.XMLStreamException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)51 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)51 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)49 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)46 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)33 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)31 Application (org.wso2.carbon.apimgt.api.model.Application)25 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)19 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)17 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)14 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)11 XMLStreamException (javax.xml.stream.XMLStreamException)10 JSONObject (org.json.simple.JSONObject)10 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)10 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)10 HashMap (java.util.HashMap)9 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)9 ServiceClient (org.apache.axis2.client.ServiceClient)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)7