Search in sources :

Example 31 with SFinishedBuild

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

the class TestOccurrenceRequestTest method testWontFetchItemsWhenNotNeededWithDefaultFieldsValue.

@Test
public void testWontFetchItemsWhenNotNeededWithDefaultFieldsValue() {
    BeanContext ctx = BaseFinderTest.getBeanContext(myFixture);
    myRequest.initForTests(ctx.getServiceLocator(), new TestOccurrenceFinderDenyingItemsFetch(), ctx.getApiUrlBuilder(), ctx);
    final SFinishedBuild build = build().in(myBuildType).withTest(BuildBuilder.TestData.test("aaa").duration(76)).finish();
    FakeHttpServletRequest mockRequest = new FakeHttpServletRequest();
    mockRequest.setRequestURL("http://test/httpAuth/app/rest/testOccurrences?locator=build:" + build.getBuildId());
    TestOccurrences testOccurrences = myRequest.getTestOccurrences("build:" + build.getBuildId(), "", null, mockRequest);
    assertEquals(new Integer(1), testOccurrences.getCount());
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) Test(org.testng.annotations.Test)

Example 32 with SFinishedBuild

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

the class ProblemOccurrenceFinderTest method testBasic.

@Test
public void testBasic() throws Exception {
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
    final SFinishedBuild build10 = build().in(buildType).withProblem(createBuildProblem()).finish();
    checkExceptionOnItemSearch(BadRequestException.class, "No_match");
    checkExceptionOnItemsSearch(BadRequestException.class, "No_match");
    check("build:(id:" + build10.getBuildId() + ")", ((BuildPromotionEx) build10.getBuildPromotion()).getBuildProblems().get(0));
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) BuildPromotionEx(jetbrains.buildServer.serverSide.BuildPromotionEx) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test)

Example 33 with SFinishedBuild

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

the class UserRequestTest method testUserEnityExposure.

@Test
void testUserEnityExposure() throws Throwable {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    final SUser user1 = createUser("user1");
    final SUser user2 = createUser("user2");
    // filling all user fields
    user1.updateUserAccount("user1", "Display Name1", "email1@domain.com");
    user2.updateUserAccount("user2", "Display Name2", "email2@domain.com");
    SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
    group1.addUser(user1);
    group1.addUser(user2);
    user1.addRole(RoleScope.globalScope(), getProjectViewerRole());
    user2.addRole(RoleScope.globalScope(), getProjectViewerRole());
    user1.setLastLoginTimestamp(new Date());
    user2.setLastLoginTimestamp(new Date());
    user1.setPassword("secret");
    user2.setPassword("secret");
    myFixture.getUserAvatarsManager().saveAvatar(user1, new BufferedImage(1, 1, 1));
    myFixture.getUserAvatarsManager().saveAvatar(user2, new BufferedImage(1, 1, 1));
    enable2FA(user1);
    enable2FA(user2);
    SecurityContextImpl securityContext = myFixture.getSecurityContext();
    user2.addRole(RoleScope.globalScope(), getProjectAdminRole());
    SFinishedBuild build10 = build().in(myBuildType).by(user1).finish();
    SFinishedBuild build20 = build().in(myBuildType).by(user2).finish();
    BuildRequest buildRequest = new BuildRequest();
    buildRequest.initForTests(BaseFinderTest.getBeanContext(myFixture));
    // if changed, the checks below should be changed
    assertEquals(15, getSubEntitiesNames(User.class).size());
    final String fields = "triggered(user($long,hasPassword))";
    {
        Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
        // check that all is present
        User user = build.getTriggered().user;
        assertNotNull(user.getUsername());
        assertNotNull(user.getName());
        assertNotNull(user.getId());
        assertNotNull(user.getEmail());
        assertNotNull(user.getLastLogin());
        assertNotNull(user.getHref());
        assertNotNull(user.getProperties());
        assertNotNull(user.getRoles());
        assertNotNull(user.getGroups());
        assertNotNull(user.getHasPassword());
        assertNotNull(user.getAvatars());
        assertNotNull(user.getEnabled2FA());
        // not included in response
        assertNull(user.getPassword());
        // submit-only
        assertNull(user.getLocator());
        // obsolete
        assertNull(user.getRealm());
    }
    {
        Build build = buildRequest.serveBuild("id:" + build20.getBuildId(), fields, new FakeHttpServletRequest());
        // check that all is present
        User user = build.getTriggered().user;
        assertNotNull(user.getUsername());
        assertNotNull(user.getName());
        assertNotNull(user.getId());
        assertNotNull(user.getEmail());
        assertNotNull(user.getLastLogin());
        assertNotNull(user.getHref());
        assertNotNull(user.getProperties());
        assertNotNull(user.getRoles());
        assertNotNull(user.getGroups());
        assertNotNull(user.getHasPassword());
        assertNotNull(user.getAvatars());
        assertNotNull(user.getEnabled2FA());
        // not included in response
        assertNull(user.getPassword());
        // submit-only
        assertNull(user.getLocator());
        // obsolete
        assertNull(user.getRealm());
    }
    securityContext.runAs(user1, () -> {
        Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
        // check that all is present
        User user = build.getTriggered().user;
        assertNotNull(user.getUsername());
        assertNotNull(user.getName());
        assertNotNull(user.getId());
        assertNotNull(user.getEmail());
        assertNotNull(user.getLastLogin());
        assertNotNull(user.getHref());
        assertNotNull(user.getProperties());
        assertNotNull(user.getRoles());
        assertNotNull(user.getGroups());
        assertNotNull(user.getHasPassword());
        assertNotNull(user.getAvatars());
        assertNotNull(user.getEnabled2FA());
        assertNull(user.getPassword());
    });
    securityContext.runAs(user2, () -> {
        Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
        // check that all is present
        User user = build.getTriggered().user;
        assertNotNull(user.getUsername());
        assertNotNull(user.getName());
        assertNotNull(user.getId());
        assertNotNull(user.getEmail());
        assertNotNull(user.getLastLogin());
        assertNotNull(user.getHref());
        assertNotNull(user.getProperties());
        assertNotNull(user.getRoles());
        assertNotNull(user.getGroups());
        assertNotNull(user.getHasPassword());
        assertNotNull(user.getAvatars());
        assertNotNull(user.getEnabled2FA());
        assertNull(user.getPassword());
    });
    securityContext.runAs(user1, () -> {
        Build build = buildRequest.serveBuild("id:" + build20.getBuildId(), fields, new FakeHttpServletRequest());
        // check that all is present
        User user = build.getTriggered().user;
        assertNotNull(user.getUsername());
        assertNotNull(user.getName());
        assertNotNull(user.getId());
        assertNull(user.getEmail());
        assertNull(user.getLastLogin());
        assertNotNull(user.getHref());
        assertNull(user.getProperties());
        assertNull(user.getRoles());
        assertNull(user.getGroups());
        assertNull(user.getHasPassword());
        assertNull(user.getPassword());
        assertNotNull(user.getAvatars());
        assertNull(user.getEnabled2FA());
    });
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) SecurityContextImpl(jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) User(jetbrains.buildServer.server.rest.model.user.User) SUser(jetbrains.buildServer.users.SUser) Build(jetbrains.buildServer.server.rest.model.build.Build) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) BufferedImage(java.awt.image.BufferedImage) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 34 with SFinishedBuild

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

