From 6dc1fa4a8673780f948c1f6e4917637467b35b47 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 14 Nov 2017 00:01:28 +0100 Subject: [PATCH] Add category "project" to integration tests --- cix.sh | 2 +- .../qa/util/pageobjects/Navigation.java | 7 + .../org/sonarqube/tests/Category1Suite.java | 16 +-- .../org/sonarqube/tests/Category2Suite.java | 2 +- .../org/sonarqube/tests/Category4Suite.java | 8 -- .../org/sonarqube/tests/Category6Suite.java | 12 -- .../BackgroundTasksTest.java | 2 +- .../{branch => component}/BranchTest.java | 8 +- .../CodePageTest.java} | 24 +--- .../tests/component/ComponentSuite.java | 46 +++++++ .../tests/component/ComponentsWsTest.java | 32 ++--- .../tests/component/ProjectsWsTest.java | 125 ------------------ .../sonarqube/tests/measure/MeasureSuite.java | 1 + .../ProjectActivityPageTest.java | 44 +++--- .../ProjectBulkDeletionPageTest.java | 18 ++- .../ProjectBulkDeletionTest.java} | 8 +- .../ProjectDeletionTest.java} | 50 ++++++- .../ProjectFilterTest.java} | 14 +- .../ProjectKeyUpdateTest.java | 53 +++++++- .../ProjectLeakPageTest.java} | 26 +--- .../ProjectLinksTest.java} | 77 ++++++----- .../tests/project/ProjectListTest.java | 57 ++++++++ .../ProjectProvisioningTest.java | 9 +- .../ProjectSearchTest.java | 6 +- .../sonarqube/tests/project/ProjectSuite.java | 63 +++++++++ .../ProjectVisibilityPageTest.java | 31 ++--- .../ProjectsPageTest.java | 28 ++-- .../ProjectAdministrationTest.java | 87 ------------ .../ProjectQualityGatePageTest.java | 54 ++++---- .../tests/qualityGate/QualityGateSuite.java | 1 + .../sonarqube/tests/source/SourceSuite.java | 1 - .../java/org/sonarqube/tests/ui/UiTest.java | 61 ++++----- 32 files changed, 462 insertions(+), 511 deletions(-) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration => ce}/BackgroundTasksTest.java (98%) rename tests/src/test/java/org/sonarqube/tests/{branch => component}/BranchTest.java (90%) rename tests/src/test/java/org/sonarqube/tests/{source/ProjectCodeTest.java => component/CodePageTest.java} (85%) create mode 100644 tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java delete mode 100644 tests/src/test/java/org/sonarqube/tests/component/ProjectsWsTest.java rename tests/src/test/java/org/sonarqube/tests/{projectEvent => measure}/ProjectActivityPageTest.java (67%) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration => project}/ProjectBulkDeletionPageTest.java (83%) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration/ProjectBulkDeleteTest.java => project/ProjectBulkDeletionTest.java} (94%) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration/ProjectDeleteTest.java => project/ProjectDeletionTest.java} (82%) rename tests/src/test/java/org/sonarqube/tests/{projectSearch/SearchProjectsTest.java => project/ProjectFilterTest.java} (95%) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration => project}/ProjectKeyUpdateTest.java (81%) rename tests/src/test/java/org/sonarqube/tests/{projectSearch/LeakProjectsPageTest.java => project/ProjectLeakPageTest.java} (83%) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration/ProjectLinksPageTest.java => project/ProjectLinksTest.java} (64%) create mode 100644 tests/src/test/java/org/sonarqube/tests/project/ProjectListTest.java rename tests/src/test/java/org/sonarqube/tests/{projectAdministration => project}/ProjectProvisioningTest.java (94%) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration => project}/ProjectSearchTest.java (97%) create mode 100644 tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java rename tests/src/test/java/org/sonarqube/tests/{projectAdministration => project}/ProjectVisibilityPageTest.java (74%) rename tests/src/test/java/org/sonarqube/tests/{projectSearch => project}/ProjectsPageTest.java (91%) rename tests/src/test/java/org/sonarqube/tests/{projectAdministration => qualityGate}/ProjectQualityGatePageTest.java (78%) diff --git a/cix.sh b/cix.sh index 073f4b76a52..6acdae1ff4e 100755 --- a/cix.sh +++ b/cix.sh @@ -30,7 +30,7 @@ case "$RUN_ACTIVITY" in ;; Category3) - CATEGORY="Category3" + CATEGORY="Category3|component|project" ;; Category4) diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java index b9770335aad..25fc6937c8e 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java @@ -187,6 +187,13 @@ public class Navigation { return open("/projects_admin", ProjectsManagementPage.class); } + /** + * Should be replaced by an intermediary OrganizationPage + */ + public ProjectsManagementPage openProjectsManagement(String orgKey) { + return open("/organizations/" + orgKey + "/projects_management", ProjectsManagementPage.class); + } + public LoginPage openLogin() { return open("/sessions/login", LoginPage.class); } diff --git a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java index 2393e681879..34afd54d11b 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java @@ -23,12 +23,8 @@ import com.sonar.orchestrator.Orchestrator; import org.junit.ClassRule; import org.junit.runner.RunWith; import org.junit.runners.Suite; -import org.sonarqube.tests.projectAdministration.BackgroundTasksTest; +import org.sonarqube.tests.ce.BackgroundTasksTest; import org.sonarqube.tests.projectAdministration.ProjectAdministrationTest; -import org.sonarqube.tests.projectAdministration.ProjectBulkDeletionPageTest; -import org.sonarqube.tests.projectAdministration.ProjectLinksPageTest; -import org.sonarqube.tests.projectAdministration.ProjectVisibilityPageTest; -import org.sonarqube.tests.projectSearch.ProjectsPageTest; import org.sonarqube.tests.settings.DeprecatedPropertiesWsTest; import org.sonarqube.tests.settings.EmailsTest; import org.sonarqube.tests.settings.PropertySetsTest; @@ -45,21 +41,13 @@ import static util.ItUtils.xooPlugin; @Deprecated @RunWith(Suite.class) @Suite.SuiteClasses({ - // administration UsersPageTest.class, - ProjectVisibilityPageTest.class, - // project administration - ProjectBulkDeletionPageTest.class, ProjectAdministrationTest.class, - ProjectLinksPageTest.class, BackgroundTasksTest.class, - // settings DeprecatedPropertiesWsTest.class, EmailsTest.class, PropertySetsTest.class, - SettingsTest.class, - // measure - ProjectsPageTest.class + SettingsTest.class }) public class Category1Suite { diff --git a/tests/src/test/java/org/sonarqube/tests/Category2Suite.java b/tests/src/test/java/org/sonarqube/tests/Category2Suite.java index 03fd21935d7..619aa95106b 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category2Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category2Suite.java @@ -23,7 +23,7 @@ import com.sonar.orchestrator.Orchestrator; import org.junit.ClassRule; import org.junit.runner.RunWith; import org.junit.runners.Suite; -import org.sonarqube.tests.branch.BranchTest; +import org.sonarqube.tests.component.BranchTest; import org.sonarqube.tests.issue.AutoAssignTest; import org.sonarqube.tests.issue.CommonRulesTest; import org.sonarqube.tests.issue.CustomRulesTest; diff --git a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java index 6c2d14ae4ba..94d9a43693a 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java @@ -27,9 +27,6 @@ import org.sonarqube.tests.analysis.FileExclusionsTest; import org.sonarqube.tests.analysis.IssueExclusionsTest; import org.sonarqube.tests.ce.CeTempDirTest; import org.sonarqube.tests.ce.CeWsTest; -import org.sonarqube.tests.component.ComponentsWsTest; -import org.sonarqube.tests.component.ProjectsWsTest; -import org.sonarqube.tests.projectEvent.ProjectActivityPageTest; import org.sonarqube.tests.qualityProfile.QualityProfilesUiTest; import org.sonarqube.tests.serverSystem.HttpHeadersTest; import org.sonarqube.tests.serverSystem.LogsTest; @@ -72,14 +69,9 @@ import static util.ItUtils.xooPlugin; LocalAuthenticationTest.class, BaseIdentityProviderTest.class, OAuth2IdentityProviderTest.class, - // component search - ProjectsWsTest.class, - ComponentsWsTest.class, // analysis exclusion FileExclusionsTest.class, IssueExclusionsTest.class, - // db cleaner - ProjectActivityPageTest.class, // http HttpHeadersTest.class, // ui diff --git a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java index 87ebf3ac247..9cb93ba6474 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java @@ -31,12 +31,6 @@ import org.sonarqube.tests.issue.IssueNotificationsTest; import org.sonarqube.tests.issue.IssueTagsTest; import org.sonarqube.tests.issue.OrganizationIssueAssignTest; import org.sonarqube.tests.issue.OrganizationIssuesPageTest; -import org.sonarqube.tests.projectAdministration.ProjectDeleteTest; -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.qualityProfile.BuiltInQualityProfilesTest; import org.sonarqube.tests.qualityProfile.CustomQualityProfilesTest; import org.sonarqube.tests.qualityProfile.QualityProfilesEditTest; @@ -64,13 +58,7 @@ import static util.ItUtils.xooPlugin; QualityProfilesWsTest.class, CustomQualityProfilesTest.class, IssueTagsTest.class, - LeakProjectsPageTest.class, - SearchProjectsTest.class, RulesWsTest.class, - ProjectDeleteTest.class, - ProjectProvisioningTest.class, - ProjectKeyUpdateTest.class, - ProjectSearchTest.class, PermissionTemplateTest.class, ReportFailureNotificationTest.class, IssueNotificationsTest.class diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/BackgroundTasksTest.java b/tests/src/test/java/org/sonarqube/tests/ce/BackgroundTasksTest.java similarity index 98% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/BackgroundTasksTest.java rename to tests/src/test/java/org/sonarqube/tests/ce/BackgroundTasksTest.java index 0e7eee2e783..059bfa26b32 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/BackgroundTasksTest.java +++ b/tests/src/test/java/org/sonarqube/tests/ce/BackgroundTasksTest.java @@ -17,7 +17,7 @@ * 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; +package org.sonarqube.tests.ce; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; diff --git a/tests/src/test/java/org/sonarqube/tests/branch/BranchTest.java b/tests/src/test/java/org/sonarqube/tests/component/BranchTest.java similarity index 90% rename from tests/src/test/java/org/sonarqube/tests/branch/BranchTest.java rename to tests/src/test/java/org/sonarqube/tests/component/BranchTest.java index aef3ab0696a..feb667dce65 100644 --- a/tests/src/test/java/org/sonarqube/tests/branch/BranchTest.java +++ b/tests/src/test/java/org/sonarqube/tests/component/BranchTest.java @@ -17,8 +17,7 @@ * 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.branch; +package org.sonarqube.tests.component; import com.sonar.orchestrator.Orchestrator; import java.util.Map; @@ -26,7 +25,6 @@ import org.assertj.core.groups.Tuple; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.sonarqube.tests.Category2Suite; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Common; import org.sonarqube.ws.WsBranches; @@ -40,10 +38,10 @@ import static util.ItUtils.runProjectAnalysis; public class BranchTest { @ClassRule - public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ComponentSuite.ORCHESTRATOR; @Rule - public Tester tester = new Tester(orchestrator).disableOrganizations(); + public Tester tester = new Tester(orchestrator); @Test public void list_branches_contains_main_branch() { diff --git a/tests/src/test/java/org/sonarqube/tests/source/ProjectCodeTest.java b/tests/src/test/java/org/sonarqube/tests/component/CodePageTest.java similarity index 85% rename from tests/src/test/java/org/sonarqube/tests/source/ProjectCodeTest.java rename to tests/src/test/java/org/sonarqube/tests/component/CodePageTest.java index 974ea41abf3..1f1b33f5ae6 100644 --- a/tests/src/test/java/org/sonarqube/tests/source/ProjectCodeTest.java +++ b/tests/src/test/java/org/sonarqube/tests/component/CodePageTest.java @@ -17,7 +17,7 @@ * 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.source; +package org.sonarqube.tests.component; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; @@ -29,16 +29,16 @@ import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; import static util.ItUtils.projectDir; -public class ProjectCodeTest { +public class CodePageTest { @ClassRule - public static Orchestrator orchestrator = SourceSuite.ORCHESTRATOR; + public static Orchestrator orchestrator = ComponentSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator); @Test - public void browse() { + public void code_page() { Project project = tester.projects().generate(null); executeAnalysis(project); @@ -49,25 +49,15 @@ public class ProjectCodeTest { .openFirstComponent() .shouldHaveCode("public class Sample") .shouldHaveBreadcrumbs(project.getName(), "src/main/xoo/sample", "Sample.xoo"); - } - - @Test - public void search() { - Project project = tester.projects().generate(null); - executeAnalysis(project); + // search tester.openBrowser().openCode(project.getKey()) .shouldHaveComponent(project.getName()) .search("xoo") .shouldSearchResult("Sample.xoo"); - } - - @Test - public void permalink() { - Project project = tester.projects().generate(null); - executeAnalysis(project); - tester.openBrowser().openCode(project.getKey(), project.getKey() + "%3Asrc%2Fmain%2Fxoo%2Fsample%2FSample.xoo") + // permalink + tester.openBrowser().openCode(project.getKey(), project.getKey() + ":src/main/xoo/sample/Sample.xoo") .shouldHaveCode("public class Sample") .shouldHaveBreadcrumbs(project.getName(), "src/main/xoo/sample", "Sample.xoo"); } diff --git a/tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java b/tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java new file mode 100644 index 00000000000..3662490b224 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/component/ComponentSuite.java @@ -0,0 +1,46 @@ +/* + * 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.component; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import static util.ItUtils.xooPlugin; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + BranchTest.class, + CodePageTest.class, + ComponentsWsTest.class +}) +public class ComponentSuite { + + @ClassRule + public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + + .addPlugin(xooPlugin()) + + .build(); + +} diff --git a/tests/src/test/java/org/sonarqube/tests/component/ComponentsWsTest.java b/tests/src/test/java/org/sonarqube/tests/component/ComponentsWsTest.java index 69cae2a8d34..2e9ccdd7819 100644 --- a/tests/src/test/java/org/sonarqube/tests/component/ComponentsWsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/component/ComponentsWsTest.java @@ -21,43 +21,39 @@ package org.sonarqube.tests.component; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category4Suite; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.rules.RuleChain; +import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.WsComponents; -import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.component.SearchWsRequest; import org.sonarqube.ws.client.component.ShowWsRequest; -import util.ItUtils; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.projectDir; public class ComponentsWsTest { - @ClassRule - public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + private static final String FILE_KEY = "sample:src/main/xoo/sample/Sample.xoo"; - @Rule - public ExpectedException expectedException = ExpectedException.none(); + @ClassRule + public static final Orchestrator orchestrator = ComponentSuite.ORCHESTRATOR; + + private static Tester tester = new Tester(orchestrator); - WsClient wsClient; + @ClassRule + public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester); - @Before - public void inspectProject() { - orchestrator.resetData(); + @BeforeClass + public static void setUp() { orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); - - wsClient = ItUtils.newAdminWsClient(orchestrator); } @Test public void show() { - WsComponents.ShowWsResponse response = wsClient.components().show(new ShowWsRequest().setKey(FILE_KEY)); + WsComponents.ShowWsResponse response = tester.wsClient().components().show(new ShowWsRequest().setKey(FILE_KEY)); assertThat(response).isNotNull(); assertThat(response.getComponent().getKey()).isEqualTo(FILE_KEY); @@ -66,7 +62,7 @@ public class ComponentsWsTest { @Test public void search() { - WsComponents.SearchWsResponse response = wsClient.components().search(new SearchWsRequest() + WsComponents.SearchWsResponse response = tester.wsClient().components().search(new SearchWsRequest() .setQualifiers(singletonList("FIL"))); assertThat(response).isNotNull(); diff --git a/tests/src/test/java/org/sonarqube/tests/component/ProjectsWsTest.java b/tests/src/test/java/org/sonarqube/tests/component/ProjectsWsTest.java deleted file mode 100644 index 75d5f5bae16..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/component/ProjectsWsTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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.component; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category4Suite; -import java.io.IOException; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.util.EntityUtils; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonarqube.ws.WsComponents; -import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse; -import org.sonarqube.ws.WsProjects.BulkUpdateKeyWsResponse.Key; -import org.sonarqube.ws.client.WsClient; -import org.sonarqube.ws.client.component.ShowWsRequest; -import org.sonarqube.ws.client.project.BulkUpdateKeyWsRequest; -import org.sonarqube.ws.client.project.UpdateKeyWsRequest; -import util.ItUtils; - -import static org.assertj.core.api.Assertions.assertThat; -import static util.ItUtils.projectDir; - -public class ProjectsWsTest { - - @ClassRule - public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; - private static final String PROJECT_KEY = "sample"; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private WsClient wsClient; - - @Before - public void inspectProject() { - orchestrator.resetData(); - orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); - - wsClient = ItUtils.newAdminWsClient(orchestrator); - } - - /** - * SONAR-3105 - */ - @Test - public void projects_web_service() throws IOException { - SonarScanner build = SonarScanner.create(projectDir("shared/xoo-sample")); - orchestrator.executeBuild(build); - - String url = orchestrator.getServer().getUrl() + "/api/projects/index?key=sample&versions=true"; - HttpClient httpclient = new DefaultHttpClient(); - try { - HttpGet get = new HttpGet(url); - HttpResponse response = httpclient.execute(get); - - assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); - String content = IOUtils.toString(response.getEntity().getContent()); - assertThat(content).doesNotContain("error"); - assertThat(content).contains("sample"); - EntityUtils.consume(response.getEntity()); - - } finally { - httpclient.getConnectionManager().shutdown(); - } - } - - @Test - public void update_key() { - String newProjectKey = "another_project_key"; - WsComponents.Component project = wsClient.components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent(); - assertThat(project.getKey()).isEqualTo(PROJECT_KEY); - - wsClient.projects().updateKey(UpdateKeyWsRequest.builder() - .setKey(PROJECT_KEY) - .setNewKey(newProjectKey) - .build()); - - assertThat(wsClient.components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey); - } - - @Test - public void bulk_update_key() { - String newProjectKey = "another_project_key"; - WsComponents.Component project = wsClient.components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent(); - assertThat(project.getKey()).isEqualTo(PROJECT_KEY); - - BulkUpdateKeyWsResponse result = wsClient.projects().bulkUpdateKey(BulkUpdateKeyWsRequest.builder() - .setKey(PROJECT_KEY) - .setFrom(PROJECT_KEY) - .setTo(newProjectKey) - .build()); - - assertThat(wsClient.components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey); - assertThat(result.getKeysCount()).isEqualTo(1); - assertThat(result.getKeys(0)) - .extracting(Key::getKey, Key::getNewKey, Key::getDuplicate) - .containsOnlyOnce(PROJECT_KEY, newProjectKey, false); - } -} diff --git a/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java b/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java index ffc9325163f..25f8b8ac230 100644 --- a/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/measure/MeasureSuite.java @@ -34,6 +34,7 @@ import static util.ItUtils.xooPlugin; DecimalScaleMetricTest.class, DifferentialPeriodsTest.class, MeasuresWsTest.class, + ProjectActivityPageTest.class, ProjectDashboardTest.class, ProjectMeasuresPageTest.class, SincePreviousVersionHistoryTest.class, diff --git a/tests/src/test/java/org/sonarqube/tests/projectEvent/ProjectActivityPageTest.java b/tests/src/test/java/org/sonarqube/tests/measure/ProjectActivityPageTest.java similarity index 67% rename from tests/src/test/java/org/sonarqube/tests/projectEvent/ProjectActivityPageTest.java rename to tests/src/test/java/org/sonarqube/tests/measure/ProjectActivityPageTest.java index 7261e43d083..188c72841ce 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectEvent/ProjectActivityPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/measure/ProjectActivityPageTest.java @@ -17,42 +17,32 @@ * 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.projectEvent; +package org.sonarqube.tests.measure; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category4Suite; import java.util.List; -import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.sonarqube.qa.util.pageobjects.Navigation; +import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.ProjectActivityPage; import org.sonarqube.qa.util.pageobjects.ProjectAnalysisItem; -import util.user.UserRule; import static util.ItUtils.projectDir; public class ProjectActivityPageTest { @ClassRule - public static Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = MeasureSuite.ORCHESTRATOR; @Rule - public UserRule userRule = UserRule.from(ORCHESTRATOR); - - private Navigation nav = Navigation.create(ORCHESTRATOR); - - @Before - public void setUp() throws Exception { - ORCHESTRATOR.resetData(); - } + public Tester tester = new Tester(orchestrator); @Test public void should_list_snapshots() { - analyzeProject("shared/xoo-history-v1", "2014-10-19"); - analyzeProject("shared/xoo-history-v2", "2014-11-13"); + analyzeXooSample("shared/xoo-history-v1", "2014-10-19"); + analyzeXooSample("shared/xoo-history-v2", "2014-11-13"); ProjectActivityPage page = openPage(); page.getAnalyses().shouldHaveSize(2); @@ -69,7 +59,7 @@ public class ProjectActivityPageTest { @Test public void add_change_delete_custom_event() { - analyzeProject(); + analyzeXooSample(); openPage().getLastAnalysis() .addCustomEvent("foo") .changeFirstEvent("bar") @@ -78,24 +68,26 @@ public class ProjectActivityPageTest { @Test public void delete_analysis() { - analyzeProject(); - analyzeProject(); + analyzeXooSample(); + analyzeXooSample(); ProjectActivityPage page = openPage(); page.getAnalyses().shouldHaveSize(2); page.getFirstAnalysis().delete(); } private ProjectActivityPage openPage() { - String userAdmin = userRule.createAdminUser(); - nav.logIn().submitCredentials(userAdmin, userAdmin); - return nav.openProjectActivity("sample"); + String userAdmin = tester.users().generateAdministratorOnDefaultOrganization().getLogin(); + return tester.openBrowser() + .logIn() + .submitCredentials(userAdmin, userAdmin) + .openProjectActivity("sample"); } - private static void analyzeProject() { - ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); + private void analyzeXooSample() { + orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); } - private static void analyzeProject(String path, String date) { - ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir(path)).setProperties("sonar.projectDate", date)); + private void analyzeXooSample(String path, String date) { + orchestrator.executeBuild(SonarScanner.create(projectDir(path)).setProperties("sonar.projectDate", date)); } } diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeletionPageTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectBulkDeletionPageTest.java similarity index 83% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeletionPageTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectBulkDeletionPageTest.java index 988f37703f8..a040b04d25d 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeletionPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectBulkDeletionPageTest.java @@ -17,14 +17,13 @@ * 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; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.sonarqube.tests.Category1Suite; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; import org.sonarqube.ws.client.component.SearchProjectsRequest; @@ -36,30 +35,29 @@ import static org.assertj.core.api.Assertions.assertThat; public class ProjectBulkDeletionPageTest { - private String adminUser; - @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator); + private String sysAdminLogin; + @Before - public void deleteData() { - orchestrator.resetData(); - adminUser = tester.users().generateAdministrator().getLogin(); + public void setUp() { + sysAdminLogin = tester.users().generateAdministratorOnDefaultOrganization().getLogin(); } /** * SONAR-2614, SONAR-3805 */ @Test - public void test_bulk_deletion_on_selected_projects() throws Exception { + public void bulk_deletion_on_selected_projects() throws Exception { Project project1 = tester.projects().generate(null, t -> t.setName("Foo")); Project project2 = tester.projects().generate(null, t -> t.setName("Bar")); Project project3 = tester.projects().generate(null, t -> t.setName("FooQux")); - tester.openBrowser().logIn().submitCredentials(adminUser).open("/admin/projects_management"); + tester.openBrowser().logIn().submitCredentials(sysAdminLogin).open("/organizations/default-organization/projects_management"); $("#projects-management-page").shouldHave(text(project1.getName())).shouldHave(text(project2.getName())).shouldHave(text(project3.getName())); $("#projects-management-page .search-box-input").val("foo").pressEnter(); diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeleteTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectBulkDeletionTest.java similarity index 94% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeleteTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectBulkDeletionTest.java index 71ac12d965c..559589ffc58 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeleteTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectBulkDeletionTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonarqube.tests.projectAdministration; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import java.util.List; @@ -26,7 +26,6 @@ import java.util.stream.IntStream; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.sonarqube.tests.Category6Suite; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Organizations; import org.sonarqube.ws.WsProjects.CreateWsResponse; @@ -36,10 +35,11 @@ import org.sonarqube.ws.client.project.SearchWsRequest; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.runProjectAnalysis; -public class ProjectBulkDeleteTest { +public class ProjectBulkDeletionTest { @ClassRule - public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; + @Rule public Tester tester = new Tester(orchestrator); diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeleteTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectDeletionTest.java similarity index 82% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeleteTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectDeletionTest.java index 788a94dfbf3..abd50a848cd 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeleteTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectDeletionTest.java @@ -17,9 +17,10 @@ * 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; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -30,13 +31,14 @@ import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import org.sonarqube.tests.Category6Suite; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Organizations; import org.sonarqube.ws.WsComponents; import org.sonarqube.ws.WsProjects; import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; +import org.sonarqube.ws.WsUsers; import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.component.SearchProjectsRequest; import org.sonarqube.ws.client.project.CreateRequest; @@ -46,17 +48,44 @@ import util.ItUtils; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.getComponent; +import static util.ItUtils.projectDir; -public class ProjectDeleteTest { +public class ProjectDeletionTest { @ClassRule - public static final Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + public static final Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; @Rule public TestRule safeguard = new DisableOnDebug(Timeout.seconds(300)); + @Rule - public Tester tester = new Tester(orchestrator) - .setElasticsearchHttpPort(Category6Suite.SEARCH_HTTP_PORT); + public Tester tester = new Tester(orchestrator).setElasticsearchHttpPort(ProjectSuite.SEARCH_HTTP_PORT); + + @Test + public void delete_project_by_web_service() { + String projectKey = "sample"; + String fileKey = "sample:src/main/xoo/sample/Sample.xoo"; + + analyzeXooSample(); + assertThat(getComponent(orchestrator, projectKey)).isNotNull(); + assertThat(getComponent(orchestrator, fileKey)).isNotNull(); + + // fail to delete a file + ItUtils.expectBadRequestError(() -> executeDeleteRequest(tester.wsClient(), fileKey)); + + // fail if anonymous + ItUtils.expectUnauthorizedError(() -> executeDeleteRequest(tester.asAnonymous().wsClient(), projectKey)); + + // fail if insufficient privilege + WsUsers.CreateWsResponse.User user = tester.users().generate(); + ItUtils.expectForbiddenError(() -> executeDeleteRequest(tester.as(user.getLogin()).wsClient(), projectKey)); + + // succeed to delete if administrator + executeDeleteRequest(tester.wsClient(), projectKey); + assertThat(getComponent(orchestrator, "sample")).isNull(); + assertThat(getComponent(orchestrator, "sample:src/main/xoo/sample/Sample.xoo")).isNull(); + } @Test public void deletion_removes_project_from_search_engines() { @@ -193,4 +222,13 @@ public class ProjectDeleteTest { .orElseThrow(() -> new IllegalStateException("missing field results/[q=TRK]")); return !items.isEmpty(); } + + private void analyzeXooSample() { + SonarScanner build = SonarScanner.create(projectDir("shared/xoo-sample")); + orchestrator.executeBuild(build); + } + + private static void executeDeleteRequest(WsClient wsClient, String key) { + wsClient.projects().delete(DeleteRequest.builder().setKey(key).build()); + } } diff --git a/tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectFilterTest.java similarity index 95% rename from tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectFilterTest.java index 2e4e6f159c2..69913864a08 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectFilterTest.java @@ -17,11 +17,10 @@ * 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.projectSearch; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category6Suite; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -47,15 +46,14 @@ import static util.ItUtils.newProjectKey; import static util.ItUtils.projectDir; import static util.ItUtils.restoreProfile; import static util.ItUtils.sanitizeTimezones; -import static util.ItUtils.setServerProperty; /** * Tests WS api/components/search_projects */ -public class SearchProjectsTest { +public class ProjectFilterTest { @ClassRule - public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator); @@ -65,7 +63,7 @@ public class SearchProjectsTest { @Before public void setUp() { organization = tester.organizations().generate(); - restoreProfile(orchestrator, SearchProjectsTest.class.getResource("/projectSearch/SearchProjectsTest/with-many-rules.xml"), organization.getKey()); + restoreProfile(orchestrator, ProjectFilterTest.class.getResource("/projectSearch/SearchProjectsTest/with-many-rules.xml"), organization.getKey()); } @Test @@ -99,7 +97,7 @@ public class SearchProjectsTest { @Test public void return_leak_period_date() throws Exception { - setServerProperty(orchestrator, "sonar.leak.period", "previous_version"); + tester.settings().setGlobalSettings("sonar.leak.period", "previous_version"); // This project has a leak period String projectKey1 = newProjectKey(); analyzeProject(projectKey1, "shared/xoo-sample", "sonar.projectDate", "2016-12-31"); @@ -220,7 +218,7 @@ public class SearchProjectsTest { @Test public void should_return_facets_on_leak() throws Exception { - setServerProperty(orchestrator, "sonar.leak.period", "previous_version"); + tester.settings().setGlobalSettings("sonar.leak.period", "previous_version"); // This project has no duplication on new code String projectKey1 = newProjectKey(); analyzeProject(projectKey1, "shared/xoo-sample", "sonar.projectDate", "2016-12-31"); diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectKeyUpdateTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectKeyUpdateTest.java similarity index 81% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectKeyUpdateTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectKeyUpdateTest.java index f1e1ba47ce4..8a2c14f3806 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectKeyUpdateTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectKeyUpdateTest.java @@ -17,7 +17,7 @@ * 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; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; @@ -33,7 +33,6 @@ import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import org.sonarqube.tests.Category6Suite; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Organizations; import org.sonarqube.ws.WsComponents; @@ -41,6 +40,8 @@ import org.sonarqube.ws.WsProjects; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.component.SearchProjectsRequest; +import org.sonarqube.ws.client.component.ShowWsRequest; +import org.sonarqube.ws.client.project.BulkUpdateKeyWsRequest; import org.sonarqube.ws.client.project.CreateRequest; import org.sonarqube.ws.client.project.UpdateKeyWsRequest; import util.ItUtils; @@ -50,20 +51,57 @@ import static util.ItUtils.projectDir; public class ProjectKeyUpdateTest { + private static final String PROJECT_KEY = "sample"; + @ClassRule - public static final Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + public static final Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; @Rule public TestRule safeguard = new DisableOnDebug(Timeout.seconds(300)); + @Rule - public Tester tester = new Tester(orchestrator) - .setElasticsearchHttpPort(Category6Suite.SEARCH_HTTP_PORT); + public Tester tester = new Tester(orchestrator).setElasticsearchHttpPort(ProjectSuite.SEARCH_HTTP_PORT); @After public void tearDown() throws Exception { unlockWritesOnProjectIndices(); } + @Test + public void update_key() { + analyzeXooSample(); + String newProjectKey = "another_project_key"; + WsComponents.Component project = tester.wsClient().components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent(); + assertThat(project.getKey()).isEqualTo(PROJECT_KEY); + + tester.wsClient().projects().updateKey(UpdateKeyWsRequest.builder() + .setKey(PROJECT_KEY) + .setNewKey(newProjectKey) + .build()); + + assertThat(tester.wsClient().components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey); + } + + @Test + public void bulk_update_key() { + analyzeXooSample(); + String newProjectKey = "another_project_key"; + WsComponents.Component project = tester.wsClient().components().show(new ShowWsRequest().setKey(PROJECT_KEY)).getComponent(); + assertThat(project.getKey()).isEqualTo(PROJECT_KEY); + + WsProjects.BulkUpdateKeyWsResponse result = tester.wsClient().projects().bulkUpdateKey(BulkUpdateKeyWsRequest.builder() + .setKey(PROJECT_KEY) + .setFrom(PROJECT_KEY) + .setTo(newProjectKey) + .build()); + + assertThat(tester.wsClient().components().show(new ShowWsRequest().setId(project.getId())).getComponent().getKey()).isEqualTo(newProjectKey); + assertThat(result.getKeysCount()).isEqualTo(1); + assertThat(result.getKeys(0)) + .extracting(WsProjects.BulkUpdateKeyWsResponse.Key::getKey, WsProjects.BulkUpdateKeyWsResponse.Key::getNewKey, WsProjects.BulkUpdateKeyWsResponse.Key::getDuplicate) + .containsOnlyOnce(PROJECT_KEY, newProjectKey, false); + } + @Test public void update_key_of_provisioned_project() { Organizations.Organization organization = tester.organizations().generate(); @@ -238,4 +276,9 @@ public class ProjectKeyUpdateTest { .map(map -> (String) map.get("key")) .collect(Collectors.toList()); } + + private void analyzeXooSample() { + SonarScanner build = SonarScanner.create(projectDir("shared/xoo-sample")); + orchestrator.executeBuild(build); + } } diff --git a/tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectLeakPageTest.java similarity index 83% rename from tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectLeakPageTest.java index 54ff1ce9bf6..1b0e145accd 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectLeakPageTest.java @@ -17,57 +17,43 @@ * 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.projectSearch; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category6Suite; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.sonarqube.qa.util.Tester; -import org.sonarqube.ws.Organizations.Organization; import org.sonarqube.qa.util.pageobjects.projects.ProjectsPage; +import org.sonarqube.ws.Organizations.Organization; import static com.codeborne.selenide.WebDriverRunner.url; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.newProjectKey; import static util.ItUtils.projectDir; -import static util.ItUtils.resetSettings; import static util.ItUtils.restoreProfile; -import static util.ItUtils.setServerProperty; -public class LeakProjectsPageTest { +public class ProjectLeakPageTest { @ClassRule - public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; @Rule public Tester tester = new Tester(orchestrator); private Organization organization; - @BeforeClass - public static void beforeClass() { - setServerProperty(orchestrator, "sonar.leak.period", "previous_version"); - } - - @AfterClass - public static void tearDown() { - resetSettings(orchestrator, null, "sonar.leak.period"); - } - @Before public void setUp() { + tester.settings().setGlobalSettings("sonar.leak.period", "previous_version"); organization = tester.organizations().generate(); - restoreProfile(orchestrator, SearchProjectsTest.class.getResource("/projectSearch/SearchProjectsTest/with-many-rules.xml"), organization.getKey()); + restoreProfile(orchestrator, ProjectLeakPageTest.class.getResource("/projectSearch/SearchProjectsTest/with-many-rules.xml"), organization.getKey()); } @Test diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectLinksPageTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectLinksTest.java similarity index 64% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectLinksPageTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectLinksTest.java index b6ad18a16b5..4efc15da144 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectLinksPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectLinksTest.java @@ -17,53 +17,45 @@ * 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; +package org.sonarqube.tests.project; import com.codeborne.selenide.Condition; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category1Suite; import java.util.List; 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.junit.rules.RuleChain; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.qa.util.pageobjects.ProjectLinkItem; +import org.sonarqube.qa.util.pageobjects.ProjectLinksPage; import org.sonarqube.ws.WsProjectLinks.CreateWsResponse; -import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.projectlinks.CreateWsRequest; import org.sonarqube.ws.client.projectlinks.DeleteWsRequest; -import org.sonarqube.qa.util.pageobjects.Navigation; -import org.sonarqube.qa.util.pageobjects.ProjectLinkItem; -import org.sonarqube.qa.util.pageobjects.ProjectLinksPage; -import util.user.UserRule; -import static com.codeborne.selenide.Condition.hasText; +import static com.codeborne.selenide.Condition.text; import static com.codeborne.selenide.Selenide.$; -import static util.ItUtils.newAdminWsClient; import static util.ItUtils.projectDir; -public class ProjectLinksPageTest { +public class ProjectLinksTest { @ClassRule - public static Orchestrator ORCHESTRATOR = Category1Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; - private Navigation nav = Navigation.create(ORCHESTRATOR); + private static Tester tester = new Tester(orchestrator); - @Rule - public UserRule userRule = UserRule.from(ORCHESTRATOR); + @ClassRule + public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester); - private static WsClient wsClient; private long customLinkId; private String adminUser; @BeforeClass public static void setUp() { - wsClient = newAdminWsClient(ORCHESTRATOR); - - ORCHESTRATOR.resetData(); - ORCHESTRATOR.executeBuild( + orchestrator.executeBuild( SonarScanner.create(projectDir("shared/xoo-sample")) .setProperty("sonar.links.homepage", "http://example.com")); } @@ -71,7 +63,7 @@ public class ProjectLinksPageTest { @Before public void prepare() { customLinkId = Long.parseLong(createCustomLink().getLink().getId()); - adminUser = userRule.createAdminUser(); + adminUser = tester.users().generateAdministratorOnDefaultOrganization().getLogin(); } @After @@ -81,7 +73,7 @@ public class ProjectLinksPageTest { @Test public void should_list_links() { - ProjectLinksPage page = openPage(); + ProjectLinksPage page = openLinksPage(); page.getLinks().shouldHaveSize(2); @@ -89,20 +81,20 @@ public class ProjectLinksPageTest { ProjectLinkItem homepageLink = links.get(0); ProjectLinkItem customLink = links.get(1); - homepageLink.getName().should(hasText("Home")); - homepageLink.getType().should(hasText("sonar.links.homepage")); - homepageLink.getUrl().should(hasText("http://example.com")); - homepageLink.getDeleteButton().shouldNot(Condition.present); + homepageLink.getName().should(text("Home")); + homepageLink.getType().should(text("sonar.links.homepage")); + homepageLink.getUrl().should(text("http://example.com")); + homepageLink.getDeleteButton().shouldNot(Condition.exist); - customLink.getName().should(hasText("Custom")); - customLink.getType().shouldNot(Condition.present); - customLink.getUrl().should(hasText("http://example.org/custom")); + customLink.getName().should(text("Custom")); + customLink.getType().shouldNot(Condition.exist); + customLink.getUrl().should(text("http://example.org/custom")); customLink.getDeleteButton().shouldBe(Condition.visible); } @Test public void should_create_link() { - ProjectLinksPage page = openPage(); + ProjectLinksPage page = openLinksPage(); page.getLinks().shouldHaveSize(2); @@ -115,15 +107,15 @@ public class ProjectLinksPageTest { ProjectLinkItem testLink = page.getLinksAsItems().get(2); - testLink.getName().should(hasText("Test")); - testLink.getType().shouldNot(Condition.present); - testLink.getUrl().should(hasText("http://example.com/test")); + testLink.getName().should(text("Test")); + testLink.getType().shouldNot(Condition.exist); + testLink.getUrl().should(text("http://example.com/test")); testLink.getDeleteButton().shouldBe(Condition.visible); } @Test public void should_delete_link() { - ProjectLinksPage page = openPage(); + ProjectLinksPage page = openLinksPage(); page.getLinks().shouldHaveSize(2); @@ -131,13 +123,15 @@ public class ProjectLinksPageTest { ProjectLinkItem customLink = links.get(1); customLink.getDeleteButton().click(); - $("#delete-link-confirm").click(); + $("#delete-link-confirm") + .shouldBe(Condition.visible) + .click(); page.getLinks().shouldHaveSize(1); } private CreateWsResponse createCustomLink() { - return wsClient.projectLinks().create(new CreateWsRequest() + return tester.wsClient().projectLinks().create(new CreateWsRequest() .setProjectKey("sample") .setName("Custom") .setUrl("http://example.org/custom")); @@ -145,14 +139,17 @@ public class ProjectLinksPageTest { private void deleteLink(long id) { try { - wsClient.projectLinks().delete(new DeleteWsRequest().setId(id)); + tester.wsClient().projectLinks().delete(new DeleteWsRequest().setId(id)); } catch (Exception e) { // fail silently } } - private ProjectLinksPage openPage() { - nav.logIn().submitCredentials(adminUser, adminUser); - return nav.openProjectLinks("sample"); + private ProjectLinksPage openLinksPage() { + return tester + .openBrowser() + .logIn() + .submitCredentials(adminUser, adminUser) + .openProjectLinks("sample"); } } diff --git a/tests/src/test/java/org/sonarqube/tests/project/ProjectListTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectListTest.java new file mode 100644 index 00000000000..55b1e4ee580 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectListTest.java @@ -0,0 +1,57 @@ +/* + * 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.project; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import java.io.IOException; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.ws.client.GetRequest; + +import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.projectDir; + +public class ProjectListTest { + + @ClassRule + public static final Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + /** + * SONAR-3105 + */ + @Test + public void test_projects_index_ws() throws IOException { + SonarScanner build = SonarScanner.create(projectDir("shared/xoo-sample")); + orchestrator.executeBuild(build); + + String json = tester.wsClient().wsConnector().call(new GetRequest("/api/projects/index?key=sample&versions=true")).content(); + + assertThat(json).doesNotContain("error"); + assertThat(json).contains("sample"); + } + + +} diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectProvisioningTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectProvisioningTest.java similarity index 94% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectProvisioningTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectProvisioningTest.java index 40140448b55..9f9b1a8b7a4 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectProvisioningTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectProvisioningTest.java @@ -17,7 +17,7 @@ * 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; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import java.util.Collection; @@ -28,7 +28,6 @@ import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import org.sonarqube.tests.Category6Suite; import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.Organizations; import org.sonarqube.ws.WsComponents; @@ -47,13 +46,13 @@ import static org.assertj.core.api.Assertions.assertThat; public class ProjectProvisioningTest { @ClassRule - public static final Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + public static final Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; @Rule public TestRule safeguard = new DisableOnDebug(Timeout.seconds(300)); + @Rule - public Tester tester = new Tester(orchestrator) - .setElasticsearchHttpPort(Category6Suite.SEARCH_HTTP_PORT); + public Tester tester = new Tester(orchestrator).setElasticsearchHttpPort(ProjectSuite.SEARCH_HTTP_PORT); @Test public void provisioned_project_is_available_in_search_engines() { diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectSearchTest.java similarity index 97% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectSearchTest.java index cd1c0107c8c..69cc1a69cfd 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectSearchTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectSearchTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonarqube.tests.projectAdministration; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import java.util.Date; @@ -26,7 +26,6 @@ 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.qa.util.Tester; import org.sonarqube.ws.Organizations; import org.sonarqube.ws.WsProjects.CreateWsResponse; @@ -43,7 +42,8 @@ import static util.ItUtils.runProjectAnalysis; public class ProjectSearchTest { @ClassRule - public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; + @Rule public Tester tester = new Tester(orchestrator); diff --git a/tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java new file mode 100644 index 00000000000..58dd29c9289 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectSuite.java @@ -0,0 +1,63 @@ +/* + * 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.project; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.util.NetworkUtils; +import java.net.InetAddress; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import static util.ItUtils.xooPlugin; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ProjectBulkDeletionTest.class, + ProjectBulkDeletionPageTest.class, + ProjectDeletionTest.class, + ProjectFilterTest.class, + ProjectKeyUpdateTest.class, + ProjectLeakPageTest.class, + ProjectLinksTest.class, + ProjectListTest.class, + ProjectsPageTest.class, + ProjectProvisioningTest.class, + ProjectSearchTest.class, + ProjectVisibilityPageTest.class +}) +public class ProjectSuite { + public static final int SEARCH_HTTP_PORT = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); + + @ClassRule + public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + // for ES resiliency tests + .setServerProperty("sonar.search.httpPort", "" + SEARCH_HTTP_PORT) + .setServerProperty("sonar.search.recovery.delayInMs", "1000") + .setServerProperty("sonar.search.recovery.minAgeInMs", "3000") + .setServerProperty("sonar.notifications.delay", "1") + + .addPlugin(xooPlugin()) + + .build(); + +} diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectVisibilityPageTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectVisibilityPageTest.java similarity index 74% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectVisibilityPageTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectVisibilityPageTest.java index d5b4b12baaf..0c2c745f9f6 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectVisibilityPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectVisibilityPageTest.java @@ -17,23 +17,20 @@ * 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; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category1Suite; -import java.sql.SQLException; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.qa.util.pageobjects.ProjectsManagementPage; import org.sonarqube.ws.WsComponents; import org.sonarqube.ws.client.component.SearchProjectsRequest; import org.sonarqube.ws.client.permission.RemoveGroupWsRequest; import org.sonarqube.ws.client.project.UpdateVisibilityRequest; -import org.sonarqube.qa.util.pageobjects.Navigation; -import org.sonarqube.qa.util.pageobjects.ProjectsManagementPage; -import util.user.UserRule; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.newAdminWsClient; @@ -42,30 +39,28 @@ import static util.ItUtils.projectDir; public class ProjectVisibilityPageTest { @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; @Rule - public UserRule userRule = UserRule.from(orchestrator); - - private Navigation nav = Navigation.create(orchestrator); + public Tester tester = new Tester(orchestrator); private String adminUser; @Before - public void initData() throws SQLException { - orchestrator.resetData(); - adminUser = userRule.createAdminUser(); + public void setUp() { + adminUser = tester.users().generateAdministratorOnDefaultOrganization().getLogin(); } @Test public void return_all_projects_even_when_no_permission() throws Exception { orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")).setProperties("sonar.projectKey", "sample1")); orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")).setProperties("sonar.projectKey", "sample2")); - newAdminWsClient(orchestrator).projects().updateVisibility(UpdateVisibilityRequest.builder().setProject("sample2").setVisibility("private").build()); + tester.wsClient().projects().updateVisibility(UpdateVisibilityRequest.builder().setProject("sample2").setVisibility("private").build()); // Remove 'Admin' permission for admin group on project 2 -> No one can access or admin this project, expect System Admin - newAdminWsClient(orchestrator).permissions().removeGroup(new RemoveGroupWsRequest().setProjectKey("sample2").setGroupName("sonar-administrators").setPermission("admin")); + tester.wsClient().permissions().removeGroup(new RemoveGroupWsRequest().setProjectKey("sample2").setGroupName("sonar-administrators").setPermission("admin")); - nav.logIn().submitCredentials(adminUser).openProjectsManagement() + tester.openBrowser().logIn().submitCredentials(adminUser) + .openProjectsManagement("default-organization") .shouldHaveProject("sample1") .shouldHaveProject("sample2"); } @@ -81,7 +76,9 @@ public class ProjectVisibilityPageTest { } private void createProjectAndVerify(String visibility) { - ProjectsManagementPage page = nav.logIn().submitCredentials(adminUser, adminUser).openProjectsManagement(); + ProjectsManagementPage page = tester.openBrowser().logIn() + .submitCredentials(adminUser, adminUser) + .openProjectsManagement("default-organization"); page .shouldHaveProjectsCount(0) .createProject("foo", "foo", visibility) diff --git a/tests/src/test/java/org/sonarqube/tests/projectSearch/ProjectsPageTest.java b/tests/src/test/java/org/sonarqube/tests/project/ProjectsPageTest.java similarity index 91% rename from tests/src/test/java/org/sonarqube/tests/projectSearch/ProjectsPageTest.java rename to tests/src/test/java/org/sonarqube/tests/project/ProjectsPageTest.java index 2843898a886..d0008cc0bd6 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectSearch/ProjectsPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/project/ProjectsPageTest.java @@ -17,24 +17,21 @@ * 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.projectSearch; +package org.sonarqube.tests.project; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.RuleChain; +import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.Navigation; import org.sonarqube.qa.util.pageobjects.projects.ProjectsPage; -import org.sonarqube.tests.Category1Suite; -import org.sonarqube.qa.util.Tester; import org.sonarqube.ws.WsUsers; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsClient; -import org.sonarqube.ws.client.project.DeleteRequest; import static com.codeborne.selenide.Selenide.clearBrowserLocalStorage; import static com.codeborne.selenide.WebDriverRunner.url; @@ -43,29 +40,22 @@ import static util.ItUtils.projectDir; public class ProjectsPageTest { + private static final String PROJECT_KEY = "key-foo"; + @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; + public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR; - private static final String PROJECT_KEY = "key-foo"; - private static Tester tester = new Tester(orchestrator).disableOrganizations(); + private static Tester tester = new Tester(orchestrator); @ClassRule - public static RuleChain ruleChain = RuleChain.outerRule(orchestrator) - .around(tester); + public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester); @BeforeClass public static void setUp() { - orchestrator.resetData(); orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample")).setProjectKey(PROJECT_KEY)); orchestrator.executeBuild(SonarScanner.create(projectDir("duplications/file-duplications")).setProjectKey("key-bar")); } - @AfterClass - public static void tearDown() { - tester.wsClient().projects().delete(DeleteRequest.builder().setKey(PROJECT_KEY).build()); - tester.wsClient().projects().delete(DeleteRequest.builder().setKey("key-bar").build()); - } - @Before public void before() { clearBrowserLocalStorage(); @@ -114,7 +104,7 @@ public class ProjectsPageTest { page.shouldHaveTotal(2).shouldDisplayAllProjectsWidthSort("-analysis_date"); // all projects by default for logged in user - WsUsers.CreateWsResponse.User administrator = tester.users().generateAdministrator(); + WsUsers.CreateWsResponse.User administrator = tester.users().generateAdministratorOnDefaultOrganization(); page = nav.logIn().submitCredentials(administrator.getLogin()).openProjects(); page.shouldHaveTotal(2).shouldDisplayAllProjects(); @@ -166,7 +156,7 @@ public class ProjectsPageTest { @Test public void should_switch_between_perspectives() { - WsUsers.CreateWsResponse.User administrator = tester.users().generateAdministrator(); + WsUsers.CreateWsResponse.User administrator = tester.users().generateAdministratorOnDefaultOrganization(); ProjectsPage page = tester.openBrowser() .logIn().submitCredentials(administrator.getLogin()) .openProjects(); diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java index b97d71f9e46..92fac69dda2 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java @@ -23,18 +23,13 @@ import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; import java.io.UnsupportedEncodingException; import java.sql.SQLException; -import java.util.Date; import javax.annotation.Nullable; -import org.apache.commons.lang.time.DateFormatUtils; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.openqa.selenium.By; -import org.sonar.wsclient.SonarClient; -import org.sonar.wsclient.base.HttpException; -import org.sonar.wsclient.user.UserParameters; import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.Navigation; import org.sonarqube.qa.util.pageobjects.ProjectsManagementPage; @@ -44,21 +39,12 @@ import org.sonarqube.ws.WsPermissions; import org.sonarqube.ws.client.permission.AddUserToTemplateWsRequest; import org.sonarqube.ws.client.permission.CreateTemplateWsRequest; import org.sonarqube.ws.client.permission.UsersWsRequest; -import org.sonarqube.ws.client.project.SearchWsRequest; import static com.codeborne.selenide.Selenide.$; -import static java.util.Collections.singletonList; -import static org.apache.commons.lang.time.DateUtils.addDays; import static org.assertj.core.api.Assertions.assertThat; -import static util.ItUtils.getComponent; import static util.ItUtils.projectDir; -import static util.selenium.Selenese.runSelenese; public class ProjectAdministrationTest { - private static final String DELETE_WS_ENDPOINT = "api/projects/bulk_delete"; - - // take some day in the past - private static final String ANALYSIS_DATE = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -1)); @ClassRule public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; @@ -71,8 +57,6 @@ public class ProjectAdministrationTest { private Navigation nav = Navigation.create(orchestrator); - private static final String PROJECT_KEY = "sample"; - private static final String FILE_KEY = "sample:src/main/xoo/sample/Sample.xoo"; private String adminUser; @Before @@ -81,69 +65,6 @@ public class ProjectAdministrationTest { adminUser = tester.users().generateAdministrator().getLogin(); } - @Test - public void delete_project_by_web_service() { - scanSampleWithDate(ANALYSIS_DATE); - - assertThat(getComponent(orchestrator, PROJECT_KEY)).isNotNull(); - assertThat(getComponent(orchestrator, FILE_KEY)).isNotNull(); - - orchestrator.getServer().adminWsClient().post(DELETE_WS_ENDPOINT, "keys", PROJECT_KEY); - - assertThat(getComponent(orchestrator, PROJECT_KEY)).isNull(); - assertThat(getComponent(orchestrator, FILE_KEY)).isNull(); - } - - @Test - public void fail_when_trying_to_delete_a_file() { - scanSampleWithDate(ANALYSIS_DATE); - assertThat(getComponent(orchestrator, PROJECT_KEY)).isNotNull(); - assertThat(getComponent(orchestrator, FILE_KEY)).isNotNull(); - - expectedException.expect(org.sonarqube.ws.client.HttpException.class); - - tester.wsClient().projects().bulkDelete(SearchWsRequest.builder() - .setQualifiers(singletonList("FIL")) - .setProjects(singletonList(FILE_KEY)).build()); - } - - @Test - public void fail_when_insufficient_privilege() { - expectedException.expect(HttpException.class); - scanSampleWithDate(ANALYSIS_DATE); - - assertThat(getComponent(orchestrator, PROJECT_KEY)).isNotNull(); - - // use wsClient() instead of adminWsClient() - orchestrator.getServer().wsClient().post(DELETE_WS_ENDPOINT, "keys", PROJECT_KEY); - } - - /** - * Test updated for SONAR-3570 and SONAR-5923 - */ - @Test - public void project_deletion() { - String projectAdminUser = "project-deletion-with-admin-permission-on-project"; - SonarClient wsClient = orchestrator.getServer().adminWsClient(); - try { - SonarScanner scan = SonarScanner.create(projectDir("shared/xoo-sample")); - orchestrator.executeBuild(scan); - - // Create user having admin permission on previously analysed project - wsClient.userClient().create( - UserParameters.create().login(projectAdminUser).name(projectAdminUser).password("password").passwordConfirmation("password")); - - wsClient.post("api/permissions/add_user", - "login", projectAdminUser, - "projectKey", "sample", - "permission", "admin"); - - runSelenese(orchestrator, "/projectAdministration/ProjectAdministrationTest/project-deletion/project-deletion.html"); - } finally { - wsClient.userClient().deactivate(projectAdminUser); - } - } - @Test public void display_project_settings() throws UnsupportedEncodingException { scanSample(null, null); @@ -214,10 +135,6 @@ public class ProjectAdministrationTest { assertThat(usersResponse.getUsers(0).getLogin()).isEqualTo(user); } - private void scanSampleWithDate(String date) { - scanSample(date, null); - } - private void scanSample(@Nullable String date, @Nullable String profile) { SonarScanner scan = SonarScanner.create(projectDir("shared/xoo-sample")) .setProperty("sonar.cpd.exclusions", "**/*"); @@ -229,8 +146,4 @@ public class ProjectAdministrationTest { } orchestrator.executeBuild(scan); } - - private int count(String condition) { - return orchestrator.getDatabase().countSql("select count(1) from " + condition); - } } diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectQualityGatePageTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/ProjectQualityGatePageTest.java similarity index 78% rename from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectQualityGatePageTest.java rename to tests/src/test/java/org/sonarqube/tests/qualityGate/ProjectQualityGatePageTest.java index 43d726a78de..d47377fd3c4 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectQualityGatePageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/ProjectQualityGatePageTest.java @@ -17,49 +17,52 @@ * 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; +package org.sonarqube.tests.qualityGate; import com.codeborne.selenide.Condition; import com.codeborne.selenide.Selenide; import com.codeborne.selenide.SelenideElement; import com.sonar.orchestrator.Orchestrator; +import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; import org.openqa.selenium.Keys; import org.sonar.wsclient.qualitygate.QualityGate; import org.sonar.wsclient.qualitygate.QualityGateClient; +import org.sonarqube.qa.util.Tester; import org.sonarqube.qa.util.pageobjects.Navigation; import org.sonarqube.qa.util.pageobjects.ProjectQualityGatePage; -import org.sonarqube.tests.Category1Suite; import org.sonarqube.ws.client.PostRequest; -import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.qualitygate.SelectWsRequest; -import static util.ItUtils.newAdminWsClient; - public class ProjectQualityGatePageTest { @ClassRule - public static Orchestrator ORCHESTRATOR = Category1Suite.ORCHESTRATOR; - - private Navigation nav = Navigation.create(ORCHESTRATOR); + public static Orchestrator orchestrator = QualityGateSuite.ORCHESTRATOR; - private static WsClient wsClient; - - @BeforeClass - public static void prepare() { - wsClient = newAdminWsClient(ORCHESTRATOR); - } + @Rule + public Tester tester = new Tester(orchestrator) + // all the tests of QualityGateSuite must disable organizations + .disableOrganizations(); @Before public void setUp() { - ORCHESTRATOR.resetData(); - - wsClient.wsConnector().call(new PostRequest("api/projects/create") + tester.wsClient().wsConnector().call(new PostRequest("api/projects/create") .setParam("name", "Sample") .setParam("key", "sample")); + defaultGate = qualityGateClient().list().defaultGate(); + } + + private QualityGate defaultGate; + + @After + public void tearDown() { + if (defaultGate != null) { + qualityGateClient().setDefault(defaultGate.id()); + } } @Test @@ -127,6 +130,7 @@ public class ProjectQualityGatePageTest { } @Test + @Ignore public void should_set_none() { qualityGateClient().unsetDefault(); QualityGate customQualityGate = createCustomQualityGate("should_set_none"); @@ -139,20 +143,20 @@ public class ProjectQualityGatePageTest { } private ProjectQualityGatePage openPage() { - nav.logIn().submitCredentials("admin", "admin"); - Selenide.$(".js-skip.text-muted").pressEscape(); - return nav.openProjectQualityGate("sample"); + tester.wsClient().users().skipOnboardingTutorial(); + Navigation navigation = tester.openBrowser().logIn().submitCredentials("admin"); + return navigation.openProjectQualityGate("sample"); } - private static QualityGate createCustomQualityGate(String name) { + private QualityGate createCustomQualityGate(String name) { return qualityGateClient().create(name); } private void associateWithQualityGate(QualityGate qualityGate) { - wsClient.qualityGates().associateProject(new SelectWsRequest().setProjectKey("sample").setGateId(qualityGate.id())); + tester.wsClient().qualityGates().associateProject(new SelectWsRequest().setProjectKey("sample").setGateId(qualityGate.id())); } - private static QualityGateClient qualityGateClient() { - return ORCHESTRATOR.getServer().adminWsClient().qualityGateClient(); + private QualityGateClient qualityGateClient() { + return orchestrator.getServer().adminWsClient().qualityGateClient(); } } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java index ce4632b235a..616f9bf35ac 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateSuite.java @@ -29,6 +29,7 @@ import static util.ItUtils.xooPlugin; @RunWith(Suite.class) @Suite.SuiteClasses({ + ProjectQualityGatePageTest.class, QualityGateTest.class, QualityGateUiTest.class, QualityGateNotificationTest.class, diff --git a/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java b/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java index 90fb2a72988..a46823621c3 100644 --- a/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java +++ b/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java @@ -29,7 +29,6 @@ import static util.ItUtils.xooPlugin; @RunWith(Suite.class) @Suite.SuiteClasses({ EncodingTest.class, - ProjectCodeTest.class, ScmTest.class, SourceViewerTest.class }) diff --git a/tests/src/test/java/org/sonarqube/tests/ui/UiTest.java b/tests/src/test/java/org/sonarqube/tests/ui/UiTest.java index 050960d843f..85e25b9e29c 100644 --- a/tests/src/test/java/org/sonarqube/tests/ui/UiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/ui/UiTest.java @@ -21,19 +21,18 @@ package org.sonarqube.tests.ui; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category4Suite; import java.util.Map; -import org.junit.After; -import org.junit.Before; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.qa.util.pageobjects.Navigation; +import org.sonarqube.tests.Category4Suite; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsResponse; -import org.sonarqube.qa.util.pageobjects.Navigation; import util.ItUtils; import static com.codeborne.selenide.Condition.exist; -import static com.codeborne.selenide.Condition.hasText; import static com.codeborne.selenide.Condition.text; import static com.codeborne.selenide.Condition.visible; import static com.codeborne.selenide.Selenide.$; @@ -41,60 +40,56 @@ import static com.codeborne.selenide.Selenide.$$; import static com.codeborne.selenide.WebDriverRunner.url; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.projectDir; -import static util.ItUtils.resetSettings; -import static util.ItUtils.setServerProperty; public class UiTest { @ClassRule - public static final Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR; - - private Navigation nav = Navigation.create(ORCHESTRATOR); + public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; - @Before - @After - public void resetData() throws Exception { - resetSettings(ORCHESTRATOR, null, "sonar.forceAuthentication"); - } + @Rule + public Tester tester = new Tester(orchestrator).disableOrganizations(); @Test public void footer_contains_information() { - nav.getFooter() - .should(hasText("Documentation")) - .should(hasText("SonarSource SA")); + tester.openBrowser().getFooter() + .should(text("Documentation")) + .should(text("SonarSource SA")); } @Test public void footer_contains_version() { - WsResponse status = ItUtils.newAdminWsClient(ORCHESTRATOR).wsConnector().call(new GetRequest("api/navigation/global")); + WsResponse status = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/global")); Map statusMap = ItUtils.jsonToMap(status.content()); - nav.getFooter().should(hasText((String) statusMap.get("version"))); + tester.openBrowser().getFooter() + .should(text((String) statusMap.get("version"))); } @Test public void footer_doesnt_contains_version_on_login_page() { - WsResponse status = ItUtils.newAdminWsClient(ORCHESTRATOR).wsConnector().call(new GetRequest("api/navigation/global")); + WsResponse status = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/global")); Map statusMap = ItUtils.jsonToMap(status.content()); - nav.openLogin(); - nav.getFooter().shouldNot(hasText((String) statusMap.get("version"))); + Navigation navigation = tester.openBrowser(); + navigation.openLogin(); + navigation.getFooter().shouldNot(text((String) statusMap.get("version"))); } @Test public void footer_doesnt_contains_about_when_not_logged_in() { - setServerProperty(ORCHESTRATOR, "sonar.forceAuthentication", "true"); - nav.openLogin(); - nav.getFooter() - .shouldNot(hasText("About")) - .shouldNot(hasText("Web API")); + tester.settings().setGlobalSettings("sonar.forceAuthentication", "true"); + Navigation navigation = tester.openBrowser(); + navigation.openLogin(); + navigation.getFooter() + .shouldNot(text("About")) + .shouldNot(text("Web API")); } @Test public void many_page_transitions() { - analyzeSampleProject(); + analyzeXooSample(); - nav.open("/about"); + tester.openBrowser().open("/about"); // on about page $(".about-page-projects-link") @@ -145,13 +140,13 @@ public class UiTest { public void markdown_help() { String tags[] = {"strong", "a", "ul", "ol", "h1", "code", "pre", "blockquote"}; - nav.open("/markdown/help"); + tester.openBrowser().open("/markdown/help"); for (String tag : tags) { $(tag).shouldBe(visible); } } - private static void analyzeSampleProject() { - ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); + private static void analyzeXooSample() { + orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); } } -- 2.39.5