Search in sources :

Example 1 with Branches

use of jetbrains.buildServer.server.rest.model.build.Branches in project teamcity-rest by JetBrains.

the class BuildTypeTest method testBranches.

@Test
public void testBranches() throws ExecutionException, InterruptedException {
    final BuildTypeEx bt = getRootProject().createProject("Project1", "Project test 1").createBuildType("testBT", "My test build type");
    final BuildTypeRequest buildTypeRequest = new BuildTypeRequest();
    buildTypeRequest.setInTests(myBuildTypeFinder, myBranchFinder, myBeanContext);
    Branches branches = buildTypeRequest.serveBranches("id:testBT", null, null);
    ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, null);
    branches = buildTypeRequest.serveBranches("id:testBT", null, Fields.ALL_NESTED.getFieldsSpec());
    ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, false);
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(collectChangesPolicy);
    final SVcsRoot vcsRoot = bt.getProject().createVcsRoot("vcs", "extId", "name");
    bt.addVcsRoot(vcsRoot);
    final VcsRootInstance vcsRootInstance = bt.getVcsRootInstances().get(0);
    collectChangesPolicy.setCurrentState(vcsRootInstance, createVersionState("master", map("master", "1", "branch1", "2", "branch2", "3")));
    setBranchSpec(vcsRootInstance, "+:*");
    branches = buildTypeRequest.serveBranches("id:testBT", null, null);
    // why default before checking for changes???
    ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, null);
    myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    branches = buildTypeRequest.serveBranches("id:testBT", null, null);
    ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null);
    branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", null);
    ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null, "branch1", null, null, "branch2", null, null);
    assertNull(branches.branches.get(0).getInternalName());
    branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", Fields.ALL_NESTED.getFieldsSpec());
    assertEquals("<default>", branches.branches.get(0).getInternalName());
    assertEquals("branch1", branches.branches.get(1).getInternalName());
    assertEquals("branch2", branches.branches.get(2).getInternalName());
    branches = buildTypeRequest.serveBranches("id:testBT", "policy:all_branches", null);
    ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null, "branch1", null, null, "branch2", null, null);
    branches = buildTypeRequest.serveBranches("id:testBT", "default:true", null);
    ProjectRequestTest.assertBranchesEquals(branches.branches, "master", true, null);
    bt.addVcsRoot(bt.getProject().createVcsRoot("vcs", "extId2", "name2"));
    final VcsRootInstance vcsRootInstance2 = bt.getVcsRootInstances().get(1);
    collectChangesPolicy.setCurrentState(vcsRootInstance2, createVersionState("master2", map("master2", "1", "branch1", "2", "branch2", "3")));
    setBranchSpec(vcsRootInstance2, "+:*");
    myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", Fields.ALL_NESTED.getFieldsSpec());
    ProjectRequestTest.assertBranchesEquals(branches.branches, "<default>", true, false, "branch1", false, false, "branch2", false, false);
    assertEquals("<default>", branches.branches.get(0).getInternalName());
    checkException(LocatorProcessException.class, new Runnable() {

        public void run() {
            buildTypeRequest.serveBranches("id:testBT", "changesFromDependencies:any", null);
        }
    }, "searching with wrong changesFromDependencies");
    checkException(BadRequestException.class, new Runnable() {

        public void run() {
            buildTypeRequest.serveBranches("id:testBT", "policy:INVALID_POLICY", null);
        }
    }, "searching with wrong changesFromDependencies");
// can also add test for branches from builds
// can also add test for "changesFromDependencies:true" locator and several defaults in different branches
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) BuildTypeRequest(jetbrains.buildServer.server.rest.request.BuildTypeRequest) 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) ProjectRequestTest(jetbrains.buildServer.server.rest.request.ProjectRequestTest) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 2 with Branches

use of jetbrains.buildServer.server.rest.model.build.Branches in project teamcity-rest by JetBrains.

the class BuildTypeTest method testBranchesCaseDiff.

