use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class MuteRequestTest method test_severalMutes.
@Test
public void test_severalMutes() {
final ProjectEx project = createProject("Project", "Project");
final BuildTypeEx bt1 = project.createBuildType("bt1");
final BuildTypeEx bt2 = project.createBuildType("bt2");
final ProjectEx project2 = createProject("Project2", "Project2");
final BuildTypeEx bt22 = project.createBuildType("bt3");
createBuild(bt1, new String[0], new String[] { "test1", "test2", "test3" });
createBuild(bt22, new String[0], new String[] { "test1", "test2", "test3", "test4" });
final STest test1 = myFixture.getTestManager().createTest(new TestName("test1"), project.getProjectId());
final STest test2 = myFixture.getTestManager().createTest(new TestName("test2"), project.getProjectId());
SUser user = createUser("user");
myMutingService.muteTestsInBuildTypes(user, null, false, null, Arrays.asList(bt1, bt2), Arrays.asList(test1, test2), false);
myMutingService.muteTestsInProject(user, null, false, null, project2, Arrays.asList(test1));
int mute1Id, mute2Id;
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(2), mutes.count);
assertEquals(2, mutes.items.size());
mute1Id = mutes.items.get(0).id;
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(2, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
mute2Id = mutes.items.get(1).id;
assertNull(mutes.items.get(1).scope.buildTypes);
assertNotNull(mutes.items.get(1).scope.project);
assertEquals(project2.getExternalId(), mutes.items.get(1).scope.project.id);
assertNull(mutes.items.get(1).target.problems);
assertEquals(1, mutes.items.get(1).target.tests.items.size());
assertTrue(mutes.items.get(1).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
}
{
setInternalProperty(Mutes.REST_MUTES_ACTUAL_STATE, "true");
Mutes mutes = myRequest.getMutes("id:" + mute2Id, "$long,mute(target(tests(test(mutes(mute(target(tests(test($long))),scope(buildTypes(buildType($long)))))))))", null, null);
assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.size());
assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).target.tests.items.size());
assertEquals(2, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).scope.buildTypes.buildTypes.size());
}
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class MuteRequestTest method test_unmuteTest.
@Test
public void test_unmuteTest() {
final ProjectEx project = createProject("Project", "Project");
final BuildTypeEx bt1 = project.createBuildType("bt1");
final BuildTypeEx bt2 = project.createBuildType("bt2");
// just a child project
final ProjectEx projectChild = project.createProject("Project2", "Project2");
final BuildTypeEx bt21 = projectChild.createBuildType("bt21");
createBuild(bt1, new String[0], new String[] { "test1", "test2", "test3" });
createBuild(bt2, new String[0], new String[] { "test1", "test2", "test3", "test4" });
createBuild(bt21, new String[0], new String[] { "test1", "test2", "test3", "test4" });
final STest test1 = myFixture.getTestManager().createTest(new TestName("test1"), project.getProjectId());
final STest test2 = myFixture.getTestManager().createTest(new TestName("test2"), project.getProjectId());
SUser user = createUser("user");
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
// assertEquals(Integer.valueOf(0), mutes.count); //todo: fix
assertEmpty(mutes.items);
}
myMutingService.muteTestsInBuildTypes(user, null, false, null, Arrays.asList(bt1, bt2), Arrays.asList(test1, test2), false);
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(1), mutes.count);
assertEquals(1, mutes.items.size());
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(2, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
}
myMutingService.unmuteTests(user, null, bt1, Arrays.asList(test1));
{
// this is the current behavior, but actually something should change, see TW-53393
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(1), mutes.count);
assertEquals(1, mutes.items.size());
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(2, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test1.getTestNameId()).equals(test.id)));
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
}
myMutingService.unmuteTests(user, null, bt2, Arrays.asList(test1));
{
Mutes mutes = myRequest.getMutes(null, null, null, null);
assertEquals(Integer.valueOf(1), mutes.count);
assertEquals(1, mutes.items.size());
assertNull(mutes.items.get(0).scope.project);
assertNotNull(mutes.items.get(0).scope.buildTypes);
assertEquals(2, mutes.items.get(0).scope.buildTypes.buildTypes.size());
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt1.getExternalId().equals(buildType.getId())));
assertTrue(mutes.items.get(0).scope.buildTypes.buildTypes.stream().anyMatch(buildType -> bt2.getExternalId().equals(buildType.getId())));
assertNull(mutes.items.get(0).target.problems);
assertEquals(1, mutes.items.get(0).target.tests.items.size());
assertTrue(mutes.items.get(0).target.tests.items.stream().anyMatch(test -> String.valueOf(test2.getTestNameId()).equals(test.id)));
}
{
setInternalProperty(Mutes.REST_MUTES_ACTUAL_STATE, "true");
Mutes mutes = myRequest.getMutes(null, "$long,mute(target(tests(test(mutes(mute(target(tests($long))))))))", null, null);
assertEquals(1, mutes.items.get(0).target.tests.items.get(0).mutes.items.get(0).target.tests.items.size());
}
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class BuildTypeTest method testAgents.
@Test
public void testAgents() {
// we will need the agent license
myBuildAgent.setAuthorized(false, null, "");
ProjectEx project10 = createProject("project10", "project 10");
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("a", null, RequirementType.EXISTS));
BuildTypeEx bt20 = project10.createBuildType("bt20", "bt 20");
// not compatible
MockBuildAgent agent10 = myFixture.createEnabledAgent("agent10", "Ant");
// compatible
MockBuildAgent agent20 = myFixture.createEnabledAgent("agent20", "Ant");
agent20.addConfigParameter("a", "b");
agent20.pushAgentTypeData();
// compatible
MockBuildAgent agent30 = myFixture.createEnabledAgent("agent30", "Ant");
agent30.addConfigParameter("a", "b");
agent30.pushAgentTypeData();
agent30.setAuthorized(false, null, "");
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), Fields.LONG, myBeanContext);
assertNotNull(buildType.getCompatibleAgents());
assertNull(buildType.getCompatibleAgents().count);
assertNotNull(buildType.getCompatibleAgents().href);
assertContains(buildType.getCompatibleAgents().href, "compatible:(buildType:(id:" + bt10.getExternalId() + "))");
assertNull(buildType.getCompatibleAgents().agents);
}
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("compatibleAgents($long)"), myBeanContext);
assertNotNull(buildType.getCompatibleAgents());
assertEquals(Integer.valueOf(1), buildType.getCompatibleAgents().count);
assertContains(buildType.getCompatibleAgents().href, "compatible:(buildType:(id:" + bt10.getExternalId() + "))");
assertNotNull(buildType.getCompatibleAgents().agents);
assertEquals(1, buildType.getCompatibleAgents().agents.size());
}
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("compatibleAgents($long,$locator(authorized:any))"), myBeanContext);
assertNotNull(buildType.getCompatibleAgents());
assertEquals(Integer.valueOf(2), buildType.getCompatibleAgents().count);
// assertContains(buildType.getCompatibleAgents().href, "compatible:(buildType:(id:" + bt10.getExternalId() + ")),authorized:any");
assertNotNull(buildType.getCompatibleAgents().agents);
assertEquals(2, buildType.getCompatibleAgents().agents.size());
}
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class BuildTypeTest method testSettings.
@Test
public void testSettings() {
ProjectEx project10 = createProject("project10", "project 10");
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long"), myBeanContext);
parameterEquals(find(buildType.getSettings().properties, "buildNumberCounter"), "buildNumberCounter", "1", null);
assertEquals(1, buildType.getSettings().properties.size());
}
bt10.setArtifactPaths("bbbb");
bt10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, false);
bt10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_bt");
bt10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_SERVER");
bt10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 17);
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long"), myBeanContext);
parameterEquals(find(buildType.getSettings().properties, "artifactRules"), "artifactRules", "bbbb", null);
// parameterEquals(find(buildType.getSettings().properties, "allowExternalStatus"), "allowExternalStatus", "false", null); //settings to default value does not set it in API...
parameterEquals(find(buildType.getSettings().properties, "checkoutDirectory"), "checkoutDirectory", "checkout_bt", null);
parameterEquals(find(buildType.getSettings().properties, "checkoutMode"), "checkoutMode", "ON_SERVER", null);
parameterEquals(find(buildType.getSettings().properties, "executionTimeoutMin"), "executionTimeoutMin", "17", null);
assertNull(find(buildType.getSettings().properties, "allowPersonalBuildTriggering"));
assertNull(find(buildType.getSettings().properties, "buildNumberPattern"));
assertNull(find(buildType.getSettings().properties, "shouldFailBuildOnAnyErrorMessage"));
assertNull(find(buildType.getSettings().properties, "showDependenciesChanges"));
}
bt10.setOption(BuildTypeOptions.BT_ALLOW_PERSONAL_BUILD_TRIGGERING, false);
bt10.setOption(BuildTypeOptions.BT_BUILD_NUMBER_PATTERN, "aaa");
bt10.setOption(BuildTypeOptions.BT_FAIL_ON_ANY_ERROR_MESSAGE, true);
bt10.setOption(BuildTypeOptions.BT_SHOW_DEPS_CHANGES, true);
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long"), myBeanContext);
parameterEquals(find(buildType.getSettings().properties, "allowPersonalBuildTriggering"), "allowPersonalBuildTriggering", "false", null);
parameterEquals(find(buildType.getSettings().properties, "buildNumberPattern"), "buildNumberPattern", "aaa", null);
parameterEquals(find(buildType.getSettings().properties, "shouldFailBuildOnAnyErrorMessage"), "shouldFailBuildOnAnyErrorMessage", "true", null);
parameterEquals(find(buildType.getSettings().properties, "showDependenciesChanges"), "showDependenciesChanges", "true", null);
}
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long,settings($long,$locator(defaults:any))"), myBeanContext);
assertEquals(24, buildType.getSettings().properties.size());
parameterEquals(find(buildType.getSettings().properties, "buildNumberCounter"), "buildNumberCounter", "1", null);
parameterEquals(find(buildType.getSettings().properties, "buildNumberPattern"), "buildNumberPattern", "aaa", null);
}
{
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), new Fields("$long,settings($long,$locator(defaults:any,name:buildNumberCounter))"), myBeanContext);
assertEquals(1, buildType.getSettings().properties.size());
parameterEquals(find(buildType.getSettings().properties, "buildNumberCounter"), "buildNumberCounter", "1", null);
}
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx 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());
}
}
Aggregations