From 3d02dcff5825ad6dd4a24a04147b302ee81cb6be Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Mon, 14 Nov 2016 11:17:36 +0100 Subject: [PATCH] SONAR 8363 IT to test favorite auto-assignment --- .../src/test/java/it/Category3Suite.java | 4 +- .../test/java/it/analysis/FavoriteTest.java | 80 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 it/it-tests/src/test/java/it/analysis/FavoriteTest.java diff --git a/it/it-tests/src/test/java/it/Category3Suite.java b/it/it-tests/src/test/java/it/Category3Suite.java index 7d96b505825..99f74cc3909 100644 --- a/it/it-tests/src/test/java/it/Category3Suite.java +++ b/it/it-tests/src/test/java/it/Category3Suite.java @@ -20,8 +20,8 @@ package it; import com.sonar.orchestrator.Orchestrator; -import it.analysis.ScannerTest; import it.analysis.ExtensionLifecycleTest; +import it.analysis.FavoriteTest; import it.analysis.IssueJsonReportTest; import it.analysis.IssuesModeTest; import it.analysis.LinksTest; @@ -30,6 +30,7 @@ import it.analysis.ProjectBuilderTest; import it.analysis.ProjectProvisioningTest; import it.analysis.ReportDumpTest; import it.analysis.SSLTest; +import it.analysis.ScannerTest; import it.analysis.SettingsEncryptionTest; import it.analysis.TempFolderTest; import it.measure.DecimalScaleMetricTest; @@ -57,6 +58,7 @@ import static util.ItUtils.xooPlugin; SettingsEncryptionTest.class, ReportDumpTest.class, SSLTest.class, + FavoriteTest.class, // measures DecimalScaleMetricTest.class, // organization diff --git a/it/it-tests/src/test/java/it/analysis/FavoriteTest.java b/it/it-tests/src/test/java/it/analysis/FavoriteTest.java new file mode 100644 index 00000000000..8ee6eaaad2b --- /dev/null +++ b/it/it-tests/src/test/java/it/analysis/FavoriteTest.java @@ -0,0 +1,80 @@ +/* + * 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.analysis; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import it.Category3Suite; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonarqube.ws.MediaTypes; +import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.client.WsClient; + +import static com.sonar.orchestrator.container.Server.ADMIN_LOGIN; +import static com.sonar.orchestrator.container.Server.ADMIN_PASSWORD; +import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.newAdminWsClient; +import static util.ItUtils.projectDir; + +public class FavoriteTest { + @ClassRule + public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; + private static WsClient adminWsClient; + + private static final String PROJECT_KEY = "sample"; + + @Before + public void setUp() { + orchestrator.resetData(); + } + + @BeforeClass + public static void classSetUp() { + adminWsClient = newAdminWsClient(orchestrator); + } + + @Test + public void project_as_favorite_when_authenticated_and_first_analysis() { + SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-sample")) + .setProperty("sonar.login", ADMIN_LOGIN) + .setProperty("sonar.password", ADMIN_PASSWORD); + orchestrator.executeBuild(sampleProject); + + String response = adminWsClient.wsConnector().call(new GetRequest("api/favourites").setMediaType(MediaTypes.JSON)).content(); + assertThat(response).contains(PROJECT_KEY); + } + + @Test + public void no_project_as_favorite_when_second_analysis() { + SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-sample")); + orchestrator.executeBuild(sampleProject); + sampleProject + .setProperty("sonar.login", ADMIN_LOGIN) + .setProperty("sonar.password", ADMIN_PASSWORD); + orchestrator.executeBuild(sampleProject); + + String response = adminWsClient.wsConnector().call(new GetRequest("api/favourites").setMediaType(MediaTypes.JSON)).content(); + assertThat(response).doesNotContain(PROJECT_KEY); + } +} -- 2.39.5