use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class SubscriptionGraphTest method multipleSuperprojectsToMultipleSubmodules.
@Test
public void multipleSuperprojectsToMultipleSubmodules() throws Exception {
// Create superprojects and subprojects.
Project.NameKey superProject1 = Project.nameKey("superproject1");
Project.NameKey superProject2 = Project.nameKey("superproject2");
Project.NameKey subProject1 = Project.nameKey("subproject1");
Project.NameKey subProject2 = Project.nameKey("subproject2");
TestRepository<Repository> superProjectRepo1 = createRepo(superProject1);
TestRepository<Repository> superProjectRepo2 = createRepo(superProject2);
TestRepository<Repository> submoduleRepo1 = createRepo(subProject1);
TestRepository<Repository> submoduleRepo2 = createRepo(subProject2);
// Initialize super branches.
BranchNameKey superBranch1 = BranchNameKey.create(superProject1, "refs/heads/one");
BranchNameKey superBranch2 = BranchNameKey.create(superProject2, "refs/heads/one");
createBranch(superProjectRepo1, superBranch1, superProjectRepo1.commit().message("Initial commit").create());
createBranch(superProjectRepo2, superBranch2, superProjectRepo2.commit().message("Initial commit").create());
// Initialize sub branches.
BranchNameKey submoduleBranch1 = BranchNameKey.create(subProject1, "refs/heads/one");
BranchNameKey submoduleBranch2 = BranchNameKey.create(subProject1, "refs/heads/two");
BranchNameKey submoduleBranch3 = BranchNameKey.create(subProject2, "refs/heads/one");
createBranch(submoduleRepo1, submoduleBranch1, submoduleRepo1.commit().message("Commit1").create());
createBranch(submoduleRepo1, submoduleBranch2, submoduleRepo1.commit().message("Commit2").create());
createBranch(submoduleRepo2, submoduleBranch3, submoduleRepo2.commit().message("Commit1").create());
allowSubscription(submoduleBranch1);
allowSubscription(submoduleBranch2);
allowSubscription(submoduleBranch3);
// Initialize subscriptions.
setSubscription(submoduleBranch1, ImmutableList.of(superBranch1, superBranch2));
setSubscription(submoduleBranch2, ImmutableList.of(superBranch1));
setSubscription(submoduleBranch3, ImmutableList.of(superBranch1, superBranch2));
SubscriptionGraph.Factory factory = new DefaultFactory(mockGitModulesFactory, mockProjectCache);
SubscriptionGraph subscriptionGraph = factory.compute(ImmutableSet.of(submoduleBranch1, submoduleBranch2), mergeOpRepoManager);
assertThat(subscriptionGraph.getAffectedSuperProjects()).containsExactly(superProject1, superProject2);
assertThat(subscriptionGraph.getAffectedSuperBranches(superProject1)).containsExactly(superBranch1);
assertThat(subscriptionGraph.getAffectedSuperBranches(superProject2)).containsExactly(superBranch2);
assertThat(subscriptionGraph.getSubscriptions(superBranch1)).containsExactly(new SubmoduleSubscription(superBranch1, submoduleBranch1, TEST_PATH), new SubmoduleSubscription(superBranch1, submoduleBranch2, TEST_PATH));
assertThat(subscriptionGraph.getSubscriptions(superBranch2)).containsExactly(new SubmoduleSubscription(superBranch2, submoduleBranch1, TEST_PATH));
assertThat(subscriptionGraph.hasSuperproject(submoduleBranch1)).isTrue();
assertThat(subscriptionGraph.hasSuperproject(submoduleBranch2)).isTrue();
assertThat(subscriptionGraph.hasSuperproject(submoduleBranch3)).isFalse();
assertThat(subscriptionGraph.getSortedSuperprojectAndSubmoduleBranches()).containsExactly(submoduleBranch2, submoduleBranch1, superBranch2, superBranch1).inOrder();
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class SubmoduleSectionParserTest method withSlashesInProjectName.
@Test
public void withSlashesInProjectName() throws Exception {
Project.NameKey p = Project.nameKey("project/with/slashes/a");
Config cfg = new Config();
cfg.fromText("" + "[submodule \"project/with/slashes/a\"]\n" + "path = a\n" + "url = http://localhost:80/" + p.get() + "\n" + "branch = master\n");
BranchNameKey targetBranch = BranchNameKey.create(Project.nameKey("project"), "master");
Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch).parseAllSections();
Set<SubmoduleSubscription> expected = Sets.newHashSet(new SubmoduleSubscription(targetBranch, BranchNameKey.create(p, "master"), "a"));
assertThat(res).containsExactlyElementsIn(expected);
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class SubmoduleSectionParserTest method withMoreSections.
@Test
public void withMoreSections() throws Exception {
Project.NameKey p1 = Project.nameKey("a");
Project.NameKey p2 = Project.nameKey("b");
Config cfg = new Config();
cfg.fromText("" + "[submodule \"a\"]\n" + " path = a\n" + " url = ssh://localhost/" + p1.get() + "\n" + " branch = .\n" + "[submodule \"b\"]\n" + " path = b\n" + " url = http://localhost:80/" + p2.get() + "\n" + " branch = master\n");
BranchNameKey targetBranch = BranchNameKey.create(Project.nameKey("project"), "master");
Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch).parseAllSections();
Set<SubmoduleSubscription> expected = Sets.newHashSet(new SubmoduleSubscription(targetBranch, BranchNameKey.create(p1, "master"), "a"), new SubmoduleSubscription(targetBranch, BranchNameKey.create(p2, "master"), "b"));
assertThat(res).containsExactlyElementsIn(expected);
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class SubmoduleSectionParserTest method withDeepRelativeURI.
@Test
public void withDeepRelativeURI() throws Exception {
Project.NameKey p1 = Project.nameKey("a");
Config cfg = new Config();
cfg.fromText("" + "[submodule \"a\"]\n" + "path = a\n" + "url = ../../" + p1.get() + "\n" + "branch = master\n");
BranchNameKey targetBranch = BranchNameKey.create(Project.nameKey("nested/project"), "master");
Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch).parseAllSections();
Set<SubmoduleSubscription> expected = Sets.newHashSet(new SubmoduleSubscription(targetBranch, BranchNameKey.create(p1, "master"), "a"));
assertThat(res).containsExactlyElementsIn(expected);
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class SubmoduleSectionParserTest method followMatchingBranch.
@Test
public void followMatchingBranch() throws Exception {
Project.NameKey p = Project.nameKey("a");
Config cfg = new Config();
cfg.fromText("" + "[submodule \"a\"]\n" + "path = a\n" + "url = ssh://localhost/" + p.get() + "\n" + "branch = .\n");
BranchNameKey targetBranch1 = BranchNameKey.create(Project.nameKey("project"), "master");
Set<SubmoduleSubscription> res1 = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch1).parseAllSections();
Set<SubmoduleSubscription> expected1 = Sets.newHashSet(new SubmoduleSubscription(targetBranch1, BranchNameKey.create(p, "master"), "a"));
assertThat(res1).containsExactlyElementsIn(expected1);
BranchNameKey targetBranch2 = BranchNameKey.create(Project.nameKey("project"), "somebranch");
Set<SubmoduleSubscription> res2 = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch2).parseAllSections();
Set<SubmoduleSubscription> expected2 = Sets.newHashSet(new SubmoduleSubscription(targetBranch2, BranchNameKey.create(p, "somebranch"), "a"));
assertThat(res2).containsExactlyElementsIn(expected2);
}
Aggregations