aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-10-24 16:58:53 +0200
committerDavid Gageot <david@gageot.net>2012-10-24 16:58:53 +0200
commitcc8897d8d488954e532aa7a98198051f417d3ae2 (patch)
treea4286de44dd4dee436af47aefd26277189af4db7 /sonar-core
parenta34fafa1ca7025b1381192043920daae72de80a1 (diff)
downloadsonarqube-cc8897d8d488954e532aa7a98198051f417d3ae2.tar.gz
sonarqube-cc8897d8d488954e532aa7a98198051f417d3ae2.zip
SONAR-3895 Use proper temp folder
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/LocalDatabaseFactory.java3
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/LocalDatabaseFactoryTest.java9
2 files changed, 9 insertions, 3 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/LocalDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/LocalDatabaseFactory.java
index f9bd10e9f1f..a2e265bd5cd 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/LocalDatabaseFactory.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/LocalDatabaseFactory.java
@@ -47,8 +47,7 @@ public class LocalDatabaseFactory implements ServerComponent {
}
public byte[] createDatabaseForLocalMode() {
- // serverFileSystem.getTempDir()
- String name = System.getenv("java.io") + System.nanoTime(); // TODO
+ String name = serverFileSystem.getTempDir().getAbsolutePath() + "db-" + System.nanoTime();
try {
BasicDataSource destination = create(DIALECT, DRIVER, USER, PASSWORD, URL + name);
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/LocalDatabaseFactoryTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/LocalDatabaseFactoryTest.java
index 79ac446b7ec..3486fb9638a 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/LocalDatabaseFactoryTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/LocalDatabaseFactoryTest.java
@@ -26,15 +26,20 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.platform.ServerFileSystem;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class LocalDatabaseFactoryTest extends AbstractDaoTestCase {
private LocalDatabaseFactory localDatabaseFactory;
+
+ private ServerFileSystem serverFileSystem = mock(ServerFileSystem.class);
private BasicDataSource dataSource;
@Rule
@@ -42,7 +47,7 @@ public class LocalDatabaseFactoryTest extends AbstractDaoTestCase {
@Before
public void setUp() {
- localDatabaseFactory = new LocalDatabaseFactory(getDatabase(), null);
+ localDatabaseFactory = new LocalDatabaseFactory(getDatabase(), serverFileSystem);
}
@After
@@ -56,6 +61,8 @@ public class LocalDatabaseFactoryTest extends AbstractDaoTestCase {
public void should_create_database() throws IOException {
setupData("should_create_database");
+ when(serverFileSystem.getTempDir()).thenReturn(temporaryFolder.getRoot());
+
byte[] database = localDatabaseFactory.createDatabaseForLocalMode();
dataSource = createDatabase(database);