Search in sources :

Example 81 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildOnAgentPoolTriggering.

@Test
public void testBuildOnAgentPoolTriggering() throws Exception {
    final MockBuildAgent agent2 = myFixture.createEnabledAgent("agent2", "Ant");
    final int poolId1 = myFixture.getAgentPoolManager().createNewAgentPool("pool1").getAgentPoolId();
    myFixture.getAgentPoolManager().moveAgentTypesToPool(poolId1, createSet(agent2.getId()));
    final Build build = new Build();
    final BuildType buildType = new BuildType();
    buildType.setId(myBuildType.getExternalId());
    build.setBuildType(buildType);
    final SUser triggeringUser = getOrCreateUser("user");
    Agent submittedAgent = new Agent();
    submittedAgent.locator = "pool:(id:" + poolId1 + ")";
    build.setAgent(submittedAgent);
    SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertNotNull(queuedBuild.getAgentRestrictor());
    assertEquals(AgentRestrictorType.SINGLE_AGENT, queuedBuild.getAgentRestrictor().getType());
    assertEquals(agent2.getId(), queuedBuild.getAgentRestrictor().getId());
    submittedAgent = new Agent();
    submittedAgent.pool = new AgentPool();
    submittedAgent.pool.id = poolId1;
    build.setAgent(submittedAgent);
    queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertNotNull(queuedBuild.getAgentRestrictor());
    assertEquals(AgentRestrictorType.AGENT_POOL, queuedBuild.getAgentRestrictor().getType());
    assertEquals(poolId1, queuedBuild.getAgentRestrictor().getId());
    submittedAgent = new Agent();
    submittedAgent.pool = new AgentPool();
    submittedAgent.pool.locator = "id:" + poolId1;
    build.setAgent(submittedAgent);
    queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
    assertNotNull(queuedBuild.getAgentRestrictor());
    assertEquals(AgentRestrictorType.AGENT_POOL, queuedBuild.getAgentRestrictor().getType());
    assertEquals(poolId1, queuedBuild.getAgentRestrictor().getId());
}
Also used : Agent(jetbrains.buildServer.server.rest.model.agent.Agent) Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) AgentPool(jetbrains.buildServer.server.rest.model.agent.AgentPool) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 82 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testDownloadedArtifactsPermission.

@Test
@TestFor(issues = "TW-21036")
public void testDownloadedArtifactsPermission() throws Throwable {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    DownloadedArtifactsLoggerImpl artifactsLogger = myFixture.getSingletonService(DownloadedArtifactsLoggerImpl.class);
    SBuildType bt0 = registerBuildType("bt0", "project0", "Ant");
    SBuild build0 = createBuild(bt0, Status.NORMAL);
    SBuildType bt1 = registerBuildType("bt1", "project1", "Ant");
    SBuild build1 = createBuild(bt1, Status.NORMAL);
    SBuildType bt2 = registerBuildType("bt2", "project2", "Ant");
    SBuild build2 = createBuild(bt2, Status.NORMAL);
    final SUser user = createUser("user1");
    myFixture.getSecurityContext().runAsSystem(new SecurityContextEx.RunAsAction() {

        @Override
        public void run() throws Throwable {
            user.addRole(RoleScope.projectScope(build1.getProjectId()), getTestRoles().getProjectViewerRole());
        }
    });
    artifactsLogger.logArtifactDownload(build2.getBuildId(), build1.getBuildId(), "path1");
    artifactsLogger.logArtifactDownload(build2.getBuildId(), build0.getBuildId(), "path0");
    artifactsLogger.waitForQueuePersisting();
    myFixture.getSecurityContext().setAuthorityHolder(user);
    Build build2model = new Build(build2, Fields.ALL_NESTED, getBeanContext(myFixture));
    jetbrains.buildServer.server.rest.model.build.downloadedArtifacts.DownloadedArtifacts build2Artifacts = build2model.getDownloadedArtifacts();
    assertEquals("There are 2 builds as a source of artifacts", 2, (int) build2Artifacts.getUnfilteredCount());
    assertEquals("There is only 1 visible build as a source of artifacts", 1, (int) build2Artifacts.getCount());
    assertEquals("There is only 1 visible build as a source of artifacts", 1, build2Artifacts.getDownloadInfo().size());
}
Also used : SUser(jetbrains.buildServer.users.SUser) Build(jetbrains.buildServer.server.rest.model.build.Build) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) TestFor(jetbrains.buildServer.util.TestFor)

Example 83 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggeringTriggeredBy.

