3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.component.index;
23 import java.util.Collections;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.sonar.db.component.ComponentDto;
27 import org.sonar.server.es.textsearch.ComponentTextSearchFeatureRepertoire;
29 import static com.google.common.collect.ImmutableSet.of;
30 import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
31 import static org.sonar.api.resources.Qualifiers.PROJECT;
33 public class ComponentIndexFeatureRecentlyBrowsedTest extends ComponentIndexTest {
36 public void before() {
37 features.set(query -> matchAllQuery(), ComponentTextSearchFeatureRepertoire.RECENTLY_BROWSED);
41 public void scoring_cares_about_recently_browsed() {
42 ComponentDto project1 = indexProject("sonarqube", "SonarQube");
43 ComponentDto project2 = indexProject("recent", "SonarQube Recently");
45 ComponentIndexQuery query1 = ComponentIndexQuery.builder()
46 .setQuery("SonarQube")
47 .setQualifiers(Collections.singletonList(PROJECT))
48 .setRecentlyBrowsedKeys(of(project1.getDbKey()))
50 assertSearch(query1).containsExactly(uuids(project1, project2));
52 ComponentIndexQuery query2 = ComponentIndexQuery.builder()
53 .setQuery("SonarQube")
54 .setQualifiers(Collections.singletonList(PROJECT))
55 .setRecentlyBrowsedKeys(of(project2.getDbKey()))
57 assertSearch(query2).containsExactly(uuids(project2, project1));