Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.remote.services.rest;
  
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.kie.remote.services.MockSetupTestHelper.FOR_INDEPENDENT_TASKS;
  import static org.kie.remote.services.MockSetupTestHelper.FOR_PROCESS_TASKS;
  import static org.kie.remote.services.MockSetupTestHelper.TASK_ID;
  import static org.kie.remote.services.MockSetupTestHelper.setupTaskMocks;
  import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 
 import  javax.servlet.http.HttpServletRequest;
 import  javax.ws.rs.core.HttpHeaders;
 import  javax.ws.rs.core.UriInfo;
 
 import  org.jboss.resteasy.specimpl.MultivaluedMapImpl;
 import  org.jbpm.kie.services.api.IdentityProvider;
 import  org.jbpm.process.audit.AuditLogService;
 import  org.jbpm.process.audit.command.ClearHistoryLogsCommand;
 import  org.jbpm.process.audit.command.FindProcessInstancesCommand;
 import  org.jbpm.services.api.ProcessService;
 import  org.jbpm.services.api.UserTaskService;
 import  org.jbpm.services.task.commands.ClaimTaskCommand;
 import  org.jbpm.services.task.commands.CompleteTaskCommand;
 import  org.jbpm.services.task.commands.TaskCommand;
 import  org.junit.Test;
 import  org.kie.services.client.serialization.jaxb.impl.JaxbCommandResponse;
 import  org.kie.services.client.serialization.jaxb.rest.JaxbExceptionResponse;
 import  org.kie.services.shared.ServicesVersion;
 
 @SuppressWarnings("unchecked")
     
     private static final String USER = "user";
 
 
     private ProcessService processServiceMock;
     private UserTaskService userTaskServiceMock;
     
     private UriInfo uriInfoMock;
     private HttpServletRequest httpRequestMock;
 
     private AuditLogService auditLogService = mock(AuditLogService.class);
     
     @Override
     public void setRuntimeMgrMgrMock(DeploymentInfoBean mock) {
         this. = mock;
     }
 
 
     @Override
     public void setProcessServiceMock(ProcessService processServiceMock) {
         this. = processServiceMock;
     }
 
     @Override
     public void setUserTaskServiceMock(UserTaskService userTaskServiceMock) {
         this. = userTaskServiceMock;
     }
 
     public void setupTestMocks() {
         // REST
          = mock(UriInfo.class);
         setUriInfo();
         doReturn(new MultivaluedMapImpl<String,String>()).when().getQueryParameters();
          = mock(HttpServletRequest.class);
         
         this. = mock(IdentityProvider.class);
         doReturn().when().getName();
 
         this. = new ProcessRequestBean();
 
        
         HttpHeaders headersMock = mock(HttpHeaders.class);
         this. = headersMock
         
         doReturn(new MultivaluedMapImpl<StringString>()).when(headersMock).getRequestHeaders();
     }
 
     @Test
     public void testRestUrlIndependentTaskProcessing() throws URISyntaxException {
         setupTaskMocks(this);
         
         String oper = "claim";
         doReturn(new String("http://localhost:8080/test/rest/task/" +  + "/" + oper)).when().getRequestURI();
        this.taskId_oper(oper);
        
        oper = "complete";
        doReturn(new String("http://localhost:8080/test/rest/task/" +  + "/" + oper)).when().getRequestURI();
        this.taskId_oper(oper);
        
        verify(times(2)).execute(any(String.class), any(TaskCommand.class));
    }

    
When doing operations with a non-process (independent) task, the injected (non-runtime engine) taskService should be used.
    @Test
        setupTaskMocks(this);
        
        JaxbCommandsRequest 
        cmdsRequest = new JaxbCommandsRequest(new ClaimTaskCommand());
        this.execute(cmdsRequest);
        cmdsRequest = new JaxbCommandsRequest(new CompleteTaskCommand(null));
        this.execute(cmdsRequest);
       
        // verify
        verify(times(2)).execute(any(String.class), any(TaskCommand.class));
    }
    @Test
    public void testRestUrlProcessTaskProcessing() throws Exception {
        setupTaskMocks(this);
        
        String oper = "claim";
        doReturn(new String("http://localhost:8080/test/rest/task/" +  + "/" + oper)).when().getRequestURI();
        this.taskId_oper(oper);
        
        oper = "complete";
        doReturn(new String("http://localhost:8080/test/rest/task/" +  + "/" + oper)).when().getRequestURI();
        this.taskId_oper(oper);
        
        // verify
        verify(times(2)).execute(any(String.class), any(TaskCommand.class));
    }
    @Test
        setupTaskMocks(this);
        JaxbCommandsRequest cmdsRequest = new JaxbCommandsRequest(new ClaimTaskCommand());
        this.execute(cmdsRequest);
        cmdsRequest = new JaxbCommandsRequest(new CompleteTaskCommand(null));
        this.execute(cmdsRequest);
    
        // verify
        verify(times(2)).execute(any(String.class), any(TaskCommand.class));
    }
    
    @Test
        // setup
        setupTaskMocks(this);
        // run cmd (no deploymentId set on JaxbConmandsRequest object
        JaxbCommandsRequest 
        cmdsRequest = new JaxbCommandsRequest(new FindProcessInstancesCommand());
        JaxbCommandsResponse 
        response = this.execute(cmdsRequest);
       
        // check result
        assertEquals( "Number of response objects", 1, response.getResponses().size() );
        JaxbCommandResponse<?> 
        responseObj = response.getResponses().get(0);
        assertFalse( "Command did not complete successfully"responseObj instanceof JaxbExceptionResponse );
        
        // run cmd (no deploymentId set on JaxbConmandsRequest object
        cmdsRequest = new JaxbCommandsRequest(new ClearHistoryLogsCommand());
        response = this.execute(cmdsRequest);
        
        // check result
        assertEquals( "Number of response objects", 0, response.getResponses().size() );
        
        // verify
        verify(times(1)).findProcessInstances();
        verify(times(1)).clear();
    }
New to GrepCode? Check out our FAQ X