Search in sources :

Example 26 with VcsRootInstance

use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.

the class ProjectRequestTest method testBranches.

@Test
public void testBranches() {
    String prjId = "Project1";
    ProjectEx project1 = getRootProject().createProject(prjId, "Project test 1");
    String bt1Id = "testBT1";
    String bt2Id = "testBT2";
    final BuildTypeEx bt1 = project1.createBuildType(bt1Id, "My test build type 1");
    final BuildTypeEx bt2 = project1.createBuildType(bt2Id, "My test build type 2");
    final ProjectRequest request = new ProjectRequest();
    request.setInTests(myProjectFinder, myBranchFinder, myBeanContext);
    Branches branches = request.getBranches("id:" + prjId, null, null);
    assertBranchesEquals(branches.branches, "<default>", true, null);
    branches = request.getBranches("id:" + prjId, null, Fields.ALL_NESTED.getFieldsSpec());
    assertBranchesEquals(branches.branches, "<default>", true, false);
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(collectChangesPolicy);
    setCurrentBranches(bt1, collectChangesPolicy, "master", map("master", "1", "branch20", "2", "branch30", "3"));
    setCurrentBranches(bt2, collectChangesPolicy, "master", map("master", "1", "branch10", "2", "branch20", "3"));
    branches = request.getBranches("id:" + prjId, null, null);
    // active branches by default
    assertBranchesEquals(branches.branches, "master", true, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "master", true, null, "branch10", null, null, "branch20", null, null, "branch30", null, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,default:true", null);
    assertBranchesEquals(branches.branches, "master", true, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,default:false", null);
    assertBranchesEquals(branches.branches, "branch10", null, null, "branch20", null, null, "branch30", null, null);
    setCurrentBranches(bt2, collectChangesPolicy, "master2", map("branch10", "2", "master2", "4", "branch20", "3"));
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "<default>", true, null, "branch10", null, null, "branch20", null, null, "branch30", null, null);
    // no default branch option test
    bt1.setOption(Option.fromKey("branchFilter"), "+:*\n-:<default>");
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "master2", true, null, "branch10", null, null, "branch20", null, null, "branch30", null, null);
    bt2.setOption(Option.fromKey("branchFilter"), "+:*\n-:<default>");
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "branch10", null, null, "branch20", null, null, "branch30", null, null);
    // revert
    bt1.setOption(Option.fromKey("branchFilter"), "+:*");
    bt2.setOption(Option.fromKey("branchFilter"), "+:*");
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,default:true", null);
    assertBranchesEquals(branches.branches, "<default>", true, null);
    setCurrentBranches(bt2, collectChangesPolicy, "master2", map("master", "1", "branch10", "2", "master2", "4", "branch20", "3"));
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "<default>", true, null, "branch10", null, null, "branch20", null, null, "branch30", null, null, "master", null, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,default:true", null);
    assertBranchesEquals(branches.branches, "<default>", true, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,default:false", null);
    assertBranchesEquals(branches.branches, "branch10", null, null, "branch20", null, null, "branch30", null, null, "master", null, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,buildType:(id:" + bt1.getExternalId() + ")", null);
    assertBranchesEquals(branches.branches, "master", true, null, "branch20", null, null, "branch30", null, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,buildType:(id:" + bt2.getExternalId() + ")", null);
    assertBranchesEquals(branches.branches, "master2", true, null, "branch10", null, null, "branch20", null, null, "master", null, null);
    // subproject
    ProjectEx project1_1 = project1.createProject("Project1_1", "Project test 1.1");
    final BuildTypeEx bt11 = project1_1.createBuildType("testBT1_1", "My test build type 1");
    final BuildTypeEx bt12 = project1_1.createBuildType("testBT1_2", "My test build type 2");
    final BuildTypeEx bt13 = project1_1.createBuildType("testBT1_3", "My test build type 3");
    setCurrentBranches(bt11, collectChangesPolicy, "master", map("master", "1", "branch30", "3", "branch120", "2"));
    setCurrentBranches(bt12, collectChangesPolicy, "master", map("master", "1", "branch10", "2", "master2", "4", "branch120", "3"));
    setCurrentBranches(bt13, collectChangesPolicy, "master", map("master", "1", "branch10", "2", "master2", "4", "branch120", "3"));
    bt13.addVcsRoot(bt13.getProject().createVcsRoot("vcs", "extId13_2", "name13_2"));
    final VcsRootInstance vcsRootInstance2 = bt13.getVcsRootInstances().get(1);
    collectChangesPolicy.setCurrentState(vcsRootInstance2, createVersionState("master3", map("branch10", "2", "master3", "2", "branch2", "3")));
    setBranchSpec(vcsRootInstance2, "+:*");
    myFixture.getVcsModificationChecker().checkForModifications(bt13.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "<default>", true, null, "branch10", null, null, "branch20", null, null, "branch30", null, null, "master", null, null);
    branches = request.getBranches("id:" + project1_1.getExternalId(), "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "<default>", true, null, "branch10", null, null, "branch120", null, null, "branch2", null, null, "branch30", null, null, "master2", null, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,buildType:(affectedProject:(id:" + prjId + "))", null);
    assertBranchesEquals(branches.branches, "<default>", true, null, "branch10", null, null, "branch120", null, null, "branch2", null, null, "branch20", null, null, "branch30", null, null, "master", null, null, "master2", null, null);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,buildType:(affectedProject:(id:" + prjId + "))", Fields.ALL_NESTED.getFieldsSpec());
    assertBranchesEquals(branches.branches, "<default>", true, false, "branch10", false, false, "branch120", false, false, "branch2", false, false, "branch20", false, false, "branch30", false, false, "master", false, false, "master2", false, false);
    branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES,buildType:(id:" + bt13.getExternalId() + ")", null);
    assertBranchesEquals(branches.branches, "<default>", true, null, "branch10", null, null, "branch120", null, null, "branch2", null, null, "master2", null, null);
    // not quite valid, but works for now
    branches = request.getBranches("id:" + project1_1.getExternalId(), "policy:ALL_BRANCHES,buildType:(id:" + bt1Id + ")", null);
    assertBranchesEquals(branches.branches, "master", true, null, "branch20", null, null, "branch30", null, null);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) Branches(jetbrains.buildServer.server.rest.model.build.Branches) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 27 with VcsRootInstance

use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.

the class BuildTypeFinderTest method testVcsDimensions.

@Test
public void testVcsDimensions() throws Exception {
    myBuildType.remove();
    final SProject project10 = createProject("p10");
    myFixture.registerVcsSupport("svn");
    myFixture.registerVcsSupport("cvs");
    final SVcsRoot vcsRoot10 = getRootProject().createVcsRoot("svn", "id10", "VCS root 10 name");
    vcsRoot10.setProperties(CollectionsUtil.asMap("url", "", "param", "%aaa%"));
    final BuildTypeTemplate template = project10.createBuildTypeTemplate("template");
    template.addConfigParameter(new SimpleParameter("aaa", "111"));
    template.addVcsRoot(vcsRoot10);
    final SBuildType buildConf10 = project10.createBuildType("buildConf10");
    buildConf10.attachToTemplate(template);
    final SBuildType buildConf20 = project10.createBuildType("buildConf20");
    buildConf20.attachToTemplate(template);
    buildConf20.addConfigParameter(new SimpleParameter("aaa", "222"));
    final SVcsRoot vcsRoot20 = project10.createVcsRoot("svn", "id20", "VCS root 20 name");
    buildConf20.addVcsRoot(vcsRoot20);
    final SBuildType buildConf30 = project10.createBuildType("buildConf30");
    final SBuildType buildConf40 = project10.createBuildType("buildConf40");
    final SVcsRoot vcsRoot30 = getRootProject().createVcsRoot("cvs", "id30", "VCS root 30 name");
    buildConf40.addVcsRoot(vcsRoot30);
    final SProject project10_10 = project10.createProject("p10_10", "p10_10");
    final SBuildType buildConf50 = project10_10.createBuildType("buildConf50");
    final SBuildType buildConf60 = project10_10.createBuildType("buildConf60");
    buildConf50.addVcsRoot(vcsRoot20);
    buildConf60.addVcsRoot(vcsRoot30);
    checkBuildTypes("templateFlag:false", buildConf10, buildConf20, buildConf30, buildConf40, buildConf50, buildConf60);
    checkBuildTypes("vcsRoot:(id:id10),templateFlag:true", template);
    checkBuildTypes("vcsRoot:(id:id10),templateFlag:false", buildConf10, buildConf20);
    checkBuildTypes("vcsRoot:(id:id10)", buildConf10, buildConf20, template);
    checkBuildTypes("vcsRoot:(type:svn)", buildConf10, buildConf20, template, buildConf50);
    checkBuildTypes("vcsRoot:(type:cvs)", buildConf40, buildConf60);
    checkBuildTypes("vcsRoot:(type:cvs),templateFlag:true");
    checkBuildTypes("vcsRoot:(type:svn),project:(id:" + project10_10.getExternalId() + ")", buildConf50);
    final VcsRootInstance vcsRootInstance10 = buildConf10.getVcsRootInstanceForParent(vcsRoot10);
    assert vcsRootInstance10 != null;
    final VcsRootInstance vcsRootInstance10_2 = buildConf20.getVcsRootInstanceForParent(vcsRoot10);
    assert vcsRootInstance10_2 != null;
    final VcsRootInstance vcsRootInstance20 = buildConf20.getVcsRootInstanceForParent(vcsRoot20);
    assert vcsRootInstance20 != null;
    checkBuildTypes("vcsRootInstance:(id:" + vcsRootInstance10.getId() + ")", buildConf10);
    checkBuildTypes("vcsRootInstance:(id:" + vcsRootInstance10_2.getId() + ")", buildConf20);
    checkBuildTypes("vcsRootInstance:(id:" + vcsRootInstance20.getId() + ")", buildConf20, buildConf50);
    checkBuildTypes("vcsRootInstance:(vcsRoot:(id:id10))", buildConf10, buildConf20);
    checkBuildTypes("vcsRootInstance:(vcsRoot:(type:svn)),project:(id:" + project10_10.getExternalId() + ")", buildConf50);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test)

Example 28 with VcsRootInstance

use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.

the class BuildFinderByPromotionTest method testBuildsOrder.

@Test
public void testBuildsOrder() {
    final BuildTypeImpl buildConf = registerBuildType("buildConf1", "project");
    final SVcsRootImpl vcsRoot = myFixture.addVcsRoot("mock", "", buildConf);
    VcsRootInstance root1 = buildConf.getVcsRootInstanceForParent(vcsRoot);
    assert root1 != null;
    final SFinishedBuild build10 = build().in(buildConf).finish();
    myFixture.addModification(modification().in(root1).version("1"));
    final SVcsModification change20 = myFixture.addModification(modification().in(root1).version("2"));
    myFixture.addModification(modification().in(root1).version("3"));
    assertEquals(3, buildConf.getPendingChanges().size());
    final SFinishedBuild build20 = build().in(buildConf).finish();
    final SFinishedBuild build30 = build().in(buildConf).onModifications(change20).finish();
    checkBuilds(null, build30, build20, build10);
    checkBuilds("buildType:(id:" + buildConf.getExternalId() + ")", build30, build20, build10);
    checkBuilds("sinceBuild:(id:" + build20.getBuildId() + ")", build30);
}
Also used : SVcsRootImpl(jetbrains.buildServer.vcs.impl.SVcsRootImpl) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test)

Example 29 with VcsRootInstance

use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.

the class BuildFinderByPromotionTest method testBranchDimension2.

@Test
public void testBranchDimension2() throws Exception {
    final BuildTypeImpl buildConf = registerBuildType("buildConf1", "project");
    // not branched build
    final SFinishedBuild build5 = build().in(buildConf).finish();
    // settings to make display name for branch != branch name
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    vcs.setDAGBased(true);
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", buildConf);
    SVcsRootEx parentRoot2 = myFixture.addVcsRoot(vcs.getName(), "", buildConf);
    VcsRootInstance root1 = buildConf.getVcsRootInstanceForParent(parentRoot1);
    VcsRootInstance root2 = buildConf.getVcsRootInstanceForParent(parentRoot2);
    assert root1 != null;
    assert root2 != null;
    setBranchSpec(root1, "+:b1");
    setBranchSpec(root2, "+:b2");
    final MockCollectRepositoryChangesPolicy changesPolicy = new MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(changesPolicy);
    changesPolicy.setCurrentState(root1, createVersionState("master", map("master", "rev1", "b1", "revB1")));
    changesPolicy.setCurrentState(root2, createVersionState("master", map("master", "rev1", "b2", "revB2")));
    final SFinishedBuild build10 = build().in(buildConf).finish();
    final SFinishedBuild build20 = build().in(buildConf).withBranch(Branch.DEFAULT_BRANCH_NAME).finish();
    final SFinishedBuild build30 = build().in(buildConf).withBranch("master").finish();
    final SFinishedBuild build40 = build().in(buildConf).withBranch("b1").finish();
    final Branch branch = build20.getBranch();
    assert branch != null;
    assertEquals("<default>", branch.getName());
    assertEquals("master", branch.getDisplayName());
    // by default no branched builds should be listed
    checkBuilds(null, build20, build10, build5);
    final String btLocator = "buildType:(id:" + buildConf.getExternalId() + ")";
    checkBuilds(btLocator, build20, build10, build5);
    checkBuilds("pinned:any", build20, build10, build5);
    checkBuilds("branch:<default>", build20, build10);
    checkBuilds("branch:(default:true)", build20, build10, build5);
    checkBuilds("branch:(default:any)", build40, build30, build20, build10, build5);
    checkBuilds("branch:<any>", build40, build30, build20, build10, build5);
    checkBuilds("branch:(default:false)", build40, build30);
    checkBuilds("branch:(b1)", build40);
    checkBuilds("branch:(name:b1)", build40);
    checkBuilds("branch:(name:branchName)");
    checkBuilds("branch:(name:master)", build30, build20, build10);
    checkBuilds("branch:(name:master,default:true)", build20, build10);
    checkBuilds("branch:(branched:true)", build40, build30, build20, build10);
    checkBuilds("branch:(branched:false)", build5);
    checkBuilds("branch:(name:master,branched:true)", build30, build20, build10);
    checkBuilds(btLocator + ",branch:<default>", build20, build10);
    checkBuilds(btLocator + ",branch:(default:true)", build20, build10, build5);
    checkBuilds(btLocator + ",branch:(default:any)", build40, build30, build20, build10, build5);
    checkBuilds(btLocator + ",branch:<any>", build40, build30, build20, build10, build5);
    checkBuilds(btLocator + ",branch:(default:false)", build40, build30);
    checkBuilds(btLocator + ",branch:(b1)", build40);
    checkBuilds(btLocator + ",branch:(name:b1)", build40);
    checkBuilds(btLocator + ",branch:(name:branchName)");
    checkBuilds(btLocator + ",branch:(name:master)", build30, build20, build10);
    checkBuilds(btLocator + ",branch:(name:master,default:true)", build20, build10);
    checkBuilds(btLocator + ",branch:(branched:true)", build40, build30, build20, build10);
    checkBuilds(btLocator + ",branch:(branched:false)", build5);
    checkBuilds(btLocator + ",branch:(name:master,branched:true)", build30, build20, build10);
    // invalid branch locator
    checkExceptionOnBuildSearch(LocatorProcessException.class, "branch:(::)");
    // unused/unknown dimension
    checkExceptionOnBuildSearch(BadRequestException.class, "branch:(name:branchName,aaa:bbb)");
    checkExceptionOnBuildSearch(BadRequestException.class, "branch:(aaa:bbb)");
}
Also used : SVcsRootEx(jetbrains.buildServer.vcs.SVcsRootEx) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test)

