aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-08-30 15:46:54 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-09-11 11:28:29 +0200
commitce06125872c315509d4687cb8cf83fff38ba31ec (patch)
tree31497bc059695fb26f70738d9b398d71099cc387 /tests/src/test
parent71140666ff0e26cc77ac42e27e8badbc4fff8893 (diff)
downloadsonarqube-ce06125872c315509d4687cb8cf83fff38ba31ec.tar.gz
sonarqube-ce06125872c315509d4687cb8cf83fff38ba31ec.zip
SONAR-4566 Search old projects in WS api/projects/search
Diffstat (limited to 'tests/src/test')
-rw-r--r--tests/src/test/java/org/sonarqube/tests/Category6Suite.java2
-rw-r--r--tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java76
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java
index 01e7db07d07..d075f209596 100644
--- a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java
+++ b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java
@@ -38,6 +38,7 @@ import org.sonarqube.tests.organization.RootUserOnOrganizationTest;
import org.sonarqube.tests.projectAdministration.ProjectDeletionTest;
import org.sonarqube.tests.projectAdministration.ProjectKeyUpdateTest;
import org.sonarqube.tests.projectAdministration.ProjectProvisioningTest;
+import org.sonarqube.tests.projectAdministration.ProjectSearchTest;
import org.sonarqube.tests.projectSearch.LeakProjectsPageTest;
import org.sonarqube.tests.projectSearch.SearchProjectsTest;
import org.sonarqube.tests.qualityGate.OrganizationQualityGateUiTest;
@@ -79,6 +80,7 @@ import static util.ItUtils.xooPlugin;
ProjectDeletionTest.class,
ProjectProvisioningTest.class,
ProjectKeyUpdateTest.class,
+ ProjectSearchTest.class,
PermissionTemplateTest.class
})
public class Category6Suite {
diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java
new file mode 100644
index 00000000000..69178286b3b
--- /dev/null
+++ b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java
@@ -0,0 +1,76 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info 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.sonarqube.tests.projectAdministration;
+
+import com.sonar.orchestrator.Orchestrator;
+import java.util.Date;
+import org.apache.commons.lang.time.DateUtils;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.tests.Category6Suite;
+import org.sonarqube.tests.Tester;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsProjects.CreateWsResponse;
+import org.sonarqube.ws.WsProjects.SearchWsResponse;
+import org.sonarqube.ws.client.project.SearchWsRequest;
+
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.formatDate;
+import static util.ItUtils.runProjectAnalysis;
+
+public class ProjectSearchTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+ @Rule
+ public Tester tester = new Tester(orchestrator);
+
+ @Test
+ public void search_old_projects() {
+ Organizations.Organization organization = tester.organizations().generate();
+ CreateWsResponse.Project oldProject = tester.projects().generate(organization);
+ CreateWsResponse.Project recentProject = tester.projects().generate(organization);
+ Date now = new Date();
+ Date oneYearAgo = DateUtils.addDays(now, -365);
+ Date moreThanOneYearAgo = DateUtils.addDays(now, -366);
+
+ analyzeProject(oldProject.getKey(), moreThanOneYearAgo, organization.getKey());
+ analyzeProject(recentProject.getKey(), now, organization.getKey());
+
+ SearchWsResponse result = tester.wsClient().projects().search(SearchWsRequest.builder()
+ .setOrganization(organization.getKey())
+ .setQualifiers(singletonList("TRK"))
+ .setAnalyzedBefore(formatDate(oneYearAgo)).build());
+
+ assertThat(result.getComponentsList()).extracting(SearchWsResponse.Component::getKey).containsExactlyInAnyOrder(oldProject.getKey());
+ }
+
+ private void analyzeProject(String projectKey, Date analysisDate, String organizationKey) {
+ runProjectAnalysis(orchestrator, "shared/xoo-sample",
+ "sonar.organization", organizationKey,
+ "sonar.projectKey", projectKey,
+ "sonar.projectDate", formatDate(analysisDate),
+ "sonar.login", "admin",
+ "sonar.password", "admin");
+ }
+}