Search in sources :

Example 11 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class ProjectFinderTest method testAgentPoolDimension.

@Test
public void testAgentPoolDimension() throws Exception {
    final SProject project10 = createProject("p10", "project 10");
    final SProject project20 = createProject("p20", "project 20");
    final SProject project30 = createProject("p30", "project 30");
    // - project10, project20
    final int poolId0 = BuildAgent.DEFAULT_POOL_ID;
    // - project20
    final int poolId10 = myFixture.getAgentPoolManager().createNewAgentPool("pool10").getAgentPoolId();
    // - project30
    final int poolId20 = myFixture.getAgentPoolManager().createNewAgentPool("pool20").getAgentPoolId();
    myFixture.getAgentPoolManager().associateProjectsWithPool(poolId10, createSet(project20.getProjectId()));
    myFixture.getAgentPoolManager().associateProjectsWithPool(poolId20, createSet(project30.getProjectId()));
    myFixture.getAgentPoolManager().dissociateProjectsFromOtherPools(poolId20, createSet(project30.getProjectId()));
    check(null, getRootProject(), project10, project20, project30);
    check("pool:(id:" + poolId0 + ")", myProjectManager.getRootProject(), project10, project20);
    check("pool:(id:" + poolId10 + ")", project20);
    check("pool:(id:" + poolId20 + ")", project30);
    check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId10 + "))", myProjectManager.getRootProject(), project10, project20);
    check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId20 + "))", myProjectManager.getRootProject(), project10, project20, project30);
    check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId20 + ")),id:" + project20.getExternalId(), project20);
    check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId20 + ")),pool:(id:" + poolId10 + ")", project20);
    check("pool:(id:" + poolId10 + "),pool:(id:" + poolId20 + ")");
    check("pool:(id:" + poolId0 + "),pool:(id:" + poolId10 + ")", project20);
    check("pool:(id:" + poolId0 + "),not(pool:(id:" + poolId10 + "))", myProjectManager.getRootProject(), project10);
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 12 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class ProjectFinderTest method testUserPermissionDimension.

