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 testDoUpgrade() 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.doUpgrade(false);

    // check that the default permission scheme was added
    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 all . The default and the one for project with permissions
    assertEquals(psm.getSchemes().size(), PROJECTS_WITH_PERMS + 1);
  }
  public void testaddOldGlobalPermissionsToScheme() throws Exception {
    GenericValue scheme = psm.createScheme("test", "test");

    EntityUtils.createValue(
        "Permission", EasyMap.build("project", null, "type", new Long(99), "group", "test"));

    task.addOldGlobalPermissionsToScheme(psm, 99, scheme);

    assertNotNull(psm.getScheme("test"));

    List perms = psm.getEntities(scheme, new Long(99), "test");

    assertTrue(perms.size() > 0);

    assertTrue(perms.size() == 1);

    GenericValue p = (GenericValue) perms.get(0);
    assertEquals(p.getString("parameter"), "test");
  }