aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java/org/sonar/batch/index
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-10-15 17:14:44 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-10-16 15:25:41 +0200
commit18a4c15b060d1b56f08826bf6006d08eaf2625ec (patch)
tree03cc1afb062054a3d3d74849bf18e7a6485ab05c /sonar-batch/src/test/java/org/sonar/batch/index
parent3f946fc11c49585f8cdf003c54f19c322a4aab29 (diff)
downloadsonarqube-18a4c15b060d1b56f08826bf6006d08eaf2625ec.tar.gz
sonarqube-18a4c15b060d1b56f08826bf6006d08eaf2625ec.zip
SONAR-4748 Introduce a new extension for managing temp files/folders.
Diffstat (limited to 'sonar-batch/src/test/java/org/sonar/batch/index')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/CacheTest.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java30
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataCacheTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java12
4 files changed, 55 insertions, 8 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/CacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/CacheTest.java
index 48bfe91417f..a888e5eb6bb 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/CacheTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/CacheTest.java
@@ -23,15 +23,22 @@ import com.google.common.collect.Iterables;
import com.persistit.exception.PersistitException;
import org.junit.After;
import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import static org.fest.assertions.Assertions.assertThat;
public class CacheTest {
- Caches caches = new Caches();
+
+ @ClassRule
+ public static TemporaryFolder temp = new TemporaryFolder();
+
+ Caches caches;
@Before
- public void start() {
+ public void start() throws Exception {
+ caches = CachesTest.createCacheOnTemp(temp);
caches.start();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java
index 200a4295afd..eafec808dc8 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java
@@ -19,17 +19,45 @@
*/
package org.sonar.batch.index;
+import edu.emory.mathcs.backport.java.util.Collections;
import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.CoreProperties;
+import org.sonar.batch.bootstrap.BatchTempUtils;
+import org.sonar.batch.bootstrap.BootstrapProperties;
+import org.sonar.batch.bootstrap.BootstrapSettings;
import java.io.File;
+import java.io.IOException;
import java.io.Serializable;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
public class CachesTest {
- Caches caches = new Caches();
+
+ @ClassRule
+ public static TemporaryFolder temp = new TemporaryFolder();
+
+ public static Caches createCacheOnTemp(TemporaryFolder temp) {
+ BootstrapSettings bootstrapSettings = new BootstrapSettings(new BootstrapProperties(Collections.emptyMap()));
+ try {
+ bootstrapSettings.properties().put(CoreProperties.WORKING_DIRECTORY, temp.newFolder().getAbsolutePath());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return new Caches(new BatchTempUtils(bootstrapSettings));
+ }
+
+ Caches caches;
+
+ @Before
+ public void prepare() throws Exception {
+ caches = createCacheOnTemp(temp);
+ }
@After
public void stop() {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataCacheTest.java
index 5b6e67b2149..26d4b8cbbe2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataCacheTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataCacheTest.java
@@ -21,16 +21,22 @@ package org.sonar.batch.index;
import org.junit.After;
import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import static org.fest.assertions.Assertions.assertThat;
public class ComponentDataCacheTest {
- Caches caches = new Caches();
+ @ClassRule
+ public static TemporaryFolder temp = new TemporaryFolder();
+
+ Caches caches;
@Before
- public void start() {
+ public void start() throws Exception {
+ caches = CachesTest.createCacheOnTemp(temp);
caches.start();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java
index 3910b0ca85b..286c75447b2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ComponentDataPersisterTest.java
@@ -21,19 +21,25 @@ package org.sonar.batch.index;
import org.junit.After;
import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.database.model.Snapshot;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.source.jdbc.SnapshotDataDao;
public class ComponentDataPersisterTest extends AbstractDaoTestCase {
+ @ClassRule
+ public static TemporaryFolder temp = new TemporaryFolder();
+
SnapshotCache snapshots = new SnapshotCache();
ComponentDataCache data;
- Caches caches = new Caches();
+ Caches caches;
@Before
- public void start() {
+ public void start() throws Exception {
+ caches = CachesTest.createCacheOnTemp(temp);
caches.start();
}
@@ -59,6 +65,6 @@ public class ComponentDataPersisterTest extends AbstractDaoTestCase {
ComponentDataPersister persister = new ComponentDataPersister(data, snapshots, dataDao, getMyBatis());
persister.persist();
- checkTables("should_persist_component_data", new String[]{"id", "created_at", "updated_at"}, "snapshot_data");
+ checkTables("should_persist_component_data", new String[] {"id", "created_at", "updated_at"}, "snapshot_data");
}
}