private ZipFunction(int arity) { this(IntStream.rangeClosed(1, arity).mapToObj(s -> "T" + s).collect(toImmutableList())); }
@Override protected Stream<String> getQueryResourcePaths() { return IntStream.rangeClosed(1, 22) .mapToObj(i -> format("q%02d", i)) .map(queryId -> format("/sql/presto/tpch/%s.sql", queryId)); }
@Test public void nextId() { // Repeat a few times just to be sure... IntStream.rangeClosed(1, 5).forEach(i -> assertNextId()); }
private static ScmInfo convertToScmInfo(ScannerReport.Changesets changesets) { return new ScmInfoImpl(IntStream.rangeClosed(1, changesets.getChangesetIndexByLineCount()) .boxed() .collect(Collectors.toMap(x -> x, new LineIndexToChangeset(changesets), MoreCollectors.mergeNotSupportedMerger(), LinkedHashMap::new))); }
private static ShowWsResponse buildResponse(ComponentDto component, OrganizationDto organizationDto, List<ComponentDto> orderedAncestors, Optional<SnapshotDto> lastAnalysis) { ShowWsResponse.Builder response = ShowWsResponse.newBuilder(); response.setComponent(componentDtoToWsComponent(component, organizationDto, lastAnalysis)); // ancestors are ordered from root to leaf, whereas it's the opposite in WS response int size = orderedAncestors.size() - 1; IntStream.rangeClosed(0, size).forEach( index -> response.addAncestors(componentDtoToWsComponent(orderedAncestors.get(size - index), organizationDto, lastAnalysis))); return response.build(); }
@Test public void testAllArities() { for (int arity = MIN_ARITY; arity <= MAX_ARITY; arity++) { String[] arguments = IntStream.rangeClosed(1, arity) .mapToObj(index -> "ARRAY[" + index + "]") .toArray(String[]::new); Type[] types = IntStream.rangeClosed(1, arity) .mapToObj(index -> INTEGER) .toArray(Type[]::new); assertFunction( format("zip(%s)", join(", ", list(arguments))), zipReturnType(types), list(IntStream.rangeClosed(1, arity).boxed().collect(toList()))); } }
public List<SecurityStandardCategoryStatistics> getOwaspTop10Report(String projectUuid, boolean isViewOrApp, boolean includeCwe) { SearchRequestBuilder request = prepareNonClosedVulnerabilitiesAndHotspotSearch(projectUuid, isViewOrApp); Stream.concat(IntStream.rangeClosed(1, 10).mapToObj(i -> "a" + i), Stream.of(UNKNOWN_STANDARD)).forEach(owaspCategory -> { AggregationBuilder owaspCategoryAggs = AggregationBuilders .filter(owaspCategory, boolQuery() .filter(termQuery(FIELD_ISSUE_OWASP_TOP_10, owaspCategory))); request.addAggregation(addSecurityReportSubAggregations(owaspCategoryAggs, includeCwe)); }); return processSecurityReportSearchResults(request, includeCwe); }
@Test public void testArrayElements() { assertFunction("var_args_sum()", INTEGER, 0); assertFunction("var_args_sum(1)", INTEGER, 1); assertFunction("var_args_sum(1, 2)", INTEGER, 3); assertFunction("var_args_sum(null)", INTEGER, null); assertFunction("var_args_sum(1, null, 2, null, 3)", INTEGER, null); assertFunction("var_args_sum(1, 2, 3)", INTEGER, 6); // var_args_sum(1, 2, 3, ..., k) int k = 100; int expectedSum = (1 + k) * k / 2; assertFunction(format("var_args_sum(%s)", Joiner.on(",").join(IntStream.rangeClosed(1, k).boxed().collect(toSet()))), INTEGER, expectedSum); }
@Test public void shouldAddPatternToExcludeLinesWithMess() throws Exception { Path filePath = getResource("file-with-double-regexp-mess.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(IntStream.rangeClosed(1, 20).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(21, 29).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(30, 37).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }
@Test public void insert_data() { int nbOfInsert = 10 + new Random().nextInt(20); List<EsQueueDto> esQueueDtos = new ArrayList<>(); IntStream.rangeClosed(1, nbOfInsert).forEach( i -> esQueueDtos.add(EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())) ); underTest.insert(dbSession, esQueueDtos); assertThat(dbTester.countSql(dbSession, "select count(*) from es_queue")).isEqualTo(nbOfInsert); }
@Test public void shouldAddPatternToExcludeLinesWithWrongOrder() throws Exception { Path filePath = getResource("file-with-double-regexp-wrong-order.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(IntStream.rangeClosed(1, 24).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(25, 35).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }
@Test public void shouldAddPatternToExcludeLinesTillTheEnd() throws Exception { Path filePath = getResource("file-with-double-regexp-unfinished.txt"); fileMetadata.readMetadata(Files.newInputStream(filePath), UTF_8, filePath.toString(), regexpScanner); assertThat(javaFile.isIgnoreAllIssues()).isFalse(); assertThat(IntStream.rangeClosed(1, 20).noneMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); assertThat(IntStream.rangeClosed(21, 34).allMatch(javaFile::isIgnoreAllIssuesOnLine)).isTrue(); }
@Test public void fail_if_more_than_100_project_keys() { List<String> keys = IntStream.rangeClosed(1, 101) .mapToObj(i -> db.components().insertPrivateProject()) .map(ComponentDto::getDbKey) .collect(Collectors.toList()); MetricDto metric = db.measures().insertMetric(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("101 projects provided, more than maximum authorized (100)"); call(keys, singletonList(metric.getKey())); }
@Setup public void setup() { String tpch = "tpch"; session = testSessionBuilder() .setCatalog(tpch) .setSchema("sf1") .setSystemProperty("iterative_optimizer_enabled", iterativeOptimizerEnabled) .build(); queryRunner = new LocalQueryRunner(session); queryRunner.createCatalog(tpch, new TpchConnectorFactory(4), ImmutableMap.of(TPCH_COLUMN_NAMING_PROPERTY, ColumnNaming.STANDARD.name())); queries = IntStream.rangeClosed(1, 22) .boxed() .filter(i -> i != 15) // q15 has two queries in it .map(i -> readResource(String.format("/io/airlift/tpch/queries/q%d.sql", i))) .collect(toImmutableList()); }
@Test public void languages_facet_should_return_top_100_items() { rangeClosed(1, 101).forEach(i -> db.rules().insert(r -> r.setLanguage("lang" + i))); index(); SearchIdResult result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_LANGUAGES))); assertThat(result.getFacets().get(FACET_LANGUAGES).size()).isEqualTo(100); }
@Test public void repositories_facet_should_return_top_10_items() { rangeClosed(1, 11).forEach(i -> db.rules().insert(r -> r.setRepositoryKey("repo" + i))); index(); SearchIdResult result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_REPOSITORIES))); assertThat(result.getFacets().get(FACET_REPOSITORIES).size()).isEqualTo(10); }
@Test public void do_nothing_if_org_disabled() throws SQLException { String defaultOrganizationUuid = "ORG_UUID_1"; setDefaultOrganization(defaultOrganizationUuid); IntStream.rangeClosed(1, 3).forEach(i -> { insertProfile(defaultOrganizationUuid, "RP_UUID_" + i, false); insertProfile("ORG_UUID_404", "RP_UUID_404_" + i, false); }); underTest.execute(); assertThat(selectRulesProfiles(false)).containsExactlyInAnyOrder("RP_UUID_1", "RP_UUID_2", "RP_UUID_3", "RP_UUID_404_1", "RP_UUID_404_2", "RP_UUID_404_3"); }
@Test public void selectGroupNamesByQuery_is_paginated() { IntStream.rangeClosed(0, 9).forEach(i -> db.users().insertGroup(db.getDefaultOrganization(), i + "-name")); List<String> groupNames = underTest.selectGroupNamesByQuery(dbSession, newQuery().setPageIndex(2).setPageSize(3).build()); assertThat(groupNames).containsExactly("3-name", "4-name", "5-name"); }
@Test public void facets_on_languages_return_100_entries_plus_selected_values() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(organizationDto); indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project, null)).setLanguage("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null)).setLanguage("language1"); IssueDoc issue2 = newDoc(newFileDto(project, null)).setLanguage("language2"); indexIssues(issue1, issue2); assertThatFacetHasSize(IssueQuery.builder().build(), "languages", 100); assertThatFacetHasSize(IssueQuery.builder().languages(asList(issue1.language(), issue2.language())).build(), "languages", 102); }
@Test public void facets_on_authors_return_100_entries_plus_selected_values() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(organizationDto); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null)).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null)).setAuthorLogin("user1"); IssueDoc issue2 = newDoc(newFileDto(project, null)).setAuthorLogin("user2"); indexIssues(issue1, issue2); assertThatFacetHasSize(IssueQuery.builder().build(), "authors", 100); assertThatFacetHasSize(IssueQuery.builder().authors(asList(issue1.authorLogin(), issue2.authorLogin())).build(), "authors", 102); }