aboutsummaryrefslogtreecommitdiffstats
path: root/it/it-tests/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'it/it-tests/src/test')
-rw-r--r--it/it-tests/src/test/java/it/Category4Suite.java3
-rw-r--r--it/it-tests/src/test/java/it/Category6Suite.java4
-rw-r--r--it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java174
-rw-r--r--it/it-tests/src/test/java/util/ItUtils.java2
-rw-r--r--it/it-tests/src/test/resources/projectSearch/SearchProjectsTest/with-many-rules.xml43
5 files changed, 195 insertions, 31 deletions
diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java
index 20fc6409fec..878c8eb846d 100644
--- a/it/it-tests/src/test/java/it/Category4Suite.java
+++ b/it/it-tests/src/test/java/it/Category4Suite.java
@@ -31,7 +31,6 @@ import it.duplication.DuplicationsTest;
import it.duplication.NewDuplicationsTest;
import it.projectEvent.EventTest;
import it.projectEvent.ProjectActivityPageTest;
-import it.projectSearch.SearchProjectsTest;
import it.qualityProfile.QualityProfilesPageTest;
import it.qualityProfile.QualityProfilesRestoreAndSearchTest;
import it.serverSystem.HttpHeadersTest;
@@ -85,8 +84,6 @@ import static util.ItUtils.xooPlugin;
// project event
EventTest.class,
ProjectActivityPageTest.class,
- // project search
- SearchProjectsTest.class,
// http
HttpHeadersTest.class,
// ui
diff --git a/it/it-tests/src/test/java/it/Category6Suite.java b/it/it-tests/src/test/java/it/Category6Suite.java
index effe0c20cfb..7c17870ee35 100644
--- a/it/it-tests/src/test/java/it/Category6Suite.java
+++ b/it/it-tests/src/test/java/it/Category6Suite.java
@@ -25,6 +25,7 @@ import it.issue.OrganizationIssueAssignTest;
import it.organization.BillingTest;
import it.organization.OrganizationMembershipTest;
import it.organization.OrganizationTest;
+import it.projectSearch.SearchProjectsTest;
import it.qualityProfile.OrganizationQualityProfilesPageTest;
import it.uiExtension.OrganizationUiExtensionsTest;
import it.user.OrganizationIdentityProviderTest;
@@ -49,7 +50,8 @@ import static util.ItUtils.xooPlugin;
OrganizationTest.class,
OrganizationUiExtensionsTest.class,
BillingTest.class,
- IssueTagsTest.class
+ IssueTagsTest.class,
+ SearchProjectsTest.class
})
public class Category6Suite {
diff --git a/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java
index 619c6b5dc24..3dc6497bb82 100644
--- a/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java
+++ b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java
@@ -20,55 +20,74 @@
package it.projectSearch;
import com.sonar.orchestrator.Orchestrator;
-import it.Category4Suite;
+import com.sonar.orchestrator.build.SonarScanner;
+import it.Category6Suite;
import java.io.IOException;
+import org.assertj.core.groups.Tuple;
+import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
-import org.sonarqube.ws.Common.FacetValue;
+import org.sonarqube.ws.Common;
import org.sonarqube.ws.WsComponents.Component;
import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse;
import org.sonarqube.ws.client.component.SearchProjectsRequest;
+import org.sonarqube.ws.client.organization.CreateWsRequest;
+import org.sonarqube.ws.client.project.CreateRequest;
+import util.ItUtils;
import static com.sonar.orchestrator.build.SonarScanner.create;
+import static it.Category6Suite.enableOrganizationsSupport;
+import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
+import static util.ItUtils.deleteOrganizationsIfExists;
import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.newProjectKey;
import static util.ItUtils.projectDir;
+import static util.ItUtils.restoreProfile;
+import static util.ItUtils.setServerProperty;
/**
* Tests WS api/components/search_projects
*/
public class SearchProjectsTest {
- private static final String PROJECT_KEY = "sample";
- private static final String PROJECT_NAME = "Sample";
-
@ClassRule
- public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
+ public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+
+ private String organizationKey;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ enableOrganizationsSupport();
+ }
@Before
public void setUp() throws Exception {
- orchestrator.resetData();
+ organizationKey = ItUtils.newOrganizationKey();
+ newAdminWsClient(orchestrator).organizations().create(CreateWsRequest.builder()
+ .setKey(organizationKey)
+ .setName(organizationKey)
+ .build());
+ restoreProfile(orchestrator, SearchProjectsTest.class.getResource("/projectSearch/SearchProjectsTest/with-many-rules.xml"), organizationKey);
}
- @Test
- public void filter_projects_by_measure_values() throws Exception {
- orchestrator.executeBuild(create(projectDir("shared/xoo-sample")));
-
- verifyFilterMatches("ncloc > 1");
- verifyFilterMatches("ncloc > 1 and comment_lines < 10000");
- verifyFilterDoesNotMatch("ncloc <= 1");
+ @After
+ public void tearDown() throws Exception {
+ deleteOrganizationsIfExists(orchestrator, organizationKey);
}
@Test
- public void provisioned_projects_should_be_included_to_results() throws Exception {
- orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_NAME);
-
- SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().build());
+ public void filter_projects_by_measure_values() throws Exception {
+ String projectKey = newProjectKey();
+ analyzeProject(projectKey, "shared/xoo-sample");
- assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(PROJECT_KEY);
+ verifyFilterMatches(projectKey, "ncloc > 1");
+ verifyFilterMatches(projectKey, "ncloc > 1 and comment_lines < 10000");
+ verifyFilterDoesNotMatch("ncloc <= 1");
}
@Test
@@ -90,27 +109,130 @@ public class SearchProjectsTest {
.extracting(Component::getKey).containsExactly("project3");
assertThat(searchProjects(SearchProjectsRequest.builder().setFilter("query = \"nd\" AND ncloc > 50").build()).getComponentsList())
.extracting(Component::getKey).containsExactly("project3", "project4");
- assertThat(searchProjects(SearchProjectsRequest.builder().setFilter("query = \"unknown\" AND ncloc > 50").build()).getComponentsList()).isEmpty();;
+ assertThat(searchProjects(SearchProjectsRequest.builder().setFilter("query = \"unknown\" AND ncloc > 50").build()).getComponentsList()).isEmpty();
+ ;
// Check facets
assertThat(searchProjects(SearchProjectsRequest.builder().setFilter("query = \"apache\"").setFacets(singletonList("ncloc")).build()).getFacets().getFacets(0).getValuesList())
- .extracting(FacetValue::getVal, FacetValue::getCount)
+ .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount)
.containsOnly(tuple("*-1000.0", 3L), tuple("1000.0-10000.0", 0L), tuple("10000.0-100000.0", 0L), tuple("100000.0-500000.0", 0L), tuple("500000.0-*", 0L));
assertThat(searchProjects(SearchProjectsRequest.builder().setFilter("query = \"unknown\"").setFacets(singletonList("ncloc")).build()).getFacets().getFacets(0)
- .getValuesList()).extracting(FacetValue::getVal, FacetValue::getCount)
- .containsOnly(tuple("*-1000.0", 0L), tuple("1000.0-10000.0", 0L), tuple("10000.0-100000.0", 0L), tuple("100000.0-500000.0", 0L), tuple("500000.0-*", 0L));
+ .getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount)
+ .containsOnly(tuple("*-1000.0", 0L), tuple("1000.0-10000.0", 0L), tuple("10000.0-100000.0", 0L), tuple("100000.0-500000.0", 0L), tuple("500000.0-*", 0L));
+ }
+
+ @Test
+ public void provisioned_projects_should_be_included_to_results() throws Exception {
+ String projectKey = newProjectKey();
+ newAdminWsClient(orchestrator).projects().create(CreateRequest.builder().setKey(projectKey).setName(projectKey).setOrganization(organizationKey).build());
+
+ SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().setOrganization(organizationKey).build());
+
+ assertThat(response.getComponentsList()).extracting(Component::getKey).contains(projectKey);
+ }
+
+ @Test
+ public void should_return_facets() throws Exception {
+ analyzeProject(newProjectKey(), "shared/xoo-sample");
+ analyzeProject(newProjectKey(), "shared/xoo-multi-modules-sample");
+
+ SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().setOrganization(organizationKey).setFacets(asList(
+ "alert_status",
+ "coverage",
+ "duplicated_lines_density",
+ "languages",
+ "ncloc",
+ "reliability_rating",
+ "security_rating",
+ "sqale_rating",
+ "tags")).build());
+
+ checkFacet(response, "alert_status",
+ tuple("OK", 2L),
+ tuple("WARN", 0L),
+ tuple("ERROR", 0L));
+ checkFacet(response, "coverage",
+ tuple("*-30.0", 0L),
+ tuple("30.0-50.0", 0L),
+ tuple("50.0-70.0", 0L),
+ tuple("70.0-80.0", 0L),
+ tuple("80.0-*", 0L));
+ checkFacet(response, "duplicated_lines_density",
+ tuple("*-3.0", 2L),
+ tuple("3.0-5.0", 0L),
+ tuple("5.0-10.0", 0L),
+ tuple("10.0-20.0", 0L),
+ tuple("20.0-*", 0L));
+ checkFacet(response, "languages",
+ tuple("xoo", 2L));
+ checkFacet(response, "ncloc",
+ tuple("*-1000.0", 2L),
+ tuple("1000.0-10000.0", 0L),
+ tuple("10000.0-100000.0", 0L),
+ tuple("100000.0-500000.0", 0L),
+ tuple("500000.0-*", 0L));
+ checkFacet(response, "reliability_rating",
+ tuple("1", 2L),
+ tuple("2", 0L),
+ tuple("3", 0L),
+ tuple("4", 0L),
+ tuple("5", 0L));
+ checkFacet(response, "security_rating",
+ tuple("1", 2L),
+ tuple("2", 0L),
+ tuple("3", 0L),
+ tuple("4", 0L),
+ tuple("5", 0L));
+ checkFacet(response, "sqale_rating",
+ tuple("1", 0L),
+ tuple("2", 0L),
+ tuple("3", 0L),
+ tuple("4", 2L),
+ tuple("5", 0L));
+ checkFacet(response, "tags");
+ }
+
+ @Test
+ public void should_return_facets_on_leak() throws Exception {
+ setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+ String projectKey = newProjectKey();
+ analyzeProject(projectKey, "shared/xoo-history-v1");
+ analyzeProject(projectKey, "shared/xoo-history-v2");
+
+ SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().setOrganization(organizationKey).setFacets(asList(
+ "new_reliability_rating")).build());
+
+ checkFacet(response, "new_reliability_rating",
+ tuple("1", 1L),
+ tuple("2", 0L),
+ tuple("3", 0L),
+ tuple("4", 0L),
+ tuple("5", 0L));
+ }
+
+ private void checkFacet(SearchProjectsWsResponse response, String facetKey, Tuple... values) {
+ Common.Facet facet = response.getFacets().getFacetsList().stream().filter(f -> f.getProperty().equals(facetKey)).findAny().get();
+ assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsExactly(values);
+ }
+
+ private void analyzeProject(String projectKey, String relativePath) {
+ orchestrator.executeBuild(SonarScanner.create(projectDir(relativePath),
+ "sonar.projectKey", projectKey,
+ "sonar.organization", organizationKey,
+ "sonar.profile", "with-many-rules",
+ "sonar.login", "admin", "sonar.password", "admin"));
}
private SearchProjectsWsResponse searchProjects(String filter) throws IOException {
- return searchProjects(SearchProjectsRequest.builder().setFilter(filter).build());
+ return searchProjects(SearchProjectsRequest.builder().setOrganization(organizationKey).setFilter(filter).build());
}
private SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) throws IOException {
return newAdminWsClient(orchestrator).components().searchProjects(request);
}
- private void verifyFilterMatches(String filter) throws IOException {
- assertThat(searchProjects(filter).getComponentsList()).extracting(Component::getKey).containsOnly(PROJECT_KEY);
+ private void verifyFilterMatches(String projectKey, String filter) throws IOException {
+ assertThat(searchProjects(filter).getComponentsList()).extracting(Component::getKey).containsOnly(projectKey);
}
private void verifyFilterDoesNotMatch(String filter) throws IOException {
diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java
index 367e3a724c8..d3ad26424f6 100644
--- a/it/it-tests/src/test/java/util/ItUtils.java
+++ b/it/it-tests/src/test/java/util/ItUtils.java
@@ -369,7 +369,7 @@ public class ItUtils {
}
public static String newProjectKey() {
- return "key-" + randomAlphabetic(200);
+ return "key-" + randomAlphabetic(100);
}
public static void deleteOrganizationsIfExists(Orchestrator orchestrator, String... organizationKeys) {
diff --git a/it/it-tests/src/test/resources/projectSearch/SearchProjectsTest/with-many-rules.xml b/it/it-tests/src/test/resources/projectSearch/SearchProjectsTest/with-many-rules.xml
new file mode 100644
index 00000000000..366a3ab7576
--- /dev/null
+++ b/it/it-tests/src/test/resources/projectSearch/SearchProjectsTest/with-many-rules.xml
@@ -0,0 +1,43 @@
+<profile>
+ <name>with-many-rules</name>
+ <language>xoo</language>
+ <rules>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerLine</key>
+ <priority>MINOR</priority>
+ </rule>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerFile</key>
+ <priority>MAJOR</priority>
+ </rule>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>OneIssuePerModule</key>
+ <priority>CRITICAL</priority>
+ </rule>
+ <rule>
+ <repositoryKey>xoo</repositoryKey>
+ <key>HasTag</key>
+ <priority>INFO</priority>
+ <parameters>
+ <parameter>
+ <key>tag</key>
+ <value>xoo</value>
+ </parameter>
+ </parameters>
+ </rule>
+ <rule>
+ <repositoryKey>common-xoo</repositoryKey>
+ <key>InsufficientLineCoverage</key>
+ <priority>BLOCKER</priority>
+ <parameters>
+ <parameter>
+ <key>minimumLineCoverageRatio</key>
+ <value>90</value>
+ </parameter>
+ </parameters>
+ </rule>
+ </rules>
+</profile>