|
| 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 | +} |
0 commit comments