Search in sources :

Example 1 with TestOccurrence

use of jetbrains.buildServer.server.rest.model.problem.TestOccurrence in project teamcity-rest by JetBrains.

the class TestOccurrenceFinder method tryGetCachedInfo.

/**
 * Checks whether response can be built only using ShortStatistics without fetching test occurrences given locator and fields. If so, get this statistics.
 * In addition, check if test runs in a returned statistics require filtering.
 * @return ShortStatistics with a post filtering flag if there is enough data to produce the response, TestOccurrencesCachedInfo.empty() otherwise.
 */
@NotNull
public TestOccurrencesCachedInfo tryGetCachedInfo(@Nullable final String locatorText, @Nullable final String fieldsText) {
    if (locatorText == null || fieldsText == null)
        return TestOccurrencesCachedInfo.empty();
    Locator locator = Locator.locator(locatorText);
    Fields fields = new Fields(fieldsText);
    boolean postFilteringRequired = false;
    boolean needsActualOccurrence = fields.isIncluded("testOccurrence", false, false);
    if (needsActualOccurrence) {
        Status status = Util.resolveNull(locator.lookupSingleDimensionValue(STATUS), TestOccurrence::getStatusFromPosted);
        if (status == null || status != Status.FAILURE) {
            return TestOccurrencesCachedInfo.empty();
        }
        Fields occurrenceFields = fields.getNestedField("testOccurrence");
        FieldInclusionChecker checker = FieldInclusionChecker.getForClass(TestOccurrence.class);
        if (!FASTPATH_ALLOWED_FIELDS.containsAll(checker.getAllPotentiallyIncludedFields(occurrenceFields))) {
            return TestOccurrencesCachedInfo.empty();
        }
        // let's just do it always if we need items
        postFilteringRequired = true;
    }
    String buildDimension = locator.getSingleDimensionValue(BUILD);
    if (buildDimension == null)
        return TestOccurrencesCachedInfo.empty();
    if (locator.getSingleDimensionValueAsStrictBoolean(EXPAND_INVOCATIONS, false)) {
        // Expand invocations requires additional logic
        return TestOccurrencesCachedInfo.empty();
    }
    List<BuildPromotion> buildPromotions = myBuildFinder.getBuilds(null, buildDimension).myEntries;
    if (buildPromotions.size() != 1) {
        // If there is not a single build to the criteria,
        return TestOccurrencesCachedInfo.empty();
    }
    SBuild build = buildPromotions.get(0).getAssociatedBuild();
    if (build == null)
        return TestOccurrencesCachedInfo.empty();
    // let's not construct a filter if we already know that we want to filter anyways
    if (!postFilteringRequired) {
        // If any kind of filter is defined then post filtering is necessary
        MultiCheckerFilter<STestRun> filter = (MultiCheckerFilter<STestRun>) getFilter(locator);
        // Personal builds filter is always there
        postFilteringRequired = filter.getSubFiltersCount() > 1;
    }
    return new TestOccurrencesCachedInfo(build.getShortStatistics(), postFilteringRequired);
}
Also used : Status(jetbrains.buildServer.messages.Status) TestOccurrence(jetbrains.buildServer.server.rest.model.problem.TestOccurrence) Fields(jetbrains.buildServer.server.rest.model.Fields) FieldInclusionChecker(jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TestOccurrence

use of jetbrains.buildServer.server.rest.model.problem.TestOccurrence 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 3 with TestOccurrence

use of jetbrains.buildServer.server.rest.model.problem.TestOccurrence in project teamcity-rest by JetBrains.

the class TestOccurrenceRequestTest method testTestOccurrenceFields.

@Test
public void testTestOccurrenceFields() {
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
    final SFinishedBuild build10 = build().in(buildType).withTest(BuildBuilder.TestData.test("aaa").duration(76)).withTest(BuildBuilder.TestData.test("bbb").out("std out").errorOut("str err").failed("error message", "stacktrace\nline 1\r\nline2").duration(67)).finish();
    {
        TestOccurrences testOccurrences = myRequest.getTestOccurrences("build:(id:" + build10.getBuildId() + "),status:FAILURE", "**", null, null);
        assertEquals(Integer.valueOf(1), testOccurrences.getCount());
        assertEquals(1, testOccurrences.items.size());
        TestOccurrence testOccurrence = testOccurrences.items.get(0);
        assertEquals("bbb", testOccurrence.getName());
        // "2" should actually be here, but API cannot guarantee preservation of the number when not all tests are retrieved, so documenting the current behavior.
        assertEquals("1", testOccurrence.getRunOrder());
        assertEquals(Integer.valueOf(67), testOccurrence.getDuration());
        assertEquals("FAILURE", testOccurrence.getStatus());
        assertEquals(Boolean.valueOf(false), testOccurrence.getIgnored());
        assertNull(testOccurrence.getIgnoreDetails());
        assertEquals("error message\nstacktrace\nline 1\r\nline2\n------- Stdout: -------\nstd out\n------- Stderr: -------\nstr err", testOccurrence.getDetails());
    }
    final SFinishedBuild build20 = build().in(buildType).withTest(BuildBuilder.TestData.test("aaa").duration(76)).withTest(BuildBuilder.TestData.test("bbb").failed("error message", "stacktrace\nline 1\nline2").duration(67)).withTest(BuildBuilder.TestData.test("ccc").ignored("Ignore reason").out("std\r\nout").duration(67)).finish();
    {
        TestOccurrences testOccurrences = myRequest.getTestOccurrences("build:(id:" + build20.getBuildId() + "),ignored:true", "**", null, null);
        assertEquals(Integer.valueOf(1), testOccurrences.getCount());
        assertEquals(1, testOccurrences.items.size());
        TestOccurrence testOccurrence = testOccurrences.items.get(0);
        assertEquals("ccc", testOccurrence.getName());
        assertEquals("3", testOccurrence.getRunOrder());
        assertEquals(Integer.valueOf(0), testOccurrence.getDuration());
        assertEquals("UNKNOWN", testOccurrence.getStatus());
        assertEquals(Boolean.valueOf(true), testOccurrence.getIgnored());
        assertEquals("Ignore reason", testOccurrence.getIgnoreDetails());
        assertNull(testOccurrence.getDetails());
    }
    // checking how ignored and failed test looks like. Just asserting current behavior
    final SFinishedBuild build30 = build().in(buildType).withTest(BuildBuilder.TestData.test("aaa").duration(76)).withTest(BuildBuilder.TestData.test("bbb").failed("error message", "stacktrace\nline 1\nline2").duration(67)).withTest(BuildBuilder.TestData.test("ccc").failed("error message", "stacktrace\nline 1\nline2").duration(67)).withTest(BuildBuilder.TestData.test("ccc").ignored("Ignore reason")).finish();
    {
        TestOccurrences testOccurrences = myRequest.getTestOccurrences("build:(id:" + build30.getBuildId() + "),test:(name:ccc)", "**", null, null);
        assertEquals(Integer.valueOf(1), testOccurrences.getCount());
        assertEquals(1, testOccurrences.items.size());
        TestOccurrence testOccurrence = testOccurrences.items.get(0);
        assertEquals("ccc", testOccurrence.getName());
        assertEquals("3", testOccurrence.getRunOrder());
        assertEquals(Integer.valueOf(67), testOccurrence.getDuration());
        assertEquals("FAILURE", testOccurrence.getStatus());
        assertEquals(Boolean.valueOf(false), testOccurrence.getIgnored());
        assertEquals("error message\nstacktrace\nline 1\nline2", testOccurrence.getDetails());
    }
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) TestOccurrence(jetbrains.buildServer.server.rest.model.problem.TestOccurrence) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test)

