use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class AgentFinderTest method testLocatorCompatibleSnapshotDep.
@Test
@TestFor(issues = { "TW-49934" })
public void testLocatorCompatibleSnapshotDep() throws Exception {
ProjectEx project10 = createProject("project10", "project 10");
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
BuildTypeEx bt20 = project10.createBuildType("bt20", "bt 20");
createDependencyChain(bt20, bt10);
checkAgents(null, myAgent1, myAgent2);
checkAgents("compatible:(buildType:(id:" + bt20.getExternalId() + "))", myAgent1);
SQueuedBuild queuedBuild = build().in(bt20).addToQueue();
// queued snapshot dependency does not affect the compatibility
checkAgents("compatible:(build:(id:" + queuedBuild.getItemId() + "))", myAgent1);
myServer.flushQueue();
final RunningBuildEx build = myFixture.waitForQueuedBuildToStart(queuedBuild.getBuildPromotion().getDependencies().iterator().next().getDependOn());
checkAgents("compatible:(build:(id:" + queuedBuild.getItemId() + "))", myAgent1);
finishBuild();
checkAgents("compatible:(build:(id:" + queuedBuild.getItemId() + "))", myAgent1);
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class BuildTypeTest method testInheritance.
@Test
public void testInheritance() {
// see also alike setup in BuildTypeRequestTest.testCreatingWithTemplate()
ProjectEx project10 = createProject("project10", "project 10");
MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
final SVcsRoot vcsRoot10 = project10.createVcsRoot("vcs", "extId10", "name10");
final SVcsRoot vcsRoot20 = project10.createVcsRoot("vcs", "extId20", "name20");
final SVcsRoot vcsRoot30 = project10.createVcsRoot("vcs", "extId30", "name30");
project10.addParameter(new SimpleParameter("p", "v"));
BuildTypeEx bt100 = project10.createBuildType("bt100", "bt 100");
BuildTypeEx bt110 = project10.createBuildType("bt110", "bt 110");
BuildTypeEx bt120 = project10.createBuildType("bt120", "bt 120");
// TEMPLATE
BuildTypeTemplate t10 = project10.createBuildTypeTemplate("t10", "bt 10");
t10.setArtifactPaths("aaaaa");
t10.setBuildNumberPattern("pattern");
t10.setOption(BuildTypeOptions.BT_ALLOW_EXTERNAL_STATUS, true);
t10.setOption(BuildTypeOptions.BT_CHECKOUT_DIR, "checkout_t");
t10.setOption(BuildTypeOptions.BT_CHECKOUT_MODE, "ON_AGENT");
t10.setOption(BuildTypeOptions.BT_FAIL_ON_ANY_ERROR_MESSAGE, true);
t10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 11);
t10.addVcsRoot(vcsRoot10);
t10.addVcsRoot(vcsRoot20);
t10.setCheckoutRules(vcsRoot20, new CheckoutRules("a=>b"));
BuildRunnerDescriptorFactory runnerDescriptorFactory = myFixture.getSingletonService(BuildRunnerDescriptorFactory.class);
t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run10", "name10", "Ant1", map("a", "b")));
t10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run20", "name20", "Ant2", map("a", "b")));
BuildTriggerDescriptor trigger10 = t10.addBuildTrigger("Type", map("a", "b"));
BuildTriggerDescriptor trigger20 = t10.addBuildTrigger("Type", map("a", "b"));
t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f10", "type", map("a", "b")));
t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f20", "type", map("a", "b")));
t10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type", map("a", "b")));
ArtifactDependencyFactory artifactDependencyFactory = myFixture.getSingletonService(ArtifactDependencyFactory.class);
ArrayList<SArtifactDependency> artifactDeps = new ArrayList<>();
artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art10", bt100.getExternalId(), "path1", RevisionRules.LAST_PINNED_RULE));
artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art20", bt100.getExternalId(), "path2", RevisionRules.LAST_PINNED_RULE));
artifactDeps.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path3", RevisionRules.LAST_PINNED_RULE));
t10.setArtifactDependencies(artifactDeps);
t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt100));
t10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
t10.addParameter(new SimpleParameter("a10", "b"));
t10.addParameter(new SimpleParameter("a20", "b"));
t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req10", "a", null, RequirementType.EXISTS));
t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req20", "b", null, RequirementType.EXISTS));
t10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "c", null, RequirementType.EXISTS));
// BUILD TYPE
BuildTypeEx bt10 = project10.createBuildType("bt10", "bt 10");
bt10.attachToTemplate(t10);
// todo: test w/o override
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_AGENT");
bt10.setOption(BuildTypeOptions.BT_EXECUTION_TIMEOUT, 17);
bt10.addVcsRoot(vcsRoot20);
bt10.setCheckoutRules(vcsRoot20, new CheckoutRules("x=>y"));
bt10.addVcsRoot(vcsRoot30);
bt10.setEnabled("run20", false);
bt10.addBuildRunner(runnerDescriptorFactory.createBuildRunner(project10, "run30", "name30", "Ant30", map("a", "b")));
bt10.setEnabled(trigger20.getId(), false);
BuildTriggerDescriptor trigger30 = bt10.addBuildTrigger("Type", map("a", "b"));
bt10.setEnabled("f20", false);
bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f30", "type_bt", map("a", "b")));
bt10.addBuildFeature(myFixture.getBuildFeatureDescriptorFactory().createBuildFeature("f40", "type", map("a", "b")));
ArrayList<SArtifactDependency> artifactDepsBt = new ArrayList<>();
artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art30", bt100.getExternalId(), "path30", RevisionRules.LAST_FINISHED_RULE));
artifactDepsBt.add(artifactDependencyFactory.createArtifactDependency("art40", bt100.getExternalId(), "path4", RevisionRules.LAST_PINNED_RULE));
bt10.setArtifactDependencies(artifactDepsBt);
bt10.setEnabled("art20", false);
bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt110));
bt10.addDependency(myFixture.getSingletonService(DependencyFactory.class).createDependency(bt120));
bt10.addParameter(new SimpleParameter("a20", "x"));
bt10.addParameter(new SimpleParameter("a30", "x"));
bt10.setEnabled("req20", false);
bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req30", "x", null, RequirementType.EQUALS));
bt10.addRequirement(myFixture.findSingletonService(RequirementFactory.class).createRequirement("req40", "y", null, RequirementType.EXISTS));
// NOW, TEST TIME!
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, "buildNumberPattern"), "buildNumberPattern", "pattern", true);
parameterEquals(find(buildType.getSettings().properties, "allowExternalStatus"), "allowExternalStatus", "false", null);
parameterEquals(find(buildType.getSettings().properties, "checkoutDirectory"), "checkoutDirectory", "checkout_bt", null);
// parameterEquals(find(buildType.getSettings().properties, "checkoutMode"), "checkoutMode", "ON_AGENT", null); //option set to the same value in bt - API does not make difference so far
parameterEquals(find(buildType.getSettings().properties, "shouldFailBuildOnAnyErrorMessage"), "shouldFailBuildOnAnyErrorMessage", "true", true);
parameterEquals(find(buildType.getSettings().properties, "executionTimeoutMin"), "executionTimeoutMin", "17", null);
// default value
assertNull(find(buildType.getSettings().properties, "showDependenciesChanges"));
assertEquals(3, buildType.getVcsRootEntries().vcsRootAssignments.size());
vcsRootEntryEquals(buildType.getVcsRootEntries().vcsRootAssignments.get(0), vcsRoot10.getExternalId(), "", true);
// bt modifications are ignored
vcsRootEntryEquals(buildType.getVcsRootEntries().vcsRootAssignments.get(1), vcsRoot20.getExternalId(), "a=>b", true);
vcsRootEntryEquals(buildType.getVcsRootEntries().vcsRootAssignments.get(2), vcsRoot30.getExternalId(), "", null);
assertEquals(3, buildType.getSteps().propEntities.size());
stepsEquals(buildType.getSteps().propEntities.get(0), "run10", "Ant1", null, true);
stepsEquals(buildType.getSteps().propEntities.get(1), "run20", "Ant2", false, true);
stepsEquals(buildType.getSteps().propEntities.get(2), "run30", "Ant30", null, null);
// TeamCity issue: order of some entities depends on where the trigger is defined (build type or template)
assertEquals(3, buildType.getTriggers().propEntities.size());
stepsEquals(buildType.getTriggers().propEntities.get(0), trigger30.getId(), "Type", null, null);
stepsEquals(buildType.getTriggers().propEntities.get(1), trigger10.getId(), "Type", null, true);
stepsEquals(buildType.getTriggers().propEntities.get(2), trigger20.getId(), "Type", false, true);
assertEquals(4, buildType.getFeatures().propEntities.size());
stepsEquals(buildType.getFeatures().propEntities.get(0), "f30", "type_bt", null, null);
stepsEquals(buildType.getFeatures().propEntities.get(1), "f40", "type", null, null);
stepsEquals(buildType.getFeatures().propEntities.get(2), "f10", "type", null, true);
stepsEquals(buildType.getFeatures().propEntities.get(3), "f20", "type", false, true);
assertEquals(4, buildType.getArtifactDependencies().propEntities.size());
stepsEquals(buildType.getArtifactDependencies().propEntities.get(0), "art30", "artifact_dependency", null, null);
stepsEquals(buildType.getArtifactDependencies().propEntities.get(1), "art40", "artifact_dependency", null, null);
stepsEquals(buildType.getArtifactDependencies().propEntities.get(2), "art10", "artifact_dependency", null, true);
stepsEquals(buildType.getArtifactDependencies().propEntities.get(3), "art20", "artifact_dependency", false, true);
assertEquals(3, buildType.getSnapshotDependencies().propEntities.size());
stepsEquals(buildType.getSnapshotDependencies().propEntities.get(0), bt100.getExternalId(), "snapshot_dependency", null, true);
stepsEquals(buildType.getSnapshotDependencies().propEntities.get(1), bt110.getExternalId(), "snapshot_dependency", null, true);
stepsEquals(buildType.getSnapshotDependencies().propEntities.get(2), bt120.getExternalId(), "snapshot_dependency", null, null);
assertEquals(4, buildType.getParameters().properties.size());
parameterEquals(buildType.getParameters().properties.get(0), "a10", "b", true);
parameterEquals(buildType.getParameters().properties.get(1), "a20", "x", null);
parameterEquals(buildType.getParameters().properties.get(2), "a30", "x", null);
parameterEquals(buildType.getParameters().properties.get(3), "p", "v", true);
assertEquals(4, buildType.getAgentRequirements().propEntities.size());
stepsEquals(buildType.getAgentRequirements().propEntities.get(0), "req30", "equals", null, null);
stepsEquals(buildType.getAgentRequirements().propEntities.get(1), "req40", "exists", null, null);
stepsEquals(buildType.getAgentRequirements().propEntities.get(2), "req10", "exists", null, true);
stepsEquals(buildType.getAgentRequirements().propEntities.get(3), "req20", "exists", false, true);
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class BuildTypeTest method testTemplates.
@Test
public void testTemplates() {
ProjectEx project10 = getRootProject().createProject("project10", "project10");
ProjectEx project10_10 = project10.createProject("project10_10", "project10_10");
project10_10.addParameter(new SimpleParameter("f", "1"));
BuildTypeTemplate t10 = project10.createBuildTypeTemplate("t10", "t10");
t10.addParameter(new SimpleParameter("e", "1"));
t10.addParameter(new SimpleParameter("d", "2"));
BuildTypeTemplate t20 = project10.createBuildTypeTemplate("t20", "t20");
BuildTypeTemplate t30 = project10_10.createBuildTypeTemplate("t30", "t30");
t30.addParameter(new SimpleParameter("b", "1"));
t30.addParameter(new SimpleParameter("c", "1"));
BuildTypeTemplate t40 = project10_10.createBuildTypeTemplate("t40", "t40");
t40.addParameter(new SimpleParameter("b", "2"));
t40.addParameter(new SimpleParameter("d", "1"));
BuildTypeEx bt10 = project10_10.createBuildType("bt10", "bt10");
bt10.addParameter(new SimpleParameter("a", "1"));
project10.setDefaultTemplate(t10);
project10_10.setDefaultTemplate(t20);
bt10.setTemplates(Arrays.asList(t30, t40), false);
BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt10), Fields.LONG, myBeanContext);
assertEquals(Integer.valueOf(3), buildType.getTemplates().count);
assertEquals("t30", buildType.getTemplates().buildTypes.get(0).getId());
assertNull(buildType.getTemplates().buildTypes.get(0).isInherited());
assertEquals("t40", buildType.getTemplates().buildTypes.get(1).getId());
assertNull(buildType.getTemplates().buildTypes.get(1).isInherited());
assertEquals("t20", buildType.getTemplates().buildTypes.get(2).getId());
assertTrue(buildType.getTemplates().buildTypes.get(2).isInherited());
assertContains(buildType.getParameters().properties.stream().collect(Collectors.toMap(p -> p.name, p -> p.value)), CollectionsUtil.asMap("a", "1", "b", "1", "c", "1", "d", "1", "f", "1"));
assertContains(buildType.getParameters().properties.stream().filter(p -> p.inherited != null).collect(Collectors.toMap(p -> p.name, p -> p.inherited)), CollectionsUtil.asMap("b", true, "c", true, "d", true, "f", true));
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.
the class UserRequestTest method testPermissionsSecurity.
@Test
public void testPermissionsSecurity() throws Throwable {
myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
ProjectEx project1 = createProject("project1", "project1");
ProjectEx project2 = createProject("project2", "project2");
SUser user1 = createUser("user1");
SUser user2 = createUser("user2");
user2.addRole(RoleScope.globalScope(), getTestRoles().createRole(Permission.RUN_BUILD, Permission.AUTHORIZE_AGENT));
user2.addRole(RoleScope.projectScope(project2.getProjectId()), getTestRoles().createRole(Permission.VIEW_PROJECT));
user2.addRole(RoleScope.projectScope(project1.getProjectId()), getTestRoles().createRole(Permission.VIEW_PROJECT, Permission.REORDER_BUILD_QUEUE));
myFixture.getSecurityContext().runAs(user1, () -> {
checkException(AuthorizationFailedException.class, () -> myRequest.getPermissions("id:" + user2.getId(), null, null), "getting permissions of another user");
});
SUser user3 = createUser("user3");
user3.addRole(RoleScope.globalScope(), getTestRoles().createRole(Permission.VIEW_USER_PROFILE, Permission.VIEW_ALL_USERS));
user3.addRole(RoleScope.projectScope(project2.getProjectId()), getTestRoles().createRole(Permission.VIEW_PROJECT));
myFixture.getSecurityContext().runAs(user3, () -> {
PermissionAssignments permissions = myRequest.getPermissions("id:" + user2.getId(), null, null);
String message = describe(permissions);
assertTrue(message, permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.AUTHORIZE_AGENT.name().toLowerCase().toLowerCase().equals(pa.permission.id) && pa.project == null));
assertTrue(message, permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.REORDER_BUILD_QUEUE.name().toLowerCase().equals(pa.permission.id) && pa.project == null));
assertTrue(message, permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.RUN_BUILD.name().toLowerCase().equals(pa.permission.id) && pa.project == null));
assertTrue(message, permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.VIEW_PROJECT.name().toLowerCase().equals(pa.permission.id) && project2.getExternalId().equals(pa.project.id)));
assertTrue(message, permissions.myPermissionAssignments.stream().noneMatch(pa -> Permission.VIEW_PROJECT.name().toLowerCase().equals(pa.permission.id) && project1.getExternalId().equals(pa.project.id)));
});
getUserModelEx().getGuestUser().addRole(RoleScope.projectScope(project2.getProjectId()), getTestRoles().createRole(Permission.RUN_BUILD));
myFixture.getSecurityContext().runAs(getUserModelEx().getGuestUser(), () -> {
PermissionAssignments permissions = myRequest.getPermissions("current", null, null);
assertTrue(describe(permissions), permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.RUN_BUILD.name().toLowerCase().equals(pa.permission.id) && project2.getExternalId().equals(pa.project.id)));
checkException(AuthorizationFailedException.class, () -> myRequest.getPermissions("id:" + user2.getId(), null, null), "getting permissions of another user");
});
myFixture.getSecurityContext().runAs(getUserModelEx().getSuperUser(), () -> {
PermissionAssignments permissions = myRequest.getPermissions("current", null, null);
assertTrue(describe(permissions), permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.EDIT_PROJECT.name().toLowerCase().equals(pa.permission.id) && pa.project == null));
permissions = myRequest.getPermissions("id:" + user2.getId(), null, null);
assertTrue(describe(permissions), permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.VIEW_PROJECT.name().toLowerCase().equals(pa.permission.id) && project1.getExternalId().equals(pa.project.id)));
assertTrue(describe(permissions), permissions.myPermissionAssignments.stream().anyMatch(pa -> Permission.AUTHORIZE_AGENT.name().toLowerCase().equals(pa.permission.id) && pa.project == null));
});
}
use of jetbrains.buildServer.serverSide.impl.ProjectEx 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());
}
Aggregations