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;
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;
SettingsEncryptionTest.class,
ReportDumpTest.class,
SSLTest.class,
+ FavoriteTest.class,
// measures
DecimalScaleMetricTest.class,
// organization
--- /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.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);
+ }
+}