use of jetbrains.buildServer.users.SUser 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())));
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class BuildTest method testBuildTriggering2.
@Test(expectedExceptions = BadRequestException.class)
public void testBuildTriggering2() {
final Build build = new Build();
final BuildType buildType = new BuildType();
buildType.setId(myBuildType.getExternalId());
// this generates BadRequestException
buildType.setPaused(true);
build.setBuildType(buildType);
final SUser triggeringUser = getOrCreateUser("user");
build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class BuildTest method testBuildTriggeringWithCustomStepReplacingStepsFromDefaultTemplate.
/**
* This test documents current behaviour, i.e. if we do not provide default template steps
* in the custom steps, they still occur in the custom build settings.
*/
@Test
public void testBuildTriggeringWithCustomStepReplacingStepsFromDefaultTemplate() {
BuildTypeImpl bt = registerBuildType("buildType1", "projectName");
ProjectEx project = bt.getProject();
BuildTypeTemplate tpl = project.createBuildTypeTemplate("tpl");
project.setDefaultTemplate(tpl);
tpl.addBuildRunner("t1", "runner1", Collections.emptyMap()).getId();
tpl.addBuildRunner("t2", "runner2", Collections.emptyMap()).getId();
bt.addBuildRunner("b1", "runner3", Collections.emptyMap()).getId();
project.setDefaultTemplate(tpl);
persist(project, tpl, bt);
assertEquals(Arrays.asList("t1", "t2", "b1"), bt.getBuildRunners().stream().map(r -> r.getName()).collect(Collectors.toList()));
final SUser user = getOrCreateUser("user");
final Build build = new Build();
final BuildType buildTypeEntity = new BuildType();
buildTypeEntity.setId(bt.getExternalId());
buildTypeEntity.getSettings();
PropEntitiesStep steps = new PropEntitiesStep();
PropEntityStep step = new PropEntityStep();
step.type = "runner2";
step.name = "custom";
step.properties = new Properties(createMap("x", "y"), null, Fields.ALL, getBeanContext(myFixture));
steps.propEntities = Arrays.asList(step);
buildTypeEntity.setSteps(steps);
build.setBuildType(buildTypeEntity);
SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
assertEquals(Arrays.asList("t1", "t2", "custom"), ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildRunners().stream().map(r -> r.getName()).collect(Collectors.toList()));
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class BuildTest method testBuildTriggeringWithEmptySets.
@Test
public void testBuildTriggeringWithEmptySets() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
BuildTypeImpl buildType2 = registerBuildType("buildType2", "projectName");
ArtifactDependencyFactory depsFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
SArtifactDependency dep2 = depsFactory.createArtifactDependency(buildType2, "path", RevisionRules.LAST_FINISHED_RULE);
buildType1.setArtifactDependencies(Arrays.asList(dep2));
buildType1.addVcsRoot(createVcsRoot("aaa", null));
buildType1.addBuildRunner("stepName", "runner", createMap("a", "b"));
buildType1.addBuildFeature("featureType", createMap("a", "b"));
buildType1.addParameter(new SimpleParameter("name", "value"));
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(1, result.getBuildPromotion().getArtifactDependencies().size());
assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getVcsRootEntries().size());
assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildRunners().size());
assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildFeatures().size());
assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getParameters().size());
}
// this test will actually test something only with option to copy the current settings from the build type. As so far empty build type is created, these checks check nothing
{
final Build build = new Build();
final BuildType buildTypeEntity = new BuildType();
buildTypeEntity.setId(buildType1.getExternalId());
buildTypeEntity.setArtifactDependencies(new PropEntitiesArtifactDep());
buildTypeEntity.setVcsRootEntries(new VcsRootEntries());
buildTypeEntity.setSteps(new PropEntitiesStep());
buildTypeEntity.setFeatures(new PropEntitiesFeature());
buildTypeEntity.setParameters(new Properties());
build.setBuildType(buildTypeEntity);
SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
assertEquals(0, result.getBuildPromotion().getArtifactDependencies().size());
// these cannot be overriden so far, should actually throw exception on triggering
assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getVcsRootEntries().size());
assertEquals(0, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildRunners().size());
assertEquals(0, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildFeatures().size());
assertEquals(0, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getParameters().size());
}
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class BuildTest method testBuildTriggeringWithCustomRequirements.
@Test
public void testBuildTriggeringWithCustomRequirements() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
buildType1.addRequirement(new Requirement("id1", "propName", "value", RequirementType.EQUALS));
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>());
// noinspection ConstantConditions
assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getRequirements().size());
}
{
final Build build = new Build();
final BuildType buildTypeEntity = new BuildType();
buildTypeEntity.setId(buildType1.getExternalId());
PropEntitiesAgentRequirement agentRequirements = new PropEntitiesAgentRequirement();
PropEntityAgentRequirement agentRequirement = new PropEntityAgentRequirement();
agentRequirement.type = RequirementType.EQUALS.getName();
agentRequirement.properties = new Properties(createMap("property-name", "propName2", "property-value", "value2"), null, Fields.ALL, getBeanContext(myFixture));
agentRequirements.propEntities = Arrays.asList(agentRequirement);
buildTypeEntity.setAgentRequirements(agentRequirements);
build.setBuildType(buildTypeEntity);
// this line can be removed after TW-44714 fix
build.setProperties(new Properties(createMap("disableBuildMerging", "See TW-44714"), null, Fields.ALL, getBeanContext(myFixture)));
SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
List<Requirement> actualAgentRequirements = ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getRequirements();
assertEquals(1, actualAgentRequirements.size());
assertEquals("propName2", actualAgentRequirements.iterator().next().getPropertyName());
}
}
Aggregations