private List<FlowNodeInstance> getFailedFlowNodes() throws SearchException { SearchOptionsBuilder builder = new SearchOptionsBuilder(0, 3); builder.filter(FlowNodeInstanceSearchDescriptor.STATE_NAME, ActivityStates.FAILED_STATE); SearchResult<FlowNodeInstance> searchResult = getProcessAPI().searchFlowNodeInstances(builder.done()); return searchResult.getResult(); }
@Override @Before public void before() throws Exception { super.before(); // Restoring up default profiles before tests: final InputStream xmlStream = ProfileImportCommandIT.class.getResourceAsStream("RestoreDefaultProfiles.xml"); final byte[] xmlContent = IOUtils.toByteArray(xmlStream); xmlStream.close(); final Map<String, Serializable> importParameters = new HashMap<String, Serializable>(); importParameters.put("xmlContent", xmlContent); getCommandAPI().execute(IMPORT_PROFILES_CMD, importParameters); // search for the newly created profile IDs: final SearchOptions searchOptions = new SearchOptionsBuilder(0, 50).sort(ProfileSearchDescriptor.ID, Order.ASC).done(); final SearchResult<Profile> searchProfiles = getProfileAPI().searchProfiles(searchOptions); final List<Profile> profiles = searchProfiles.getResult(); assertEquals(2, profiles.size()); for (final Profile map : profiles) { if ("Administrator".equals(map.getName())) { adminProfileId = map.getId(); } else if ("User".equals(map.getName())) { userProfileId = map.getId(); } } }
/** * Search and get next human task * * @param apiSession * @return * @throws Exception */ public TestHumanTask getNextHumanTask(final APISession apiSession) { final ProcessAPI processAPI = TestProcess.getProcessAPI(apiSession); final SearchOptionsBuilder searchOptBuilder = new SearchOptionsBuilder(0, 1); searchOptBuilder.filter( HumanTaskInstanceSearchDescriptor.STATE_NAME, ActivityStates.READY_STATE); /** Get next workable human task. (e.g not in initialization state) */ HumanTaskInstance humanTask = null; SearchResult<HumanTaskInstance> result = null; for (int i = 0; i < GET_NEXT_NB_ATTEMPT; i++) { try { result = processAPI.searchHumanTaskInstances(searchOptBuilder.done()); if (!result.getResult().isEmpty()) { humanTask = result.getResult().get(0); break; } Thread.sleep(SLEEP_TIME_MS); } catch (final InvalidSessionException e) { throw new TestToolkitException("Can't search human task instances. Invalid session", e); } catch (final SearchException e) { throw new TestToolkitException("Can't search human task instances", e); } catch (final InterruptedException e) { throw new TestToolkitException("Interrupted during searching process", e); } } if (humanTask != null) { return new TestHumanTask(humanTask); } else { if (result != null && result.getResult().size() > 0) { throw new NextActivityIsNotAllowedStateException(result.getResult().get(0)); } else { throw new NoActivityLeftException(); } } }
/* * dynamic -> deployAndEnable(receiveProcess), startProcess(receiveProcess), cancelProcessInstance(receiveProcess) * checks : receiveProcess wait on receive task, 1 waiting event, receiveProcess is cancelled, receiveProcess is archived, no more waiting event */ @SuppressWarnings("unchecked") @Cover( classes = {EventInstance.class, ReceiveTaskInstance.class}, concept = BPMNConcept.EVENTS, keywords = {"Event", "Message event", "Receive task", "Send", "Receive"}, jira = "") @Test public void cancelInstanceShouldDeleteWaitingEvents() throws Exception { final ProcessDefinition receiveMessageProcess = deployAndEnableProcessWithReceivedTask( "receiveMessageProcess", "waitForMessage", "userTask1", "delivery", user, "m1", null, null, null); final ProcessInstance receiveMessageProcessInstance = getProcessAPI().startProcess(receiveMessageProcess.getId()); waitForFlowNodeInState( receiveMessageProcessInstance, "waitForMessage", TestStates.WAITING, true); SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 10); searchOptionsBuilder.filter( WaitingEventSearchDescriptor.ROOT_PROCESS_INSTANCE_ID, receiveMessageProcessInstance.getId()); final Map<String, Serializable> parameters = new HashMap<String, Serializable>(1); parameters.put(SEARCH_OPTIONS_KEY, searchOptionsBuilder.done()); SearchResult<WaitingEvent> searchResult = (SearchResult<WaitingEvent>) getCommandAPI().execute(SEARCH_WAITING_EVENTS_COMMAND, parameters); assertEquals(1, searchResult.getCount()); getProcessAPI().cancelProcessInstance(receiveMessageProcessInstance.getId()); waitForProcessToBeInState(receiveMessageProcessInstance, ProcessInstanceState.CANCELLED); searchOptionsBuilder = new SearchOptionsBuilder(0, 10); searchOptionsBuilder.filter( ArchivedActivityInstanceSearchDescriptor.ROOT_PROCESS_INSTANCE_ID, receiveMessageProcessInstance.getId()); searchOptionsBuilder.filter( ArchivedActivityInstanceSearchDescriptor.ACTIVITY_TYPE, FlowNodeType.RECEIVE_TASK); final SearchResult<ArchivedActivityInstance> archivedActivityInstancesSearch = getProcessAPI().searchArchivedActivities(searchOptionsBuilder.done()); assertEquals(1, archivedActivityInstancesSearch.getCount()); assertTrue( archivedActivityInstancesSearch.getResult().get(0) instanceof ArchivedReceiveTaskInstance); assertEquals( TestStates.CANCELLED.getStateName(), archivedActivityInstancesSearch.getResult().get(0).getState()); searchResult = (SearchResult<WaitingEvent>) getCommandAPI().execute(SEARCH_WAITING_EVENTS_COMMAND, parameters); assertEquals(0, searchResult.getCount()); disableAndDeleteProcess(receiveMessageProcess); }