Adapt plugin to latest master

Change-Id: I243499ea491b3322a505d46edb6c1ebe48fad829
diff --git a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
index 01b983a..4a2ba0f 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRights.java
@@ -15,6 +15,7 @@
 package com.ericsson.gerrit.plugins.projectgroupstructure;
 
 import com.google.gerrit.common.data.AccessSection;
+import com.google.gerrit.common.data.GroupReference;
 import com.google.gerrit.common.data.Permission;
 import com.google.gerrit.common.data.PermissionRule;
 import com.google.gerrit.entities.AccountGroup;
@@ -198,7 +199,7 @@
           log.error("Group {} not found", rule.getGroup().getName());
           continue;
         }
-        rule.getGroup().setUUID(group.get().getGroupUUID());
+        rule.setGroup(GroupReference.create(group.get().getGroupUUID(), rule.getGroup().getName()));
       }
       perm.add(rule);
     }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
index 7eca913..2f93c5b 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/DefaultAccessRightsIT.java
@@ -84,6 +84,7 @@
     in.permissionsOnly = true;
     String projectName = name("someProject");
     userRestSession.put("/projects/" + projectName, in).assertCreated();
+    projectCache.evict(Project.nameKey(projectName));
 
     Optional<ProjectState> projectState = projectCache.get(Project.nameKey(projectName));
     AccountGroup.UUID ownerUUID = projectState.get().getOwners().iterator().next();
diff --git a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
index 1f1d52c..2ddf589 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/projectgroupstructure/ProjectCreationValidatorIT.java
@@ -233,7 +233,7 @@
       cfg.getPluginConfig(PLUGIN_NAME)
           .setGroupReference(
               ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
-              new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
+              GroupReference.create(AccountGroup.UUID.parse(gId), delegatingGroup));
       cfgUpdate.save();
     }
     userRestSession.put("/projects/" + Url.encode(parent + "/childProject"), in).assertCreated();
@@ -256,7 +256,7 @@
       cfg.getPluginConfig(PLUGIN_NAME)
           .setGroupReference(
               ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
-              new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
+              GroupReference.create(AccountGroup.UUID.parse(gId), delegatingGroup));
       cfgUpdate.save();
     }
 
@@ -307,7 +307,7 @@
       cfg.getPluginConfig(PLUGIN_NAME)
           .setGroupReference(
               ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
-              new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
+              GroupReference.create(AccountGroup.UUID.parse(gId), delegatingGroup));
       cfg.getPluginConfig(PLUGIN_NAME)
           .setBoolean(ProjectCreationValidator.DISABLE_GRANTING_PROJECT_OWNERSHIP, true);
       cfgUpdate.save();
@@ -387,7 +387,7 @@
       cfg.getPluginConfig(PLUGIN_NAME)
           .setGroupReference(
               ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
-              new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
+              GroupReference.create(AccountGroup.UUID.parse(gId), delegatingGroup));
       cfgUpdate.save();
     }
     userRestSession.put("/projects/" + Url.encode(parent + "/childProject"), in).assertCreated();
@@ -422,7 +422,7 @@
       cfg.getPluginConfig(PLUGIN_NAME)
           .setGroupReference(
               ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
-              new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
+              GroupReference.create(AccountGroup.UUID.parse(gId), delegatingGroup));
       cfgUpdate.save();
     }
     userRestSession.put("/projects/" + Url.encode(parent + "/childProject"), in).assertConflict();
@@ -455,7 +455,7 @@
       cfg.getPluginConfig(PLUGIN_NAME)
           .setGroupReference(
               ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
-              new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
+              GroupReference.create(AccountGroup.UUID.parse(gId), delegatingGroup));
       cfgUpdate.save();
     }
     userRestSession.put("/projects/" + Url.encode(parent + "/childProject"), in).assertConflict();
@@ -484,6 +484,8 @@
     dGroup.addMembers(user.username());
     // the group is in the project.config
     Project.NameKey parentNameKey = Project.nameKey(parent);
+    projectCache.evict(parentNameKey);
+
     try (ProjectConfigUpdate cfgUpdate = updateProject(parentNameKey)) {
       ProjectConfig cfg = cfgUpdate.getConfig();
 
@@ -491,12 +493,12 @@
       cfg.getPluginConfig("project-group-structure")
           .setGroupReference(
               ProjectCreationValidator.DELEGATE_PROJECT_CREATION_TO,
-              new GroupReference(AccountGroup.UUID.parse(gId), delegatingGroup));
+              GroupReference.create(AccountGroup.UUID.parse(gId), delegatingGroup));
       cfgUpdate.save();
-    }
 
-    String newDelegatingGroup = name("groupC");
-    gApi.groups().id(delegatingGroup).name(newDelegatingGroup);
+      String newDelegatingGroup = name("groupC");
+      cfg.renameGroup(cfg.getGroup(delegatingGroup).getUUID(), newDelegatingGroup);
+    }
 
     userRestSession.put("/projects/" + Url.encode(parent + "/childProject"), in).assertCreated();
   }