Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions golem-xiv-server/src/test/kotlin/GolemServerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,59 @@ import com.xemantic.kotlin.test.coroutines.should
import com.xemantic.kotlin.test.have
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.install
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation as ServerContentNegotiation
import io.ktor.server.response.respondText
import io.ktor.server.routing.get
import io.ktor.server.routing.route
import io.ktor.server.routing.routing
import io.ktor.server.testing.testApplication
import org.junit.jupiter.api.AfterEach
import kotlin.test.Test

class GolemServerTest {

// just a bootstrap of server tests, needs to be expanded, see xemantic-neo4j-demo for inspiration
@AfterEach
fun cleanDatabase() {
TestNeo4j.cleanDatabase()
}

@Test
fun `should check health endpoint status`() = testApplication {
fun `should respond to ping endpoint with neo4j available`() = testApplication {
// given
// TestNeo4j is initialized lazily and provides an embedded neo4j instance
// This ensures neo4j harness is running for the integration test
TestNeo4j.isInitialized

application {
//module()
install(ServerContentNegotiation) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of mocking, we should use actual golem instance. It might require modularazing neo4j setup further, as it is done in the demo project.

json()
}
routing {
route("/api") {
get("/ping") {
call.respondText("pong")
}
}
}
}

client = createClient {
val client = createClient {
install(ContentNegotiation) {
json()
}
}

// when
val response = client.get("/health")
val response = client.get("/api/ping")

// then
response should {
have(status == HttpStatusCode.NotFound)
//have(bodyAsText() == "")
have(status == HttpStatusCode.OK)
have(bodyAsText() == "pong")
}
}

Expand Down
67 changes: 67 additions & 0 deletions golem-xiv-server/src/test/kotlin/TestNeo4j.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Golem XIV - Autonomous metacognitive AI system with semantic memory and self-directed research
* Copyright (C) 2026 Kazimierz Pogoda / Xemantic
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.xemantic.ai.golem.server

import org.neo4j.configuration.connectors.BoltConnector
import org.neo4j.configuration.connectors.HttpConnector
import org.neo4j.driver.AuthTokens
import org.neo4j.driver.Driver
import org.neo4j.driver.GraphDatabase
import org.neo4j.harness.Neo4j
import org.neo4j.harness.internal.InProcessNeo4jBuilder

/**
* Test utility that provides an embedded Neo4j instance using neo4j-harness.
* Used for integration tests that require a running Neo4j database.
*/
object TestNeo4j {

private val db: Neo4j by lazy {
InProcessNeo4jBuilder()
.withDisabledServer()
.withConfig(HttpConnector.enabled, false)
.withConfig(BoltConnector.enabled, true)
.build()
}

private val driver: Driver by lazy {
GraphDatabase.driver(
db.boltURI(),
AuthTokens.none()
)
}

/**
* Ensures the Neo4j instance is initialized.
* Call this property to start the embedded database before running tests.
*/
val isInitialized: Boolean
get() {
// Access driver to trigger lazy initialization
driver
return true
}

fun cleanDatabase() {
driver.executableQuery(
"MATCH (n) DETACH DELETE n"
).execute()
}

}
Loading