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());
}
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());
}
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();
}
}
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"));
}
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());
}
Aggregations