SubmoduleSubscriptions tests: use Project.NameKey

This prepares for using ProjectOperations to instantiate repositories

Change-Id: I84680a2d5af493ec2038d4f0147223683342c5a3
diff --git a/javatests/com/google/gerrit/acceptance/git/AbstractSubmoduleSubscription.java b/javatests/com/google/gerrit/acceptance/git/AbstractSubmoduleSubscription.java
index f306932..2633569 100644
--- a/javatests/com/google/gerrit/acceptance/git/AbstractSubmoduleSubscription.java
+++ b/javatests/com/google/gerrit/acceptance/git/AbstractSubmoduleSubscription.java
@@ -121,11 +121,6 @@
     return cloneProject(createProjectForPush(name, parent, createEmptyCommit, submitType));
   }
 
-  protected TestRepository<?> createProjectWithPush(String name, boolean createEmptyCommit)
-      throws Exception {
-    return cloneProject(createProjectForPush(name, null, createEmptyCommit, getSubmitType()));
-  }
-
   private static AtomicInteger contentCounter = new AtomicInteger(0);
   protected TestRepository<?> superRepo;
   protected Project.NameKey superKey;
@@ -198,13 +193,6 @@
     return Iterables.getLast(res).getRemoteUpdate(remoteBranch).getNewObjectId();
   }
 
-  protected void allowSubmoduleSubscription(
-      String submodule, String subBranch, String superproject, String superBranch, boolean match)
-      throws Exception {
-    allowSubmoduleSubscription(
-        nameKey(submodule), subBranch, nameKey(superproject), superBranch, match);
-  }
-
   protected void allowMatchingSubmoduleSubscription(
       Project.NameKey submodule, String subBranch, Project.NameKey superproject, String superBranch)
       throws Exception {
@@ -246,18 +234,6 @@
     }
   }
 
