-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #394 from modelix/issue/MODELIX-678
MODELIX-678 model-server content explorer raises an error when trying to unfold the root node of an empty repository
- Loading branch information
Showing
2 changed files
with
90 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
model-server/src/test/kotlin/org/modelix/model/server/handlers/ContentExplorerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2024. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.modelix.model.server.handlers | ||
|
||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.post | ||
import io.ktor.serialization.kotlinx.json.json | ||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.server.resources.Resources | ||
import io.ktor.server.routing.IgnoreTrailingSlash | ||
import io.ktor.server.testing.ApplicationTestBuilder | ||
import io.ktor.server.testing.testApplication | ||
import io.ktor.server.websocket.WebSockets | ||
import org.modelix.model.client.successful | ||
import org.modelix.model.lazy.CLVersion | ||
import org.modelix.model.server.api.v2.VersionDelta | ||
import org.modelix.model.server.store.InMemoryStoreClient | ||
import org.modelix.model.server.store.LocalModelClient | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation as ClientContentNegotiation | ||
|
||
class ContentExplorerTest { | ||
|
||
private val repoId = "test-repo" | ||
private val modelClient = LocalModelClient(InMemoryStoreClient()) | ||
private val repoManager = RepositoriesManager(modelClient) | ||
|
||
private fun runTest(body: suspend (ApplicationTestBuilder.() -> Unit)) { | ||
testApplication { | ||
install(WebSockets) | ||
install(ContentNegotiation) { json() } | ||
install(Resources) | ||
install(IgnoreTrailingSlash) | ||
application { | ||
ModelReplicationServer(repoManager).init(this) | ||
ContentExplorer(modelClient, repoManager).init(this) | ||
} | ||
|
||
body() | ||
} | ||
} | ||
|
||
@Test | ||
fun `node inspector finds root node`() = runTest { | ||
val client = createClient { | ||
install(ClientContentNegotiation) { json() } | ||
} | ||
|
||
val delta: VersionDelta = client.post("/v2/repositories/$repoId/init").body() | ||
|
||
val versionHash = delta.versionHash | ||
val version = CLVersion.loadFromHash(versionHash, modelClient.storeCache) | ||
val nodeId = checkNotNull(version.getTree().root?.id) | ||
|
||
val response = client.get("/content/$versionHash/$nodeId/") | ||
assertTrue(response.successful) | ||
} | ||
} |