aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-05-11 10:21:52 +0200
committerSonarTech <sonartech@sonarsource.com>2018-05-14 20:20:48 +0200
commit45be4f8e5a05e2c5d9b7d9573a69af24a06e317c (patch)
tree77119a444241e0d184dd90d9b6e0aa0a205fc3b3 /tests/src
parent08438a2c47112f2fce1e512f6c843c908abed4c7 (diff)
downloadsonarqube-45be4f8e5a05e2c5d9b7d9573a69af24a06e317c.tar.gz
sonarqube-45be4f8e5a05e2c5d9b7d9573a69af24a06e317c.zip
SONAR-10661 Use ZipUtils from Orchestrator in integration tests
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/test/java/org/sonarqube/tests/source/NoScmThenScmTest.java8
-rw-r--r--tests/src/test/java/org/sonarqube/tests/source/ScmThenNoScmTest.java6
-rw-r--r--tests/src/test/java/org/sonarqube/tests/source/ZipUtils.java70
3 files changed, 7 insertions, 77 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/source/NoScmThenScmTest.java b/tests/src/test/java/org/sonarqube/tests/source/NoScmThenScmTest.java
index f44fc83c68a..0edc2048d54 100644
--- a/tests/src/test/java/org/sonarqube/tests/source/NoScmThenScmTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/source/NoScmThenScmTest.java
@@ -33,11 +33,11 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.qa.util.Tester;
+import static com.sonar.orchestrator.util.ZipUtils.unzip;
import static org.apache.commons.io.FileUtils.copyDirectory;
import static org.apache.commons.io.FileUtils.moveFile;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonarqube.tests.source.SourceSuite.ORCHESTRATOR;
-import static org.sonarqube.tests.source.ZipUtils.unzip;
import static util.ItUtils.projectDir;
public class NoScmThenScmTest {
@@ -77,7 +77,7 @@ public class NoScmThenScmTest {
assertThat(scmData.get(1).date).isInSameMinuteWindowAs(new Date());
// Restore SCM Repository
- unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+ unzip(new File(source, "scm-repository.zip"), source);
// 2nd run
orchestrator.executeBuild(newScannerWithSCM(source));
@@ -104,7 +104,7 @@ public class NoScmThenScmTest {
assertThat(scmData.get(1).date).isInSameMinuteWindowAs(new Date());
// Restore SCM Repository
- unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+ unzip(new File(source, "scm-repository.zip"), source);
// Swap analysed fo to a modified one
File sample = new File(source, PATH_TO_SAMPLE);
@@ -140,7 +140,7 @@ public class NoScmThenScmTest {
assertThat(scmData.get(1).date).isInSameMinuteWindowAs(new Date());
// Restore SCM Repository
- unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+ unzip(new File(source, "scm-repository.zip"), source);
// Swap analysed fo to a modified one
File sample = new File(source, PATH_TO_SAMPLE);
diff --git a/tests/src/test/java/org/sonarqube/tests/source/ScmThenNoScmTest.java b/tests/src/test/java/org/sonarqube/tests/source/ScmThenNoScmTest.java
index 2a61e74dd37..5e035e9e5cb 100644
--- a/tests/src/test/java/org/sonarqube/tests/source/ScmThenNoScmTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/source/ScmThenNoScmTest.java
@@ -35,12 +35,12 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.qa.util.Tester;
+import static com.sonar.orchestrator.util.ZipUtils.unzip;
import static org.apache.commons.io.FileUtils.copyDirectory;
import static org.apache.commons.io.FileUtils.deleteDirectory;
import static org.apache.commons.io.FileUtils.moveFile;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonarqube.tests.source.SourceSuite.ORCHESTRATOR;
-import static org.sonarqube.tests.source.ZipUtils.unzip;
import static util.ItUtils.projectDir;
public class ScmThenNoScmTest {
@@ -64,7 +64,7 @@ public class ScmThenNoScmTest {
public void with_and_then_without_scm_on_same_file() throws ParseException, IOException {
File source = disposableWorkspaceFor("xoo-sample-with-then-without-scm");
- unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+ unzip(new File(source, "scm-repository.zip"), source);
// First run
SonarScanner scanner = SonarScanner.create(source)
@@ -99,7 +99,7 @@ public class ScmThenNoScmTest {
public void with_and_then_without_scm_on_modified_file() throws ParseException, IOException {
File source = disposableWorkspaceFor("xoo-sample-with-then-without-scm");
- unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+ unzip(new File(source, "scm-repository.zip"), source);
// First run
SonarScanner scanner = SonarScanner.create(source)
diff --git a/tests/src/test/java/org/sonarqube/tests/source/ZipUtils.java b/tests/src/test/java/org/sonarqube/tests/source/ZipUtils.java
deleted file mode 100644
index 258cc38128a..00000000000
--- a/tests/src/test/java/org/sonarqube/tests/source/ZipUtils.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 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.source;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-public class ZipUtils {
-
- // I see that we have apache commons compress in the path so it should be possible to reduce the boiler plate
- // -- but nothing out of the box : still have to walk the tree and uncompress file by file.
-
- static void unzip(File archive, String directory) throws IOException {
- try (ZipInputStream zis = new ZipInputStream(new FileInputStream(archive))) {
-
- ZipEntry entry = zis.getNextEntry();
- while (entry != null) {
-
- File file = new File(directory, entry.getName());
-
- if (entry.isDirectory()) {
- file.mkdirs();
- } else {
-
- File parent = file.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
- long size = entry.getSize();
- byte[] buffer = new byte[Math.toIntExact(size)];
- if (size > 0) {
- int location;
- while ((location = zis.read(buffer)) != -1) {
- bos.write(buffer, 0, location);
- }
- }
- }
-
- }
-
- entry = zis.getNextEntry();
- }
- }
- }
-
-}