-  protected void allowMatchingSubmoduleSubscription(
-      String submodule, String subBranch, String superproject, String superBranch)
-      throws Exception {
-    allowSubmoduleSubscription(submodule, subBranch, superproject, superBranch, true);
-  }
-
-  protected void createSubmoduleSubscription(
-      TestRepository<?> repo, String branch, String subscribeToRepo, String subscribeToBranch)
-      throws Exception {
-    createSubmoduleSubscription(repo, branch, nameKey(subscribeToRepo), subscribeToBranch);
-  }
-
   protected void createSubmoduleSubscription(
       TestRepository<?> repo,
       String branch,
@@ -273,7 +249,7 @@
       TestRepository<?> repo,
       String branch,
       String subscribeToRepoPrefix,
-      String subscribeToRepo,
+      Project.NameKey subscribeToRepo,
       String subscribeToBranch)
       throws Exception {
     Config config = new Config();
@@ -285,15 +261,6 @@
   protected void prepareRelativeSubmoduleConfigEntry(
       Config config,
       String subscribeToRepoPrefix,
-      String subscribeToRepo,
-      String subscribeToBranch) {
-    prepareRelativeSubmoduleConfigEntry(
-        config, subscribeToRepoPrefix, nameKey(subscribeToRepo), subscribeToBranch);
-  }
-
-  protected void prepareRelativeSubmoduleConfigEntry(
-      Config config,
-      String subscribeToRepoPrefix,
       Project.NameKey subscribeToRepo,
       String subscribeToBranch) {
     String url = subscribeToRepoPrefix + subscribeToRepo.get();
@@ -305,15 +272,6 @@
   }
 
   protected void prepareSubmoduleConfigEntry(
-      Config config, String subscribeToRepo, String subscribeToBranch) {
-    // The submodule subscription module checks for gerrit.canonicalWebUrl to
-    // detect if it's configured for automatic updates. It doesn't matter if
-    // it serves from that URL.
-    prepareSubmoduleConfigEntry(
-        config, nameKey(subscribeToRepo), nameKey(subscribeToRepo), subscribeToBranch);
-  }
-
-  protected void prepareSubmoduleConfigEntry(
       Config config, Project.NameKey subscribeToRepo, String subscribeToBranch) {
     // The submodule subscription module checks for gerrit.canonicalWebUrl to
     // detect if it's configured for automatic updates. It doesn't matter if
@@ -321,16 +279,6 @@
     prepareSubmoduleConfigEntry(config, subscribeToRepo, subscribeToRepo, subscribeToBranch);
   }
 
-  protected Project.NameKey nameKey(String s) {
-    return new Project.NameKey(name(s));
-  }
-
-  protected void prepareSubmoduleConfigEntry(
-      Config config, String subscribeToRepo, String subscribeToRepoPath, String subscribeToBranch) {
-    prepareSubmoduleConfigEntry(
-        config, nameKey(subscribeToRepo), nameKey(subscribeToRepoPath), subscribeToBranch);
-  }
-
   protected void prepareSubmoduleConfigEntry(
       Config config,
       Project.NameKey subscribeToRepo,
@@ -367,16 +315,6 @@
   protected void expectToHaveSubmoduleState(
       TestRepository<?> repo,
       String branch,
-      String submodule,
-      TestRepository<?> subRepo,
-      String subBranch)
-      throws Exception {
-    expectToHaveSubmoduleState(repo, branch, nameKey(submodule), subRepo, subBranch);
-  }
-
-  protected void expectToHaveSubmoduleState(
-      TestRepository<?> repo,
-      String branch,
       Project.NameKey submodule,
       TestRepository<?> subRepo,
       String subBranch)
@@ -410,12 +348,6 @@
   }
 
   protected void expectToHaveSubmoduleState(
-      TestRepository<?> repo, String branch, String submodule, ObjectId expectedId)
-      throws Exception {
-    expectToHaveSubmoduleState(repo, branch, nameKey(submodule), expectedId);
-  }
-
-  protected void expectToHaveSubmoduleState(
       TestRepository<?> repo, String branch, Project.NameKey submodule, ObjectId expectedId)
       throws Exception {
     ObjectId commitId =
@@ -490,11 +422,6 @@
     assertThat(actualId).isEqualTo(expectedId);
   }
 
-  protected boolean hasSubmodule(TestRepository<?> repo, String branch, String submodule)
-      throws Exception {
-    return hasSubmodule(repo, branch, new Project.NameKey(name(submodule)));
-  }
-
   protected boolean hasSubmodule(TestRepository<?> repo, String branch, Project.NameKey submodule)
       throws Exception {
     Ref branchTip =
@@ -549,11 +476,6 @@
     return c.getAuthorIdent();
   }
 
-  protected void directUpdateSubmodule(String project, String refName, String path, AnyObjectId id)
-      throws Exception {
-    directUpdateSubmodule(nameKey(project), refName, nameKey(path), id);
-  }
-
   protected void directUpdateSubmodule(
       Project.NameKey project, String refName, Project.NameKey path, AnyObjectId id)
       throws Exception {
diff --git a/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java b/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
index d76b310..94e3c0a 100644
--- a/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
+++ b/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
@@ -452,12 +452,11 @@
     allowMatchingSubmoduleSubscription(nest, "refs/heads/master", superKey, null);
 
     pushChangeTo(subRepo, "master");
-    createRelativeSubmoduleSubscription(
-        superRepo, "master", "../", "nested/subscribed-to-project", "master");
+    createRelativeSubmoduleSubscription(superRepo, "master", "../", nest, "master");
 
     ObjectId subHEAD = pushChangeTo(subRepo, "master");
 
-    expectToHaveSubmoduleState(superRepo, "master", "nested/subscribed-to-project", subHEAD);
+    expectToHaveSubmoduleState(superRepo, "master", nest, subHEAD);
   }
 
   @Test
@@ -617,22 +616,22 @@
     allowMatchingSubmoduleSubscription(subkey2, "refs/heads/master", superKey, "refs/heads/master");
 
     Config config = new Config();
-    prepareSubmoduleConfigEntry(config, "subscribed-to-project-1", "master");
-    prepareSubmoduleConfigEntry(config, "subscribed-to-project-2", "master");
+    prepareSubmoduleConfigEntry(config, subkey1, "master");
+    prepareSubmoduleConfigEntry(config, subkey2, "master");
     pushSubmoduleConfig(superRepo, "master", config);
 
     // Push once to initialize submodules.
     ObjectId subTip2 = pushChangeTo(subRepo2, "master");
     ObjectId subTip1 = pushChangeTo(subRepo1, "master");
 
-    expectToHaveSubmoduleState(superRepo, "master", "subscribed-to-project-1", subTip1);
-    expectToHaveSubmoduleState(superRepo, "master", "subscribed-to-project-2", subTip2);
+    expectToHaveSubmoduleState(superRepo, "master", subkey1, subTip1);
+    expectToHaveSubmoduleState(superRepo, "master", subkey2, subTip2);
 
-    directUpdateRef("subscribed-to-project-2", "refs/heads/master");
+    directUpdateRef(subkey2, "refs/heads/master");
     subTip1 = pushChangeTo(subRepo1, "master");
 
-    expectToHaveSubmoduleState(superRepo, "master", "subscribed-to-project-1", subTip1);
-    expectToHaveSubmoduleState(superRepo, "master", "subscribed-to-project-2", subTip2);
+    expectToHaveSubmoduleState(superRepo, "master", subkey1, subTip1);
+    expectToHaveSubmoduleState(superRepo, "master", subkey2, subTip2);
   }
 
   @Test
@@ -655,8 +654,8 @@
     expectToHaveSubmoduleState(superRepo, "master", subKey, badId);
   }
 