@Test
public void testBuildTriggeringTriggeredBy() throws Throwable {
    final Build build = new Build();
    final BuildType buildType = new BuildType();
    buildType.setId(myBuildType.getExternalId());
    build.setBuildType(buildType);
    final SUser triggeringUser = getOrCreateUser("userName");
    {
        final SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
        TriggeredBy triggeredBy = queuedBuild.getTriggeredBy();
        assertContains(triggeredBy.getParameters(), CollectionsUtil.asMap("userId", String.valueOf(triggeringUser.getId()), "type", "user", "origin", "rest"));
        myServer.getQueue().removeAllFromQueue();
    }
    myFixture.getSecurityContext().runAsSystem(() -> {
        final SQueuedBuild queuedBuild = build.triggerBuild(null, myFixture, new HashMap<Long, Long>());
        TriggeredBy triggeredBy = queuedBuild.getTriggeredBy();
        assertContains(triggeredBy.getParameters(), CollectionsUtil.asMap("type", "request", "origin", "rest"));
        assertNull(triggeredBy.getParameters().get("userId"));
        myServer.getQueue().removeAllFromQueue();
    });
    {
        jetbrains.buildServer.server.rest.model.build.TriggeredBy submittedTriggeredBy = new jetbrains.buildServer.server.rest.model.build.TriggeredBy();
        build.setTriggered(submittedTriggeredBy);
        submittedTriggeredBy.type = "idePlugin";
        submittedTriggeredBy.details = "IntelliJ IDEA";
        final SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
        TriggeredBy triggeredBy = queuedBuild.getTriggeredBy();
        assertContains(triggeredBy.getParameters(), CollectionsUtil.asMap("userId", String.valueOf(triggeringUser.getId()), "type", "xmlRpc", "IDEPlugin", "IntelliJ IDEA", "origin", "rest"));
        myServer.getQueue().removeAllFromQueue();
    }
    {
        jetbrains.buildServer.server.rest.model.build.TriggeredBy submittedTriggeredBy = new jetbrains.buildServer.server.rest.model.build.TriggeredBy();
        build.setTriggered(submittedTriggeredBy);
        submittedTriggeredBy.type = "build";
        submittedTriggeredBy.build = new Build();
        SFinishedBuild aFinishedBuild = build().in(myBuildType).finish();
        submittedTriggeredBy.build.setId(aFinishedBuild.getBuildId());
        final SQueuedBuild queuedBuild = build.triggerBuild(triggeringUser, myFixture, new HashMap<Long, Long>());
        TriggeredBy triggeredBy = queuedBuild.getTriggeredBy();
        assertContains(triggeredBy.getParameters(), CollectionsUtil.asMap("userId", String.valueOf(triggeringUser.getId()), "type", "user", "buildId", String.valueOf(aFinishedBuild.getBuildId()), "origin", "rest"));
        myServer.getQueue().removeAllFromQueue();
    }
}
Also used : SUser(jetbrains.buildServer.users.SUser) Build(jetbrains.buildServer.server.rest.model.build.Build) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 84 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggeringWithBuildTypeAndCustomDefaultParameter.

@Test(enabled = false)
@TestFor(issues = "TW-48945")
public void testBuildTriggeringWithBuildTypeAndCustomDefaultParameter() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    buildType1.addParameter(new SimpleParameter("name", "value"));
    final SUser user = getOrCreateUser("user");
    // end of setup
    final Build build = new Build();
    final BuildType buildTypeEntity = new BuildType();
    buildTypeEntity.setId(buildType1.getExternalId());
    buildTypeEntity.setDescription("some description");
    build.setBuildType(buildTypeEntity);
    build.setProperties(new Properties(createMap("name", "value"), null, Fields.ALL, getBeanContext(myFixture)));
    SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
    assertEquals("value", result.getBuildPromotion().getParameterValue("name"));
}
Also used : Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) TestFor(jetbrains.buildServer.util.TestFor)

Example 85 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class ChangeStatusTest method testCancelled.

@Test(enabled = false, description = "Cancelled builds are not counted at all, as MergedChangeStatus does not contain them for some reason.")
public void testCancelled() {
    final BuildTypeImpl buildConf = registerBuildType("buildConf1", "project");
    VcsRootInstance root1 = prepareSingleVscRoot(buildConf);
    SVcsModification m20 = myFixture.addModification(modification().in(root1).version("20").parentVersions("10"));
    SUser user = createUser("testuser");
    RunningBuildEx runningBuildEx = build().in(buildConf).onModifications(m20).withFailedTests("failedTestName").run();
    runningBuildEx.stop(user, "Stopped manually");
    finishBuild(runningBuildEx, false);
    ChangeStatus status = new ChangeStatus(myFixture.getChangeStatusProvider().getMergedChangeStatus(m20), Fields.ALL_NESTED, getBeanContext(myFixture));
    assertEquals(0, (int) status.getFinished());
    assertEquals(0, (int) status.getSuccessful());
    assertEquals(0, (int) status.getFailed());
    assertEquals(1, (int) status.getCancelled());
    assertEquals(1, (int) status.getPendingBuildTypes());
}
Also used : SVcsModification(jetbrains.buildServer.vcs.SVcsModification) RunningBuildEx(jetbrains.buildServer.serverSide.RunningBuildEx) ChangeStatus(jetbrains.buildServer.server.rest.model.change.ChangeStatus) SUser(jetbrains.buildServer.users.SUser) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Aggregations

SUser (jetbrains.buildServer.users.SUser)125 Test (org.testng.annotations.Test)70 ApiOperation (io.swagger.annotations.ApiOperation)35 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)35 Build (jetbrains.buildServer.server.rest.model.build.Build)20 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)18 NotNull (org.jetbrains.annotations.NotNull)18 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)15 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)13 Fields (jetbrains.buildServer.server.rest.model.Fields)12 SUserGroup (jetbrains.buildServer.groups.SUserGroup)11 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)10 ServiceLocator (jetbrains.buildServer.ServiceLocator)9 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)9 Nullable (org.jetbrains.annotations.Nullable)9 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)8 SecurityContextImpl (jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl)8 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)7