aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-05-31 15:21:44 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-06-09 08:26:48 +0200
commit1440ed4179e20a21a2b413dfaff98d2ff03346c0 (patch)
tree300c2815a9e5064cdcec93776e18ab3e047f69c9
parentf44d1beadc348d158996388fb2e68e8ab146d919 (diff)
downloadsonarqube-1440ed4179e20a21a2b413dfaff98d2ff03346c0.tar.gz
sonarqube-1440ed4179e20a21a2b413dfaff98d2ff03346c0.zip
Update projects page IT's
-rw-r--r--it/it-tests/src/test/java/it/Category6Suite.java2
-rw-r--r--it/it-tests/src/test/java/it/projectSearch/LeakProjectsPageTest.java130
-rw-r--r--it/it-tests/src/test/java/it/projectSearch/ProjectsPageTest.java18
-rw-r--r--it/it-tests/src/test/java/pageobjects/Navigation.java4
-rw-r--r--it/it-tests/src/test/java/pageobjects/projects/ProjectsPage.java33
5 files changed, 173 insertions, 14 deletions
diff --git a/it/it-tests/src/test/java/it/Category6Suite.java b/it/it-tests/src/test/java/it/Category6Suite.java
index 7c17870ee35..23383060fd2 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.LeakProjectsPageTest;
import it.projectSearch.SearchProjectsTest;
import it.qualityProfile.OrganizationQualityProfilesPageTest;
import it.uiExtension.OrganizationUiExtensionsTest;
@@ -51,6 +52,7 @@ import static util.ItUtils.xooPlugin;
OrganizationUiExtensionsTest.class,
BillingTest.class,
IssueTagsTest.class,
+ LeakProjectsPageTest.class,
SearchProjectsTest.class
})
public class Category6Suite {
diff --git a/it/it-tests/src/test/java/it/projectSearch/LeakProjectsPageTest.java b/it/it-tests/src/test/java/it/projectSearch/LeakProjectsPageTest.java
new file mode 100644
index 00000000000..95e06a627cc
--- /dev/null
+++ b/it/it-tests/src/test/java/it/projectSearch/LeakProjectsPageTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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 it.projectSearch;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import it.Category6Suite;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.client.WsClient;
+import org.sonarqube.ws.client.organization.CreateWsRequest;
+import pageobjects.Navigation;
+import pageobjects.projects.ProjectsPage;
+import util.ItUtils;
+
+import static com.codeborne.selenide.WebDriverRunner.url;
+import static it.Category6Suite.enableOrganizationsSupport;
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+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;
+
+public class LeakProjectsPageTest {
+
+ @ClassRule
+ public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+
+ @Rule
+ public Navigation nav = Navigation.get(orchestrator);
+
+ private static WsClient wsClient;
+
+ private String organizationKey;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ enableOrganizationsSupport();
+ setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+ wsClient = newAdminWsClient(orchestrator);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ organizationKey = ItUtils.newOrganizationKey();
+ wsClient.organizations().create(CreateWsRequest.builder()
+ .setKey(organizationKey)
+ .setName(organizationKey)
+ .build());
+ restoreProfile(orchestrator, SearchProjectsTest.class.getResource("/projectSearch/SearchProjectsTest/with-many-rules.xml"), organizationKey);
+ }
+
+ @After
+ public void tearDown() {
+ wsClient.organizations().delete(organizationKey);
+ }
+
+ @Test
+ public void should_display_leak_information() {
+ // This project has 0% duplication on new code
+ String projectKey2 = newProjectKey();
+ analyzeProject(projectKey2, "projectSearch/xoo-history-v1", "2016-12-31");
+ analyzeProject(projectKey2, "projectSearch/xoo-history-v2", null);
+
+ // This project has no duplication on new code
+ String projectKey1 = newProjectKey();
+ analyzeProject(projectKey1, "shared/xoo-sample", "2016-12-31");
+ analyzeProject(projectKey1, "shared/xoo-sample", null);
+
+ // Check the facets and project cards
+ ProjectsPage page = nav.logIn().asAdmin().openProjects(organizationKey);
+ page.changePerspective("Leak");
+ assertThat(url()).endsWith("/projects?view=leak");
+ page.shouldHaveTotal(2);
+ page.getProjectByKey(projectKey2)
+ .shouldHaveMeasure("new_reliability_rating", "0A")
+ .shouldHaveMeasure("new_security_rating", "0A")
+ .shouldHaveMeasure("new_maintainability_rating", "17A")
+ .shouldHaveMeasure("new_coverage", "–")
+ .shouldHaveMeasure("new_duplicated_lines_density", "0.0%")
+ .shouldHaveMeasure("new_lines", "17");
+ page.getFacetByProperty("new_duplications")
+ .shouldHaveValue("1", "1")
+ .shouldHaveValue("2", "0")
+ .shouldHaveValue("3", "0")
+ .shouldHaveValue("4", "0")
+ .shouldHaveValue("5", "0")
+ .shouldHaveValue("6", "1");
+ }
+
+ private void analyzeProject(String projectKey, String relativePath, @Nullable String analysisDate) {
+ List<String> keyValueProperties = new ArrayList<>(asList(
+ "sonar.projectKey", projectKey,
+ "sonar.organization", organizationKey,
+ "sonar.profile", "with-many-rules",
+ "sonar.login", "admin", "sonar.password", "admin",
+ "sonar.scm.disabled", "false"));
+ if (analysisDate != null) {
+ keyValueProperties.add("sonar.projectDate");
+ keyValueProperties.add(analysisDate);
+ }
+ orchestrator.executeBuild(SonarScanner.create(projectDir(relativePath), keyValueProperties.toArray(new String[0])));
+ }
+}
diff --git a/it/it-tests/src/test/java/it/projectSearch/ProjectsPageTest.java b/it/it-tests/src/test/java/it/projectSearch/ProjectsPageTest.java
index ee9024db54e..610d9ba0eb0 100644
--- a/it/it-tests/src/test/java/it/projectSearch/ProjectsPageTest.java
+++ b/it/it-tests/src/test/java/it/projectSearch/ProjectsPageTest.java
@@ -31,6 +31,8 @@ import org.sonarqube.ws.client.WsClient;
import pageobjects.Navigation;
import pageobjects.projects.ProjectsPage;
+import static com.codeborne.selenide.WebDriverRunner.url;
+import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.newAdminWsClient;
import static util.ItUtils.projectDir;
@@ -74,7 +76,8 @@ public class ProjectsPageTest {
.shouldHaveValue("2", "1")
.shouldHaveValue("3", "1")
.shouldHaveValue("4", "1")
- .shouldHaveValue("5", "1");
+ .shouldHaveValue("5", "1")
+ .shouldHaveValue("6", "0");
}
@Test
@@ -90,8 +93,8 @@ public class ProjectsPageTest {
// default page can be "All Projects" or "Favorite Projects" depending on your last choice
ProjectsPage page = nav.openProjects();
- // all projects for anonymous user
- page.shouldHaveTotal(2).shouldDisplayAllProjects();
+ // all projects for anonymous user with default sorting to analysis date
+ page.shouldHaveTotal(2).shouldDisplayAllProjectsWidthSort("-analysis_date");
// all projects by default for logged in user
page = nav.logIn().asAdmin().openProjects();
@@ -144,6 +147,15 @@ public class ProjectsPageTest {
}
@Test
+ public void should_switch_between_perspectives() {
+ ProjectsPage page = nav.logIn().asAdmin().openProjects();
+ page.changePerspective("Risk");
+ assertThat(url()).endsWith("/projects?view=visualizations&visualization=risk");
+ page.changePerspective("Leak");
+ assertThat(url()).endsWith("/projects?view=leak");
+ }
+
+ @Test
public void should_sort_by_facet() {
ProjectsPage page = nav.openProjects();
page.sortProjects("Duplications");
diff --git a/it/it-tests/src/test/java/pageobjects/Navigation.java b/it/it-tests/src/test/java/pageobjects/Navigation.java
index 09474474a04..47a0dd966f6 100644
--- a/it/it-tests/src/test/java/pageobjects/Navigation.java
+++ b/it/it-tests/src/test/java/pageobjects/Navigation.java
@@ -63,6 +63,10 @@ public class Navigation extends ExternalResource {
return open("/projects", ProjectsPage.class);
}
+ public ProjectsPage openProjects(String organization) {
+ return open("/organizations/" + organization + "/projects", ProjectsPage.class);
+ }
+
public IssuesPage openIssues() {
return open("/issues", IssuesPage.class);
}
diff --git a/it/it-tests/src/test/java/pageobjects/projects/ProjectsPage.java b/it/it-tests/src/test/java/pageobjects/projects/ProjectsPage.java
index 2395f837b7f..21bc73da4a0 100644
--- a/it/it-tests/src/test/java/pageobjects/projects/ProjectsPage.java
+++ b/it/it-tests/src/test/java/pageobjects/projects/ProjectsPage.java
@@ -69,6 +69,11 @@ public class ProjectsPage {
return this;
}
+ public ProjectsPage shouldDisplayAllProjectsWidthSort(String sort) {
+ assertThat(url()).endsWith("/projects?sort=" + sort);
+ return this;
+ }
+
public ProjectsPage shouldDisplayFavoriteProjects() {
assertThat(url()).endsWith("/projects/favorite");
return this;
@@ -90,25 +95,31 @@ public class ProjectsPage {
return this;
}
+ public ProjectsPage changePerspective(String perspective) {
+ SelenideElement sortSelect = getOpenTopBar().$(".js-projects-perspective-select");
+ sortSelect.$(".Select-value").should(Condition.exist).click();
+ sortSelect.$(".Select-option[title='" + perspective + "']").should(Condition.exist).click();
+ return this;
+ }
+
public ProjectsPage sortProjects(String sort) {
- SelenideElement topbar = $(".projects-topbar-actions").should(Condition.exist);
- if (!topbar.has(Condition.hasClass("open"))){
- $(".js-projects-topbar-open").click();
- }
- topbar.should(Condition.hasClass("open"));
- SelenideElement sortSelect = topbar.$(".js-projects-sorting-select");
+ SelenideElement sortSelect = getOpenTopBar().$(".js-projects-sorting-select");
sortSelect.$(".Select-value").should(Condition.exist).click();
sortSelect.$(".Select-option[title='" + sort + "']").should(Condition.exist).click();
return this;
}
public ProjectsPage invertSorting() {
- SelenideElement topbar = $(".projects-topbar-actions").should(Condition.exist);
- if (!topbar.has(Condition.hasClass("open"))){
+ getOpenTopBar().$(".js-projects-sorting-select a.button-icon").should(Condition.exist).click();
+ return this;
+ }
+
+ private SelenideElement getOpenTopBar() {
+ SelenideElement topBar = $(".projects-topbar-actions").should(Condition.exist);
+ if (!topBar.has(Condition.hasClass("open"))){
$(".js-projects-topbar-open").click();
}
- topbar.should(Condition.hasClass("open"));
- topbar.$(".js-projects-sorting-select a.button-icon").should(Condition.exist).click();
- return this;
+ topBar.should(Condition.hasClass("open"));
+ return topBar;
}
}