-  private ObjectId directUpdateRef(String project, String ref) throws Exception {
-    try (Repository serverRepo = repoManager.openRepository(nameKey(project))) {
+  private ObjectId directUpdateRef(Project.NameKey project, String ref) throws Exception {
+    try (Repository serverRepo = repoManager.openRepository(project)) {
       return new TestRepository<>(serverRepo).branch(ref).commit().create().copy();
     }
   }
diff --git a/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsWholeTopicMergeIT.java b/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsWholeTopicMergeIT.java
index 0b583bf..96b545c 100644
--- a/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsWholeTopicMergeIT.java
+++ b/javatests/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsWholeTopicMergeIT.java
@@ -616,9 +616,9 @@
 
     approve(changeId);
     exception.expectMessage("Branch level circular subscriptions detected");
-    exception.expectMessage("top-project,refs/heads/master");
-    exception.expectMessage("mid-project,refs/heads/master");
-    exception.expectMessage("bottom-project,refs/heads/master");
+    exception.expectMessage(topKey.get() + ",refs/heads/master");
+    exception.expectMessage(midKey.get() + ",refs/heads/master");
+    exception.expectMessage(botKey.get() + ",refs/heads/master");
     return changeId;
   }
 
@@ -661,8 +661,11 @@
 
   @Test
   public void projectNoSubscriptionWholeTopic() throws Exception {
-    TestRepository<?> repoA = createProjectWithPush("project-a", null, true, getSubmitType());
-    TestRepository<?> repoB = createProjectWithPush("project-b", null, true, getSubmitType());
+    Project.NameKey keyA = createProjectForPush("project-a", null, true, getSubmitType());
+    Project.NameKey keyB = createProjectForPush("project-b", null, true, getSubmitType());
+
+    TestRepository<?> repoA = cloneProject(keyA);
+    TestRepository<?> repoB = cloneProject(keyB);
     // bootstrap the dev branch
     ObjectId a0 = pushChangeTo(repoA, "dev");
 
@@ -717,33 +720,33 @@
     approve(getChangeId(repoB, bDevHead).get());
 
     gApi.changes().id(getChangeId(repoA, aDevHead).get()).current().submit();
-    assertThat(getRemoteHead(name("project-a"), "refs/heads/master").getShortMessage())
+    assertThat(getRemoteHead(keyA, "refs/heads/master").getShortMessage())
         .contains("some message in a master.txt");
-    assertThat(getRemoteHead(name("project-a"), "refs/heads/dev").getShortMessage())
+    assertThat(getRemoteHead(keyA, "refs/heads/dev").getShortMessage())
         .contains("some message in a dev.txt");
-    assertThat(getRemoteHead(name("project-b"), "refs/heads/master").getShortMessage())
+    assertThat(getRemoteHead(keyB, "refs/heads/master").getShortMessage())
         .contains("some message in b master.txt");
-    assertThat(getRemoteHead(name("project-b"), "refs/heads/dev").getShortMessage())
+    assertThat(getRemoteHead(keyB, "refs/heads/dev").getShortMessage())
         .contains("some message in b dev.txt");
   }
 
   @Test
   public void twoProjectsMultipleBranchesWholeTopic() throws Exception {
-    TestRepository<?> repoA = createProjectWithPush("project-a", null, true, getSubmitType());
-    TestRepository<?> repoB = createProjectWithPush("project-b", null, true, getSubmitType());
+    Project.NameKey keyA = createProjectForPush("project-a", null, true, getSubmitType());
+    Project.NameKey keyB = createProjectForPush("project-b", null, true, getSubmitType());
+    TestRepository<?> repoA = cloneProject(keyA);
+    TestRepository<?> repoB = cloneProject(keyB);
     // bootstrap the dev branch
     pushChangeTo(repoA, "dev");
 
     // bootstrap the dev branch
     ObjectId b0 = pushChangeTo(repoB, "dev");
 
-    allowMatchingSubmoduleSubscription(
-        "project-b", "refs/heads/master", "project-a", "refs/heads/master");
-    allowMatchingSubmoduleSubscription(
-        "project-b", "refs/heads/dev", "project-a", "refs/heads/dev");
+    allowMatchingSubmoduleSubscription(keyB, "refs/heads/master", keyA, "refs/heads/master");
+    allowMatchingSubmoduleSubscription(keyB, "refs/heads/dev", keyA, "refs/heads/dev");
 
-    createSubmoduleSubscription(repoA, "master", "project-b", "master");
-    createSubmoduleSubscription(repoA, "dev", "project-b", "dev");
+    createSubmoduleSubscription(repoA, "master", keyB, "master");
+    createSubmoduleSubscription(repoA, "dev", keyB, "dev");
 
     // create a change for master branch in repo b
     ObjectId bHead =
@@ -770,8 +773,8 @@
     approve(getChangeId(repoB, bDevHead).get());
     gApi.changes().id(getChangeId(repoB, bHead).get()).current().submit();
 
-    expectToHaveSubmoduleState(repoA, "master", "project-b", repoB, "master");
-    expectToHaveSubmoduleState(repoA, "dev", "project-b", repoB, "dev");
+    expectToHaveSubmoduleState(repoA, "master", keyB, repoB, "master");
+    expectToHaveSubmoduleState(repoA, "dev", keyB, repoB, "dev");
   }
 
   @Test
@@ -876,4 +879,8 @@
     expectToHaveSubmoduleState(superRepo, "master", subKey1, badId);
     expectToHaveSubmoduleState(superRepo, "master", subKey2, sub2, "master");
   }
+
+  private Project.NameKey nameKey(String s) {
+    return new Project.NameKey(name(s));
+  }
 }