Search in sources :

Example 1 with FakeHttpServletRequest

use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.

the class TestOccurrenceRequestTest method testInvocationsAreFoundCorrectly.

@Test
@TestFor(issues = { "TW-70206" })
public void testInvocationsAreFoundCorrectly() {
    if (true)
        throw new SkipException("Ignored as current implementation does work only in a very specific number of cases when specific build is available when preparing TestOccurrences");
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
    final SFinishedBuild build = build().in(buildType).withTest("aaa", false).withTest("aaa", true).withTest("aaa", true).finish();
    String fields = "testCounters(failed,success,all,duration),testOccurrence(id,name,muted,status,invocations($locator(count:90000),testCounters(all,success,failed),testOccurrence(id,name,status,muted)))";
    String locator = "currentlyFailing:true,affectedProject:" + buildType.getProject().getExternalId();
    FakeHttpServletRequest mockRequest = new FakeHttpServletRequest();
    mockRequest.setRequestURL(String.format("http://test/httpAuth/app/rest/testOccurrences?locator=%s&fields=%s", locator, fields));
    TestOccurrences testOccurrences = myRequest.getTestOccurrences(locator, fields, null, mockRequest);
    assertEquals("Should return exactly one 'grouping' test run.", 1, testOccurrences.items.size());
    TestOccurrence grouping = testOccurrences.items.get(0);
    assertNotNull("Should contain invocations node.", grouping.getInvocations());
    assertEquals("Should contain exactly 3 occurrences.", 3, grouping.getInvocations().items.size());
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) TestOccurrence(jetbrains.buildServer.server.rest.model.problem.TestOccurrence) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 2 with FakeHttpServletRequest

use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.

the class TestOccurrenceRequestTest method testShouldRespectExpandInvocationsDimension.

@Test
@TestFor(issues = { "TW-70331" })
public void testShouldRespectExpandInvocationsDimension() {
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
    final SFinishedBuild build = build().in(buildType).withTest("aaa", false).withTest("aaa", false).withTest("aaa", true).finish();
    FakeHttpServletRequest mockRequest = new FakeHttpServletRequest();
    String fields = "testCounters(all,success,failed)";
    String locator = "build:" + build.getBuildId() + ",expandInvocations:true";
    mockRequest.setRequestURL(String.format("http://test/httpAuth/app/rest/testOccurrences?locator=%s&fields=%s", locator, fields));
    TestOccurrences testOccurrences = myRequest.getTestOccurrences(locator, fields, null, mockRequest);
    assertEquals(new Integer(3), testOccurrences.getTestCounters().getAll());
    assertEquals(new Integer(2), testOccurrences.getTestCounters().getFailed());
    assertEquals(new Integer(1), testOccurrences.getTestCounters().getSuccess());
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 3 with FakeHttpServletRequest

use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.

the class TestOccurrenceRequestTest method testWontFetchItemsWhenNotNeededWithExplicitFieldsValue.

@Test
public void testWontFetchItemsWhenNotNeededWithExplicitFieldsValue() {
    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() + "&fields=id,count,failed,testCounters(all,success)");
    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 4 with FakeHttpServletRequest

use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.

the class TwoFactorRequestTest method testSetupAdminKey.

@Test
public void testSetupAdminKey() throws Throwable {
    final SUser admin = createAdmin("admin");
    myFixture.getSecurityContext().runAs(admin, new SecurityContextEx.RunAsAction() {

        @Override
        public void run() {
            TwoFactorCredentials credentials = myRequest.setupTwoFactor();
            myRequest.confirmTwoFactor(credentials.uuid.toString(), 0, new FakeHttpServletRequest());
            assertNotNull(admin.getPropertyValue(SECRET_KEY_PROPERTY));
            assertNotNull(admin.getPropertyValue(RECOVERY_KEY_PROPERTY));
        }
    });
}
Also used : FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) SUser(jetbrains.buildServer.users.SUser) TwoFactorCredentials(jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 5 with FakeHttpServletRequest

use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.

the class TwoFactorRequestTest method testSetupUserKey.

@Test
public void testSetupUserKey() throws Throwable {
    final SUser user = createUser("user");
    myFixture.getSecurityContext().runAs(user, new SecurityContextEx.RunAsAction() {

        @Override
        public void run() throws Throwable {
            TwoFactorCredentials credentials = myRequest.setupTwoFactor();
            myRequest.confirmTwoFactor(credentials.uuid.toString(), 0, new FakeHttpServletRequest());
            assertNotNull(myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(SECRET_KEY_PROPERTY)));
            assertNotNull(myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(RECOVERY_KEY_PROPERTY)));
        }
    });
}
Also used : FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) SUser(jetbrains.buildServer.users.SUser) TwoFactorCredentials(jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Aggregations

FakeHttpServletRequest (jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest)10 Test (org.testng.annotations.Test)10 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)7 TestOccurrences (jetbrains.buildServer.server.rest.model.problem.TestOccurrences)6 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)4 SUser (jetbrains.buildServer.users.SUser)4 TwoFactorCredentials (jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials)3 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)3 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)3 TestFor (jetbrains.buildServer.util.TestFor)3 TestOccurrence (jetbrains.buildServer.server.rest.model.problem.TestOccurrence)2 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)2 SkipException (org.testng.SkipException)2 BufferedImage (java.awt.image.BufferedImage)1 SUserGroup (jetbrains.buildServer.groups.SUserGroup)1 Build (jetbrains.buildServer.server.rest.model.build.Build)1 User (jetbrains.buildServer.server.rest.model.user.User)1 SecurityContextImpl (jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl)1