Example 4 with TestOccurrence

use of jetbrains.buildServer.server.rest.model.problem.TestOccurrence in project teamcity-rest by JetBrains.

the class TestOccurrenceRequestTest method testInvocationsAreFoundCorrectly2.

@Test
@TestFor(issues = { "TW-70206" })
public void testInvocationsAreFoundCorrectly2() {
    if (true)
        throw new SkipException("Reverted correct behaviour due to TW-70587");
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
    final SFinishedBuild build = build().in(buildType).withTest("aaa", false).withTest("aaa", false).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 5 with TestOccurrence

use of jetbrains.buildServer.server.rest.model.problem.TestOccurrence in project teamcity-rest by JetBrains.

the class TestOccurrenceFinderTest method testTestOccurrenceEntityInvocations.

@Test
public void testTestOccurrenceEntityInvocations() throws Exception {
    final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
    final SFinishedBuild build10 = build().in(buildType).withTest("aaa", true).withTest("aaa", true).withTest("bbb", true).withTest("ccc", false).withTest("bbb", true).withTest("aaa", false).withTest("aaa", true).withTest("ddd", true).finish();
    STestRun testRunAAA = build10.getFullStatistics().getAllTests().get(0);
    {
        TestOccurrence testOccurrence = new TestOccurrence(testRunAAA, getBeanContext(myServer), new Fields("invocations($long)"));
        assertEquals(Integer.valueOf(4), testOccurrence.getInvocations().getCount());
        assertEquals(Integer.valueOf(1), testOccurrence.getInvocations().getFailed());
        assertNotNull(testOccurrence.getInvocations().items);
        assertEquals(4, testOccurrence.getInvocations().items.size());
        assertEquals("SUCCESS", testOccurrence.getInvocations().items.get(0).getStatus());
        assertEquals("FAILURE", testOccurrence.getInvocations().items.get(2).getStatus());
    }
    {
        TestOccurrence testOccurrence = new TestOccurrence(testRunAAA, getBeanContext(myServer), new Fields("invocations($long,$locator(status:FAILURE))"));
        assertEquals(Integer.valueOf(1), testOccurrence.getInvocations().getCount());
        assertNotNull(testOccurrence.getInvocations().items);
        assertEquals(1, testOccurrence.getInvocations().items.size());
        assertEquals("FAILURE", testOccurrence.getInvocations().items.get(0).getStatus());
    }
}
Also used : TestOccurrence(jetbrains.buildServer.server.rest.model.problem.TestOccurrence) Fields(jetbrains.buildServer.server.rest.model.Fields) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test)

Aggregations

TestOccurrence (jetbrains.buildServer.server.rest.model.problem.TestOccurrence)8 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 Test (org.testng.annotations.Test)6 Fields (jetbrains.buildServer.server.rest.model.Fields)4 TestOccurrences (jetbrains.buildServer.server.rest.model.problem.TestOccurrences)3 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)3 FakeHttpServletRequest (jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest)2 Status (jetbrains.buildServer.messages.Status)2 TestFor (jetbrains.buildServer.util.TestFor)2 NotNull (org.jetbrains.annotations.NotNull)2 SkipException (org.testng.SkipException)2 BigDecimal (java.math.BigDecimal)1 TestMetadata (jetbrains.buildServer.messages.TestMetadata)1 TestScopeFilter (jetbrains.buildServer.server.rest.data.problem.scope.TestScopeFilter)1 AggregatingItemHolder (jetbrains.buildServer.server.rest.data.util.AggregatingItemHolder)1 TypedValue (jetbrains.buildServer.server.rest.model.problem.TypedValue)1 FieldInclusionChecker (jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker)1 Nullable (org.jetbrains.annotations.Nullable)1