Search in sources :

Example 21 with MockVcsSupport

use of jetbrains.buildServer.serverSide.impl.MockVcsSupport in project teamcity-rest by JetBrains.

the class ChangeFinderTest method testChangesFromDependenciesDAG.

@Test
public void testChangesFromDependenciesDAG() {
    final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
    final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
    createDependencyChain(buildConf2, buildConf1);
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    vcs.setDAGBased(true);
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", buildConf1);
    SVcsRootEx parentRoot2 = myFixture.addVcsRoot(vcs.getName(), "", buildConf2);
    VcsRootInstance root1 = buildConf1.getVcsRootInstanceForParent(parentRoot1);
    VcsRootInstance root2 = buildConf2.getVcsRootInstanceForParent(parentRoot2);
    assert root1 != null;
    assert root2 != null;
    setBranchSpec(root1, "+:*");
    setBranchSpec(root2, "+:*");
    final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(changesPolicy);
    SVcsModification m120 = myFixture.addModification(modification().in(root1).version("120").parentVersions("10"));
    SVcsModification m250 = myFixture.addModification(modification().in(root2).version("250").parentVersions("10"));
    changesPolicy.setCurrentState(root1, RepositoryStateData.createVersionState("master", Util.map("master", "120")));
    changesPolicy.setCurrentState(root2, RepositoryStateData.createVersionState("master", Util.map("master", "250")));
    myFixture.getVcsModificationChecker().checkForModifications(buildConf1.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    myFixture.getVcsModificationChecker().checkForModifications(buildConf2.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    String btLocator1 = "buildType:(id:" + buildConf1.getExternalId() + ")";
    String btLocator2 = "buildType:(id:" + buildConf2.getExternalId() + ")";
    check(null, m250, m120);
    check(btLocator1, m120);
    check(btLocator1 + ",branch:(default:true)", m120);
    check(btLocator1 + ",branch:(name:master)", m120);
    check(btLocator1 + ",branch:(name:branch1)");
    check(btLocator1 + ",pending:true", m120);
    check(btLocator1 + ",pending:true,branch:(default:true)", m120);
    check(btLocator1 + ",pending:true,branch:(default:any)", m120);
    check(btLocator1 + ",pending:true,branch:(name:branch1)");
    check(btLocator1 + ",pending:true,branch:(policy:ACTIVE_VCS_BRANCHES)", m120);
    check(btLocator2, m250);
    check(btLocator2 + ",branch:(default:true)", m250);
    check(btLocator2 + ",branch:(name:master)", m250);
    check(btLocator2 + ",branch:(name:branch1)");
    check(btLocator2 + ",pending:true", m250);
    check(btLocator2 + ",pending:true,branch:(default:true)", m250);
    check(btLocator2 + ",pending:true,branch:(default:any)", m250);
    check(btLocator2 + ",pending:true,branch:(name:branch1)");
    check(btLocator2 + ",pending:true,branch:(policy:ACTIVE_VCS_BRANCHES)", m250);
    build().in(buildConf1).onModifications(m120).finish();
    SFinishedBuild build20 = build().in(buildConf2).onModifications(m250).finish();
    assertEquals("120", build20.getBuildPromotion().getDependencies().iterator().next().getDependOn().getRevisions().get(0).getRevision());
    SVcsModification m130 = myFixture.addModification(modification().in(root1).version("130").parentVersions("120"));
    SVcsModification m140 = myFixture.addModification(modification().in(root1).version("140").parentVersions("10"));
    SVcsModification m150 = myFixture.addModification(modification().in(root1).version("150").parentVersions("140"));
    SVcsModification m260 = myFixture.addModification(modification().in(root2).version("260").parentVersions("250"));
    SVcsModification m270 = myFixture.addModification(modification().in(root2).version("270").parentVersions("10"));
    changesPolicy.setCurrentState(root1, RepositoryStateData.createVersionState("master", Util.map("master", "130", "branch1", "150")));
    changesPolicy.setCurrentState(root2, RepositoryStateData.createVersionState("master", Util.map("master", "260", "branch1", "270")));
    myFixture.getVcsModificationChecker().checkForModifications(buildConf1.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    myFixture.getVcsModificationChecker().checkForModifications(buildConf2.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    check(null, m270, m260, m150, m140, m130, m250, m120);
    // documenting current behavior, should be check(btLocator1, m130, m120);
    check(btLocator1, m150, m140, m130, m120);
    check(btLocator1 + ",branch:(default:true)", m130, m120);
    check(btLocator1 + ",branch:(default:any)", m150, m140, m130, m120);
    check(btLocator1 + ",branch:(name:master)", m130, m120);
    check(btLocator1 + ",branch:(name:branch1)", m150, m140);
    check(btLocator1 + ",pending:true", m130);
    check(btLocator1 + ",pending:true,branch:(default:true)", m130);
    check(btLocator1 + ",pending:true,branch:(default:any)", m150, m140, m130);
    check(btLocator1 + ",pending:true,branch:(name:branch1)", m150, m140);
    check(btLocator1 + ",pending:true,branch:(policy:ACTIVE_VCS_BRANCHES)", m150, m140, m130);
    // documenting current behavior should be check(btLocator2, m260, m250);
    check(btLocator2, m270, m260, m250);
    check(btLocator2 + ",branch:(default:true)", m260, m250);
    check(btLocator2 + ",branch:(name:master)", m260, m250);
    check(btLocator2 + ",branch:(name:branch1)", m270);
    check(btLocator2 + ",pending:true", m260);
    check(btLocator2 + ",pending:true,branch:(default:true)", m260);
    check(btLocator2 + ",pending:true,branch:(default:any)", m270, m260);
    check(btLocator2 + ",pending:true,branch:(name:branch1)", m270);
    check(btLocator2 + ",pending:true,branch:(policy:ACTIVE_VCS_BRANCHES)", m270, m260);
    check("build:(" + build20.getBuildId() + ")", m250);
    buildConf2.setOption(BuildTypeOptions.BT_SHOW_DEPS_CHANGES, true);
    check(btLocator2, m260, m130, m250, m120);
    check(btLocator2 + ",branch:(default:true)", m260, m130, m250, m120);
    check(btLocator2 + ",branch:(name:master)", m260, m130, m250, m120);
    check(btLocator2 + ",branch:(name:branch1)", m270, m150, m140);
    check(btLocator2 + ",pending:true", m260, m130);
    check(btLocator2 + ",pending:true,branch:(default:true)", m260, m130);
    check(btLocator2 + ",pending:true,branch:(default:any)", m270, m260, m150, m140, m130);
    check(btLocator2 + ",pending:true,branch:(name:branch1)", m270, m150, m140);
    check(btLocator2 + ",pending:true,branch:(policy:ACTIVE_VCS_BRANCHES)", m270, m260, m150, m140, m130);
    check("build:(" + build20.getBuildId() + ")", m250, m120);
}
Also used : MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test)

Example 22 with MockVcsSupport

use of jetbrains.buildServer.serverSide.impl.MockVcsSupport in project teamcity-rest by JetBrains.

the class BuildTypeRequestTest method testCreatingWithTemplate.

@Test
public void testCreatingWithTemplate() {
    // see also alike setup in BuildTypeTest.testInheritance()
    ProjectEx project10 = createProject("project10", "project 10");
    MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
    final SVcsRoot vcsRoot10 = project10.createVcsRoot("vcs", "extId10", "name10");
    final SVcsRoot vcsRoot20 = project10.createVcsRoot("vcs", "extId20", "name20");
    final SVcsRoot vcsRoot30 = project10.createVcsRoot("vcs", "extId30", "name30");
    project10.addParameter(new SimpleParameter("p", "v"));
    BuildTypeEx bt100 = project10.createBuildType("bt100", "bt 100");
    BuildTypeEx bt110 = project10.createBuildType("bt110", "bt 110");
    BuildTypeEx bt120 = project10.createBuildType("bt120", "bt 120");
    // TEMPLATE
    BuildTypeTemplate t10 = project10.createBuildTypeTemplate("t10", "bt 10");
    t10.setArtifactPaths("aaaaa");
    t10.setBuildNumberPattern("pattern");
    t10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, true);
    t10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, true);
    t10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_t");
    t10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_AGENT");
    t10.setOption(BuildTypeOptions.BT_FAIL_ON_ANY_ERROR_MESSAGE, true);
    t10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 11);
    t10.addVcsRoot(vcsRoot10);
    t10.addVcsRoot(vcsRoot20);
    t10.setCheckoutRules(vcsRoot20, new CheckoutRules("a=>b"));
    BuildRunnerDescriptorFactory runnerDescriptorFactory = myFixture.getSingletonService(BuildRunnerDescriptorFactory.class);
    t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run10", "name10", "Ant1", map("a", "b")));
    t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run20", "name20", "Ant2", map("a", "b")));
    BuildTriggerDescriptor trigger10 = t10.addBuildTrigger("Type", map("a", "b"));
    BuildTriggerDescriptor trigger20 = t10.addBuildTrigger("Type", map("a", "b"));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f10", "type", map("a", "b")));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f20", "type", map("a", "b")));
    t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type", map("a", "b")));
    ArtifactDependencyFactory artifactDependencyFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
    ArrayList<SArtifactDependency> artifactDeps = new ArrayList<>();
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art10", bt100.getExternalId(), "path1", RevisionRules.LAST_PINNED_RULE));
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art20", bt100.getExternalId(), "path2", RevisionRules.LAST_PINNED_RULE));
    artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path3", RevisionRules.LAST_PINNED_RULE));
    t10.setArtifactDependencies(artifactDeps);
    t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt100));
    t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
    t10.addParameter(new SimpleParameter("a10", "b"));
    t10.addParameter(new SimpleParameter("a20", "b"));
    t10.addParameter(new SimpleParameter("a30", "b"));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req10", "a", null, RequirementType.EXISTS));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req20", "b", null, RequirementType.EXISTS));
    t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "c", null, RequirementType.EXISTS));
    // BUILD TYPE
    BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
    bt10.attachToTemplate(t10);
    // todo: test w/o override
    bt10.setArtifactPaths("bbbb");
    bt10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, false);
    bt10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
    {
    // hack to reproduce case related to https://youtrack.jetbrains.com/issue/TW-45273
    // comment until TW-45273 is fixed      t10.setOption(BuildTypeOptions.BT_FAIL_IF_TESTS_FAIL, false);
    }
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_bt");
    bt10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_SERVER");
    bt10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 17);
    bt10.addVcsRoot(vcsRoot20);
    bt10.setCheckoutRules(vcsRoot20, new CheckoutRules("x=>y"));
    bt10.addVcsRoot(vcsRoot30);
    bt10.setEnabled("run20", false);
    bt10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run30", "name30", "Ant30", map("a", "b")));
    bt10.setEnabled(trigger20.getId(), false);
    BuildTriggerDescriptor trigger30 = bt10.addBuildTrigger("Type", map("a", "b"));
    bt10.setEnabled("f20", false);
    bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type_bt", map("a", "b")));
    bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f40", "type", map("a", "b")));
    ArrayList<SArtifactDependency> artifactDepsBt = new ArrayList<>();
    artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path30", RevisionRules.LAST_FINISHED_RULE));
    artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art40", bt100.getExternalId(), "path4", RevisionRules.LAST_PINNED_RULE));
    bt10.setArtifactDependencies(artifactDepsBt);
    bt10.setEnabled("art20", false);
    bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
    bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt120));
    bt10.addParameter(new SimpleParameter("a20", "x"));
    bt10.addParameter(new SimpleParameter("a30", "b"));
    bt10.addParameter(new SimpleParameter("a40", "x"));
    bt10.setEnabled("req20", false);
    bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "x", null, RequirementType.EQUALS));
    bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req40", "y", null, RequirementType.EXISTS));
    // NOW, TEST TIME!
    // get buildType
    BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long"), getBeanContext(myServer));
    // post buildType to create new one
    buildType.initializeSubmittedFromUsual();
    buildType.setId("bt10_copy");
    buildType.setName("bt 10 - copy");
    BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
    // compare initial and new buildType
    BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
    assertNotNull(bt10_copy);
    assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
