use of jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker 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);
}
use of jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker in project teamcity-rest by JetBrains.
the class FieldInclusionCheckerTest method testDefaultsDefaults.
@Test
public void testDefaultsDefaults() {
FieldInclusionChecker checker = FieldInclusionChecker.getForClass(Model.class);
Assert.assertNull(checker.isIncluded("getter", Fields.SHORT));
Assert.assertNull(checker.isIncluded("getter", Fields.LONG));
Assert.assertFalse(checker.isIncluded("getter", Fields.NONE));
Assert.assertTrue(checker.isIncluded("getter", Fields.ALL));
}
use of jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker in project teamcity-rest by JetBrains.
the class FieldInclusionCheckerTest method doesNotCreateDuplicates.
@Test
public void doesNotCreateDuplicates() {
FieldInclusionChecker checker1 = FieldInclusionChecker.getForClass(Model.class);
FieldInclusionChecker checker2 = FieldInclusionChecker.getForClass(Model.class);
Assert.assertSame(checker1, checker2);
}
use of jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker in project teamcity-rest by JetBrains.
the class FieldInclusionCheckerTest method testDefaultsExclude.
@Test
public void testDefaultsExclude() {
FieldInclusionChecker checker = FieldInclusionChecker.getForClass(Model.class);
Assert.assertFalse(checker.isIncluded("exclude", Fields.SHORT));
Assert.assertFalse(checker.isIncluded("exclude", Fields.LONG));
Assert.assertFalse(checker.isIncluded("exclude", Fields.NONE));
Assert.assertTrue(checker.isIncluded("exclude", Fields.ALL));
}
use of jetbrains.buildServer.server.rest.util.fieldInclusion.FieldInclusionChecker in project teamcity-rest by JetBrains.
the class FieldInclusionCheckerTest method testPotentiallyIncluded.
@Test
public void testPotentiallyIncluded() {
FieldInclusionChecker checker = FieldInclusionChecker.getForClass(Model.class);
List<String> shouldInclude = Arrays.asList("field", "getter", "include", "includeNonDefault", "public void jetbrains.buildServer.server.rest.model.fields.FieldInclusionCheckerTest$Model.forgottenField()");
Set<String> toCheck = checker.getAllPotentiallyIncludedFields(new Fields(null));
Assert.assertEquals(shouldInclude.size(), toCheck.size());
for (String f : shouldInclude) {
Assert.assertTrue(toCheck.contains(f));
}
}
Aggregations