Search in sources :

Example 71 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationRegistrationWSWorkflowExecutorTest method init.

@Before
public void init() throws Exception {
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    configurationContext = Mockito.mock(ConfigurationContext.class);
    PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
    serviceClient = Mockito.mock(ServiceClient.class);
    PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
    applicationRegistrationWSWorkflowExecutor = new ApplicationRegistrationWSWorkflowExecutor();
    apiMgtDAO = TestUtils.getApiMgtDAO();
    application = new Application("test", new Subscriber("testUser"));
    application.setCallbackUrl(callBaclURL);
    application.setTier("Unlimited");
    PowerMockito.mockStatic(KeyManagerHolder.class);
    keyManager = Mockito.mock(KeyManager.class);
    KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
    Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration);
    PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager);
    OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
    PowerMockito.when(keyManager.createApplication((OAuthAppRequest) Mockito.anyObject())).thenReturn(oAuthApplicationInfo);
    OAuthAppRequest oAuthAppRequest = new OAuthAppRequest();
    oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
    workflowDTO = new ApplicationRegistrationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    workflowDTO.setApplication(application);
    workflowDTO.setCallbackUrl(callBaclURL);
    workflowDTO.setTenantDomain("carbon.super");
    workflowDTO.setUserName("testUser");
    workflowDTO.setExternalWorkflowReference("testUser");
    workflowDTO.setKeyType("PRODUCTION");
    workflowDTO.setAppInfoDTO(oAuthAppRequest);
    KeyManagerConfigurationDTO kmConfigDTO = new KeyManagerConfigurationDTO();
    kmConfigDTO.setOrganization("carbon.super");
    kmConfigDTO.setName("default");
    PowerMockito.when(apiMgtDAO.getKeyManagerConfigurationByUUID("default")).thenReturn(kmConfigDTO);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) OAuthAppRequest(org.wso2.carbon.apimgt.api.model.OAuthAppRequest) ServiceClient(org.apache.axis2.client.ServiceClient) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) Application(org.wso2.carbon.apimgt.api.model.Application) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) KeyManagerConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConfiguration) Before(org.junit.Before)

Example 72 with WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO 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 WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO 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 WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO 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 WorkflowDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO 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

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