use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testCreatingWithDefaultTemplate.
@Test
public void testCreatingWithDefaultTemplate() {
ProjectEx project10 = getRootProject().createProject("project10", "project10");
project10.addParameter(new SimpleParameter("e", "1"));
BuildTypeTemplate t10 = project10.createBuildTypeTemplate("t10", "t10");
t10.addParameter(new SimpleParameter("d", "1"));
t10.addParameter(new SimpleParameter("a", "1"));
BuildTypeTemplate t20 = project10.createBuildTypeTemplate("t20", "t20");
t20.addParameter(new SimpleParameter("a", "2"));
t20.addParameter(new SimpleParameter("b", "1"));
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt10");
bt10.addParameter(new SimpleParameter("a", "3"));
bt10.addParameter(new SimpleParameter("c", "1"));
project10.setDefaultTemplate(t10);
bt10.setTemplates(Arrays.asList(t20), false);
{
BuildType buildType = myBuildTypeRequest.serveBuildTypeXML("id:" + bt10.getExternalId(), "$long");
buildType.initializeSubmittedFromUsual();
buildType.setId("bt20");
buildType.setName("bt20");
myBuildTypeRequest.addBuildType(buildType, "$long");
}
BuildTypeImpl bt20 = myFixture.getProjectManager().findBuildTypeByExternalId("bt20");
assertEquals(bt10.getTemplates(), bt20.getTemplates());
assertEquals(bt10.getOwnTemplates(), bt20.getOwnTemplates());
assertEquals(bt10.getOwnParameters(), bt20.getOwnParameters());
bt10.setTemplates(Arrays.asList(t10, t20), false);
{
BuildType buildType = myBuildTypeRequest.serveBuildTypeXML("id:" + bt10.getExternalId(), "$long");
buildType.initializeSubmittedFromUsual();
buildType.setId("bt30");
buildType.setName("bt30");
myBuildTypeRequest.addBuildType(buildType, "$long");
}
BuildTypeImpl bt30 = myFixture.getProjectManager().findBuildTypeByExternalId("bt30");
assertEquals(bt10.getTemplates(), bt30.getTemplates());
assertEquals(bt10.getOwnTemplates(), bt30.getOwnTemplates());
assertEquals(bt10.getOwnParameters(), bt30.getOwnParameters());
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingSteps2.
@Test
public void testUpdatingSteps2() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
SBuildRunnerDescriptor buildRunner1 = 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();
{
Properties properties = new Properties();
Property prop = new Property();
prop.name = "x";
// no value
properties.properties = new ArrayList<>();
properties.properties.add(prop);
assertExceptionThrown(() -> myBuildTypeRequest.replaceStepParameters(btLocator, buildRunner1.getId(), properties, "$long"), BadRequestException.class);
}
{
Properties properties = new Properties();
Property prop = new Property();
prop.name = "";
prop.value = "y";
properties.properties = new ArrayList<>();
properties.properties.add(prop);
assertExceptionThrown(() -> myBuildTypeRequest.replaceStepParameters(btLocator, buildRunner1.getId(), properties, "$long"), BadRequestException.class);
}
{
Properties properties = new Properties();
Property prop = new Property();
prop.name = "x";
prop.value = "y";
properties.properties = new ArrayList<>();
properties.properties.add(prop);
assertEquals("b", buildType1.findBuildRunnerById(buildRunner1.getId()).getParameters().get("a"));
myBuildTypeRequest.replaceStepParameters(btLocator, buildRunner1.getId(), properties, "$long");
assertEquals("y", buildType1.findBuildRunnerById(buildRunner1.getId()).getParameters().get("x"));
assertNull(buildType1.findBuildRunnerById(buildRunner1.getId()).getParameters().get("a"));
}
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingVcsRoots.
@Test
public void testUpdatingVcsRoots() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
buildType1.addVcsRoot(createVcsRoot("name1", null));
buildType1.addVcsRoot(createVcsRoot("name2", null));
buildType1.addVcsRoot(createVcsRoot("name3", null));
String newRootId = createVcsRoot("name4", null).getExternalId();
final String btLocator = "id:" + buildType1.getExternalId();
assertEquals(3, myBuildTypeRequest.getVcsRootEntries(btLocator, "$long,vcs-root-entry($long)").vcsRootAssignments.size());
{
VcsRootEntry submitted = new VcsRootEntry();
submitted.vcsRoot = new VcsRoot();
submitted.vcsRoot.id = newRootId;
myBuildTypeRequest.addVcsRootEntry(btLocator, submitted, "$long");
assertEquals(4, myBuildTypeRequest.getVcsRootEntries(btLocator, "$long,vcs-root-entry($long)").vcsRootAssignments.size());
myBuildTypeRequest.deleteVcsRootEntry(btLocator, newRootId);
assertEquals(3, myBuildTypeRequest.getVcsRootEntries(btLocator, "$long,vcs-root-entry($long)").vcsRootAssignments.size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 1;
@Override
public void afterAddVcsRoot(@NotNull final SVcsRoot vcsRoot) {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
{
VcsRootEntries submitted = new VcsRootEntries();
VcsRootEntry submitted1 = new VcsRootEntry();
submitted1.vcsRoot = new VcsRoot();
submitted1.vcsRoot.id = newRootId;
submitted.vcsRootAssignments = Arrays.asList(submitted1);
checkException(RuntimeException.class, new Runnable() {
public void run() {
myBuildTypeRequest.replaceVcsRootEntries(btLocator, submitted, "$long");
}
}, null);
assertEquals(3, myBuildTypeRequest.getVcsRootEntries(btLocator, "$long,vcs-root-entry($long)").vcsRootAssignments.size());
assertEquals(3, buildType1.getVcsRootEntries().size());
}
buildType1.getSettings().addListener(new BuildTypeSettingsAdapter() {
private int myTriggerOnCall = 1;
@Override
public void afterAddVcsRoot(@NotNull final SVcsRoot vcsRoot) {
if (--myTriggerOnCall == 0) {
throw new RuntimeException("I need error here ");
}
}
});
{
VcsRootEntry submitted = new VcsRootEntry();
submitted.vcsRoot = new VcsRoot();
submitted.vcsRoot.id = newRootId;
checkException(RuntimeException.class, new Runnable() {
public void run() {
myBuildTypeRequest.addVcsRootEntry(btLocator, submitted, "$long");
}
}, null);
assertEquals(3, myBuildTypeRequest.getVcsRootEntries(btLocator, "$long,vcs-root-entry($long)").vcsRootAssignments.size());
assertEquals(3, buildType1.getVcsRootEntries().size());
}
{
myBuildTypeRequest.replaceVcsRootEntries(btLocator, new VcsRootEntries(), "$long");
assertEquals(0, buildType1.getVcsRootEntries().size());
}
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testCreatingWithInheritedParams.
@Test
public void testCreatingWithInheritedParams() {
// see also alike setup in BuildTypeTest.testInheritance()
ProjectEx project10 = createProject("project10", "project 10");
final ParameterFactory parameterFactory = myFixture.getSingletonService(ParameterFactory.class);
project10.addParameter(parameterFactory.createTypedParameter("a_pwd", "secret", "password"));
project10.addParameter(new SimpleParameter("b_normal", "value"));
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
// 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());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
bt10_copy.remove();
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(1).value = null;
buildType.setParameters(parameters);
BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
bt10_copy.remove();
// reset params
buildType.setParameters(buildType.getParameters());
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).type.rawValue = "text";
buildType.setParameters(parameters);
checkException(BadRequestException.class, () -> myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec()), null);
// reset params
buildType.setParameters(buildType.getParameters());
}
{
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).inherited = null;
buildType.setParameters(parameters);
}
checkException(BadRequestException.class, () -> myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec()), null);
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).inherited = false;
buildType.setParameters(parameters);
}
checkException(BadRequestException.class, () -> myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec()), null);
// reset params
buildType.setParameters(buildType.getParameters());
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).value = "secret";
buildType.setParameters(parameters);
BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
assertNull(BuildTypeUtil.compareBuildTypes(bt10.getSettings(), bt10_copy.getSettings(), true, false));
bt10_copy.remove();
// reset params
buildType.setParameters(buildType.getParameters());
}
{
Properties parameters = buildType.getParameters();
parameters.properties.get(0).value = "secret2";
buildType.setParameters(parameters);
BuildType buildType_copy = myBuildTypeRequest.addBuildType(buildType, Fields.LONG.getFieldsSpec());
BuildTypeImpl bt10_copy = myFixture.getProjectManager().findBuildTypeByExternalId("bt10_copy");
assertNotNull(bt10_copy);
// present - another value
assertNotNull(bt10_copy.getOwnParameter("a_pwd"));
assertEquals("secret2", parameterFactory.getRawValue(bt10_copy.getOwnParameter("a_pwd")));
bt10_copy.remove();
// reset params
buildType.setParameters(buildType.getParameters());
}
}
use of jetbrains.buildServer.serverSide.impl.BuildTypeImpl in project teamcity-rest by JetBrains.
the class BuildTypeRequestTest method testUpdatingAgentRequirements.
@Test
public void testUpdatingAgentRequirements() {
BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
buildType1.addRequirement(new Requirement("prop1", null, RequirementType.EXISTS));
String disabledId = "id2";
buildType1.addRequirement(new Requirement(disabledId, "prop2", null, RequirementType.EXISTS));
buildType1.setEnabled(disabledId, false);
buildType1.addRequirement(new Requirement("prop3", null, RequirementType.EXISTS));
final String btLocator = "id:" + buildType1.getExternalId();
assertEquals(3, myBuildTypeRequest.getAgentRequirements(btLocator, "$long,agent-requirement($long)").propEntities.size());
{
PropEntityAgentRequirement submitted = new PropEntityAgentRequirement();
submitted.type = "not-exists";
submitted.disabled = true;
submitted.properties = new Properties();
submitted.properties.properties = Arrays.asList(new Property(new SimpleParameter("property-name", "aaa"), false, Fields.LONG, myFixture));
String newId = myBuildTypeRequest.addAgentRequirement(btLocator, "$long", submitted).id;
assertEquals(4, myBuildTypeRequest.getAgentRequirements(btLocator, "$long,agent-requirement($long)").propEntities.size());
assertTrue(myBuildTypeRequest.getAgentRequirements(btLocator, "$long,agent-requirement($long)").propEntities.get(3).disabled);
myBuildTypeRequest.deleteAgentRequirement(btLocator, newId);
assertEquals(3, myBuildTypeRequest.getAgentRequirements(btLocator, "$long,agent-requirement($long)").propEntities.size());
}
{
PropEntitiesAgentRequirement submitted = new PropEntitiesAgentRequirement();
PropEntityAgentRequirement submitted1 = new PropEntityAgentRequirement();
submitted1.type = "agentRequirementType1";
PropEntityAgentRequirement submitted2 = new PropEntityAgentRequirement();
submitted2.type = "agentRequirementType1";
submitted.propEntities = Arrays.asList(submitted1, submitted2);
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.replaceAgentRequirements(btLocator, "$long", // error will be reported: BadRequestException: No name is specified. Make sure 'property-name' property is present and has not empty value
submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getAgentRequirements(btLocator, "$long,agent-requirement($long)").propEntities.size());
assertEquals(3, buildType1.getRequirements().size());
assertFalse(buildType1.isEnabled(disabledId));
}
{
PropEntityAgentRequirement submitted = new PropEntityAgentRequirement();
submitted.type = "agentRequirementType1";
checkException(BadRequestException.class, new Runnable() {
public void run() {
myBuildTypeRequest.addAgentRequirement(btLocator, "$long", submitted);
}
}, null);
assertEquals(3, myBuildTypeRequest.getAgentRequirements(btLocator, "$long,agent-requirement($long)").propEntities.size());
assertEquals(3, buildType1.getRequirements().size());
assertFalse(buildType1.isEnabled(disabledId));
}
myBuildTypeRequest.replaceAgentRequirements(btLocator, "$long", new PropEntitiesAgentRequirement());
assertEquals(0, buildType1.getRequirements().size());
}
Aggregations