From: Stas Vilchik Date: Mon, 8 Aug 2016 08:45:56 +0000 (+0200) Subject: fix snapshot deletion X-Git-Tag: 6.1-RC1~436 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=864b32a022faf7a476573edf8d66b0daffd578f3;p=sonarqube.git fix snapshot deletion --- diff --git a/it/it-tests/src/test/java/it/projectAdministration/ProjectHistoryPageTest.java b/it/it-tests/src/test/java/it/projectAdministration/ProjectHistoryPageTest.java new file mode 100644 index 00000000000..f7e2afdcd49 --- /dev/null +++ b/it/it-tests/src/test/java/it/projectAdministration/ProjectHistoryPageTest.java @@ -0,0 +1,91 @@ +/* + * 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.projectAdministration; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import it.Category1Suite; +import java.util.List; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import pageobjects.Navigation; +import pageobjects.ProjectHistoryPage; +import pageobjects.ProjectHistorySnapshotItem; + +import static com.codeborne.selenide.Condition.exist; +import static com.codeborne.selenide.Condition.text; +import static com.codeborne.selenide.Selenide.confirm; +import static util.ItUtils.projectDir; + +public class ProjectHistoryPageTest { + + @ClassRule + public static Orchestrator ORCHESTRATOR = Category1Suite.ORCHESTRATOR; + + @Rule + public Navigation nav = Navigation.get(ORCHESTRATOR); + + @Before + public void setUp() { + ORCHESTRATOR.resetData(); + analyzeProject("shared/xoo-history-v1", "2014-10-19"); + analyzeProject("shared/xoo-history-v2", "2014-11-13"); + } + + @Test + public void should_list_snapshots() { + ProjectHistoryPage page = openPage(); + + page.getSnapshots().shouldHaveSize(2); + + List snapshots = page.getSnapshotsAsItems(); + + snapshots.get(0).getVersionText().shouldBe(text("1.0-SNAPSHOT")); + snapshots.get(0).getDeleteButton().shouldNot(exist); + + snapshots.get(1).getVersionText().shouldBe(text("0.9-SNAPSHOT")); + snapshots.get(1).getDeleteButton().should(exist); + } + + @Test + public void should_delete_snapshot() { + ProjectHistoryPage page = openPage(); + + page.getSnapshots().shouldHaveSize(2); + + page.getSnapshotsAsItems().get(1).clickDelete(); + confirm(); + + page.checkAlertDisplayed(); + page.getSnapshots().shouldHaveSize(1); + } + + private ProjectHistoryPage openPage() { + nav.logIn().submitCredentials("admin", "admin"); + return nav.openProjectHistory("sample"); + } + + private static void analyzeProject(String path, String date) { + ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir(path)) + .setProperties("sonar.projectDate", date)); + } +} diff --git a/it/it-tests/src/test/java/pageobjects/Navigation.java b/it/it-tests/src/test/java/pageobjects/Navigation.java index 46ee57ca425..e615acdcded 100644 --- a/it/it-tests/src/test/java/pageobjects/Navigation.java +++ b/it/it-tests/src/test/java/pageobjects/Navigation.java @@ -56,6 +56,12 @@ public class Navigation extends ExternalResource { return open(url, ProjectLinksPage.class); } + public ProjectHistoryPage openProjectHistory(String projectKey) { + // TODO encode projectKey + String url = "/project/history?id=" + projectKey; + return open(url, ProjectHistoryPage.class); + } + public void open(String relativeUrl) { Selenide.open(relativeUrl); } diff --git a/it/it-tests/src/test/java/pageobjects/ProjectHistoryPage.java b/it/it-tests/src/test/java/pageobjects/ProjectHistoryPage.java new file mode 100644 index 00000000000..83b0f5c9241 --- /dev/null +++ b/it/it-tests/src/test/java/pageobjects/ProjectHistoryPage.java @@ -0,0 +1,50 @@ +/* + * 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 pageobjects; + +import com.codeborne.selenide.ElementsCollection; +import java.util.List; +import java.util.stream.Collectors; + +import static com.codeborne.selenide.Condition.exist; +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; + +public class ProjectHistoryPage { + + public ProjectHistoryPage() { + $("#project-history").should(exist); + } + + public ElementsCollection getSnapshots() { + return $$("tr.snapshot"); + } + + public List getSnapshotsAsItems() { + return getSnapshots() + .stream() + .map(ProjectHistorySnapshotItem::new) + .collect(Collectors.toList()); + } + + public void checkAlertDisplayed() { + $("#info:not(.hidden)").should(exist); + } +} diff --git a/it/it-tests/src/test/java/pageobjects/ProjectHistorySnapshotItem.java b/it/it-tests/src/test/java/pageobjects/ProjectHistorySnapshotItem.java new file mode 100644 index 00000000000..d265e98f00b --- /dev/null +++ b/it/it-tests/src/test/java/pageobjects/ProjectHistorySnapshotItem.java @@ -0,0 +1,56 @@ +/* + * 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 pageobjects; + +import com.codeborne.selenide.SelenideElement; +import org.openqa.selenium.NoSuchElementException; + +public class ProjectHistorySnapshotItem { + + private final SelenideElement elt; + + public ProjectHistorySnapshotItem(SelenideElement elt) { + this.elt = elt; + } + + public SelenideElement getVersionText() { + return elt.$("td:nth-child(5) table td:nth-child(1)"); + } + + public SelenideElement getType() { + try { + return elt.$(".js-type"); + } catch (NoSuchElementException e) { + return null; + } + } + + public SelenideElement getUrl() { + return elt.$(".js-url"); + } + + public SelenideElement getDeleteButton() { + return elt.$("td:nth-child(9) input[type=\"submit\"]"); + } + + public void clickDelete() { + getDeleteButton().click(); + } +} diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index dbd5d6a434e..9fc1a288f7b 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -287,6 +287,18 @@ class ProjectController < ApplicationController redirect_to :action => 'history', :id => resource_id end + def delete_snapshot_history + @project = get_current_project(params[:id]) + + sid = params[:snapshot_id] + if sid + Snapshot.update_all("status='U'", ["id=?", sid.to_i]) + flash[:notice] = message('project_history.snapshot_deleted') + end + + redirect_to :action => 'history', :id => @project.id + end + protected def get_current_project(project_id)