--- /dev/null
+/*
+ * 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<ProjectHistorySnapshotItem> 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));
+ }
+}
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);
}
--- /dev/null
+/*
+ * 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<ProjectHistorySnapshotItem> getSnapshotsAsItems() {
+ return getSnapshots()
+ .stream()
+ .map(ProjectHistorySnapshotItem::new)
+ .collect(Collectors.toList());
+ }
+
+ public void checkAlertDisplayed() {
+ $("#info:not(.hidden)").should(exist);
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
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)