Search in sources :

Example 1 with Builds

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

the class BuildTest method testBuildTriggeringWithArtifactDeps.

@Test
public void testBuildTriggeringWithArtifactDeps() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    BuildTypeImpl buildType2 = registerBuildType("buildType2", "projectName");
    BuildTypeImpl buildType3 = registerBuildType("buildType3", "projectName");
    BuildTypeImpl buildType4 = registerBuildType("buildType4", "projectName");
    SFinishedBuild build2_1 = build().in(buildType2).finish();
    SFinishedBuild build2_2 = build().in(buildType2).finish();
    SFinishedBuild build3_1 = build().in(buildType3).finish();
    SFinishedBuild build3_2 = build().in(buildType3).finish();
    SFinishedBuild build4_1 = build().in(buildType4).finish();
    ArtifactDependencyFactory depsFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
    SArtifactDependency dep2 = depsFactory.createArtifactDependency(buildType2, "path", RevisionRules.LAST_FINISHED_RULE);
    dep2.setCleanDestinationFolder(true);
    SArtifactDependency dep3 = depsFactory.createArtifactDependency(buildType3, "path2", RevisionRules.newBuildIdRule(build3_1.getBuildId(), build3_1.getBuildNumber()));
    dep3.setCleanDestinationFolder(false);
    buildType1.setArtifactDependencies(Arrays.asList(dep2, dep3));
    final SUser user = getOrCreateUser("user");
    // end of setup
    final Build build = new Build();
    final BuildType buildTypeEntity = new BuildType();
    buildTypeEntity.setId(buildType1.getExternalId());
    build.setBuildType(buildTypeEntity);
    SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(2, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType2.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals("latest.lastFinished", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    assertEquals(buildType3.getId(), result.getBuildPromotion().getArtifactDependencies().get(1).getSourceBuildTypeId());
    assertEquals(build3_1.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(1).getRevisionRule().getRevision());
    Builds builds1 = new Builds();
    Build build1 = new Build();
    build1.setLocator("buildType:(id:" + buildType3.getExternalId() + "),number:" + build3_2.getBuildNumber());
    builds1.builds = Arrays.asList(build1);
    build.setBuildArtifactDependencies(builds1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType3.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals(build3_2.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    Builds builds2 = new Builds();
    Build build2 = new Build();
    build2.setLocator("buildType:(id:" + buildType4.getExternalId() + "),number:" + build4_1.getBuildNumber());
    builds2.builds = Arrays.asList(build2);
    build.setBuildArtifactDependencies(builds2);
    checkException(BadRequestException.class, new Runnable() {

        public void run() {
            build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        }
    }, "triggering build with artifact dependency not in default artifact dependencies");
    build.setBuildArtifactDependencies(builds1);
    PropEntitiesArtifactDep propEntitiesArtifactDep1 = new PropEntitiesArtifactDep();
    propEntitiesArtifactDep1.setReplace("false");
    build.setCustomBuildArtifactDependencies(propEntitiesArtifactDep1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(2, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType3.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals(build3_2.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    assertEquals(buildType2.getId(), result.getBuildPromotion().getArtifactDependencies().get(1).getSourceBuildTypeId());
    assertEquals("latest.lastFinished", result.getBuildPromotion().getArtifactDependencies().get(1).getRevisionRule().getRevision());
    PropEntitiesArtifactDep propEntitiesArtifactDep2 = new PropEntitiesArtifactDep();
    PropEntityArtifactDep propEntityArtifactDep1 = new PropEntityArtifactDep();
    propEntityArtifactDep1.properties = new Properties(createMap("revisionName", "buildId", "revisionValue", "1000", "pathRules", "path3", "cleanDestinationDirectory", "true"), null, Fields.ALL_NESTED, getBeanContext(myFixture));
    propEntityArtifactDep1.sourceBuildType = new BuildType();
    propEntityArtifactDep1.sourceBuildType.setId(buildType4.getExternalId());
    propEntityArtifactDep1.type = "artifact_dependency";
    propEntitiesArtifactDep2.propEntities = Arrays.asList(propEntityArtifactDep1);
    build.setCustomBuildArtifactDependencies(propEntitiesArtifactDep2);
    checkException(BadRequestException.class, new Runnable() {

        public void run() {
            build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        }
    }, "triggering build with artifact dependency not in posted custom-artifact-dependnecies");
    build.setBuildArtifactDependencies(null);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType4.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals("1000" + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    assertEquals("path3", result.getBuildPromotion().getArtifactDependencies().get(0).getSourcePaths());
    assertEquals(true, result.getBuildPromotion().getArtifactDependencies().get(0).isCleanDestinationFolder());
    build.setBuildArtifactDependencies(builds2);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(buildType4.getId(), result.getBuildPromotion().getArtifactDependencies().get(0).getSourceBuildTypeId());
    assertEquals(build4_1.getBuildId() + ".tcbuildid", result.getBuildPromotion().getArtifactDependencies().get(0).getRevisionRule().getRevision());
    propEntitiesArtifactDep2.setReplace("false");
    build.setCustomBuildArtifactDependencies(propEntitiesArtifactDep2);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(3, result.getBuildPromotion().getArtifactDependencies().size());
}
Also used : Builds(jetbrains.buildServer.server.rest.model.build.Builds) SUser(jetbrains.buildServer.users.SUser) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) Build(jetbrains.buildServer.server.rest.model.build.Build) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 2 with Builds

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

the class BuildTest method testBuildTriggeringWithTwoArtifactDepsOnSameBuildType.

@Test
public void testBuildTriggeringWithTwoArtifactDepsOnSameBuildType() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    BuildTypeImpl buildType2 = registerBuildType("buildType2", "projectName");
    BuildTypeImpl buildType3 = registerBuildType("buildType3", "projectName");
    BuildTypeImpl buildType4 = registerBuildType("buildType4", "projectName");
    SFinishedBuild build2_1 = build().in(buildType2).finish();
    SFinishedBuild build2_2 = build().in(buildType2).finish();
    SFinishedBuild build2_3 = build().in(buildType2).finish();
    SFinishedBuild build3_1 = build().in(buildType3).finish();
    SFinishedBuild build3_2 = build().in(buildType3).finish();
    SFinishedBuild build3_3 = build().in(buildType3).finish();
    SFinishedBuild build4_1 = build().in(buildType4).finish();
    ArtifactDependencyFactory depsFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
    SArtifactDependency dep2_1 = depsFactory.createArtifactDependency(buildType2, "path2_1", RevisionRules.newBuildNumberRule(build2_2.getBuildNumber()));
    dep2_1.setCleanDestinationFolder(true);
    SArtifactDependency dep2_2 = depsFactory.createArtifactDependency(buildType2, "path2_2=>a", RevisionRules.LAST_FINISHED_RULE);
    dep2_2.setCleanDestinationFolder(false);
    SArtifactDependency dep3 = depsFactory.createArtifactDependency(buildType3, "path3=>b", RevisionRules.newBuildIdRule(build3_1.getBuildId(), build3_1.getBuildNumber()));
    dep3.setCleanDestinationFolder(false);
    buildType1.setArtifactDependencies(Arrays.asList(dep2_1, dep2_2, dep3));
    final SUser user = getOrCreateUser("user");
    // end of setup
    final Build build = new Build();
    final BuildType buildTypeEntity = new BuildType();
    buildTypeEntity.setId(buildType1.getExternalId());
    build.setBuildType(buildTypeEntity);
    SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(3, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(result.getBuildPromotion().getArtifactDependencies(), EQUALS_TEST, new TestArtifactDep(buildType2.getBuildTypeId(), "path2_1", true, RevisionRules.newBuildNumberRule(build2_2.getBuildNumber())), new TestArtifactDep(buildType2.getBuildTypeId(), "path2_2=>a", false, RevisionRules.LAST_FINISHED_RULE), new TestArtifactDep(buildType3.getBuildTypeId(), "path3=>b", false, RevisionRules.newBuildIdRule(build3_1.getBuildId(), build3_1.getBuildNumber())));
    Builds builds1 = new Builds();
    Build build1 = new Build();
    build1.setLocator("id:" + build3_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    build.setBuildArtifactDependencies(builds1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(result.getBuildPromotion().getArtifactDependencies(), EQUALS_TEST, new TestArtifactDep(buildType3.getBuildTypeId(), "path3=>b", false, RevisionRules.newBuildIdRule(build3_1.getBuildId(), build3_1.getBuildNumber())));
    builds1 = new Builds();
    build1 = new Build();
    build1.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    build.setBuildArtifactDependencies(builds1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(1, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(result.getBuildPromotion().getArtifactDependencies(), EQUALS_TEST, new TestArtifactDep(buildType2.getBuildTypeId(), "path2_1", true, RevisionRules.newBuildIdRule(build2_1.getBuildId(), build2_1.getBuildNumber())));
    builds1 = new Builds();
    build1 = new Build();
    build1.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    Build build2 = new Build();
    build2.setLocator("id:" + build2_2.getBuildId());
    builds1.builds = Arrays.asList(build1, build2);
    build.setBuildArtifactDependencies(builds1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(2, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(result.getBuildPromotion().getArtifactDependencies(), EQUALS_TEST, new TestArtifactDep(buildType2.getBuildTypeId(), "path2_1", true, RevisionRules.newBuildIdRule(build2_1.getBuildId(), build2_1.getBuildNumber())), new TestArtifactDep(buildType2.getBuildTypeId(), "path2_2=>a", false, RevisionRules.newBuildIdRule(build2_2.getBuildId(), build2_2.getBuildNumber())));
    builds1 = new Builds();
    build1 = new Build();
    build1.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    build2 = new Build();
    build2.setLocator("id:" + build2_2.getBuildId());
    builds1.builds = Arrays.asList(build2, build1);
    build.setBuildArtifactDependencies(builds1);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(2, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(result.getBuildPromotion().getArtifactDependencies(), EQUALS_TEST, new TestArtifactDep(buildType2.getBuildTypeId(), "path2_1", true, RevisionRules.newBuildIdRule(build2_2.getBuildId(), build2_2.getBuildNumber())), new TestArtifactDep(buildType2.getBuildTypeId(), "path2_2=>a", false, RevisionRules.newBuildIdRule(build2_1.getBuildId(), build2_1.getBuildNumber())));
    builds1 = new Builds();
    build1 = new Build();
    build1.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    build2 = new Build();
    build2.setLocator("id:" + build2_2.getBuildId());
    Build build3 = new Build();
    build3.setLocator("id:" + build2_3.getBuildId());
    builds1.builds = Arrays.asList(build2, build3, build1);
    build.setBuildArtifactDependencies(builds1);
    checkException(BadRequestException.class, new Runnable() {

        public void run() {
            build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        }
    }, "triggering build with more builds in artifact dependencies then there are default artifact dependencies");
    builds1 = new Builds();
    build1 = new Build();
    build1.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    build2 = new Build();
    build2.setLocator("id:" + build2_2.getBuildId());
    build3 = new Build();
    build3.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build2, build3, build1);
    build.setBuildArtifactDependencies(builds1);
    PropEntitiesArtifactDep customDeps = new PropEntitiesArtifactDep();
    PropEntityArtifactDep dep1 = new PropEntityArtifactDep();
    dep1.properties = new Properties(createMap("revisionName", "buildId", "revisionValue", "1000", "pathRules", "path3=>x", "cleanDestinationDirectory", "true"), null, Fields.ALL_NESTED, getBeanContext(myFixture));
    dep1.sourceBuildType = new BuildType();
    dep1.sourceBuildType.setId(buildType2.getExternalId());
    dep1.type = "artifact_dependency";
    customDeps.propEntities = Arrays.asList(dep1);
    build.setCustomBuildArtifactDependencies(customDeps);
    checkException(BadRequestException.class, new Runnable() {

        public void run() {
            build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        }
    }, "triggering build with more builds in artifact dependencies then there are in custom artifact dependencies");
    builds1 = new Builds();
    build1 = new Build();
    build1.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    build2 = new Build();
    build2.setLocator("id:" + build2_2.getBuildId());
    builds1.builds = Arrays.asList(build1, build2);
    build.setBuildArtifactDependencies(builds1);
    customDeps = new PropEntitiesArtifactDep();
    customDeps.setReplace("false");
    build.setCustomBuildArtifactDependencies(customDeps);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(3, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(result.getBuildPromotion().getArtifactDependencies(), EQUALS_TEST, new TestArtifactDep(buildType2.getBuildTypeId(), "path2_1", true, RevisionRules.newBuildIdRule(build2_1.getBuildId(), build2_1.getBuildNumber())), new TestArtifactDep(buildType2.getBuildTypeId(), "path2_2=>a", false, RevisionRules.newBuildIdRule(build2_2.getBuildId(), build2_2.getBuildNumber())), new TestArtifactDep(buildType3.getBuildTypeId(), "path3=>b", false, RevisionRules.newBuildIdRule(build3_1.getBuildId(), build3_1.getBuildNumber())));
    builds1 = new Builds();
    build1 = new Build();
    build1.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build1);
    build2 = new Build();
    build2.setLocator("id:" + build2_2.getBuildId());
    build3 = new Build();
    build3.setLocator("id:" + build2_1.getBuildId());
    builds1.builds = Arrays.asList(build2, build3, build1);
    build.setBuildArtifactDependencies(builds1);
    customDeps = new PropEntitiesArtifactDep();
    dep1 = new PropEntityArtifactDep();
    dep1.properties = new Properties(createMap("revisionName", "buildId", "revisionValue", "1000", "pathRules", "path3=>x", "cleanDestinationDirectory", "true"), null, Fields.ALL_NESTED, getBeanContext(myFixture));
    dep1.sourceBuildType = new BuildType();
    dep1.sourceBuildType.setId(buildType2.getExternalId());
    dep1.type = "artifact_dependency";
    customDeps.propEntities = Arrays.asList(dep1);
    customDeps.setReplace("false");
    build.setCustomBuildArtifactDependencies(customDeps);
    result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals(4, result.getBuildPromotion().getArtifactDependencies().size());
    assertEquals(result.getBuildPromotion().getArtifactDependencies(), EQUALS_TEST, new TestArtifactDep(buildType2.getBuildTypeId(), "path2_1", true, RevisionRules.newBuildIdRule(build2_2.getBuildId(), build2_2.getBuildNumber())), new TestArtifactDep(buildType2.getBuildTypeId(), "path2_2=>a", false, RevisionRules.newBuildIdRule(build2_1.getBuildId(), build2_1.getBuildNumber())), new TestArtifactDep(buildType2.getBuildTypeId(), "path3=>x", true, RevisionRules.newBuildIdRule(build2_1.getBuildId(), build2_1.getBuildNumber())), new TestArtifactDep(buildType3.getBuildTypeId(), "path3=>b", false, RevisionRules.newBuildIdRule(build3_1.getBuildId(), build3_1.getBuildNumber())));
}
Also used : Builds(jetbrains.buildServer.server.rest.model.build.Builds) SUser(jetbrains.buildServer.users.SUser) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) Build(jetbrains.buildServer.server.rest.model.build.Build) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Aggregations

BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 Build (jetbrains.buildServer.server.rest.model.build.Build)2 Builds (jetbrains.buildServer.server.rest.model.build.Builds)2 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)2 SUser (jetbrains.buildServer.users.SUser)2 Test (org.testng.annotations.Test)2