the class BaseTestScopesCollectorTest method buildTree.

protected void buildTree() {
    /* Builds a following tree:

                                 project
                               /        \
                       project1          project2
                      /        \                \
                buildconf1   subproject11    subproject21
                    |               \                    \
                  suite1          buildconf2            buildconf1
                 /      \             \             /        |    \
            packageA    packageB    suite2       suite1  suite2   suite0
             /     \        \          \           |         |         \
         class1   class2    class1   packageA   packageB   packageC    packageZ
         / | \       |         \        \          |         |            \
        b  a  c      a          b     class3    class1       class2      classZ
                                         \         |       / | | | | \      \
                                          c        a      h  g f e d  c      z
     */
    ProjectEx project = myFixture.createProject("project", "project");
    ProjectEx project1 = project.createProject("project1", "project1");
    ProjectEx project2 = project.createProject("project2", "project2");
    ProjectEx subproject11 = project1.createProject("subproject11", "subproject11");
    ProjectEx subproject21 = project2.createProject("subproject21", "subproject21");
    BuildTypeEx buildconf1 = project1.createBuildType("buildconf1");
    BuildTypeEx buildconf2 = subproject11.createBuildType("buildconf2");
    BuildTypeEx buildconf11 = subproject21.createBuildType("buildconf1");
    final SFinishedBuild build1 = build().in(buildconf1).startSuite("suite1").withTest("packageA.class1.b", false).withTest("packageA.class1.a", false).withTest("packageB.class1.b", false).withTest("packageA.class2.a", false).withTest("packageA.class1.c", false).endSuite().finish();
    final SFinishedBuild build2 = build().in(buildconf2).startSuite("suite2").withTest("packageA.class3.c", false).endSuite().finish();
    final SFinishedBuild build3 = build().in(buildconf11).startSuite("suite1").withTest("packageB.class1.a", false).endSuite().startSuite("suite2").withTest("packageC.class2.h", false).withTest("packageC.class2.g", false).withTest("packageC.class2.f", false).withTest("packageC.class2.e", false).withTest("packageC.class2.d", false).withTest("packageC.class2.c", false).endSuite().startSuite("suite0").withTest("packageZ.classZ.z", false).endSuite().finish();
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild)

Aggregations

SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)34 Test (org.testng.annotations.Test)32 TestFor (jetbrains.buildServer.util.TestFor)12 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)9 FakeHttpServletRequest (jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest)7 TestOccurrences (jetbrains.buildServer.server.rest.model.problem.TestOccurrences)7 TestScope (jetbrains.buildServer.server.rest.data.problem.scope.TestScope)4 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 TestOccurrence (jetbrains.buildServer.server.rest.model.problem.TestOccurrence)3 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)2 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)2 SkipException (org.testng.SkipException)2 BufferedImage (java.awt.image.BufferedImage)1 SUserGroup (jetbrains.buildServer.groups.SUserGroup)1 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)1 Build (jetbrains.buildServer.server.rest.model.build.Build)1 User (jetbrains.buildServer.server.rest.model.user.User)1 BuildPromotionEx (jetbrains.buildServer.serverSide.BuildPromotionEx)1 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)1