use of jetbrains.buildServer.serverSide.BuildTypeEx in project teamcity-rest by JetBrains.
the class BranchFinderTest method testBranchExists.
@Test
public void testBranchExists() {
final BuildTypeEx bt = registerBuildType("10", "Project");
MockVcsSupport vcs = new MockVcsSupport("vcs");
vcs.setDAGBased(true);
myFixture.getVcsManager().registerVcsSupport(vcs);
SVcsRootEx parentRoot = myFixture.addVcsRoot(vcs.getName(), "", bt);
VcsRootInstance root = bt.getVcsRootInstanceForParent(parentRoot);
assert root != null;
setBranchSpec(root, "+:*");
final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
vcs.setCollectChangesPolicy(changesPolicy);
SVcsModification m10 = myFixture.addModification(modification().in(root).version("10").parentVersions("1"));
SVcsModification m20 = myFixture.addModification(modification().in(root).version("20").parentVersions("1"));
SVcsModification m30 = myFixture.addModification(modification().in(root).version("30").parentVersions("1"));
changesPolicy.setCurrentState(root, RepositoryStateData.createVersionState("master", Util.map("master", "10", "branch1", "20", "branch2", "30")));
myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
assertTrue("There are more than one branch by this locator.", myBranchFinder.itemsExist(new Locator("buildType:(id:" + bt.getExternalId() + ")")));
assertTrue("Should find default branch.", myBranchFinder.itemsExist(new Locator("buildType:(id:" + bt.getExternalId() + "),default:true")));
assertTrue("Should find non-default branch.", myBranchFinder.itemsExist(new Locator("buildType:(id:" + bt.getExternalId() + "),default:false")));
assertTrue("Should find branch by name.", myBranchFinder.itemsExist(new Locator("buildType:(id:" + bt.getExternalId() + "),name:branch1")));
assertFalse("Should not find branch of there isn't one.", myBranchFinder.itemsExist(new Locator("buildType:(id:" + bt.getExternalId() + "),name:branch999")));
}
use of jetbrains.buildServer.serverSide.BuildTypeEx in project teamcity-rest by JetBrains.
the class BranchFinderTest method testBranchesFromDependencies.
@Test
public void testBranchesFromDependencies() {
final BuildTypeEx bt10 = registerBuildType("10", "Project");
final BuildTypeEx bt20 = registerBuildType("20", "Project");
createDependencyChain(bt20, bt10);
MockVcsSupport vcs = new MockVcsSupport("vcs");
vcs.setDAGBased(true);
myFixture.getVcsManager().registerVcsSupport(vcs);
SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", bt10);
SVcsRootEx parentRoot2 = myFixture.addVcsRoot(vcs.getName(), "", bt20);
VcsRootInstance root1 = bt10.getVcsRootInstanceForParent(parentRoot1);
VcsRootInstance root2 = bt20.getVcsRootInstanceForParent(parentRoot2);
assert root1 != null;
assert root2 != null;
setBranchSpec(root1, "+:*");
setBranchSpec(root2, "+:*");
final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
vcs.setCollectChangesPolicy(changesPolicy);
SVcsModification m10 = myFixture.addModification(modification().in(root1).version("10").parentVersions("1"));
SVcsModification m20 = myFixture.addModification(modification().in(root1).version("20").parentVersions("1"));
SVcsModification m30 = myFixture.addModification(modification().in(root1).version("30").parentVersions("1"));
SVcsModification n10 = myFixture.addModification(modification().in(root2).version("10").parentVersions("1"));
SVcsModification n20 = myFixture.addModification(modification().in(root2).version("20").parentVersions("1"));
SVcsModification n30 = myFixture.addModification(modification().in(root2).version("30").parentVersions("1"));
changesPolicy.setCurrentState(root1, RepositoryStateData.createVersionState("master", Util.map("master", "10", "branch1", "20", "branch2", "30")));
changesPolicy.setCurrentState(root2, RepositoryStateData.createVersionState("master", Util.map("master", "10", "branch2", "20", "branch3", "30")));
myFixture.getVcsModificationChecker().checkForModifications(bt10.getVcsRootInstances(), OperationRequestor.UNKNOWN);
myFixture.getVcsModificationChecker().checkForModifications(bt20.getVcsRootInstances(), OperationRequestor.UNKNOWN);
check("buildType:(id:" + bt10.getExternalId() + ")", "<default>", "branch1", "branch2");
check("buildType:(id:" + bt20.getExternalId() + ")", "<default>", "branch2", "branch3");
check("buildType:(id:" + bt20.getExternalId() + "),changesFromDependencies:true", "<default>", "branch1", "branch2", "branch3");
check("buildType:(id:" + bt20.getExternalId() + "),changesFromDependencies:false", "<default>", "branch2", "branch3");
bt20.setOption(BuildTypeOptions.BT_SHOW_DEPS_CHANGES, true);
check("buildType:(id:" + bt20.getExternalId() + ")", "<default>", "branch1", "branch2", "branch3");
check("buildType:(id:" + bt20.getExternalId() + "),changesFromDependencies:false", "<default>", "branch2", "branch3");
check("buildType:(id:" + bt20.getExternalId() + "),changesFromDependencies:true", "<default>", "branch1", "branch2", "branch3");
checkExceptionOnItemsSearch(LocatorProcessException.class, "buildType:(id:" + bt20.getExternalId() + "),changesFromDependencies:any");
}
use of jetbrains.buildServer.serverSide.BuildTypeEx in project teamcity-rest by JetBrains.
the class MuteRequestTest method test_severalMutes.
@Test
public void test_severalMutes() {
final ProjectEx project = createProject("Project", "Project");
final BuildTypeEx bt1 = project.createBuildType("bt1");
final BuildTypeEx bt2 = project.createBuildType("bt2");
final ProjectEx project2 = createProject("Project2", "Project2");
final BuildTypeEx bt22 = project.createBuildType("bt3");
createBuild(bt1, new String[0], new String[] { "test1", "test2", "test3" });
createBuild(bt22, new String[0], new String[] { "test1", "test2", "test3", "test4" });
final STest test1 = myFixture.getTestManager().createTest(new TestName("test1"), project.getProjectId());
final STest test2 = myFixture.getTestManager().createTest(new TestName("test2"), project.getProjectId());
SUser user = createUser("user");
myMutingService.muteTestsInBuildTypes(user, null, false, null, Arrays.asList(bt1, bt2), Arrays.asList(test1, test2), false);
myMutingService.muteTestsInProject(user, null, false, null, project2, Arrays.asList(test1));
int mute1Id, mute2Id;
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(2), mutes.count);
assertEquals(2, mutes.items.size());
mute1Id = mutes.items.get(0).id;
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(2, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
mute2Id = mutes.items.get(1).id;
assertNull(mutes.items.get(1).scope.buildTypes);
assertNotNull(mutes.items.get(1).scope.project);
assertEquals(project2.getExternalId(), mutes.items.get(1).scope.project.id);
assertNull(mutes.items.get(1).target.problems);
assertEquals(1, mutes.items.get(1).target.tests.items.size());
assertTrue(mutes.items.get(1).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
}
{
setInternalProperty(Mutes.REST_MUTES_ACTUAL_STATE, "true");
Mutes mutes = myRequest.getMutes("id:" + mute2Id, "$long,mute(target(tests(test(mutes(mute(target(tests(test($long))),scope(buildTypes(buildType($long)))))))))", null, null);
assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.size());
assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).target.tests.items.size());
assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).scope.buildTypes.buildTypes.size());
}
}
use of jetbrains.buildServer.serverSide.BuildTypeEx in project teamcity-rest by JetBrains.
the class MuteRequestTest method test_unmuteTest.
@Test
public void test_unmuteTest() {
final ProjectEx project = createProject("Project", "Project");
final BuildTypeEx bt1 = project.createBuildType("bt1");
final BuildTypeEx bt2 = project.createBuildType("bt2");
// just a child project
final ProjectEx projectChild = project.createProject("Project2", "Project2");
final BuildTypeEx bt21 = projectChild.createBuildType("bt21");
createBuild(bt1, new String[0], new String[] { "test1", "test2", "test3" });
createBuild(bt2, new String[0], new String[] { "test1", "test2", "test3", "test4" });
createBuild(bt21, new String[0], new String[] { "test1", "test2", "test3", "test4" });
final STest test1 = myFixture.getTestManager().createTest(new TestName("test1"), project.getProjectId());
final STest test2 = myFixture.getTestManager().createTest(new TestName("test2"), project.getProjectId());
SUser user = createUser("user");
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
// assertEquals(Integer.valueOf(0), mutes.count); //todo: fix
assertEmpty(mutes.items);
}
myMutingService.muteTestsInBuildTypes(user, null, false, null, Arrays.asList(bt1, bt2), Arrays.asList(test1, test2), false);
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(1), mutes.count);
assertEquals(1, mutes.items.size());
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(2, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
}
myMutingService.unmuteTests(user, null, bt1, Arrays.asList(test1));
{
// this is the current behavior, but actually something should change, see TW-53393
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(1), mutes.count);
assertEquals(1, mutes.items.size());
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(2, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
}
myMutingService.unmuteTests(user, null, bt2, Arrays.asList(test1));
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(1), mutes.count);
assertEquals(1, mutes.items.size());
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(1, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
}
{
setInternalProperty(Mutes.REST_MUTES_ACTUAL_STATE, "true");
Mutes mutes = myRequest.getMutes(null, "$long,mute(target(tests(test(mutes(mute(target(tests($long))))))))", null, null);
assertEquals(1, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).target.tests.items.size());
}
}
use of jetbrains.buildServer.serverSide.BuildTypeEx 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);
}
Aggregations