Search in sources :

Example 91 with SUser

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

the class TestOccurrenceFinderTest method testInvestigationState.

@Test
public void testInvestigationState() throws Exception {
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project1");
    final SFinishedBuild build = build().in(buildType).withTest("aaa_active", false).withTest("bbb_fixed", false).withTest("ccc_given_up", false).withTest("ddd_none", false).finish();
    long activeNameId = myFixture.getSingletonService(TestName2Index.class).getOrSaveTestNameId("aaa_active");
    long fixedNameId = myFixture.getSingletonService(TestName2Index.class).getOrSaveTestNameId("bbb_fixed");
    long givenUpNameId = myFixture.getSingletonService(TestName2Index.class).getOrSaveTestNameId("ccc_given_up");
    SUser user = createUser("user");
    ProjectEx project = myServer.getProjectManager().getRootProject().findProjectByName("project1");
    TestNameResponsibilityEntryImpl activeEntry = new TestNameResponsibilityEntryImpl(new TestName("aaa_active"), activeNameId, ResponsibilityEntry.State.TAKEN, user, user, new Date(), "Please, fix", project, ResponsibilityEntry.RemoveMethod.MANUALLY);
    TestNameResponsibilityEntryImpl fixedEntry = new TestNameResponsibilityEntryImpl(new TestName("bbb_fixed"), fixedNameId, ResponsibilityEntry.State.FIXED, user, user, new Date(), "Please, fix", project, ResponsibilityEntry.RemoveMethod.MANUALLY);
    TestNameResponsibilityEntryImpl givenUpEntry = new TestNameResponsibilityEntryImpl(new TestName("ccc_given_up"), givenUpNameId, ResponsibilityEntry.State.GIVEN_UP, user, user, new Date(), "Please, fix", project, ResponsibilityEntry.RemoveMethod.MANUALLY);
    TestNameResponsibilityFacade testNameResponsibilityFacade = myFixture.getSingletonService(TestNameResponsibilityFacade.class);
    testNameResponsibilityFacade.setTestNameResponsibility(new TestName("aaa_active"), project.getProjectId(), activeEntry);
    testNameResponsibilityFacade.setTestNameResponsibility(new TestName("bbb_fixed"), project.getProjectId(), fixedEntry);
    testNameResponsibilityFacade.setTestNameResponsibility(new TestName("ccc_given_up"), project.getProjectId(), givenUpEntry);
    TestRunData activeRunData = t("aaa_active", Status.FAILURE, 1);
    TestRunData fixedRunData = t("bbb_fixed", Status.FAILURE, 2);
    TestRunData givenUpRunData = t("ccc_given_up", Status.FAILURE, 3);
    TestRunData noneRunData = t("ddd_none", Status.FAILURE, 4);
    check("currentlyFailing:true,currentlyInvestigated:true", TEST_MATCHER, activeRunData);
    check("currentlyFailing:true,currentlyInvestigated:false", TEST_MATCHER, fixedRunData, givenUpRunData, noneRunData);
    check("currentlyFailing:true,investigationState:active", TEST_MATCHER, activeRunData);
    check("currentlyFailing:true,investigationState:fixed", TEST_MATCHER, fixedRunData);
    check("currentlyFailing:true,investigationState:givenUp", TEST_MATCHER, givenUpRunData);
    check("currentlyFailing:true,investigationState:none", TEST_MATCHER, noneRunData);
    check("currentlyFailing:true", TEST_MATCHER, activeRunData, fixedRunData, givenUpRunData, noneRunData);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) TestName(jetbrains.buildServer.tests.TestName) TestNameResponsibilityFacade(jetbrains.buildServer.responsibility.TestNameResponsibilityFacade) SUser(jetbrains.buildServer.users.SUser) TestNameResponsibilityEntryImpl(jetbrains.buildServer.responsibility.impl.TestNameResponsibilityEntryImpl) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 92 with SUser

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

the class TestOccurrenceFinderTest method testSameTestInDifferentBuilds.

@Test
public void testSameTestInDifferentBuilds() throws Exception {
    final BuildTypeImpl buildType1 = registerBuildType("buildConf1", "project1");
    final BuildTypeImpl buildType2 = registerBuildType("buildConf2", "project2");
    final SFinishedBuild build10 = build().in(buildType1).withTest("aaa", false).finish();
    final SFinishedBuild build20 = build().in(buildType2).withTest("aaa", false).finish();
    check("currentlyFailing:true", TEST_MATCHER, t("aaa", Status.FAILURE, 1), t("aaa", Status.FAILURE, 1));
    check("currentlyFailing:true,buildType:(id:" + buildType1.getExternalId() + ")", TEST_MATCHER, t("aaa", Status.FAILURE, 1));
    STestRun testRun1 = getFinder().getItems("currentlyFailing:true").myEntries.get(0);
    STestRun testRun2 = getFinder().getItems("currentlyFailing:true").myEntries.get(1);
    assertEquals(testRun1.getBuildId(), build10.getBuildId());
    assertEquals(testRun2.getBuildId(), build20.getBuildId());
    check("currentlyFailing:true,currentlyInvestigated:false", TEST_MATCHER, t("aaa", Status.FAILURE, 1), t("aaa", Status.FAILURE, 1));
    long nameId = myFixture.getSingletonService(TestName2Index.class).getOrSaveTestNameId("aaa");
    SUser user = createUser("user");
    ProjectEx project = myServer.getProjectManager().getRootProject().findProjectByName("project1");
    TestNameResponsibilityEntryImpl testNameResponsibilityEntry = new TestNameResponsibilityEntryImpl(new TestName("aaa"), nameId, ResponsibilityEntry.State.TAKEN, user, user, new Date(), "Please, fix", project, ResponsibilityEntry.RemoveMethod.MANUALLY);
    myFixture.getSingletonService(TestNameResponsibilityFacade.class).setTestNameResponsibility(new TestName("aaa"), project.getProjectId(), testNameResponsibilityEntry);
    check("currentlyFailing:true,currentlyInvestigated:false", TEST_MATCHER, t("aaa", Status.FAILURE, 1));
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) TestName(jetbrains.buildServer.tests.TestName) TestNameResponsibilityFacade(jetbrains.buildServer.responsibility.TestNameResponsibilityFacade) SUser(jetbrains.buildServer.users.SUser) TestNameResponsibilityEntryImpl(jetbrains.buildServer.responsibility.impl.TestNameResponsibilityEntryImpl) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 93 with SUser

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

