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.kie.remote.services.MockSetupTestHelper.DEPLOYMENT_ID;
  import static org.kie.remote.services.MockSetupTestHelper.setupProcessMocks;
  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 java.util.Map;
 
 import  javax.servlet.http.HttpServletRequest;
 import  javax.ws.rs.core.HttpHeaders;
 import  javax.ws.rs.core.Response;
 
 import  org.jboss.resteasy.specimpl.MultivaluedMapImpl;
 import  org.jbpm.services.api.ProcessService;
 import  org.jbpm.services.api.UserTaskService;
 import  org.junit.Before;
 import  org.junit.Test;
 import  org.junit.runner.RunWith;
 import  org.kie.api.command.Command;
 import  org.kie.api.runtime.KieSession;
 import  org.kie.internal.runtime.conf.RuntimeStrategy;
 import  org.kie.internal.runtime.manager.context.EmptyContext;
 import  org.kie.internal.runtime.manager.context.ProcessInstanceIdContext;
 import  org.kie.services.client.serialization.jaxb.impl.process.JaxbProcessInstanceResponse;
 import  org.powermock.api.mockito.PowerMockito;
 import  org.powermock.core.classloader.annotations.PrepareForTest;
 import  org.powermock.modules.junit4.PowerMockRunner;
 
 @RunWith(PowerMockRunner.class)
 @PrepareForTest({ EmptyContext.class, ProcessInstanceIdContext.class })
 
     private KieSession kieSessionMock;
 
     private ProcessService processServiceMock;
     private UserTaskService userTaskServiceMock;
     
     private HttpServletRequest httpRequestMock;
 
     private Map<StringString[]> queryParams;
 
     public void setRuntimeMgrMgrMock(DeploymentInfoBean mock) {
         this. = mock;
     }
 
     @Override
     public void setProcessServiceMock(ProcessService processServiceMock) {
         this. = processServiceMock;
     }
 
     @Override
     public void setUserTaskServiceMock(UserTaskService userTaskServiceMock) {
         this. = userTaskServiceMock;
     }
 
     @Override
     public void setupTestMocks() {
          = mock(HttpServletRequest.class);
         doReturn().when().getParameterMap();
 
         this. = new ProcessRequestBean();
 
         HttpHeaders headersMock = mock(HttpHeaders.class);
         this. = headersMock;
         doReturn(new MultivaluedMapImpl<StringString>()).when(headersMock).getRequestHeaders();
     }
 
 
     @Before
     public void before() {
         this. = new HashMap<StringString[]>();
         this. = ;
     }
 
     @Test
     public void startProcessAndDoStuffPerProcessStartegyTest() throws Exception {
         // This method does some static mock magic to make sure
         // that EmptyContext.get() throws an exception if it is called here
         // (since a ProcessInstanceIdContext should be used instead
 
         setupProcessMocks(this, RuntimeStrategy.PER_PROCESS_INSTANCE);
         doReturn(new String("http://localhost:8080/test/rest/process/" +  + "/start")).when()
                 .getRequestURI();
 
         Response resp = process_defId_start();
         // verify ksession is called
        JaxbProcessInstanceResponse procInstResp = (JaxbProcessInstanceResponse) resp.getEntity();
        assertEquals("Invalid process instance id"procInstResp.getId());
        // Do rest call with process instance id this time. This will fail if:
        // - the ProcessInstanceIdContext is not used (and an EmptyContext is used instead)
        // - The ProcessInstanceIdContext constructor gets a null value for the process instance id
        String [] procInstParamVal = {String.valueOf()};
        .put(procInstParamVal);
        String [] signalParamVal = { "test" };
        .put("signal"signalParamVal);
        resp = signal();
        // verify ksession is called
        verify(times(2)).execute(any(String.class), any(Command.class));
        PowerMockito.verifyStatic(times(0));
        EmptyContext.get();
    }
    @Test
        setupProcessMocks(this, RuntimeStrategy.PER_REQUEST);
        doReturn(new String("http://localhost:8080/test/rest/process/" +  + "/start")).when()
                .getRequestURI();
        Response resp = process_defId_start();
        // verify non-process contexts are used
        JaxbProcessInstanceResponse procInstResp = (JaxbProcessInstanceResponse) resp.getEntity();
        assertEquals("Invalid process instance id"procInstResp.getId());
        String [] signalParamVal = {"test"};
        .put("signal"signalParamVal);
        resp = signal();
        // verify ksession is called
        verify(times(2)).execute(any(String.class), any(Command.class));
    }
    @Test
    public void startProcessAndDoStuffSingletonStrategyTest() throws Exception {
        setupProcessMocks(this, RuntimeStrategy.SINGLETON);
        doReturn(new String("http://localhost:8080/test/rest/process/" +  + "/start")).when()
                .getRequestURI();
        Response resp = process_defId_start();
        // verify non-process contexts are used
        JaxbProcessInstanceResponse procInstResp = (JaxbProcessInstanceResponse) resp.getEntity();
        assertEquals("Invalid process instance id"procInstResp.getId());
        String [] signalParamVal = { "test" };
        .put("signal"signalParamVal);
        resp = signal();
        // verify ksession is called
        verify(times(2)).execute(any(String.class),any(Command.class));
    }
New to GrepCode? Check out our FAQ X