/**
   * Check running processes
   *
   * @throws Exception
   */
  @Test
  public void testGetRunningProcesses() throws Exception {

    // two users with tasks, only florent is the current user
    User user =
        new UserImpl("florent", "id-2314", "token-2323", Collections.<String>emptyList(), false);
    User dummy =
        new UserImpl("dummy", "id-2315", "token-2324", Collections.<String>emptyList(), false);
    EnvironmentContext context = EnvironmentContext.getCurrent();
    context.setUser(user);

    // add 5 tasks for 4 projects with Florent and one for dummy user
    String workspaceFlorent = "workspaceFlorent";
    String workspaceCodenvy = "workspaceCodenvy";
    String projectA = "/projectA";
    String projectFlorentA = projectA;
    String projectFlorentB = "projectB";
    String projectCodenvyA = projectA;

    List<RunQueueTask> tasks = new ArrayList<>(4);
    tasks.add(createTask(user, workspaceFlorent, projectFlorentA));
    tasks.add(createTask(user, workspaceFlorent, projectFlorentB));
    tasks.add(createTask(user, workspaceCodenvy, projectCodenvyA));
    tasks.add(createTask(dummy, "dummyWorkspace", "dummyProject"));
    doReturn(tasks).when(runQueue).getTasks();

    // we should have all the processes without specifying anything
    List<ApplicationProcessDescriptor> processes = service.getRunningProcesses(null, null);
    // list is 3 as we don't have task for dummy user
    assertEquals(processes.size(), 3);

    // we should have all the processes without specifying anything
    processes = service.getRunningProcesses(workspaceCodenvy, null);
    // list is 1 for this workspace
    assertEquals(processes.size(), 1);
    ApplicationProcessDescriptor process = processes.get(0);
    assertEquals(process.getWorkspace(), workspaceCodenvy);
    assertEquals(process.getProject(), projectCodenvyA);

    // we should have all the processes without specifying anything
    processes = service.getRunningProcesses(workspaceCodenvy, projectA);
    // list is 1 as we only have one matching workspace + project
    assertEquals(processes.size(), 1);

    // we should have all the processes without specifying anything
    processes = service.getRunningProcesses(null, projectA);
    // list is 2 as we have two workspaces with this project name
    assertEquals(processes.size(), 2);

    // no workspace with that name
    processes = service.getRunningProcesses("dummy", null);
    assertEquals(processes.size(), 0);

    // no project with that name
    processes = service.getRunningProcesses(null, "project");
    assertEquals(processes.size(), 0);

    // no project with that workspace + name
    processes = service.getRunningProcesses("dummy", "project");
    assertEquals(processes.size(), 0);
  }