Search in sources :

Example 86 with WorkflowDTO

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

the class APIProviderImplTest method testChangeLifeCycleStatusOfAPIProduct.

@Test
public void testChangeLifeCycleStatusOfAPIProduct() throws APIManagementException, FaultGatewaysException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    String provider = "admin";
    PrivilegedCarbonContext carbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(carbonContext);
    PowerMockito.doNothing().when(carbonContext).setUsername(Mockito.anyString());
    PowerMockito.doNothing().when(carbonContext).setTenantDomain(Mockito.anyString(), Mockito.anyBoolean());
    APIProduct product = createMockAPIProduct(provider);
    Mockito.when(apimgtDAO.getAPIProductId(product.getId())).thenReturn(1);
    WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
    Mockito.when(workflowDTO.getStatus()).thenReturn(WorkflowStatus.CREATED);
    Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1), WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(workflowDTO);
    APIStateChangeResponse response = apiProvider.changeLifeCycleStatus("carbon.super", new ApiTypeWrapper(product), "Publish", null);
    Assert.assertNotNull(response);
}
Also used : PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 87 with WorkflowDTO

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

the class ApiMgtDAO method retrieveWorkflow.

/**
 * Returns a workflow object for a given external workflow reference.
 *
 * @param workflowReference
 * @return
 * @throws APIManagementException
 */
public WorkflowDTO retrieveWorkflow(String workflowReference) throws APIManagementException {
    Connection connection = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    WorkflowDTO workflowDTO = null;
    String query = SQLConstants.GET_ALL_WORKFLOW_ENTRY_SQL;
    try {
        connection = APIMgtDBUtil.getConnection();
        prepStmt = connection.prepareStatement(query);
        prepStmt.setString(1, workflowReference);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            workflowDTO = WorkflowExecutorFactory.getInstance().createWorkflowDTO(rs.getString("WF_TYPE"));
            workflowDTO.setStatus(WorkflowStatus.valueOf(rs.getString("WF_STATUS")));
            workflowDTO.setExternalWorkflowReference(rs.getString("WF_EXTERNAL_REFERENCE"));
            workflowDTO.setCreatedTime(rs.getTimestamp("WF_CREATED_TIME").getTime());
            workflowDTO.setWorkflowReference(rs.getString("WF_REFERENCE"));
            workflowDTO.setTenantDomain(rs.getString("TENANT_DOMAIN"));
            workflowDTO.setTenantId(rs.getInt("TENANT_ID"));
            workflowDTO.setWorkflowDescription(rs.getString("WF_STATUS_DESC"));
        }
    } catch (SQLException e) {
        handleException("Error while retrieving workflow details for " + workflowReference, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
    }
    return workflowDTO;
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 88 with WorkflowDTO

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

the class UserSignUpWSWorkflowExecutorTest method init.

@Before
public void init() throws Exception {
    ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    RealmService realmService = Mockito.mock(RealmService.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    userStoreManager = Mockito.mock(UserStoreManager.class);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    serviceClient = Mockito.mock(ServiceClient.class);
    APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
    PowerMockito.mockStatic(SelfSignUpUtil.class);
    PowerMockito.mockStatic(CarbonUtils.class);
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.when(APIUtil.isAnalyticsEnabled()).thenReturn(true);
    PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.any());
    PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
    PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
    PowerMockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
    Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
    Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    apiMgtDAO = TestUtils.getApiMgtDAO();
    userSignUpWSWorkflowExecutor = new UserSignUpWSWorkflowExecutor();
    workflowDTO = new WorkflowDTO();
    workflowDTO.setCallbackUrl(callBackURL);
    workflowDTO.setTenantDomain(tenantDomain);
    workflowDTO.setExternalWorkflowReference(externalWFReference);
    workflowDTO.setWorkflowReference(testUsername + "@carbon.super");
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) UserRealm(org.wso2.carbon.user.core.UserRealm) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) RealmService(org.wso2.carbon.user.core.service.RealmService) ServiceClient(org.apache.axis2.client.ServiceClient) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Before(org.junit.Before)

Example 89 with WorkflowDTO

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

the class UserSignUpWSWorkflowExecutorTest method testFailureToExecuteUserSignUpWSWorkflow.

@Test
public void testFailureToExecuteUserSignUpWSWorkflow() throws Exception {
    userSignUpWSWorkflowExecutor.setUsername(username);
    userSignUpWSWorkflowExecutor.setPassword(password.toCharArray());
    PowerMockito.doNothing().when(apiMgtDAO).addWorkflowEntry(workflowDTO);
    // Test failure to execute user sign up workflow, when APIManagementException has been thrown while persisting
    // workflow entry in database
    PowerMockito.doThrow(new APIManagementException("Error while persisting workflow")).when(apiMgtDAO).addWorkflowEntry(workflowDTO);
    try {
        userSignUpWSWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException has not occurred while executing user sign up workflow");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error while persisting workflow");
    }
    // Test failure to execute user sign up workflow, when AxisFault has been thrown while sending the message out
    PowerMockito.doThrow(new AxisFault("Error sending out message")).when(serviceClient).fireAndForget((OMElement) Mockito.anyObject());
    try {
        userSignUpWSWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException has not occurred while executing user sign up workflow");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error sending out message");
    }
    // Test failure to execute user sign up workflow, when XMLStreamException has been thrown while building payload
    PowerMockito.mockStatic(AXIOMUtil.class);
    PowerMockito.when(AXIOMUtil.stringToOM(Mockito.anyString())).thenThrow(new XMLStreamException("Error " + "converting String to OMElement"));
    try {
        userSignUpWSWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException has not occurred while executing user sign up workflow");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error converting String to OMElement");
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) XMLStreamException(javax.xml.stream.XMLStreamException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 90 with WorkflowDTO

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

the class APIProviderImpl method cleanUpPendingAPIStateChangeTask.

private void cleanUpPendingAPIStateChangeTask(int apiId, boolean isAPIProduct) throws WorkflowException, APIManagementException {
    // Run cleanup task for workflow
    WorkflowExecutor apiStateChangeWFExecutor;
    WorkflowDTO wfDTO;
    if (isAPIProduct) {
        apiStateChangeWFExecutor = getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE);
        wfDTO = apiMgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(apiId), WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE);
    } else {
        apiStateChangeWFExecutor = getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_STATE);
        wfDTO = apiMgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(apiId), WorkflowConstants.WF_TYPE_AM_API_STATE);
    }
    if (wfDTO != null && WorkflowStatus.CREATED == wfDTO.getStatus()) {
        apiStateChangeWFExecutor.cleanUpPendingTask(wfDTO.getExternalWorkflowReference());
    }
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIStateWorkflowDTO(org.wso2.carbon.apimgt.impl.workflow.APIStateWorkflowDTO) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)

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