Example 30 with VcsRootInstance

use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.

the class BuildFinderTest method testBuildsOrder.

@Test
public void testBuildsOrder() {
    final BuildTypeImpl buildConf = registerBuildType("buildConf1", "project");
    final SVcsRootImpl vcsRoot = myFixture.addVcsRoot("mock", "", buildConf);
    VcsRootInstance root1 = buildConf.getVcsRootInstanceForParent(vcsRoot);
    assert root1 != null;
    final SFinishedBuild build10 = build().in(buildConf).finish();
    myFixture.addModification(modification().in(root1).version("1"));
    final SVcsModification change20 = myFixture.addModification(modification().in(root1).version("2"));
    myFixture.addModification(modification().in(root1).version("3"));
    assertEquals(3, buildConf.getPendingChanges().size());
    final SFinishedBuild build20 = build().in(buildConf).finish();
    final SFinishedBuild build30 = build().in(buildConf).onModifications(change20).finish();
    checkBuilds(null, build30, build20, build10);
    checkBuilds("buildType:(id:" + buildConf.getExternalId() + ")", build30, build20, build10);
    checkBuilds("sinceBuild:(id:" + build20.getBuildId() + ")", build30);
}
Also used : SVcsRootImpl(jetbrains.buildServer.vcs.impl.SVcsRootImpl) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Test(org.testng.annotations.Test)

Aggregations

VcsRootInstance (jetbrains.buildServer.vcs.VcsRootInstance)31 Test (org.testng.annotations.Test)15 SVcsModification (jetbrains.buildServer.vcs.SVcsModification)14 ChangeStatus (jetbrains.buildServer.server.rest.model.change.ChangeStatus)12 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)12 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)6 RunningBuildEx (jetbrains.buildServer.serverSide.RunningBuildEx)5 BuildFinderTestBase (jetbrains.buildServer.server.rest.data.BuildFinderTestBase)4 Nullable (org.jetbrains.annotations.Nullable)4 SUser (jetbrains.buildServer.users.SUser)3 NotNull (org.jetbrains.annotations.NotNull)3 Logger (com.intellij.openapi.diagnostic.Logger)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ActionErrors (jetbrains.buildServer.controllers.ActionErrors)2 Branches (jetbrains.buildServer.server.rest.model.build.Branches)2 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)2