// todo:
// check different settings in submitted from the inherited one, but with inherited flag
// check submitting with different enabled state
// check submitting with different id
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) ArrayList(java.util.ArrayList) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTriggerDescriptor(jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 23 with MockVcsSupport

use of jetbrains.buildServer.serverSide.impl.MockVcsSupport in project teamcity-rest by JetBrains.

the class BranchFinderTest method testBranchExistsLaziness.

@Test
public void testBranchExistsLaziness() {
    final BuildTypeEx bt1 = registerBuildType("10", "Project");
    final BuildTypeEx bt2 = registerBuildType("20", "Project");
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    vcs.setDAGBased(true);
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", bt1);
    SVcsRootEx parentRoot2 = myFixture.addVcsRoot(vcs.getName(), "", bt2);
    VcsRootInstance root1 = bt1.getVcsRootInstanceForParent(parentRoot1);
    VcsRootInstance root2 = bt2.getVcsRootInstanceForParent(parentRoot2);
    assert root1 != null && root2 != null;
    setBranchSpec(root1, "+:*");
    setBranchSpec(root2, "+:*");
    final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(changesPolicy);
    SVcsModification m = myFixture.addModification(modification().in(root1).version("10").parentVersions("1"));
    SVcsModification n = myFixture.addModification(modification().in(root2).version("10").parentVersions("1"));
    changesPolicy.setCurrentState(root1, RepositoryStateData.createVersionState("master", Util.map("branch1", "10")));
    changesPolicy.setCurrentState(root2, RepositoryStateData.createVersionState("master", Util.map("branch1", "10")));
    myFixture.getVcsModificationChecker().checkForModifications(bt1.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    myFixture.getVcsModificationChecker().checkForModifications(bt2.getVcsRootInstances(), OperationRequestor.UNKNOWN);
    assertTrue("Branch 'branch1' exists.", myBranchFinder.itemsExist(new Locator("buildType:(project:(name:Project)),name:branch1")));
    List<String> usedBuildTypes = ((BranchFinder1) myBranchFinder).getBuildTypeIdsUsedInGetBranches();
    assertTrue("Lazy lookup failed: we needed to get branches of exactly one build type, second one is excessive.", usedBuildTypes.contains(bt1.getBuildTypeId()) && !usedBuildTypes.contains(bt2.getBuildTypeId()) || usedBuildTypes.contains(bt2.getBuildTypeId()) && !usedBuildTypes.contains(bt1.getBuildTypeId()));
    assertFalse("Branch 'branch2' does not exist.", myBranchFinder.itemsExist(new Locator("buildType:(project:(name:Project)),name:branch2")));
    // We must look into both buildtypes as neither of them has a branch that we look for.
    assertContains(((BranchFinder1) myBranchFinder).getBuildTypeIdsUsedInGetBranches(), bt1.getBuildTypeId(), bt2.getBuildTypeId());
}
Also used : BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) ServiceLocator(jetbrains.buildServer.ServiceLocator) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) Test(org.testng.annotations.Test)

Aggregations

MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)23 Test (org.testng.annotations.Test)20 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)10 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)6 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)6 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)5 BuildFinderTestBase (jetbrains.buildServer.server.rest.data.BuildFinderTestBase)4 Branches (jetbrains.buildServer.server.rest.model.build.Branches)4 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)4 SVcsModificationOrChangeDescriptor (jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor)3 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)3 VcsRootInstance (jetbrains.buildServer.vcs.VcsRootInstance)3 NotNull (org.jetbrains.annotations.NotNull)3 ArrayList (java.util.ArrayList)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)2 BuildTriggerDescriptor (jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor)2 BuildTypeRequest (jetbrains.buildServer.server.rest.request.BuildTypeRequest)2 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)2 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)2 TestFor (jetbrains.buildServer.util.TestFor)2