public void testMergeDuplicateSchemes() throws Exception {

    for (int i = 1; i <= PROJECTS_WITH_PERMS; i++) {
      // if (i > Permissions.MAX_PERMISSION) break;
      projectPerms = EntityUtils.createValue("Project", EasyMap.build("name", "Test Project" + i));
      EntityUtils.createValue(
          "Permission",
          EasyMap.build(
              "project", projectPerms.getLong("id"), "type", new Long(10), "group", "test"));
    }

    task.createProjectSchemes(psm, psm.createDefaultScheme());

    task.mergeDuplicateSchemes(psm);

    // There should be a scheme for projects with permissions and the default
    assertEquals(psm.getSchemes().size(), 2);

    List schemes = psm.getSchemes();
    for (int i = 0; i < schemes.size(); i++) {
      GenericValue scheme = (GenericValue) schemes.get(i);

      List projects = psm.getProjects(scheme);
      for (int j = 0; j < projects.size(); j++) {
        GenericValue project = (GenericValue) projects.get(j);
      }
    }
  }
  public void testCreateProjectSchemes() throws Exception {
    for (int i = 1; i <= PROJECTS_WITH_PERMS; i++) {
      if (i > Permissions.MAX_PERMISSION) break;
      projectPerms = EntityUtils.createValue("Project", EasyMap.build("name", "Project" + i));
      EntityUtils.createValue(
          "Permission",
          EasyMap.build(
              "project", projectPerms.getLong("id"), "type", new Long(10 + i), "group", "test"));
    }

    for (int i = 1; i <= PROJECTS_WITHOUT_PERMS; i++) {
      projectNoPerms = EntityUtils.createValue("Project", EasyMap.build("name", "No Perms" + i));
    }

    task.createProjectSchemes(psm, psm.createDefaultScheme());

    assertNotNull(psm.getDefaultScheme());

    // All projects with no permissions should be added to default scheme
    assertEquals(psm.getProjects(psm.getDefaultScheme()).size(), PROJECTS_WITHOUT_PERMS);

    // There should be a scheme for projects with permissions and the default
    assertEquals(psm.getSchemes().size(), PROJECTS_WITH_PERMS + 1);
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    final FieldVisibilityManager visibilityBean = EasyMock.createMock(FieldVisibilityManager.class);
    EasyMock.expect(
            visibilityBean.isFieldHidden(
                (String) EasyMock.anyObject(), (Issue) EasyMock.anyObject()))
        .andReturn(false)
        .anyTimes();
    EasyMock.replay(visibilityBean);
    ManagerFactory.addService(FieldVisibilityManager.class, visibilityBean);

    originalFactory =
        ComponentManager.getComponentInstanceOfType(FieldClausePermissionChecker.Factory.class);
    ManagerFactory.addService(
        FieldClausePermissionChecker.Factory.class, new MockFieldClausePermissionFactory());
    bob = createMockUser("bob");

    final Group group = addUserToNewGroup(bob, "group");
    carl = createMockUser("carl");

    final GenericValue project =
        UtilsForTests.getTestEntity("Project", EasyMap.build("key", "TST"));

    final PermissionSchemeManager permissionSchemeManager =
        ManagerFactory.getPermissionSchemeManager();
    final GenericValue defaultScheme = permissionSchemeManager.createDefaultScheme();
    final SchemeEntity schemeEntity =
        new SchemeEntity(GroupDropdown.DESC, null, Permissions.BROWSE);
    permissionSchemeManager.createSchemeEntity(defaultScheme, schemeEntity);

    permissionSchemeManager.addSchemeToProject(project, defaultScheme);

    UtilsForTests.getTestEntity("Resolution", EasyMap.build("id", resolutionId));
    // Create two Issues with same comment but different level
    final GenericValue issue1 =
        UtilsForTests.getTestEntity(
            "Issue",
            EasyMap.build(
                "project",
                project.getLong("id"),
                "key",
                "TST-1",
                "resolution",
                resolutionId,
                "summary",
                SUMMARY_BODY));
    UtilsForTests.getTestEntity(
        "Action",
        EasyMap.build(
            "issue",
            issue1.getLong("id"),
            "type",
            ActionConstants.TYPE_COMMENT,
            "body",
            COMMENT_BODY));

    final GenericValue issue2 =
        UtilsForTests.getTestEntity(
            "Issue",
            EasyMap.build(
                "project",
                project.getLong("id"),
                "key",
                "TST-2",
                "resolution",
                resolutionId,
                "summary",
                SUMMARY_BODY));
    UtilsForTests.getTestEntity(
        "Action",
        EasyMap.build(
            "issue",
            issue2.getLong("id"),
            "type",
            ActionConstants.TYPE_COMMENT,
            "body",
            COMMENT_BODY,
            "level",
            group.getName()));

    final GenericValue issue3 =
        UtilsForTests.getTestEntity(
            "Issue",
            EasyMap.build(
                "project",
                project.getLong("id"),
                "key",
                "TST-3",
                "resolution",
                resolutionId,
                "summary",
                ANOTHER_SUMMARY_BODY));
    UtilsForTests.getTestEntity(
        "Action",
        EasyMap.build(
            "issue",
            issue3.getLong("id"),
            "type",
            ActionConstants.TYPE_COMMENT,
            "body",
            ANOTHER_COMMENT_BODY,
            "level",
            group.getName()));

    ManagerFactory.getIndexManager().reIndexAll();
  }