the class AvatarRequest method getAvatar.

@GET
@Produces(MediaType.IMAGE_PNG_VALUE)
@Path("/{userLocator}/{size}/avatar.png")
@ApiOperation("Get a users avatar")
public Response getAvatar(@Context HttpServletResponse response, @ApiParam(format = LocatorName.USER) @PathParam("userLocator") String userLocator, @ApiParam(value = "avatar's size", allowableValues = "range[" + MIN_AVATAR_SIZE + ", " + MAX_AVATAR_SIZE + "]") @PathParam("size") Integer size) throws IOException {
    if (size < MIN_AVATAR_SIZE || size > MAX_AVATAR_SIZE) {
        throw new BadRequestException("\"size\" must be bigger or equal than " + MIN_AVATAR_SIZE + " and lower or equal than " + MAX_AVATAR_SIZE);
    }
    final SUser user = myUserFinder.getItem(userLocator);
    final BufferedImage image = myUserAvatarsManager.getAvatar(user, size);
    if (image == null)
        throw new NotFoundException("avatar (username: " + user.getUsername() + ") not found");
    final int avatarCacheLifeTime = getAvatarCacheLifetime();
    response.setHeader(HttpHeaders.CACHE_CONTROL, CACHE_CONTROL_MAX_AGE + avatarCacheLifeTime);
    ImageIO.write(image, "png", response.getOutputStream());
    return Response.ok().build();
}
Also used : SUser(jetbrains.buildServer.users.SUser) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) BufferedImage(java.awt.image.BufferedImage) ApiOperation(io.swagger.annotations.ApiOperation)

Example 94 with SUser

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

the class BuildRequest method deleteBuilds.

/**
 * @deprecated Use DELETE request to .../app/rest/builds/multiple/{locator}
 */
@DELETE
@ApiOperation(value = "deleteBuilds", hidden = true)
@Produces({ "application/xml", "application/json" })
public void deleteBuilds(@ApiParam(format = LocatorName.BUILD) @QueryParam("locator") String locator, @Context HttpServletRequest request) {
    if (locator == null) {
        throw new BadRequestException("Empty 'locator' parameter specified.");
    }
    final List<BuildPromotion> builds = myBuildFinder.getBuilds(null, locator).myEntries;
    final int deleteLimit = TeamCityProperties.getInteger(REST_BUILD_REQUEST_DELETE_LIMIT, 10);
    if (builds.size() > deleteLimit) {
        throw new BadRequestException("Refusing to delete more than " + deleteLimit + " builds as a precaution measure." + " The limit is set via '" + REST_BUILD_REQUEST_DELETE_LIMIT + "' internal property on the server.");
    }
    SUser user = SessionUser.getUser(request);
    Map<Long, RuntimeException> errors = deleteBuilds(builds, user, null);
    if (!errors.isEmpty()) {
        throw errors.values().iterator().next();
    }
}
Also used : SUser(jetbrains.buildServer.users.SUser) ApiOperation(io.swagger.annotations.ApiOperation)

Example 95 with SUser

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

the class BuildRequest method addProblemToBuild.

/**
 * Experimental.
 * Adds a build problem with given details. The same as marking the build as failed from UI.
 */
@POST
@Path("/{buildLocator}/problemOccurrences")
@Consumes({ "text/plain" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Add a build problem to the matching build.", nickname = "addProblemToBuild")
public ProblemOccurrence addProblemToBuild(@ApiParam(format = LocatorName.BUILD) @PathParam("buildLocator") String buildLocator, String problemDetails, @QueryParam("fields") String fields) {
    BuildPromotion buildPromotion = myBuildFinder.getBuildPromotion(null, buildLocator);
    SBuild build = buildPromotion.getAssociatedBuild();
    if (build == null) {
        throw new NotFoundException("No finished build associated with promotion id " + buildPromotion.getId());
    }
    User user = myPermissionChecker.getCurrent().getAssociatedUser();
    if (user == null) {
        throw new BadRequestException("Cannot perform operation: no current user");
    }
    BuildProblemData problemData = build.addUserBuildProblem((SUser) user, problemDetails);
    return new ProblemOccurrence(myBeanContext.getSingletonService(ProblemOccurrenceFinder.class).getProblem(build, problemData), myBeanContext, new Fields(fields));
}
Also used : SessionUser(jetbrains.buildServer.web.util.SessionUser) SUser(jetbrains.buildServer.users.SUser) User(jetbrains.buildServer.users.User) BuildProblemData(jetbrains.buildServer.BuildProblemData) ProblemOccurrence(jetbrains.buildServer.server.rest.model.problem.ProblemOccurrence) ApiOperation(io.swagger.annotations.ApiOperation)

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