|
| 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.model.server.handlers |
| 18 | + |
| 19 | +import io.ktor.client.call.body |
| 20 | +import io.ktor.client.request.get |
| 21 | +import io.ktor.client.request.post |
| 22 | +import io.ktor.serialization.kotlinx.json.json |
| 23 | +import io.ktor.server.plugins.contentnegotiation.ContentNegotiation |
| 24 | +import io.ktor.server.resources.Resources |
| 25 | +import io.ktor.server.routing.IgnoreTrailingSlash |
| 26 | +import io.ktor.server.testing.ApplicationTestBuilder |
| 27 | +import io.ktor.server.testing.testApplication |
| 28 | +import io.ktor.server.websocket.WebSockets |
| 29 | +import org.modelix.model.client.successful |
| 30 | +import org.modelix.model.lazy.CLVersion |
| 31 | +import org.modelix.model.server.api.v2.VersionDelta |
| 32 | +import org.modelix.model.server.store.InMemoryStoreClient |
| 33 | +import org.modelix.model.server.store.LocalModelClient |
| 34 | +import kotlin.test.Test |
| 35 | +import kotlin.test.assertTrue |
| 36 | +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation as ClientContentNegotiation |
| 37 | + |
| 38 | +class ContentExplorerTest { |
| 39 | + |
| 40 | + private val repoId = "test-repo" |
| 41 | + private val modelClient = LocalModelClient(InMemoryStoreClient()) |
| 42 | + private val repoManager = RepositoriesManager(modelClient) |
| 43 | + |
| 44 | + private fun runTest(body: suspend (ApplicationTestBuilder.() -> Unit)) { |
| 45 | + testApplication { |
| 46 | + install(WebSockets) |
| 47 | + install(ContentNegotiation) { json() } |
| 48 | + install(Resources) |
| 49 | + install(IgnoreTrailingSlash) |
| 50 | + application { |
| 51 | + ModelReplicationServer(repoManager).init(this) |
| 52 | + ContentExplorer(modelClient, repoManager).init(this) |
| 53 | + } |
| 54 | + |
| 55 | + body() |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + fun `node inspector finds root node`() = runTest { |
| 61 | + val client = createClient { |
| 62 | + install(ClientContentNegotiation) { json() } |
| 63 | + } |
| 64 | + |
| 65 | + val delta: VersionDelta = client.post("/v2/repositories/$repoId/init").body() |
| 66 | + |
| 67 | + val versionHash = delta.versionHash |
| 68 | + val version = CLVersion.loadFromHash(versionHash, modelClient.storeCache) |
| 69 | + val nodeId = checkNotNull(version.getTree().root?.id) |
| 70 | + |
| 71 | + val response = client.get("/content/$versionHash/$nodeId/") |
| 72 | + assertTrue(response.successful) |
| 73 | + } |
| 74 | +} |
0 commit comments