aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-home/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-05-13 10:35:18 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-05-13 15:03:56 +0200
commit35997d8bbebb20e87f78ab1d7a7a77ab28cf16a9 (patch)
tree36655ed02200f6a120b2c3d2ddf435315efcf110 /sonar-home/src/test
parent1d0523368d43ccf4bef67ee9918a84419b4073b7 (diff)
downloadsonarqube-35997d8bbebb20e87f78ab1d7a7a77ab28cf16a9.tar.gz
sonarqube-35997d8bbebb20e87f78ab1d7a7a77ab28cf16a9.zip
SONAR-7367 Remove code previously used by SonarLint
Diffstat (limited to 'sonar-home/src/test')
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java77
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java145
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java55
3 files changed, 0 insertions, 277 deletions
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java
deleted file mode 100644
index 56ed229db43..00000000000
--- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 org.sonar.home.cache;
-
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-import static org.mockito.Mockito.mock;
-
-public class PersistentCacheBuilderTest {
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void user_home_property_can_be_null() {
- PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(null).setAreaForGlobal("url").build();
- assertTrue(Files.isDirectory(cache.getDirectory()));
- assertThat(cache.getDirectory()).endsWith(Paths.get("url", "global"));
- }
-
- @Test
- public void set_user_home() {
- PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(temp.getRoot().toPath()).setAreaForGlobal("url").build();
-
- assertThat(cache.getDirectory()).isDirectory();
- assertThat(cache.getDirectory()).startsWith(temp.getRoot().toPath());
- assertTrue(Files.isDirectory(cache.getDirectory()));
- }
-
- @Test
- public void read_system_env() {
- assumeTrue(System.getenv("SONAR_USER_HOME") == null);
-
- System.setProperty("user.home", temp.getRoot().getAbsolutePath());
-
- PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url").build();
- assertTrue(Files.isDirectory(cache.getDirectory()));
- assertThat(cache.getDirectory()).startsWith(temp.getRoot().toPath());
- }
-
- @Test
- public void directories() {
- System.setProperty("user.home", temp.getRoot().getAbsolutePath());
-
- PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForProject("url", "0", "proj").build();
- assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "0", "projects", "proj"));
-
- cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForLocalProject("url", "0").build();
- assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "0", "local"));
-
- cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url").build();
- assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "global"));
- }
-}
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
deleted file mode 100644
index 1c149a44b0f..00000000000
--- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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 org.sonar.home.cache;
-
-import org.apache.commons.io.IOUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-import static org.mockito.Matchers.any;
-
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.verify;
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class PersistentCacheTest {
- private final static String URI = "key1";
- private final static String VALUE = "cache content";
- private PersistentCache cache = null;
- private DirectoryLock lock = null;
- private PersistentCacheInvalidation invalidation = null;
-
- @Rule
- public TemporaryFolder tmp = new TemporaryFolder();
-
- @Before
- public void setUp() throws IOException {
- invalidation = mock(PersistentCacheInvalidation.class);
- when(invalidation.test(any(Path.class))).thenReturn(false);
- lock = mock(DirectoryLock.class);
- when(lock.getFileLockName()).thenReturn("lock");
- cache = new PersistentCache(tmp.getRoot().toPath(), invalidation, mock(Logger.class), lock);
- }
-
- @Test
- public void testCacheMiss() throws Exception {
- assertCacheHit(false);
- }
-
- @Test
- public void testClean() throws Exception {
- Path lockFile = cache.getDirectory().resolve("lock");
- // puts entry
- cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8));
- Files.write(lockFile, "test".getBytes(StandardCharsets.UTF_8));
- assertCacheHit(true);
- when(invalidation.test(any(Path.class))).thenReturn(true);
- cache.clean();
- when(invalidation.test(any(Path.class))).thenReturn(false);
- assertCacheHit(false);
- // lock file should not get deleted
- assertThat(new String(Files.readAllBytes(lockFile), StandardCharsets.UTF_8)).isEqualTo("test");
- }
-
- @Test
- public void testStream() throws IOException {
- cache.put("id", "test".getBytes());
- InputStream stream = cache.getStream("id");
- assertThat(IOUtils.toString(stream)).isEqualTo("test");
-
- assertThat(cache.getStream("non existing")).isNull();
- }
-
- @Test
- public void testClear() throws Exception {
- Path lockFile = cache.getDirectory().resolve("lock");
- cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8));
- Files.write(lockFile, "test".getBytes(StandardCharsets.UTF_8));
- assertCacheHit(true);
- cache.clear();
- assertCacheHit(false);
- // lock file should not get deleted
- assertThat(new String(Files.readAllBytes(lockFile), StandardCharsets.UTF_8)).isEqualTo("test");
- }
-
- @Test
- public void testCacheHit() throws Exception {
- cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8));
- assertCacheHit(true);
- }
-
- @Test
- public void testReconfigure() throws Exception {
- assertCacheHit(false);
- cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8));
- assertCacheHit(true);
-
- File root = tmp.getRoot();
- FileUtils.deleteQuietly(root);
-
- // should re-create cache directory and start using the cache
- cache.reconfigure();
- assertThat(root).exists();
-
- assertCacheHit(false);
- cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8));
- assertCacheHit(true);
- }
-
- @Test
- public void testExpiration() throws Exception {
- when(invalidation.test(any(Path.class))).thenReturn(true);
- cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8));
- assertCacheHit(false);
- }
-
- private void assertCacheHit(boolean hit) throws Exception {
- assertCacheHit(cache, hit);
- }
-
- private void assertCacheHit(PersistentCache pCache, boolean hit) throws Exception {
- String expected = hit ? VALUE : null;
- assertThat(pCache.getString(URI)).isEqualTo(expected);
- verify(lock, atLeast(1)).unlock();
- }
-
-}
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java b/sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java
deleted file mode 100644
index 4f60b66d46e..00000000000
--- a/sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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 org.sonar.home.cache;
-
-import org.junit.Before;
-
-import java.io.IOException;
-import java.nio.file.Path;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Test;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-
-public class TTLCacheInvalidationTest {
- private Path testFile;
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Before
- public void setUp() throws IOException {
- testFile = temp.newFile().toPath();
- }
-
- @Test
- public void testExpired() throws IOException {
- TTLCacheInvalidation invalidation = new TTLCacheInvalidation(-100);
- assertThat(invalidation.test(testFile)).isEqualTo(true);
- }
-
- @Test
- public void testValid() throws IOException {
- TTLCacheInvalidation invalidation = new TTLCacheInvalidation(100_000);
- assertThat(invalidation.test(testFile)).isEqualTo(false);
- }
-}