Search in sources :

Example 11 with BranchNameKey

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();
}
Also used : Project(com.google.gerrit.entities.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) BranchNameKey(com.google.gerrit.entities.BranchNameKey) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) DefaultFactory(com.google.gerrit.server.submit.SubscriptionGraph.DefaultFactory) Test(org.junit.Test)

Example 12 with BranchNameKey

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);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) Test(org.junit.Test)

Example 13 with BranchNameKey

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);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) Test(org.junit.Test)

Example 14 with BranchNameKey

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);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) Test(org.junit.Test)

Example 15 with BranchNameKey

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);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) Test(org.junit.Test)

Aggregations

BranchNameKey (com.google.gerrit.entities.BranchNameKey)75 Test (org.junit.Test)48 Project (com.google.gerrit.entities.Project)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)25 Config (org.eclipse.jgit.lib.Config)19 SubmoduleSubscription (com.google.gerrit.entities.SubmoduleSubscription)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 AuthException (com.google.gerrit.extensions.restapi.AuthException)13 Change (com.google.gerrit.entities.Change)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 StorageException (com.google.gerrit.exceptions.StorageException)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Repository (org.eclipse.jgit.lib.Repository)9 PatchSet (com.google.gerrit.entities.PatchSet)8 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)8 HashMap (java.util.HashMap)7 Ref (org.eclipse.jgit.lib.Ref)7