use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class ChangeFinderTest method testChangesByBuildIdFromDependenciesHaveDescriptor.
@Test
@TestFor(issues = "TW-60774")
public void testChangesByBuildIdFromDependenciesHaveDescriptor() {
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, "+:*");
SVcsModification m1 = myFixture.addModification(modification().in(root1).version("1").parentVersions("0"));
SVcsModification m2 = myFixture.addModification(modification().in(root2).version("2").parentVersions("0"));
SQueuedBuild qb1 = build().in(buildConf1).onModifications(m1).addToQueue();
SQueuedBuild qb2 = build().in(buildConf2).onModifications(m2).snapshotDepends(qb1.getBuildPromotion()).addToQueue();
SFinishedBuild build1 = finishBuild(myFixture.flushQueueAndWait(), false);
SFinishedBuild build2 = finishBuild(myFixture.flushQueueAndWait(), false);
List<SVcsModificationOrChangeDescriptor> items = getFinder().getItems("build:" + build2.getBuildId() + ",changesFromDependencies:true,vcsRoot:(id:" + root1.getExternalId() + ")").myEntries;
assertEquals("There is exactly one change coming from dependency.", 1, items.size());
ChangeDescriptor descriptor = items.get(0).getChangeDescriptor();
assertNotNull("Change descriptor must be present when looking for changes using build id.", descriptor);
assertEquals(ChangeDescriptorConstants.SNAPSHOT_DEPENDENCY_VCS_CHANGE, descriptor.getType());
SVcsModification modification = items.get(0).getSVcsModification();
assertEquals("1", modification.getDisplayVersion());
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class ChangeFinderTest method testBranchFromBranch.
@Test
public void testBranchFromBranch() {
final BuildTypeImpl buildConf = registerBuildType("buildConf1", "project");
MockVcsSupport vcs = new MockVcsSupport("vcs");
vcs.setDAGBased(true);
myFixture.getVcsManager().registerVcsSupport(vcs);
SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", buildConf);
VcsRootInstance root1 = buildConf.getVcsRootInstanceForParent(parentRoot1);
assert root1 != null;
setBranchSpec(root1, "+:*");
final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
vcs.setCollectChangesPolicy(changesPolicy);
SVcsModification m20 = myFixture.addModification(modification().in(root1).version("20").parentVersions("10"));
build().in(buildConf).onModifications(m20).finish();
SVcsModification m30 = myFixture.addModification(modification().in(root1).version("30").parentVersions("20"));
SVcsModification m40 = myFixture.addModification(modification().in(root1).version("40").parentVersions("30"));
SVcsModification m45 = myFixture.addModification(modification().in(root1).version("45").parentVersions("30"));
SVcsModification m60 = myFixture.addModification(modification().in(root1).version("60").parentVersions("20"));
changesPolicy.setCurrentState(root1, RepositoryStateData.createVersionState("master", Util.map("master", "60", "branch1", "40", "branch2", "45")));
myFixture.getVcsModificationChecker().checkForModifications(buildConf.getVcsRootInstances(), OperationRequestor.UNKNOWN);
check(null, m60, m45, m40, m30, m20);
String btLocator = "buildType:(id:" + buildConf.getExternalId() + ")";
// documenting current behavior, should be check(btLocator, m60, m20);
check(btLocator, m60, m45, m40, m30, m20);
check(btLocator + ",branch:(default:any)", m60, m45, m40, m30, m20);
check(btLocator + ",pending:true", m60);
check(btLocator + ",pending:true,branch:branch1", m40, m30);
check(btLocator + ",pending:true,branch:(default:false)", m45, m40, m30);
check(btLocator + ",pending:true,branch:(default:any)", m60, m45, m40, m30);
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingArtifactDependencies.
@Test
public void testUpdatingArtifactDependencies() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
BuildTypeImpl buildType2 = registerBuildType("buildType2", "projectName");
ArtifactDependencyFactory factory = myFixture.findSingletonService(ArtifactDependencyFactory.class);
assert factory != null;
SArtifactDependency dep1 = factory.createArtifactDependency(buildType2, "paths1", RevisionRules.LAST_FINISHED_RULE);
String disabledId = "id2";
SArtifactDependency dep2 = factory.createArtifactDependency(disabledId, buildType2.getExternalId(), "paths2", RevisionRules.LAST_FINISHED_RULE);
buildType1.setEnabled(disabledId, false);
SArtifactDependency dep3 = factory.createArtifactDependency(buildType2, "paths3", RevisionRules.LAST_FINISHED_RULE);
buildType1.setArtifactDependencies(Arrays.asList(dep1, dep2, dep3));
final String btLocator = "id:" + buildType1.getExternalId();
assertEquals(3, myBuildTypeRequest.getArtifactDeps(btLocator, "$long,artifact-dependencies($long)").propEntities.size());
{
PropEntityArtifactDep submitted = new PropEntityArtifactDep();
submitted.type = "artifact_dependency";
submitted.sourceBuildType = new BuildType();
submitted.sourceBuildType.setId(buildType2.getExternalId());
submitted.properties = new Properties();
submitted.properties.properties = Arrays.asList(new Property(new SimpleParameter("revisionName", "aaa"), false, Fields.LONG, myFixture), new Property(new SimpleParameter("revisionValue", "aaa"), false, Fields.LONG, myFixture), new Property(new SimpleParameter("pathRules", "aaa"), false, Fields.LONG, myFixture));
submitted.disabled = true;
String newId = myBuildTypeRequest.addArtifactDep(btLocator, "$long", submitted).id;
assertEquals(4, myBuildTypeRequest.getArtifactDeps(btLocator, "$long,artifact-dependencies($long)").propEntities.size());
assertTrue(myBuildTypeRequest.getArtifactDeps(btLocator, "$long,artifact-dependencies($long)").propEntities.get(3).disabled);
myBuildTypeRequest.deleteArtifactDep(btLocator, newId);
assertEquals(3, myBuildTypeRequest.getArtifactDeps(btLocator, "$long,artifact-dependencies($long)").propEntities.size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private boolean myAlreadyThrown = false;
@Override
public void textValueChanged() {
if (!myAlreadyThrown) {
myAlreadyThrown = true;
throw new RuntimeException("I need error here ");
}
}
});
{
PropEntitiesArtifactDep submitted = new PropEntitiesArtifactDep();
PropEntityArtifactDep submitted1 = new PropEntityArtifactDep();
submitted1.type = "artifact_dependency";
submitted1.sourceBuildType = new BuildType();
submitted1.sourceBuildType.setId(buildType2.getExternalId());
submitted1.properties = new Properties();
submitted1.properties.properties = Arrays.asList(new Property(new SimpleParameter("revisionName", "aaa"), false, Fields.LONG, myFixture), new Property(new SimpleParameter("revisionValue", "aaa"), false, Fields.LONG, myFixture), new Property(new SimpleParameter("pathRules", "aaa"), false, Fields.LONG, myFixture));
submitted.propEntities = Arrays.asList(submitted1);
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.replaceArtifactDeps(btLocator, "$long", submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getArtifactDeps(btLocator, "$long,artifact-dependencies($long)").propEntities.size());
assertEquals(3, buildType1.getArtifactDependencies().size());
assertFalse(buildType1.isEnabled(disabledId));
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private boolean myAlreadyThrown = false;
@Override
public void textValueChanged() {
if (!myAlreadyThrown) {
myAlreadyThrown = true;
throw new RuntimeException("I need error here ");
}
}
});
{
PropEntityArtifactDep submitted = new PropEntityArtifactDep();
submitted.type = "artifact_dependency";
submitted.sourceBuildType = new BuildType();
submitted.sourceBuildType.setId(buildType2.getExternalId());
submitted.properties = new Properties();
submitted.properties.properties = Arrays.asList(new Property(new SimpleParameter("revisionName", "aaa"), false, Fields.LONG, myFixture), new Property(new SimpleParameter("revisionValue", "aaa"), false, Fields.LONG, myFixture), new Property(new SimpleParameter("pathRules", "aaa"), false, Fields.LONG, myFixture));
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.addArtifactDep(btLocator, "$long", submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getArtifactDeps(btLocator, "$long,artifact-dependencies($long)").propEntities.size());
assertEquals(3, buildType1.getArtifactDependencies().size());
assertFalse(buildType1.isEnabled(disabledId));
}
myBuildTypeRequest.replaceArtifactDeps(btLocator, "$long", new PropEntitiesArtifactDep());
assertEquals(0, buildType1.getArtifactDependencies().size());
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingParametersWithTemplate2.
@Test
public void testUpdatingParametersWithTemplate2() {
BuildTypeImpl buildType1 = registerTemplateBasedBuildType("buildType1");
buildType1.addParameter(new SimpleParameter("a1", "b10"));
buildType1.addParameter(new SimpleParameter("a2", "b9"));
buildType1.addParameter(new SimpleParameter("a3", "b8"));
buildType1.getTemplate().addParameter(new SimpleParameter("a1", "a7"));
buildType1.getTemplate().addParameter(new SimpleParameter("a2", "b9"));
buildType1.getTemplate().addParameter(new SimpleParameter("t1", "a5"));
final String btLocator = "id:" + buildType1.getExternalId();
final String templateLocator = "id:" + buildType1.getTemplate().getExternalId() + ",templateFlag:true";
assertEquals(4, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
assertEquals(3, myBuildTypeRequest.getParametersSubResource(templateLocator).getParameters(null, "$long,property($long)").properties.size());
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 1;
@Override
public void textValueChanged() {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
assertEquals(3, buildType1.getOwnParameters().size());
{
Properties submitted = new Properties();
submitted.properties = Arrays.asList(new Property(new SimpleParameter("n1", "v1"), false, Fields.LONG, myFixture));
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(submitted, "$long");
}
}, null);
assertEquals(4, buildType1.getParameters().size());
assertEquals(3, buildType1.getOwnParameters().size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
// 4 removals and one set
private int myTriggerOnCall = 5;
@Override
public void textValueChanged() {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
{
Properties submitted = new Properties();
submitted.properties = Arrays.asList(new Property(new SimpleParameter("t1", "new"), false, Fields.LONG, myFixture));
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(submitted, "$long");
}
}, null);
assertEquals(4, buildType1.getParameters().size());
assertEquals(3, buildType1.getOwnParameters().size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 1;
@Override
public void textValueChanged() {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
{
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("t1", "new"), false, Fields.LONG, myFixture), "$long");
}
}, null);
assertEquals(4, buildType1.getParameters().size());
assertEquals(3, buildType1.getOwnParameters().size());
}
{
myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("t1", "a5"), true, Fields.LONG, myFixture), "$long");
assertEquals(4, buildType1.getParameters().size());
assertEquals(3, buildType1.getOwnParameters().size());
}
{
myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("t1", "a5"), false, Fields.LONG, myFixture), "$long");
assertEquals(4, buildType1.getParameters().size());
assertEquals(4, buildType1.getOwnParameters().size());
buildType1.removeParameter("t1");
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 1;
@Override
public void textValueChanged() {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
checkException(RuntimeException.class, new Runnable() {
public void run() {
myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("n1", "v1"), false, Fields.LONG, myFixture), "$long");
}
}, null);
assertEquals(4, buildType1.getParameters().size());
assertEquals(3, buildType1.getOwnParameters().size());
myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(new Properties(), "$long");
assertEquals(3, buildType1.getParameters().size());
assertEquals(0, buildType1.getOwnParameters().size());
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingSteps.
@Test
public void testUpdatingSteps() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
buildType1.addBuildRunner("name1", "runnerType1", createMap("a", "b"));
String disabledId = buildType1.addBuildRunner("name2", "runnerType1", createMap("a", "b")).getId();
buildType1.setEnabled(disabledId, false);
buildType1.addBuildRunner("name3", "runnerType1", createMap("a", "b"));
final String btLocator = "id:" + buildType1.getExternalId();
assertEquals(3, myBuildTypeRequest.getSteps(btLocator, "$long,step($long)").propEntities.size());
{
PropEntityStep submitted = new PropEntityStep();
submitted.name = "name4";
submitted.type = "runnerType1";
submitted.disabled = true;
String newId = myBuildTypeRequest.addStep(btLocator, "$long,step($long)", submitted).id;
List<PropEntityStep> steps = myBuildTypeRequest.getSteps(btLocator, "$long,step($long)").propEntities;
assertEquals(4, steps.size());
assertTrue(steps.get(3).disabled);
myBuildTypeRequest.deleteStep(btLocator, newId);
assertEquals(3, myBuildTypeRequest.getSteps(btLocator, "$long,step($long)").propEntities.size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 4;
@Override
public void newBuildRunnersOrderApplied(@NotNull final String[] ids) {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
{
PropEntitiesStep submitted = new PropEntitiesStep();
PropEntityStep submitted1 = new PropEntityStep();
submitted1.type = "a";
PropEntityStep submitted2 = new PropEntityStep();
submitted2.type = "b";
submitted.propEntities = Arrays.asList(submitted1, submitted2);
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.replaceSteps(btLocator, "$long", submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getSteps(btLocator, "$long,step($long)").propEntities.size());
assertEquals(3, buildType1.getBuildRunners().size());
assertFalse(buildType1.isEnabled(disabledId));
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 1;
@Override
public void newBuildRunnersOrderApplied(@NotNull final String[] ids) {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
{
PropEntityStep submitted = new PropEntityStep();
submitted.type = "a";
checkException(RuntimeException.class, new Runnable() {
public void run() {
myBuildTypeRequest.addStep(btLocator, "$long", submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getSteps(btLocator, "$long,step($long)").propEntities.size());
assertEquals(3, buildType1.getBuildRunners().size());
assertFalse(buildType1.isEnabled(disabledId));
}
myBuildTypeRequest.replaceSteps(btLocator, "$long", new PropEntitiesStep());
assertEquals(0, buildType1.getBuildRunners().size());
}
Aggregations