Browse Source

SONAR-8221 Add IT on search projects action

tags/6.2-RC1
Julien Lancelot 7 years ago
parent
commit
20aa37c82a

+ 3
- 0
it/it-tests/src/test/java/it/Category4Suite.java View File

@@ -34,6 +34,7 @@ import it.duplication.NewDuplicationsTest;
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;
@@ -87,6 +88,8 @@ import static util.ItUtils.xooPlugin;
DashboardTest.class,
// project comparison
ProjectComparisonTest.class,
// project search
SearchProjectsTest.class,
// component search
AllProjectsTest.class,
// http

+ 73
- 0
it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java View File

@@ -0,0 +1,73 @@
/*
* 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);
}
}

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresResultSetIterator.java View File

@@ -141,7 +141,7 @@ public class ProjectMeasuresResultSetIterator extends ResultSetIterator<ProjectM
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()) {

+ 3
- 1
server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java View File

@@ -33,6 +33,7 @@ import org.sonar.api.utils.log.Loggers;
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;
@@ -56,7 +57,7 @@ public class BackendCleanup {
"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;
@@ -125,6 +126,7 @@ public class BackendCleanup {

clearIndex(IssueIndexDefinition.INDEX);
clearIndex(ViewIndexDefinition.INDEX);
clearIndex(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES);

} catch (SQLException e) {
throw new IllegalStateException("Fail to reset data", e);

server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java → server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupTest.java View File

@@ -25,6 +25,8 @@ 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;
@@ -36,14 +38,14 @@ 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 {
public class BackendCleanupTest {

@Rule
public EsTester esTester = new EsTester(
new RuleIndexDefinition(new MapSettings()),
new IssueIndexDefinition(new MapSettings()),
new ViewIndexDefinition(new MapSettings())
);
new ViewIndexDefinition(new MapSettings()),
new ProjectMeasuresIndexDefinition(new MapSettings()));

@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -95,6 +97,10 @@ public class BackendCleanupMediumTest {
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();

@@ -103,6 +109,7 @@ public class BackendCleanupMediumTest {
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);

server/sonar-server/src/test/resources/org/sonar/server/platform/BackendCleanupMediumTest/shared.xml → server/sonar-server/src/test/resources/org/sonar/server/platform/BackendCleanupTest/shared.xml View File


+ 3
- 5
sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java View File

@@ -20,6 +20,8 @@

package org.sonarqube.ws.client.component;

import javax.annotation.CheckForNull;

import static com.google.common.base.Preconditions.checkArgument;

public class SearchProjectsRequest {
@@ -36,6 +38,7 @@ public class SearchProjectsRequest {
this.filter = builder.filter;
}

@CheckForNull
public String getFilter() {
return filter;
}
@@ -83,12 +86,7 @@ public class SearchProjectsRequest {
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);
}
}

Loading…
Cancel
Save