@Test
public void testUserPermissionDimension() throws Exception {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    ProjectEx root = myProjectManager.getRootProject();
    final SProject project10 = createProject("p10", "project 10");
    final SProject project10_10 = project10.createProject("p10_10", "p10 child1");
    final SProject project20 = createProject("p20", "project 20");
    final SProject project30 = createProject("p30", "project 30");
    RoleImpl role10 = new RoleImpl("role10", "custom role", new Permissions(Permission.TAG_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role10);
    RoleImpl role20 = new RoleImpl("role20", "custom role", new Permissions(Permission.CHANGE_SERVER_SETTINGS, Permission.LABEL_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role20);
    RoleImpl role30 = new RoleImpl("role30", "custom role", new Permissions(Permission.RUN_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role30);
    role30.addIncludedRole(role10);
    final SUser user10 = createUser("user10");
    final SUser user20 = createUser("user20");
    final SUser user30 = createUser("user30");
    final SUser user40 = createUser("user40");
    final SUserGroup group10 = myFixture.createUserGroup("group1", "group 1", "");
    final SUserGroup group20 = myFixture.createUserGroup("group1.1", "group 1.1", "");
    group10.addSubgroup(group20);
    group20.addUser(user20);
    group10.addRole(RoleScope.projectScope(project10.getProjectId()), role30);
    user10.addRole(RoleScope.projectScope(project10_10.getProjectId()), role10);
    user30.addRole(RoleScope.globalScope(), role30);
    user40.addRole(RoleScope.projectScope(project10_10.getProjectId()), role20);
    check(null, getRootProject(), project10, project10_10, project20, project30);
    check("userPermission:(user:(id:" + user10.getId() + "),permission:tag_build)", project10_10);
    checkExceptionOnItemsSearch(LocatorProcessException.class, "userPermission:(user:(id:" + user10.getId() + "))");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "userPermission:(permission:view_project)");
    check("userPermission:(user:(id:" + user20.getId() + "),permission:tag_build)", project10, project10_10);
    // project permission granted globally
    check("userPermission:(user:(id:" + user30.getId() + "),permission:TAG_BUILD)", getRootProject(), project10, project10_10, project20, project30);
    check("userPermission:(user:(id:" + user30.getId() + "),permission:change_server_settings)");
    // global permission
    check("userPermission:(user:(id:" + user40.getId() + "),permission:change_server_settings)", getRootProject(), project10, project10_10, project20, project30);
    check("userPermission:(user:(id:" + user40.getId() + "),permission:TAG_BUILD)");
    RoleImpl role11 = new RoleImpl("role11", "custom role", new Permissions(Permission.VIEW_PROJECT), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role11);
    user10.addRole(RoleScope.projectScope(project10_10.getProjectId()), role11);
    // view project is propagated on top
    check("userPermission:(user:(id:" + user10.getId() + "),permission:view_project)", getRootProject(), project10, project10_10);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) RoleImpl(jetbrains.buildServer.serverSide.impl.auth.RoleImpl) SUser(jetbrains.buildServer.users.SUser) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) SUserGroup(jetbrains.buildServer.groups.SUserGroup) SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 13 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class ProjectFinderTest method testProjectDimensions.

@Test
public void testProjectDimensions() throws Exception {
    final SProject project10 = createProject("p1");
    final SProject project20 = createProject("p2");
    final SProject project20_10 = project20.createProject("p2", "xxx");
    final SProject project10_10 = project10.createProject("p10_10", "p1_child1");
    final SProject project10_20 = project10.createProject("p10_20", "xxx");
    project10_20.setArchived(true, null);
    final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
    final SProject project10_10_10_10 = project10_10_10.createProject("p10_10_10_10", "xxx");
    final SProject project10_10_20 = project10_10.createProject("p10_10_20", "p1_child2_child2");
    project10_10_20.setArchived(true, null);
    final SProject project10_10_20_10 = project10_10_20.createProject("p10_10_20_10", "p1_child2_child2_child1");
    final SProject project30 = createProject("p30", "p3");
    final SProject project30_10 = project30.createProject("p30_10", "p3_p1");
    final SProject project30_10_10 = project30_10.createProject("p30_10_10", "xxx");
    final SProject project40 = createProject(project10.getProjectId(), "p4");
    // sequence is used as is, documenting the current behavior
    check(null, myProjectManager.getRootProject(), project10, project10_10, project10_10_10, project10_10_10_10, project10_10_20_10, project20, project20_10, project30, project30_10, project30_10_10, project40, project10_10_20, project10_20);
    check("name:(" + "xxx" + ")", project10_10_10, project10_10_10_10, project20_10, project30_10_10, project10_20);
    check("name:(" + "xxx" + "),affectedProject:(id:" + project10.getExternalId() + ")", project10_20, project10_10_10, project10_10_10_10);
    check("name:(" + "xxx" + "),affectedProject:(id:" + project20.getExternalId() + ")", project20_10);
    check("name:(" + "xxx" + "),affectedProject:(id:" + project10_10.getExternalId() + ")", project10_10_10, project10_10_10_10);
    check("name:(" + "xxx" + "),affectedProject:(id:" + project30.getExternalId() + ")", project30_10_10);
    check("name:(" + "xxx" + "),affectedProject:(id:" + project10_10_10.getExternalId() + ")", project10_10_10_10);
    check("name:(" + "xxx" + "),parentProject:(id:" + project10.getExternalId() + ")", project10_20, project10_10_10, project10_10_10_10);
    check("name:(" + "xxx" + "),parentProject:(id:" + project20.getExternalId() + ")", project20_10);
    check("name:(" + "xxx" + "),parentProject:(id:" + project10_10.getExternalId() + ")", project10_10_10, project10_10_10_10);
    check("name:(" + "xxx" + "),parentProject:(id:" + project30.getExternalId() + ")", project30_10_10);
    check("name:(" + "xxx" + "),parentProject:(id:" + project10_10_10.getExternalId() + ")", project10_10_10_10);
    check("name:(" + "xxx" + "),project:(id:" + project10.getExternalId() + ")", project10_20);
    check("name:(" + "xxx" + "),project:(id:" + project20.getExternalId() + ")", project20_10);
    check("name:(" + "xxx" + "),project:(id:" + project10_10_20.getExternalId() + ")");
    check("name:(" + "xxx" + "),project:(id:" + project30.getExternalId() + ")");
    check("name:(" + "xxx" + "),project:(id:" + project10_10_10.getExternalId() + ")", project10_10_10_10);
    check("affectedProject:(id:" + project10.getExternalId() + ")", project10_10, project10_20, project10_10_10, project10_10_20, project10_10_10_10, project10_10_20_10);
    check("affectedProject:(id:" + project20.getExternalId() + ")", project20_10);
    check("affectedProject:(id:" + project40.getExternalId() + ")");
    check("affectedProject:(id:" + project10_10.getExternalId() + ")", project10_10_10, project10_10_20, project10_10_10_10, project10_10_20_10);
    check("parentProject:(id:" + project10.getExternalId() + ")", project10_10, project10_20, project10_10_10, project10_10_20, project10_10_10_10, project10_10_20_10);
    check("parentProject:(id:" + project20.getExternalId() + ")", project20_10);
    check("parentProject:(id:" + project40.getExternalId() + ")");
    check("project:(id:" + project10.getExternalId() + ")", project10_10, project10_20);
    check("project:(id:" + project20.getExternalId() + ")", project20_10);
    check("project:(id:" + project40.getExternalId() + ")");
    check("affectedProject:(id:" + project10.getExternalId() + "),archived:false", project10_10, project10_10_10, project10_10_10_10, project10_10_20_10);
    check("affectedProject:(id:" + project20.getExternalId() + "),archived:false", project20_10);
    check("affectedProject:(id:" + project40.getExternalId() + "),archived:false");
    check("parentProject:(id:" + project10.getExternalId() + "),archived:false", project10_10, project10_10_10, project10_10_10_10, project10_10_20_10);
    check("parentProject:(id:" + project20.getExternalId() + "),archived:false", project20_10);
    check("parentProject:(id:" + project40.getExternalId() + "),archived:false");
    check("project:(id:" + project10.getExternalId() + "),archived:false", project10_10);
    check("project:(id:" + project20.getExternalId() + "),archived:false", project20_10);
    check("project:(id:" + project40.getExternalId() + "),archived:false");
    check("item:(id:" + project40.getExternalId() + ")", project40);
    check("item:(id:" + project40.getExternalId() + "),item:(id:" + project20.getExternalId() + ")", project40, project20);
    // nothing found: no error
    check("id:XXX");
    checkExceptionOnItemSearch(NotFoundException.class, "id:XXX");
    checkExceptionOnItemsSearch(NotFoundException.class, "project:(id:XXX)");
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 14 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class ProjectFinderTest method testSingleDimensions.

@Test
public void testSingleDimensions() throws Exception {
    final SProject project10 = createProject("p1");
    final SProject project20 = createProject("p2");
    final SProject project10_10 = project10.createProject("p10_10", "p1_child1");
    final SProject project10_20 = project10.createProject("p10_20", "xxx");
    final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
    final SProject project30 = createProject(project10.getProjectId(), "p3");
    check(project20.getProjectId(), project20);
    check(project20.getExternalId(), project20);
    check(project20.getName(), project20);
    check("id:" + project10.getExternalId(), project10);
    check("id:" + project10.getExternalId().toUpperCase(), project10);
    check("internalId:" + project10.getProjectId(), project10);
    check("id:" + project30.getExternalId(), project30);
    check("id:XXXX");
    check(project30.getExternalId(), project30);
    check("name:(" + project10.getName() + ")", project10);
    check("name:(" + project10.getName().toUpperCase() + ")");
    check("uuid:(" + project10.getConfigId() + ")", project10);
    check("name:(" + project10_10.getName() + ")", project10_10);
    check("name:(" + project10_10.getName().toUpperCase() + ")");
    check("name:(" + "xxx" + ")", project10_10_10, project10_20);
    check(project10.getExternalId(), project10);
    check(project10.getName(), project10);
    check("No_match");
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 15 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class RootApiRequest method serveBuildFieldShort.

@GET
@ApiOperation(value = "serveBuildFieldShort", hidden = true)
@Path("/{projectLocator}/{btLocator}/{buildLocator}/{field}")
@Produces("text/plain")
public String serveBuildFieldShort(@PathParam("projectLocator") String projectLocator, @PathParam("btLocator") String buildTypeLocator, @PathParam("buildLocator") String buildLocator, @PathParam("field") String field) {
    SProject project = myProjectFinder.getItem(projectLocator);
    SBuildType buildType = myBuildTypeFinder.getBuildType(project, buildTypeLocator, false);
    final BuildPromotion buildPromotion = myBuildFinder.getBuildPromotion(buildType, buildLocator);
    return Build.getFieldValue(buildPromotion, field, new BeanContext(myDataProvider.getBeanFactory(), myDataProvider.getServer(), myApiUrlBuilder));
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) BuildPromotion(jetbrains.buildServer.serverSide.BuildPromotion) SBuildType(jetbrains.buildServer.serverSide.SBuildType) SProject(jetbrains.buildServer.serverSide.SProject) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SProject (jetbrains.buildServer.serverSide.SProject)42 NotNull (org.jetbrains.annotations.NotNull)22 Test (org.testng.annotations.Test)11 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)10 ProjectManager (jetbrains.buildServer.serverSide.ProjectManager)8 Nullable (org.jetbrains.annotations.Nullable)8 SBuildType (jetbrains.buildServer.serverSide.SBuildType)7 ApiOperation (io.swagger.annotations.ApiOperation)6 Logger (com.intellij.openapi.diagnostic.Logger)5 Collectors (java.util.stream.Collectors)5 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 Permission (jetbrains.buildServer.serverSide.auth.Permission)5 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)5 java.util (java.util)4 List (java.util.List)4 ServiceLocator (jetbrains.buildServer.ServiceLocator)4 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)4 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)4 Predicate (java.util.function.Predicate)3