aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);