import it.http.HttpHeadersTest;
import it.projectComparison.ProjectComparisonTest;
import it.projectEvent.EventTest;
+import it.projectSearch.SearchProjectsTest;
import it.qualityProfile.QualityProfilesPageTest;
import it.serverSystem.LogsTest;
import it.serverSystem.ServerSystemTest;
DashboardTest.class,
// project comparison
ProjectComparisonTest.class,
+ // project search
+ SearchProjectsTest.class,
// component search
AllProjectsTest.class,
// http
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package it.projectSearch;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import it.Category4Suite;
+import java.io.IOException;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonarqube.ws.WsComponents.Component;
+import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse;
+import org.sonarqube.ws.client.component.SearchProjectsRequest;
+
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.projectDir;
+
+public class SearchProjectsTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+
+ @Before
+ public void setUp() throws Exception {
+ orchestrator.resetData();
+ }
+
+ @Test
+ public void search_projects_with_filter_having_one_criterion() throws Exception {
+ orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")));
+
+ SearchProjectsWsResponse response = searchProjects("ncloc > 1");
+
+ assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("sample");
+ }
+
+ @Test
+ public void return_project_even_without_analysis() throws Exception {
+ orchestrator.getServer().provisionProject("sample", "sample");
+
+ SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().build());
+
+ assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("sample");
+ }
+
+ private SearchProjectsWsResponse searchProjects(String filter) throws IOException {
+ return searchProjects(SearchProjectsRequest.builder().setFilter(filter).build());
+ }
+
+ private SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) throws IOException {
+ return newAdminWsClient(orchestrator).components().searchProjects(request);
+ }
+}
return doc;
}
- private Measures selectMeasures(String projectUuid, String analysisUuid) {
+ private Measures selectMeasures(String projectUuid, @Nullable String analysisUuid) {
Measures measures = new Measures();
try (PreparedStatement stmt = createMeasuresStatement(projectUuid, analysisUuid);
ResultSet rs = stmt.executeQuery()) {
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.version.DatabaseVersion;
+import org.sonar.server.component.es.ProjectMeasuresIndexDefinition;
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
import org.sonar.server.issue.index.IssueIndexDefinition;
"organizations", BackendCleanup::truncateOrganizations,
"users", BackendCleanup::truncateUsers,
"internal_properties", BackendCleanup::truncateInternalProperties,
- "schema_migrations", BackendCleanup::truncateSchemaMigrations);
+ "schema_migrations", BackendCleanup::truncateSchemaMigrations);
private final EsClient esClient;
private final MyBatis myBatis;
clearIndex(IssueIndexDefinition.INDEX);
clearIndex(ViewIndexDefinition.INDEX);
+ clearIndex(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES);
} catch (SQLException e) {
throw new IllegalStateException("Fail to reset data", e);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.config.MapSettings;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.issue.IssueTesting;
-import org.sonar.server.issue.index.IssueIndexDefinition;
-import org.sonar.server.rule.index.RuleDoc;
-import org.sonar.server.rule.index.RuleIndexDefinition;
-import org.sonar.server.view.index.ViewDoc;
-import org.sonar.server.view.index.ViewIndexDefinition;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class BackendCleanupMediumTest {
-
- @Rule
- public EsTester esTester = new EsTester(
- new RuleIndexDefinition(new MapSettings()),
- new IssueIndexDefinition(new MapSettings()),
- new ViewIndexDefinition(new MapSettings())
- );
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- BackendCleanup backendCleanup = new BackendCleanup(esTester.client(), dbTester.myBatis());
-
- @Test
- public void clear_db() {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
-
- backendCleanup.clearDb();
-
- assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(0);
- assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(0);
- assertThat(dbTester.countRowsOfTable("rules")).isEqualTo(0);
- assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(0);
- }
-
- @Test
- public void clear_indexes() throws Exception {
- esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
- esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
-
- backendCleanup.clearIndexes();
-
- assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isEqualTo(0);
- }
-
- @Test
- public void clear_all() throws Exception {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
- esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
- esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
-
- backendCleanup.clearAll();
-
- assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isEqualTo(0);
- assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE)).isEqualTo(0);
-
- assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(0);
- assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(0);
- assertThat(dbTester.countRowsOfTable("rules")).isEqualTo(0);
- assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(0);
- }
-
- @Test
- public void reset_data() throws Exception {
- dbTester.prepareDbUnit(getClass(), "shared.xml");
- esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
- esTester.putDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, new ViewDoc().setUuid("CDEF").setProjects(newArrayList("DEFG")));
- esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
-
- backendCleanup.resetData();
-
- assertThat(dbTester.countRowsOfTable("projects")).isZero();
- assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
- assertThat(dbTester.countRowsOfTable("properties")).isZero();
- assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isZero();
- assertThat(esTester.countDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW)).isZero();
-
- // Rules should not be removed
- assertThat(dbTester.countRowsOfTable("rules")).isEqualTo(1);
- assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE)).isEqualTo(1);
- }
-
- private static RuleDoc newRuleDoc() {
- return new RuleDoc().setKey(RuleTesting.XOO_X1.toString()).setRepository(RuleTesting.XOO_X1.repository());
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.config.MapSettings;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.db.rule.RuleTesting;
+import org.sonar.server.component.es.ProjectMeasuresDoc;
+import org.sonar.server.component.es.ProjectMeasuresIndexDefinition;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.issue.IssueTesting;
+import org.sonar.server.issue.index.IssueIndexDefinition;
+import org.sonar.server.rule.index.RuleDoc;
+import org.sonar.server.rule.index.RuleIndexDefinition;
+import org.sonar.server.view.index.ViewDoc;
+import org.sonar.server.view.index.ViewIndexDefinition;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class BackendCleanupTest {
+
+ @Rule
+ public EsTester esTester = new EsTester(
+ new RuleIndexDefinition(new MapSettings()),
+ new IssueIndexDefinition(new MapSettings()),
+ new ViewIndexDefinition(new MapSettings()),
+ new ProjectMeasuresIndexDefinition(new MapSettings()));
+
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+ BackendCleanup backendCleanup = new BackendCleanup(esTester.client(), dbTester.myBatis());
+
+ @Test
+ public void clear_db() {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+ backendCleanup.clearDb();
+
+ assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("rules")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(0);
+ }
+
+ @Test
+ public void clear_indexes() throws Exception {
+ esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
+ esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
+
+ backendCleanup.clearIndexes();
+
+ assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isEqualTo(0);
+ }
+
+ @Test
+ public void clear_all() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+ esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
+ esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
+
+ backendCleanup.clearAll();
+
+ assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isEqualTo(0);
+ assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE)).isEqualTo(0);
+
+ assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("rules")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("properties")).isEqualTo(0);
+ }
+
+ @Test
+ public void reset_data() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "shared.xml");
+ esTester.putDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, IssueTesting.newDoc());
+ esTester.putDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, new ViewDoc().setUuid("CDEF").setProjects(newArrayList("DEFG")));
+ esTester.putDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE, newRuleDoc());
+ esTester.putDocuments(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES, ProjectMeasuresIndexDefinition.TYPE_PROJECT_MEASURES, new ProjectMeasuresDoc()
+ .setId("PROJECT")
+ .setKey("Key")
+ .setName("Name"));
+
+ backendCleanup.resetData();
+
+ assertThat(dbTester.countRowsOfTable("projects")).isZero();
+ assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
+ assertThat(dbTester.countRowsOfTable("properties")).isZero();
+ assertThat(esTester.countDocuments(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).isZero();
+ assertThat(esTester.countDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW)).isZero();
+ assertThat(esTester.countDocuments(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES, ProjectMeasuresIndexDefinition.TYPE_PROJECT_MEASURES)).isZero();
+
+ // Rules should not be removed
+ assertThat(dbTester.countRowsOfTable("rules")).isEqualTo(1);
+ assertThat(esTester.countDocuments(RuleIndexDefinition.INDEX, RuleIndexDefinition.TYPE_RULE)).isEqualTo(1);
+ }
+
+ private static RuleDoc newRuleDoc() {
+ return new RuleDoc().setKey(RuleTesting.XOO_X1.toString()).setRepository(RuleTesting.XOO_X1.repository());
+ }
+}
+++ /dev/null
-<dataset>
-
- <projects uuid="JKLM"
- uuid_path="NOT_USED"
- root_uuid="JKLM"
- project_uuid="JKLM"
- module_uuid="[null]"
- module_uuid_path="."
- enabled="[true]"
- path="[null]"
- id="100"
- scope="PRJ"
- qualifier="TRK"
- kee="org.struts:struts"
- name="Struts"/>
-
- <snapshots id="100"
- uuid="u100"
- component_uuid="JKLM"
- status="P"
- islast="[true]"
- purge_status="[null]"
- version="[null]"
- />
-
- <rules tags="[null]"
- system_tags="[null]"
- id="1"
- plugin_rule_key="NewRuleKey"
- plugin_name="plugin"
- name="new name"
- description="new description"
- status="DEPRECATED"
- plugin_config_key="NewConfigKey"
- priority="0"
- is_template="[true]"
- language="dart"
- template_id="3"
- note_data="[null]"
- note_user_login="[null]"
- note_created_at="[null]"
- note_updated_at="[null]"
- remediation_function="LINEAR"
- def_remediation_function="LINEAR_OFFSET"
- remediation_gap_mult="1h"
- def_remediation_gap_mult="5d"
- remediation_base_effort="5min"
- def_remediation_base_effort="10h"
- gap_description="squid.S115.effortToFix"
- description_format="MARKDOWN"
- created_at="150000"
- updated_at="150000"
- />
-
- <properties id="1"
- prop_key="sonar.profile.java"
- resource_id="1"
- user_id="[null]"
- is_empty="[true]"
- text_value="Sonar Way"/>
-
-</dataset>
--- /dev/null
+<dataset>
+
+ <projects uuid="JKLM"
+ uuid_path="NOT_USED"
+ root_uuid="JKLM"
+ project_uuid="JKLM"
+ module_uuid="[null]"
+ module_uuid_path="."
+ enabled="[true]"
+ path="[null]"
+ id="100"
+ scope="PRJ"
+ qualifier="TRK"
+ kee="org.struts:struts"
+ name="Struts"/>
+
+ <snapshots id="100"
+ uuid="u100"
+ component_uuid="JKLM"
+ status="P"
+ islast="[true]"
+ purge_status="[null]"
+ version="[null]"
+ />
+
+ <rules tags="[null]"
+ system_tags="[null]"
+ id="1"
+ plugin_rule_key="NewRuleKey"
+ plugin_name="plugin"
+ name="new name"
+ description="new description"
+ status="DEPRECATED"
+ plugin_config_key="NewConfigKey"
+ priority="0"
+ is_template="[true]"
+ language="dart"
+ template_id="3"
+ note_data="[null]"
+ note_user_login="[null]"
+ note_created_at="[null]"
+ note_updated_at="[null]"
+ remediation_function="LINEAR"
+ def_remediation_function="LINEAR_OFFSET"
+ remediation_gap_mult="1h"
+ def_remediation_gap_mult="5d"
+ remediation_base_effort="5min"
+ def_remediation_base_effort="10h"
+ gap_description="squid.S115.effortToFix"
+ description_format="MARKDOWN"
+ created_at="150000"
+ updated_at="150000"
+ />
+
+ <properties id="1"
+ prop_key="sonar.profile.java"
+ resource_id="1"
+ user_id="[null]"
+ is_empty="[true]"
+ text_value="Sonar Way"/>
+
+</dataset>
package org.sonarqube.ws.client.component;
+import javax.annotation.CheckForNull;
+
import static com.google.common.base.Preconditions.checkArgument;
public class SearchProjectsRequest {
this.filter = builder.filter;
}
+ @CheckForNull
public String getFilter() {
return filter;
}
if (pageSize == null) {
pageSize = DEFAULT_PAGE_SIZE;
}
- if (filter == null) {
- filter = "";
- }
-
checkArgument(pageSize <= MAX_PAGE_SIZE, "Page size must not be greater than %s", MAX_PAGE_SIZE);
-
return new SearchProjectsRequest(this);
}
}