aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-05-13 13:35:10 +0200
committersonartech <sonartech@sonarsource.com>2020-05-26 20:05:32 +0000
commit21dacef212465e85aff5cec8803536f5f76a5192 (patch)
treeaebb036a938ecdf2034d190ecc375842e7ad062c
parent4fc4a5853354a00e80f1e27556385e4338b57cd0 (diff)
downloadsonarqube-21dacef212465e85aff5cec8803536f5f76a5192.tar.gz
sonarqube-21dacef212465e85aff5cec8803536f5f76a5192.zip
SONAR-13291 index components with qualifier ['APP', 'TRK', 'VW', 'SVW'] only in Component ES index
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java4
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java69
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java61
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java9
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json17
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json10
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java46
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java18
11 files changed, 100 insertions, 146 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index 3cf5437e300..d95733ac75c 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -295,9 +295,9 @@ public class ComponentDao implements Dao {
/**
* Selects all components that are relevant for indexing. The result is not returned (since it is usually too big), but handed over to the <code>handler</code>
*
- * @param session the database session
+ * @param session the database session
* @param projectUuid the project uuid, which is selected with all of its children
- * @param handler the action to be applied to every result
+ * @param handler the action to be applied to every result
*/
public void scrollForIndexing(DbSession session, @Nullable String projectUuid, ResultHandler<ComponentDto> handler) {
mapper(session).scrollForIndexing(projectUuid, handler);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 5e69f21aec5..f6513e87ee6 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -516,6 +516,8 @@
p.enabled=${_true}
and p.copy_component_uuid is null
and p.main_branch_project_uuid is null
+ and p.scope = 'PRJ'
+ and p.qualifier in ('TRK','VW','SVW','APP')
<if test="projectUuid != null">
and p.project_uuid = #{projectUuid,jdbcType=VARCHAR}
</if>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index bced88cba5d..eb93250b8d0 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -41,7 +41,6 @@ import javax.annotation.Nullable;
import org.assertj.core.api.ListAssert;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.api.resources.Qualifiers;
@@ -63,6 +62,7 @@ import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.resources.Qualifiers.APP;
@@ -92,9 +92,6 @@ public class ComponentDaoTest {
private static final String A_VIEW_UUID = "view-uuid";
private static final ComponentQuery ALL_PROJECTS_COMPONENT_QUERY = ComponentQuery.builder().setQualifiers("TRK").build();
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
private System2 system2 = new AlwaysIncreasingSystem2(1000L);
@Rule
@@ -181,9 +178,8 @@ public class ComponentDaoTest {
public void selectOrFailByUuid_fails_when_component_not_found() {
db.components().insertPublicProject();
- expectedException.expect(RowNotFoundException.class);
-
- underTest.selectOrFailByUuid(dbSession, "unknown");
+ assertThatThrownBy(() -> underTest.selectOrFailByUuid(dbSession, "unknown"))
+ .isInstanceOf(RowNotFoundException.class);
}
@Test
@@ -251,9 +247,8 @@ public class ComponentDaoTest {
public void selectOrFailByKey_fails_when_component_not_found() {
db.components().insertPrivateProject();
- expectedException.expect(RowNotFoundException.class);
-
- underTest.selectOrFailByKey(dbSession, "unknown");
+ assertThatThrownBy(() -> underTest.selectOrFailByKey(dbSession, "unknown"))
+ .isInstanceOf(RowNotFoundException.class);
}
@Test
@@ -391,10 +386,9 @@ public class ComponentDaoTest {
@Test
public void fail_with_IAE_select_component_keys_by_qualifiers_on_empty_qualifier() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Qualifiers cannot be empty");
-
- underTest.selectComponentsByQualifiers(dbSession, Collections.emptySet());
+ assertThatThrownBy(() -> underTest.selectComponentsByQualifiers(dbSession, Collections.emptySet()))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Qualifiers cannot be empty");
}
@Test
@@ -1166,10 +1160,9 @@ public class ComponentDaoTest {
@Test
public void countByQuery_with_organization_throws_NPE_of_organizationUuid_is_null() {
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("organizationUuid can't be null");
-
- underTest.countByQuery(dbSession, null, ALL_PROJECTS_COMPONENT_QUERY);
+ assertThatThrownBy(() -> underTest.countByQuery(dbSession, null, ALL_PROJECTS_COMPONENT_QUERY))
+ .isInstanceOf(NullPointerException.class)
+ .hasMessage("organizationUuid can't be null");
}
@Test
@@ -1193,10 +1186,9 @@ public class ComponentDaoTest {
}
private void assertThatCountByQueryThrowsIAE(ComponentQuery.Builder query, String expectedMessage) {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage(expectedMessage);
-
- underTest.countByQuery(dbSession, query.build());
+ assertThatThrownBy(() -> underTest.countByQuery(dbSession, query.build()))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(expectedMessage);
}
@Test
@@ -1223,16 +1215,24 @@ public class ComponentDaoTest {
public void selectForIndexing_all() {
assertSelectForIndexing(null)
.doesNotContain("DIS7")
- .doesNotContain("COPY8")
- .containsExactlyInAnyOrder("U1", "U2", "U3", "U4", "U5", "U6", "VW1");
+ .doesNotContain("COPY8") // copied projects
+ .doesNotContain("U2", "U6")// modules
+ .doesNotContain("U3")// dir
+ .doesNotContain("U4")// file
+ .containsExactlyInAnyOrder("U1", "U5", "VW1");
}
@Test
public void selectForIndexing_project() {
assertSelectForIndexing("U1")
.doesNotContain("DIS7")
- .doesNotContain("COPY8")
- .containsExactlyInAnyOrder("U1", "U2", "U3", "U4");
+ .doesNotContain("COPY8") // copied projects
+ .doesNotContain("U6") // other projects
+ .doesNotContain("VW1") // view
+ .doesNotContain("U2", "U6")// modules
+ .doesNotContain("U3")// dir
+ .doesNotContain("U4")// file
+ .containsExactlyInAnyOrder("U1");
}
private ListAssert<String> assertSelectForIndexing(@Nullable String projectUuid) {
@@ -1253,7 +1253,8 @@ public class ComponentDaoTest {
ComponentDto moduleOnProject2 = db.components().insertComponent(newModuleDto("U6", project2));
List<ComponentDto> components = new ArrayList<>();
- underTest.scrollForIndexing(dbSession, projectUuid, context -> components.add(context.getResultObject()));
+ underTest.scrollForIndexing(dbSession, projectUuid,
+ context -> components.add(context.getResultObject()));
return (ListAssert<String>) assertThat(components).extracting(ComponentDto::uuid);
}
@@ -1361,10 +1362,9 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_with_organization_throws_NPE_of_organizationUuid_is_null() {
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("organizationUuid can't be null");
-
- underTest.selectByQuery(dbSession, null, ALL_PROJECTS_COMPONENT_QUERY, 1, 1);
+ assertThatThrownBy(() -> underTest.selectByQuery(dbSession, null, ALL_PROJECTS_COMPONENT_QUERY, 1, 1))
+ .isInstanceOf(NullPointerException.class)
+ .hasMessage("organizationUuid can't be null");
}
@Test
@@ -1388,10 +1388,9 @@ public class ComponentDaoTest {
}
private void assertThatSelectByQueryThrowsIAE(ComponentQuery.Builder query, String expectedMessage) {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage(expectedMessage);
-
- underTest.selectByQuery(dbSession, query.build(), 0, Integer.MAX_VALUE);
+ assertThatThrownBy(() -> underTest.selectByQuery(dbSession, query.build(), 0, Integer.MAX_VALUE))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(expectedMessage);
}
@Test
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
index 32ffaa2dcf3..896979d097e 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
@@ -40,12 +40,11 @@ import static java.util.Collections.emptySet;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
-import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.server.component.index.ComponentIndexDefinition.FIELD_NAME;
import static org.sonar.server.component.index.ComponentIndexDefinition.TYPE_COMPONENT;
-import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
import static org.sonar.server.es.ProjectIndexer.Cause.PROJECT_CREATION;
import static org.sonar.server.es.ProjectIndexer.Cause.PROJECT_DELETION;
+import static org.sonar.server.es.newindex.DefaultIndexSettingsElement.SORTABLE_ANALYZER;
public class ComponentIndexerTest {
@@ -112,11 +111,10 @@ public class ComponentIndexerTest {
@Test
public void indexOnAnalysis_indexes_project() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
underTest.indexOnAnalysis(project.uuid());
- assertThatIndexContainsOnly(project, file);
+ assertThatIndexContainsOnly(project);
}
@Test
@@ -125,9 +123,8 @@ public class ComponentIndexerTest {
underTest.indexOnAnalysis(project.uuid());
assertThatIndexContainsOnly(project);
- ComponentDto file = db.components().insertComponent(newFileDto(project));
underTest.indexOnAnalysis(project.uuid());
- assertThatIndexContainsOnly(project, file);
+ assertThatIndexContainsOnly(project);
}
@Test
@@ -177,54 +174,31 @@ public class ComponentIndexerTest {
@Test
public void update_index_on_project_creation() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
IndexingResult result = indexProject(project, PROJECT_CREATION);
- assertThatIndexContainsOnly(project, file);
- // two requests (one per component)
- assertThat(result.getTotal()).isEqualTo(2L);
- assertThat(result.getSuccess()).isEqualTo(2L);
- }
-
- @Test
- public void do_not_delete_orphans_when_updating_project() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
-
- indexProject(project, PROJECT_CREATION);
- assertThatIndexContainsOnly(project, file);
-
- db.getDbClient().componentDao().delete(db.getSession(), file.uuid());
-
- IndexingResult result = indexProject(project, ProjectIndexer.Cause.PROJECT_KEY_UPDATE);
- assertThatIndexContainsOnly(project, file);
- // single request for project, no request for file
- assertThat(result.getTotal()).isEqualTo(1);
- assertThat(result.getSuccess()).isEqualTo(1);
+ assertThatIndexContainsOnly(project);
+ assertThat(result.getTotal()).isEqualTo(1L);
+ assertThat(result.getSuccess()).isEqualTo(1L);
}
@Test
public void delete_some_components() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file1 = db.components().insertComponent(newFileDto(project));
- ComponentDto file2 = db.components().insertComponent(newFileDto(project));
indexProject(project, PROJECT_CREATION);
- underTest.delete(project.uuid(), singletonList(file1.uuid()));
+ underTest.delete(project.uuid(), emptySet());
- assertThatIndexContainsOnly(project, file2);
+ assertThatIndexContainsOnly(project);
}
@Test
public void delete_project() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
indexProject(project, PROJECT_CREATION);
- assertThatIndexHasSize(2);
+ assertThatIndexHasSize(1);
db.getDbClient().componentDao().delete(db.getSession(), project.uuid());
- db.getDbClient().componentDao().delete(db.getSession(), file.uuid());
indexProject(project, PROJECT_DELETION);
assertThatIndexHasSize(0);
@@ -232,26 +206,25 @@ public class ComponentIndexerTest {
@Test
public void errors_during_indexing_are_recovered() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
+ ComponentDto project1 = db.components().insertPrivateProject();
es.lockWrites(TYPE_COMPONENT);
- IndexingResult result = indexProject(project, PROJECT_CREATION);
- assertThat(result.getTotal()).isEqualTo(2L);
- assertThat(result.getFailures()).isEqualTo(2L);
+ IndexingResult result = indexProject(project1, PROJECT_CREATION);
+ assertThat(result.getTotal()).isEqualTo(1L);
+ assertThat(result.getFailures()).isEqualTo(1L);
// index is still read-only, fail to recover
result = recover();
- assertThat(result.getTotal()).isEqualTo(2L);
- assertThat(result.getFailures()).isEqualTo(2L);
+ assertThat(result.getTotal()).isEqualTo(1L);
+ assertThat(result.getFailures()).isEqualTo(1L);
assertThat(es.countDocuments(TYPE_COMPONENT)).isEqualTo(0);
es.unlockWrites(TYPE_COMPONENT);
result = recover();
- assertThat(result.getTotal()).isEqualTo(2L);
+ assertThat(result.getTotal()).isEqualTo(1L);
assertThat(result.getFailures()).isEqualTo(0L);
- assertThatIndexContainsOnly(project, file);
+ assertThatIndexContainsOnly(project1);
}
private IndexingResult indexProject(ComponentDto project, ProjectIndexer.Cause cause) {
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
index 7d4c2bcb1e9..ae98138c4e2 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
@@ -59,6 +60,7 @@ public class ComponentIndexSearchTest {
private ComponentIndex underTest = new ComponentIndex(es.client(), new WebAuthorizationTypeSupport(userSession), System2.INSTANCE);
@Test
+ @Ignore
public void filter_by_language() {
ComponentDto project = db.components().insertPrivateProject();
db.components().insertComponent(newFileDto(project).setLanguage("java"));
@@ -97,12 +99,13 @@ public class ComponentIndexSearchTest {
@Test
public void filter_by_qualifier() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
+ ComponentDto portfolio = db.components().insertPrivatePortfolio();
index(project);
+ index(portfolio);
- SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQualifiers(singleton(Qualifiers.FILE)).build(), new SearchOptions());
+ SearchIdResult<String> result = underTest.search(ComponentQuery.builder().setQualifiers(singleton(Qualifiers.PROJECT)).build(), new SearchOptions());
- assertThat(result.getUuids()).containsExactlyInAnyOrder(file.uuid());
+ assertThat(result.getUuids()).containsExactlyInAnyOrder(project.uuid());
}
@Test
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
index 4d81269850c..54fdab08141 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
@@ -89,8 +89,10 @@ public class SearchAction implements ComponentsWsAction {
.setDescription("Search for components")
.addPagingParams(100, MAX_LIMIT)
.setChangelog(
- new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS)),
- new Change("8.0", "Field 'id' from response has been removed"))
+ new Change("8.4", String.format("The use of 'DIR','FIL','UTS' as values for parameter '%s' is no longer supported", PARAM_QUALIFIERS)),
+ new Change("8.0", "Field 'id' from response has been removed"),
+ new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_QUALIFIERS))
+ )
.setResponseExample(getClass().getResource("search-components-example.json"))
.setHandler(this);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
index 0adc826a924..f570389fc21 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
@@ -119,6 +119,7 @@ public class SuggestionsAction implements ComponentsWsAction {
.setHandler(this)
.setResponseExample(Resources.getResource(this.getClass(), "suggestions-example.json"))
.setChangelog(
+ new Change("8.4", String.format("The use of 'DIR', 'FIL','UTS' as values for parameter '%s' is no longer supported", PARAM_MORE)),
new Change("7.6", String.format("The use of 'BRC' as value for parameter '%s' is deprecated", PARAM_MORE)));
action.createParam(PARAM_QUERY)
@@ -259,6 +260,9 @@ public class SuggestionsAction implements ComponentsWsAction {
Set<String> availableQualifiers = resourceTypes.getAll().stream()
.map(ResourceType::getQualifier)
.filter(q -> !q.equals(Qualifiers.MODULE))
+ .filter(q -> !q.equals(Qualifiers.DIRECTORY))
+ .filter(q -> !q.equals(Qualifiers.FILE))
+ .filter(q -> !q.equals(Qualifiers.UNIT_TEST_FILE))
.collect(MoreCollectors.toSet());
if (more == null) {
return stream(SuggestionCategory.values())
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json
index 0eb71aa1f14..641a8c7152d 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search-components-example.json
@@ -2,26 +2,11 @@
"paging": {
"pageIndex": 1,
"pageSize": 100,
- "total": 3
+ "total": 1
},
"components": [
{
"organization": "my-org-1",
- "key": "directory-key",
- "qualifier": "DIR",
- "name": "Directory Name",
- "project": "project-key"
- },
- {
- "organization": "my-org-1",
- "key": "file-key",
- "qualifier": "FIL",
- "name": "File Name",
- "language": "java",
- "project": "project-key"
- },
- {
- "organization": "my-org-1",
"key": "project-key",
"qualifier": "TRK",
"name": "Project Name",
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json
index 48a24e137b7..18e95da7cda 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/suggestions-example.json
@@ -38,16 +38,6 @@
}
],
"more": 0
- },
- {
- "q": "FIL",
- "items": [],
- "more": 0
- },
- {
- "q": "UTS",
- "items": [],
- "more": 0
}
],
"organizations": [
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
index c8a9f8664d9..8692d26d4b3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
@@ -120,8 +120,9 @@ public class SearchActionTest {
assertThat(action.changelog())
.extracting(Change::getVersion, Change::getDescription)
.containsExactlyInAnyOrder(
- tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"),
- tuple("8.0", "Field 'id' from response has been removed"));
+ tuple("8.4", "The use of 'DIR','FIL','UTS' as values for parameter 'qualifiers' is no longer supported"),
+ tuple("8.0", "Field 'id' from response has been removed"),
+ tuple("7.6", "The use of 'BRC' as value for parameter 'qualifiers' is deprecated"));
assertThat(action.responseExampleAsString()).isNotEmpty();
assertThat(action.params()).hasSize(6);
@@ -155,7 +156,7 @@ public class SearchActionTest {
}
@Test
- public void search_for_files() {
+ public void returns_empty_result_when_search_for_files() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
ComponentDto file1 = newFileDto(project).setDbKey("file1");
ComponentDto file2 = newFileDto(project).setDbKey("file2");
@@ -164,7 +165,7 @@ public class SearchActionTest {
SearchWsResponse response = call(new SearchRequest().setQuery(file1.getDbKey()).setQualifiers(singletonList(FILE)));
- assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(file1.getDbKey());
+ assertThat(response.getComponentsList()).isEmpty();
}
@Test
@@ -194,40 +195,35 @@ public class SearchActionTest {
}
@Test
- public void return_only_components_from_projects_on_which_user_has_browse_permission() {
+ public void return_only_projects_on_which_user_has_browse_permission() {
ComponentDto project1 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto file1 = newFileDto(project1).setDbKey("file1");
- ComponentDto file2 = newFileDto(project1).setDbKey("file2");
ComponentDto project2 = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto file3 = newFileDto(project2).setDbKey("file3");
- db.components().insertComponents(project1, file1, file2, project2, file3);
+ ComponentDto portfolio = ComponentTesting.newView(db.getDefaultOrganization());
+
+ db.components().insertComponents(project1, project2, portfolio);
setBrowsePermissionOnUserAndIndex(project1);
- SearchWsResponse response = call(new SearchRequest().setQualifiers(singletonList(FILE)));
+ SearchWsResponse response = call(new SearchRequest().setQualifiers(singletonList(PROJECT)));
assertThat(response.getComponentsList()).extracting(Component::getKey)
- .containsExactlyInAnyOrder(file1.getDbKey(), file2.getDbKey());
- assertThat(response.getPaging().getTotal()).isEqualTo(2);
+ .containsExactlyInAnyOrder(project1.getDbKey());
+ assertThat(response.getPaging().getTotal()).isEqualTo(1);
}
@Test
public void return_project_key() {
ComponentDto project = ComponentTesting.newPublicProjectDto(db.getDefaultOrganization());
ComponentDto module = ComponentTesting.newModuleDto(project);
- ComponentDto file1 = newFileDto(module).setDbKey("file1");
- ComponentDto file2 = newFileDto(module).setDbKey("file2");
- ComponentDto file3 = newFileDto(project).setDbKey("file3");
- db.components().insertComponents(project, module, file1, file2, file3);
+ ComponentDto dir1 = newDirectory(module, "dir1").setDbKey("dir1");
+ ComponentDto dir2 = newDirectory(module, "dir2").setDbKey("dir2");
+ ComponentDto dir3 = newDirectory(project, "dir3").setDbKey("dir3");
+ db.components().insertComponents(project, module, dir1, dir2, dir3);
setBrowsePermissionOnUserAndIndex(project);
- SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, MODULE, FILE)));
+ SearchWsResponse response = call(new SearchRequest().setQualifiers(asList(PROJECT, MODULE, DIRECTORY)));
assertThat(response.getComponentsList()).extracting(Component::getKey, Component::getProject)
- .containsOnly(tuple(project.getDbKey(), project.getDbKey()),
- tuple(module.getDbKey(), project.getDbKey()),
- tuple(file1.getDbKey(), project.getDbKey()),
- tuple(file2.getDbKey(), project.getDbKey()),
- tuple(file3.getDbKey(), project.getDbKey()));
+ .containsOnly(tuple(project.getDbKey(), project.getDbKey()));
}
@Test
@@ -265,14 +261,14 @@ public class SearchActionTest {
ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid").setName("Project Name").setDbKey("project-key");
ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setDbKey("module-key");
ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setDbKey("directory-key").setName("Directory Name");
- db.components().insertComponents(project, module, directory,
- newFileDto(module, directory, "file-uuid").setDbKey("file-key").setLanguage("java").setName("File Name"));
+ ComponentDto view = newView(organizationDto);
+ db.components().insertComponents(project, module, directory, view);
setBrowsePermissionOnUserAndIndex(project);
String response = ws.newRequest()
.setMediaType(MediaTypes.JSON)
.setParam(PARAM_ORGANIZATION, organizationDto.getKey())
- .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, DIRECTORY, FILE))
+ .setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, DIRECTORY))
.execute().getInput();
assertJson(response).isSimilarTo(ws.getDef().responseExampleAsString());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
index 8f1238b4d5d..cef814630e8 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
@@ -69,6 +69,7 @@ import static org.sonar.api.resources.Qualifiers.FILE;
import static org.sonar.api.resources.Qualifiers.MODULE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.SUBVIEW;
+import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
@@ -120,6 +121,7 @@ public class SuggestionsActionTest {
PARAM_QUERY,
PARAM_RECENTLY_BROWSED);
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
+ tuple("8.4", "The use of 'DIR', 'FIL','UTS' as values for parameter 'more' is no longer supported"),
tuple("7.6", "The use of 'BRC' as value for parameter 'more' is deprecated"));
WebService.Param recentlyBrowsed = action.param(PARAM_RECENTLY_BROWSED);
@@ -346,13 +348,13 @@ public class SuggestionsActionTest {
assertThat(response.getResultsList())
.extracting(Category::getQ, Category::getItemsCount)
- .containsExactlyInAnyOrder(tuple("VW", 0), tuple("APP", 0), tuple("SVW", 0), tuple("TRK", 1), tuple("FIL", 0), tuple("UTS", 0))
- .doesNotContain(tuple("BRC", 0));
+ .containsExactlyInAnyOrder(tuple("VW", 0), tuple("APP", 0), tuple("SVW", 0), tuple("TRK", 1))
+ .doesNotContain(tuple("BRC", 0), tuple("FIL", 0), tuple("UTS", 0));
}
@Test
public void suggestions_should_filter_allowed_qualifiers() {
- resourceTypes.setAllQualifiers(PROJECT, MODULE, FILE);
+ resourceTypes.setAllQualifiers(PROJECT, MODULE, FILE, UNIT_TEST_FILE);
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
componentIndexer.indexOnAnalysis(project.projectUuid());
userSessionRule.addProjectPermission(USER, project);
@@ -364,7 +366,7 @@ public class SuggestionsActionTest {
assertThat(response.getResultsList())
.extracting(Category::getQ)
- .containsExactlyInAnyOrder(PROJECT, FILE).doesNotContain(MODULE);
+ .containsExactlyInAnyOrder(PROJECT).doesNotContain(MODULE, FILE, UNIT_TEST_FILE);
}
@Test
@@ -577,7 +579,7 @@ public class SuggestionsActionTest {
assertThat(response.getResultsList())
.extracting(Category::getQ, Category::getItemsCount)
- .containsExactlyInAnyOrder(tuple("VW", 0), tuple("SVW", 0), tuple("APP", 0), tuple("TRK", 1), tuple("FIL", 0), tuple("UTS", 0));
+ .containsExactlyInAnyOrder(tuple("VW", 0), tuple("SVW", 0), tuple("APP", 0), tuple("TRK", 1));
}
@Test
@@ -590,7 +592,7 @@ public class SuggestionsActionTest {
ComponentDto project = db.components().insertPrivateProject(organization, p -> p.setName(query));
ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query));
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query));
- ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(Qualifiers.UNIT_TEST_FILE));
+ ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(UNIT_TEST_FILE));
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
authorizationIndexerTester.allowOnlyAnyone(view);
@@ -607,9 +609,7 @@ public class SuggestionsActionTest {
tuple(SuggestionCategory.APP.getName(), false),
tuple(SuggestionCategory.VIEW.getName(), false),
tuple(SuggestionCategory.SUBVIEW.getName(), false),
- tuple(SuggestionCategory.PROJECT.getName(), false),
- tuple(SuggestionCategory.FILE.getName(), true),
- tuple(SuggestionCategory.UNIT_TEST_FILE.getName(), true));
+ tuple(SuggestionCategory.PROJECT.getName(), false));
}
@Test