use of org.wso2.carbon.apimgt.impl.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);
}
use of org.wso2.carbon.apimgt.impl.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;
}
use of org.wso2.carbon.apimgt.impl.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");
}
use of org.wso2.carbon.apimgt.impl.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");
}
}
use of org.wso2.carbon.apimgt.impl.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());
}
}
Aggregations