// TW-49294
@Test
public void testBranchesCaseDiff() throws ExecutionException, InterruptedException {
    final BuildTypeEx bt = getRootProject().createProject("Project1", "Project test 1").createBuildType("testBT", "My test build type");
    final BuildTypeRequest buildTypeRequest = new BuildTypeRequest();
    buildTypeRequest.setInTests(myBuildTypeFinder, myBranchFinder, myBeanContext);
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(collectChangesPolicy);
    final SVcsRoot vcsRoot = bt.getProject().createVcsRoot("vcs", "extId", "name");
    bt.addVcsRoot(vcsRoot);
    final VcsRootInstance vcsRootInstance = bt.getVcsRootInstances().get(0);
    collectChangesPolicy.setCurrentState(vcsRootInstance, createVersionState("master", map("master", "1", "aaa", "2", "bbb", "2", "Aaa", "3")));
    setBranchSpec(vcsRootInstance, "+:*");
    myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    Branches branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", Fields.ALL_NESTED.getFieldsSpec());
    assertEquals("<default>", branches.branches.get(0).getInternalName());
    assertEquals("Aaa", branches.branches.get(1).getInternalName());
    assertEquals("aaa", branches.branches.get(2).getInternalName());
    assertEquals("bbb", branches.branches.get(3).getInternalName());
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) BuildTypeRequest(jetbrains.buildServer.server.rest.request.BuildTypeRequest) 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) ProjectRequestTest(jetbrains.buildServer.server.rest.request.ProjectRequestTest) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 3 with Branches

use of jetbrains.buildServer.server.rest.model.build.Branches 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 4 with Branches

use of jetbrains.buildServer.server.rest.model.build.Branches in project teamcity-rest by JetBrains.

the class ProjectRequestTest method testBranchesDiffInCaseOnly.

@Test
public void testBranchesDiffInCaseOnly() {
    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);
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(collectChangesPolicy);
    setCurrentBranches(bt1, collectChangesPolicy, "master", map("master", "1", "aaa", "2", "bbb", "3", "Aaa", "3"));
    setCurrentBranches(bt2, collectChangesPolicy, "Master", map("Master", "1", "bBb", "2", "ccc", "3"));
    Branches branches = request.getBranches("id:" + prjId, "policy:ALL_BRANCHES", null);
    assertBranchesEquals(branches.branches, "<default>", true, null, "Aaa", null, null, "aaa", null, null, "bBb", null, null, "bbb", null, null, "ccc", 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) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 5 with Branches

use of jetbrains.buildServer.server.rest.model.build.Branches in project teamcity-rest by JetBrains.

the class ProjectRequest method getBranches.

/**
 * Experimental support only.
 * Lists branches from the build configurations of the project
 * @param branchesLocator experimental use only!
 * @return
 */
@GET
@Path("/{projectLocator}/branches")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get all branches of the matching project.", nickname = "getAllBranches")
public Branches getBranches(@ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, @QueryParam("locator") String branchesLocator, @QueryParam("fields") String fieldsSpec) {
    final SProject project = myProjectFinder.getItem(projectLocator);
    String updatedBranchLocator = BranchFinder.patchLocatorWithBuildType(branchesLocator, BuildTypeFinder.patchLocator(null, project));
    Fields fields = new Fields(fieldsSpec);
    return new Branches(myBranchFinder.getItems(updatedBranchLocator).myEntries, null, fields, myBeanContext);
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) Branches(jetbrains.buildServer.server.rest.model.build.Branches) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Branches (jetbrains.buildServer.server.rest.model.build.Branches)5 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)4 BuildFinderTestBase (jetbrains.buildServer.server.rest.data.BuildFinderTestBase)4 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)4 Test (org.testng.annotations.Test)4 VcsRootInstance (jetbrains.buildServer.vcs.VcsRootInstance)3 BuildTypeRequest (jetbrains.buildServer.server.rest.request.BuildTypeRequest)2 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)2 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)2 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)2 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)2 ApiOperation (io.swagger.annotations.ApiOperation)1 Fields (jetbrains.buildServer.server.rest.model.Fields)1