Skip to content

Commit 1641fdc

Browse files
committed
test(modelql): add implementations for TypedModelQlTest
1 parent f77c675 commit 1641fdc

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package org.modelix.modelql.typed
15+
16+
import io.ktor.server.testing.testApplication
17+
import org.modelix.apigen.test.ApigenTestLanguages
18+
import org.modelix.model.api.IBranch
19+
import org.modelix.model.api.PBranch
20+
import org.modelix.model.api.getRootNode
21+
import org.modelix.model.client.IdGenerator
22+
import org.modelix.model.lazy.CLTree
23+
import org.modelix.model.lazy.ObjectStoreCache
24+
import org.modelix.model.persistent.MapBasedStore
25+
import org.modelix.model.server.light.LightModelServer
26+
import org.modelix.modelql.client.ModelQLClient
27+
import kotlin.test.BeforeTest
28+
29+
class TypedModelQLTestWithLightModelServer : TypedModelQLTest() {
30+
private lateinit var branch: IBranch
31+
32+
override fun runTest(block: suspend (ModelQLClient) -> Unit) = testApplication {
33+
application {
34+
LightModelServer(80, branch.getRootNode()).apply { installHandlers() }
35+
}
36+
val httpClient = createClient {
37+
}
38+
val modelQlClient = ModelQLClient.builder().url("http://localhost/query").httpClient(httpClient).build()
39+
block(modelQlClient)
40+
}
41+
42+
@BeforeTest
43+
fun setup() {
44+
ApigenTestLanguages.registerAll()
45+
val tree = CLTree(ObjectStoreCache(MapBasedStore()))
46+
branch = PBranch(tree, IdGenerator.getInstance(1))
47+
branch.runWrite {
48+
createTestData(branch.getRootNode())
49+
}
50+
}
51+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.modelix.modelql.typed
18+
19+
import kotlinx.coroutines.runBlocking
20+
import org.junit.jupiter.api.TestInstance
21+
import org.modelix.apigen.test.ApigenTestLanguages
22+
import org.modelix.model.ModelFacade
23+
import org.modelix.model.client2.ModelClientV2
24+
import org.modelix.model.client2.runWrite
25+
import org.modelix.model.lazy.RepositoryId
26+
import org.modelix.modelql.client.ModelQLClient
27+
import kotlin.test.BeforeTest
28+
29+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
30+
class TypedModelQLWithModelServerTest : TypedModelQLTest() {
31+
private var testRun = 0
32+
private val modelClient = ModelClientV2.builder().url("http://localhost:28102/v2/").build().also { runBlocking { it.init() } }
33+
private val branchRef
34+
get() = ModelFacade.createBranchReference(RepositoryId("modelql-test$testRun"), "master")
35+
36+
override fun runTest(block: suspend (ModelQLClient) -> Unit) {
37+
val modelQlClient = ModelQLClient.builder()
38+
.url("http://localhost:28102/v2/repositories/${branchRef.repositoryId.id}/branches/${branchRef.branchName}/query")
39+
.build()
40+
41+
runBlocking { block(modelQlClient) }
42+
}
43+
44+
init {
45+
ApigenTestLanguages.registerAll()
46+
}
47+
48+
@BeforeTest
49+
fun setup() {
50+
testRun++
51+
runBlocking {
52+
modelClient.runWrite(branchRef) {
53+
createTestData(it)
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)