Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Update LW Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Jun 21, 2024
1 parent a83d78c commit 4080dad
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ version=0.1.12-SNAPSHOT
jvmVersion=11
kotestVersion=2.0.2
kotlinVersion=2.0.0
lionwebRepositoryCommitID=9a8e8ce
lionwebRepositoryCommitID=988b48d
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class PropertiesFunctionalTest {
}
modelRepository!!.withCommand()
modelRepository!!.start()

// Initialization may change in the future (see https://github.com/LionWeb-io/lionweb-repository/issues/61)
val client = LionWebClient(port = modelRepository!!.firstMappedPort)
// We need to create the database
client.createDatabase()
// We then need to create a default database
client.createRepository(history = false)
}

@AfterTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.internal.EMPTY_REQUEST
import java.net.ConnectException
import java.net.HttpURLConnection
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -83,6 +84,36 @@ class LionWebClient(
}
}

fun createDatabase() {
val url = "http://$hostname:$port/createDatabase"
val request: Request =
Request.Builder()
.url(url)
.considerAuthenticationToken()
.post(EMPTY_REQUEST)
.build()
OkHttpClient().newCall(request).execute().use { response ->
if (response.code != HttpURLConnection.HTTP_OK) {
throw RuntimeException("DB initialization failed, HTTP ${response.code}: ${response.body?.string()}")
}
}
}

fun createRepository(history: Boolean = false) {
val url = "http://$hostname:$port/createRepository?history=$history"
val request: Request =
Request.Builder()
.url(url)
.considerAuthenticationToken()
.post(EMPTY_REQUEST)
.build()
OkHttpClient().newCall(request).execute().use { response ->
if (response.code != HttpURLConnection.HTTP_OK) {
throw RuntimeException("DB initialization failed, HTTP ${response.code}: ${response.body?.string()}")
}
}
}

// Partitions

fun createPartition(node: Node) {
Expand Down Expand Up @@ -131,7 +162,7 @@ class LionWebClient(
.url(url)
.considerAuthenticationToken()
.addHeader("Accept-Encoding", "gzip")
.get()
.post(EMPTY_REQUEST)
.build()
httpClient.newCall(request).execute().use { response ->
if (response.code == HttpURLConnection.HTTP_OK) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.strumenta.kolasu.lionweb.LWNode
import com.strumenta.lwrepoclient.base.FunctionalTestBuildConfig
import com.strumenta.lwrepoclient.base.LionWebClient
import io.lionweb.lioncore.java.utils.ModelComparator
import org.testcontainers.containers.GenericContainer
import org.testcontainers.containers.Network
Expand Down Expand Up @@ -67,6 +68,13 @@ abstract class AbstractFunctionalTest {
}
modelRepository!!.withCommand()
modelRepository!!.start()

// Initialization may change in the future (see https://github.com/LionWeb-io/lionweb-repository/issues/61)
val client = LionWebClient(port = modelRepository!!.firstMappedPort)
// We need to create the database
client.createDatabase()
// We then need to create a default database
client.createRepository(history = false)
}

@AfterTest
Expand Down

0 comments on commit 4080dad

Please sign in to comment.