Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashev committed Jan 25, 2024
1 parent cae751b commit 695265e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cloud.ganttproject.colloboque/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`() {
Expand Down

0 comments on commit 695265e

Please sign in to comment.