use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingParameters.
@Test
public void testUpdatingParameters() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
buildType1.addParameter(new SimpleParameter("a1", "b"));
buildType1.addParameter(new SimpleParameter("a2", "b"));
buildType1.addParameter(new SimpleParameter("a3", "b"));
final String btLocator = "id:" + buildType1.getExternalId();
assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("a4", "b"), false, Fields.LONG, myFixture), "$long");
assertEquals(4, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
myBuildTypeRequest.getParametersSubResource(btLocator).deleteParameter("a3");
assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
{
Properties submitted = new Properties();
Property p10 = new Property();
p10.name = "n1";
p10.value = null;
submitted.properties = Arrays.asList(p10);
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(submitted, "$long");
}
}, null);
assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
assertEquals(3, buildType1.getParameters().size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 1;
@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("n1", "v1"), false, Fields.LONG, myFixture));
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(submitted, "$long");
}
}, null);
assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
assertEquals(3, buildType1.getParameters().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(RuntimeException.class, new Runnable() {
public void run() {
myBuildTypeRequest.getParametersSubResource(btLocator).setParameter(new Property(new SimpleParameter("n1", "v1"), false, Fields.LONG, myFixture), "$long");
}
}, null);
assertEquals(3, myBuildTypeRequest.getParametersSubResource(btLocator).getParameters(null, "$long,property($long)").properties.size());
assertEquals(3, buildType1.getParameters().size());
myBuildTypeRequest.getParametersSubResource(btLocator).setParameters(new Properties(), "$long");
assertEquals(0, buildType1.getParameters().size());
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingTriggers.
@Test
public void testUpdatingTriggers() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
buildType1.addBuildTrigger("trigger1", createMap("a", "b"));
String disabledTriggerId = buildType1.addBuildTrigger("trigger2", createMap("a", "b")).getId();
buildType1.setEnabled(disabledTriggerId, false);
buildType1.addBuildTrigger("trigger3", createMap("a", "b"));
final String btLocator = "id:" + buildType1.getExternalId();
assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
{
PropEntityTrigger submitted = new PropEntityTrigger();
submitted.type = "triggerType1";
String newId = myBuildTypeRequest.addTrigger(btLocator, "$long", submitted).id;
assertEquals(4, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
myBuildTypeRequest.deleteTrigger(btLocator, newId);
assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private boolean myAlreadyThrown = false;
@Override
public void afterAddBuildTrigger(@NotNull final BuildTriggerDescriptor btd) {
if (!myAlreadyThrown) {
myAlreadyThrown = true;
throw new RuntimeException("I need error here ");
}
}
});
{
PropEntitiesTrigger submitted = new PropEntitiesTrigger();
PropEntityTrigger submitted1 = new PropEntityTrigger();
submitted1.type = "triggerType1";
PropEntityTrigger submitted2 = new PropEntityTrigger();
submitted2.type = "triggerType1";
submitted.propEntities = Arrays.asList(submitted1, submitted2);
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.replaceTriggers(btLocator, "$long", submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
assertEquals(3, buildType1.getBuildTriggersCollection().size());
assertFalse(buildType1.isEnabled(disabledTriggerId));
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private boolean myAlreadyThrown = false;
@Override
public void afterAddBuildTrigger(@NotNull final BuildTriggerDescriptor btd) {
if (!myAlreadyThrown) {
myAlreadyThrown = true;
throw new RuntimeException("I need error here ");
}
}
});
{
PropEntityTrigger submitted = new PropEntityTrigger();
submitted.type = "triggerType1";
checkException(RuntimeException.class, new Runnable() {
public void run() {
myBuildTypeRequest.addTrigger(btLocator, "$long", submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getTriggers(btLocator, "$long,trigger($long)").propEntities.size());
assertEquals(3, buildType1.getBuildTriggersCollection().size());
assertFalse(buildType1.isEnabled(disabledTriggerId));
}
myBuildTypeRequest.replaceTriggers(btLocator, "$long", new PropEntitiesTrigger());
assertEquals(0, buildType1.getBuildTriggersCollection().size());
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildType method getTemplates.
@Nullable
public static BuildTypes getTemplates(@NotNull final SBuildType buildType, @NotNull final Fields fields, final BeanContext beanContext) {
try {
PermissionChecker permissionChecker = beanContext.getSingletonService(PermissionChecker.class);
List<? extends BuildTypeTemplate> templates = buildType.getTemplates();
Set<String> ownTemplatesIds = buildType.getOwnTemplates().stream().map(t -> t.getInternalId()).collect(Collectors.toSet());
return new BuildTypes(templates.stream().map(t -> shouldRestrictSettingsViewing(t, permissionChecker) ? new BuildTypeOrTemplate.IdsOnly(t.getExternalId(), t.getInternalId()) : new BuildTypeOrTemplate(t)).map(t -> t.markInherited(!ownTemplatesIds.contains(t.getInternalId()))).collect(Collectors.toList()), null, fields, beanContext);
} catch (RuntimeException e) {
LOG.debug("Error retrieving templates for build configuration " + LogUtil.describe(buildType) + ": " + e.toString(), e);
List<String> templateIds = ((BuildTypeImpl) buildType).getOwnTemplateIds();
if (templateIds.isEmpty())
return null;
List<BuildTypeOrTemplate> result = getBuildTypeOrTemplates(templateIds, fields.getNestedField("template"), beanContext);
return result.isEmpty() ? null : new BuildTypes(result, null, fields, beanContext);
}
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class ChangeFinderTest method testChangesByBuildTypeFromDependenciesHaveDescriptor.
@Test
@TestFor(issues = "TW-72448")
public void testChangesByBuildTypeFromDependenciesHaveDescriptor() {
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);
myFixture.addModification(modification().in(root1).version("1").parentVersions("0"));
myFixture.addModification(modification().in(root2).version("2").parentVersions("0"));
List<SVcsModificationOrChangeDescriptor> items = getFinder().getItems("buildType:buildConf2,changesFromDependencies:true,vcsRoot:(id:" + root1.getExternalId() + ")").myEntries;
assertEquals("There is exactly one pending change coming from dependency.", 1, items.size());
ChangeDescriptor descriptor = items.get(0).getChangeDescriptor();
assertNotNull("Depency change descriptor must be present when looking for changes using build type.", 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 testChangesFromDependenciesNoDAG.
@Test
public void testChangesFromDependenciesNoDAG() {
final BuildTypeImpl buildConf1 = registerBuildType("buildConf1", "project");
final BuildTypeImpl buildConf2 = registerBuildType("buildConf2", "project");
createDependencyChain(buildConf2, buildConf1);
SVcsRoot vcsRoot1 = myFixture.addVcsRoot("svn", "", buildConf1);
SVcsModification m10 = myFixture.addModification(ModificationDataForTest.forTests("descr1", "user1", vcsRoot1, "ver1"));
SVcsRoot vcsRoot2 = myFixture.addVcsRoot("svn", "", buildConf2);
SVcsModification m20 = myFixture.addModification(ModificationDataForTest.forTests("descr2", "user2", vcsRoot2, "ver2"));
check(null, m20, m10);
String btLocator1 = "buildType:(id:" + buildConf1.getExternalId() + ")";
String btLocator2 = "buildType:(id:" + buildConf2.getExternalId() + ")";
check(btLocator1, m10);
check(btLocator1 + ",pending:true", m10);
check(btLocator2, m20);
check(btLocator2 + ",pending:true", m20);
buildConf2.setOption(BuildTypeOptions.BT_SHOW_DEPS_CHANGES, true);
check(btLocator2, m20, m10);
check(btLocator2 + ",pending:true", m20, m10);
}
Aggregations