From 7a1c1f3bdff7193e448f3d5746bde3c82a9f6a4d Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 8 Apr 2016 16:44:18 +0200 Subject: [PATCH] Fix ITs --- .../sonar-project.properties | 7 - .../src/basic/Hello.java | 9 - .../src/basic/World.java | 8 - .../java/com/sonar/runner/it/CacheTest.java | 159 ------------------ .../runner/it/SonarScannerTestSuite.java | 2 +- pom.xml | 4 +- 6 files changed, 3 insertions(+), 186 deletions(-) delete mode 100644 it/projects/java-sample-non-associated/sonar-project.properties delete mode 100644 it/projects/java-sample-non-associated/src/basic/Hello.java delete mode 100644 it/projects/java-sample-non-associated/src/basic/World.java delete mode 100644 it/src/test/java/com/sonar/runner/it/CacheTest.java diff --git a/it/projects/java-sample-non-associated/sonar-project.properties b/it/projects/java-sample-non-associated/sonar-project.properties deleted file mode 100644 index bd17a41..0000000 --- a/it/projects/java-sample-non-associated/sonar-project.properties +++ /dev/null @@ -1,7 +0,0 @@ -# Note that the format of project key is still groupId:artifactId in order to support test with sonar 2.6. -#sonar.projectKey=java:sample -sonar.projectName=Java Sample, with comma -sonar.projectDescription=This is a Java sample -sonar.projectVersion=1.2.3 - -sonar.sources=src diff --git a/it/projects/java-sample-non-associated/src/basic/Hello.java b/it/projects/java-sample-non-associated/src/basic/Hello.java deleted file mode 100644 index b9db5a0..0000000 --- a/it/projects/java-sample-non-associated/src/basic/Hello.java +++ /dev/null @@ -1,9 +0,0 @@ -package basic; - -public class Hello { - - public void hello() { - int i=356; - if (true) i=5658; - } -} diff --git a/it/projects/java-sample-non-associated/src/basic/World.java b/it/projects/java-sample-non-associated/src/basic/World.java deleted file mode 100644 index c65d91c..0000000 --- a/it/projects/java-sample-non-associated/src/basic/World.java +++ /dev/null @@ -1,8 +0,0 @@ -package basic; - -public final class World { - - public void world() { - System.out.println("hello world"); - } -} diff --git a/it/src/test/java/com/sonar/runner/it/CacheTest.java b/it/src/test/java/com/sonar/runner/it/CacheTest.java deleted file mode 100644 index a226521..0000000 --- a/it/src/test/java/com/sonar/runner/it/CacheTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * SonarSource :: IT :: SonarQube Scanner - * 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 com.sonar.runner.it; - -import com.sonar.orchestrator.build.BuildFailureException; -import com.sonar.orchestrator.build.BuildResult; -import com.sonar.orchestrator.build.SonarRunner; -import com.sonar.orchestrator.locator.ResourceLocation; -import java.io.File; -import java.io.IOException; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CacheTest extends ScannerTestCase { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - private File currentTemp = null; - private static boolean serverRunning = false; - - @BeforeClass - public static void setUpClass() { - orchestrator.resetData(); - orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); - orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma"); - orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way"); - serverRunning = true; - } - - @AfterClass - public static void restartForOtherTests() { - ensureStarted(); - } - - private static void ensureStarted() { - if (!serverRunning) { - orchestrator.start(); - serverRunning = true; - } - } - - private static void ensureStopped() { - if (serverRunning) { - orchestrator.stop(); - serverRunning = false; - } - } - - @Test - public void testIssuesMode() throws IOException { - Assume.assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("5.3")); - - // online, cache empty -> should sync - ensureStarted(); - SonarRunner build = createRunner("issues", true, "java-sample"); - BuildResult result = orchestrator.executeBuild(build, false); - assertThat(result.isSuccess()).isTrue(); - - // offline, don't use cache by default -> should fail - ensureStopped(); - build = createRunner("issues", false, "java-sample"); - result = orchestrator.executeBuildQuietly(build, false); - assertThat(result.isSuccess()).isFalse(); - - // offline, don't use cache -> should run from cache - build = createRunner("issues", false, "java-sample"); - build.setProperty("sonar.useWsCache", "true"); - result = orchestrator.executeBuild(build, false); - assertThat(result.isSuccess()).isTrue(); - - // offline, cache empty -> should fail - build = createRunner("issues", true, "java-sample"); - build.setProperty("sonar.useWsCache", "true"); - result = orchestrator.executeBuildQuietly(build, false); - assertThat(result.isSuccess()).isFalse(); - // this message is specific to the server_first cache strategy - assertThat(result.getLogs()).contains("can not be reached, trying cache"); - assertThat(result.getLogs()).contains("can not be reached and data is not cached"); - } - - @Test - public void testNonAssociatedMode() throws IOException { - Assume.assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("5.2")); - - // online, without cache -> should sync - ensureStarted(); - SonarRunner build = createRunner("issues", true, "java-sample-non-associated"); - BuildResult result = orchestrator.executeBuild(build, false); - assertThat(result.isSuccess()).isTrue(); - - // offline, with cache -> should run from cache - ensureStopped(); - build = createRunner("issues", false, "java-sample-non-associated"); - build.setProperty("sonar.useWsCache", "true"); - result = orchestrator.executeBuild(build, false); - assertThat(result.isSuccess()).isTrue(); - } - - @Test - public void testPublishModeOffline() throws IOException { - Assume.assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("5.2")); - - // online (cache not used) - ensureStarted(); - SonarRunner build = createRunner("publish", "java-sample"); - BuildResult result = orchestrator.executeBuild(build, false); - assertThat(result.isSuccess()).isTrue(); - - // offline (cache not used) -> should fail - ensureStopped(); - build = createRunner("publish", false, "java-sample"); - try { - result = orchestrator.executeBuild(build); - } catch (BuildFailureException e) { - assertThat(e.getResult().getLogs()).contains("Fail to download libraries from server"); - } - - } - - private SonarRunner createRunner(String mode, String project) throws IOException { - return createRunner(mode, false, project); - } - - private SonarRunner createRunner(String mode, boolean refreshCache, String project) throws IOException { - if (refreshCache || currentTemp == null) { - currentTemp = temp.newFolder(); - } - - SonarRunner runner = newScanner(new File("projects/" + project)) - .setProperty("sonar.analysis.mode", mode) - .setProperty("sonar.userHome", currentTemp.getAbsolutePath()); - - return runner; - } - -} diff --git a/it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java b/it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java index 1cb56cc..b835e67 100644 --- a/it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java +++ b/it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java @@ -26,7 +26,7 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({JavaTest.class, MultimoduleTest.class, CacheTest.class}) +@SuiteClasses({JavaTest.class, MultimoduleTest.class}) public class SonarScannerTestSuite { @ClassRule diff --git a/pom.xml b/pom.xml index d490039..a8c73ce 100644 --- a/pom.xml +++ b/pom.xml @@ -158,8 +158,8 @@ - 490000 - 500000 + 500000 + 510000 ${project.build.directory}/sonar-scanner-${project.version}.zip -- 2.39.5