diff --git a/cloud.ganttproject.colloboque/build.gradle.kts b/cloud.ganttproject.colloboque/build.gradle.kts index 949d482361..e5ee9f1bd7 100644 --- a/cloud.ganttproject.colloboque/build.gradle.kts +++ b/cloud.ganttproject.colloboque/build.gradle.kts @@ -44,6 +44,7 @@ dependencies { implementation(kotlin("reflect", version = kotlinVersion)) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") implementation("org.jooq:jooq:3.19.1") + implementation("com.h2database:h2:2.1.214") implementation("org.slf4j:slf4j-api:1.7.36") implementation("com.github.ajalt.clikt:clikt:4.+") implementation("org.nanohttpd:nanohttpd:2.3.1") @@ -54,7 +55,6 @@ dependencies { implementation(files("lib/eclipsito.jar")) testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0") - testImplementation("com.h2database:h2:2.1.214") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0") } diff --git a/cloud.ganttproject.colloboque/src/main/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdater.kt b/cloud.ganttproject.colloboque/src/main/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdater.kt index 6a6e8ff20d..a6c8d33fe5 100644 --- a/cloud.ganttproject.colloboque/src/main/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdater.kt +++ b/cloud.ganttproject.colloboque/src/main/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdater.kt @@ -25,12 +25,18 @@ import net.sourceforge.ganttproject.TaskManagerConfigImpl import net.sourceforge.ganttproject.io.GanttXMLSaver import net.sourceforge.ganttproject.resource.HumanResourceManager import net.sourceforge.ganttproject.roles.RoleManager -import net.sourceforge.ganttproject.storage.LazyProjectDatabaseProxy -import net.sourceforge.ganttproject.storage.SqlProjectDatabaseImpl -import net.sourceforge.ganttproject.storage.XlogRecord +import net.sourceforge.ganttproject.storage.* import net.sourceforge.ganttproject.task.* +import org.h2.jdbcx.JdbcDataSource import java.io.ByteArrayOutputStream +private var databaseCounter: Long = 0 +private fun createInMemoryDatabase(): ProjectDatabase { + val dataSource = JdbcDataSource() + dataSource.setURL("jdbc:h2:mem:update${databaseCounter++};DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true") + return SqlProjectDatabaseImpl(dataSource) +} + /** * This function applies the `updates` to the contents of `projectXml` and returns the updated XML as a String. */ @@ -42,9 +48,10 @@ fun updateProjectXml(projectXml: String, updates: XlogRecord): String { ) val taskManagerConfig = TaskManagerConfigImpl(humanResourceManager, calendar) val taskManager = TaskManagerImpl(null, taskManagerConfig) - val projectDatabase = LazyProjectDatabaseProxy(databaseFactory = { - SqlProjectDatabaseImpl.createInMemoryDatabase() - }, taskManager = {taskManager}).also { + val projectDatabase = LazyProjectDatabaseProxy( + databaseFactory = { createInMemoryDatabase() }, + taskManager = {taskManager} + ).also { it.startLog("0") } val project = GanttProjectImpl(taskManager, projectDatabase) diff --git a/cloud.ganttproject.colloboque/src/test/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdaterTest.kt b/cloud.ganttproject.colloboque/src/test/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdaterTest.kt index 831f406029..72baeb5781 100644 --- a/cloud.ganttproject.colloboque/src/test/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdaterTest.kt +++ b/cloud.ganttproject.colloboque/src/test/kotlin/cloud/ganttproject/colloboque/ProjectFileUpdaterTest.kt @@ -33,7 +33,7 @@ class ProjectFileUpdaterTest { } @Test fun `empty xlog`() { - assertEquals(PROJECT_XML_TEMPLATE, ProjectFileUpdater().applyXlog(PROJECT_XML_TEMPLATE, XlogRecord(emptyList()))) + assertEquals(PROJECT_XML_TEMPLATE, updateProjectXml(PROJECT_XML_TEMPLATE, XlogRecord(emptyList()))) } @Test fun `apply task name change`() {