private JaxbCommandResponse<?> executeTaskCommand(String deploymentId, Command<?> command) throws Exception { List<Command<?>> commands = new ArrayList<Command<?>>(); commands.add(command); String urlString = new URL( deploymentUrl, deploymentUrl.getPath() + "rest/runtime/" + DEPLOYMENT_ID + "/execute") .toExternalForm(); logger.info("Client request to: " + urlString); ClientRequest restRequest = new ClientRequest(urlString); JaxbCommandsRequest commandMessage = new JaxbCommandsRequest(commands); assertNotNull("Commands are null!", commandMessage.getCommands()); assertTrue("Commands are empty!", commandMessage.getCommands().size() > 0); String body = JaxbSerializationProvider.convertJaxbObjectToString(commandMessage); restRequest.body(MediaType.APPLICATION_XML, body); ClientResponse<JaxbCommandsResponse> responseObj = restRequest.post(JaxbCommandsResponse.class); checkResponse(responseObj); JaxbCommandsResponse cmdsResp = responseObj.getEntity(); return cmdsResp.getResponses().get(0); }
@Test @Ignore("JMS isn't working.. :/") public void testJmsStartProcess() throws Exception { // send cmd Command<?> cmd = new StartProcessCommand("org.jbpm.humantask"); JaxbCommandsRequest req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); JaxbCommandsResponse response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); // check response assertNotNull("response was null.", response); assertTrue( "response did not contain any command responses", response.getResponses() != null && response.getResponses().size() > 0); JaxbCommandResponse<?> cmdResponse = response.getResponses().get(0); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbProcessInstanceResponse); ProcessInstance procInst = (ProcessInstance) cmdResponse; long procInstId = procInst.getId(); // send cmd cmd = new GetTasksByProcessInstanceIdCommand(procInstId); req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); // check response assertNotNull("response was null.", response); assertTrue( "response did not contain any command responses", response.getResponses() != null && response.getResponses().size() > 0); cmdResponse = response.getResponses().get(0); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbLongListResponse); long taskId = ((JaxbLongListResponse) cmdResponse).getResult().get(0); // send cmd cmd = new StartTaskCommand(taskId, USER_ID); req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); req.getCommands().add(new CompleteTaskCommand(taskId, USER_ID, null)); response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); // check response assertNotNull("response was null.", response); assertTrue("response list was not empty", response.getResponses().size() == 0); // send cmd cmd = new GetTasksOwnedCommand(USER_ID, "en-UK"); req = new JaxbCommandsRequest(DEPLOYMENT_ID, cmd); req.getCommands().add(new GetTasksOwnedCommand("bob", "fr-CA")); req.getCommands().add(new GetProcessInstanceCommand(procInstId)); response = sendJmsJaxbCommandsRequest(TASK_QUEUE_NAME, req); assertNotNull("response was null.", response); assertTrue( "response did not contain any command responses", response.getResponses() != null && response.getResponses().size() > 0); cmdResponse = response.getResponses().get(0); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbTaskSummaryListResponse); List<TaskSummary> taskSummaries = ((JaxbTaskSummaryListResponse) cmdResponse).getResult(); assertTrue("task summary list is empty", taskSummaries.size() > 0); for (TaskSummary taskSum : taskSummaries) { if (taskSum.getId() == taskId) { assertTrue( "Task " + taskId + " should have completed.", taskSum.getStatus().equals(Status.Completed)); } } cmdResponse = response.getResponses().get(1); assertTrue( "response is not the proper class type : " + cmdResponse.getClass().getSimpleName(), cmdResponse instanceof JaxbTaskSummaryListResponse); taskSummaries = ((JaxbTaskSummaryListResponse) cmdResponse).getResult(); assertTrue( "task summary list should be empty, but has " + taskSummaries.size() + " elements", taskSummaries.size() == 0); cmdResponse = response.getResponses().get(2); assertNotNull(cmdResponse); }