Skip to content

Commit

Permalink
Merge pull request #873 from modelix/test/migrate-cucumber-to-ktor
Browse files Browse the repository at this point in the history
MODELIX-721 Migrate cucumber tests for model-server to ktor tests
  • Loading branch information
mhuster23 authored Jul 4, 2024
2 parents 601ef68 + c473039 commit 3725bfc
Show file tree
Hide file tree
Showing 15 changed files with 575 additions and 659 deletions.
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ ignite-indexing = { group = "org.apache.ignite", name = "ignite-indexing", versi
logback-classic = { group = "ch.qos.logback", name = "logback-classic", version = "1.5.6" }
postgresql = { group = "org.postgresql", name = "postgresql", version = "42.7.3" }
jcommander = { group = "com.beust", name = "jcommander", version = "1.82" }
cucumber-java = { group = "io.cucumber", name = "cucumber-java", version = "7.18.0" }
junit = { group = "junit", name = "junit", version = "4.13.2" }
xmlunit-core = { group = "org.xmlunit", name = "xmlunit-core", version.ref="xmlunit"}
xmlunit-matchers = { group = "org.xmlunit", name = "xmlunit-matchers", version.ref="xmlunit"}
Expand Down
28 changes: 0 additions & 28 deletions model-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.kotest.assertions.coreJvm)
testImplementation(libs.kotest.assertions.ktor)
testImplementation(libs.cucumber.java)
testImplementation(libs.ktor.server.test.host)
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.jsoup)
Expand All @@ -84,10 +83,6 @@ tasks.test {
useJUnitPlatform()
}

val cucumberRuntime by configurations.creating {
extendsFrom(configurations["testImplementation"])
}

tasks.named<ShadowJar>("shadowJar") {
archiveBaseName.set("model-server")
archiveClassifier.set("fatJar")
Expand All @@ -113,28 +108,6 @@ val fatJarArtifact = artifacts.add("archives", fatJarFile) {
builtBy("shadowJar")
}

val cucumber = task("cucumber") {
dependsOn("shadowJar", "compileTestJava")
doLast {
javaexec {
mainClass.set("io.cucumber.core.cli.Main")
classpath = cucumberRuntime + sourceSets.main.get().output + sourceSets.test.get().output
args = listOf(
"--plugin",
"pretty",
// Enable junit reporting so that GitHub actions can report on these tests, too
"--plugin",
"junit:${project.layout.buildDirectory.dir("test-results/cucumber.xml").get()}",
// Change glue for your project package where the step definitions are.
"--glue",
"org.modelix.model.server.functionaltests",
// Specify where the feature files are.
"src/test/resources/functionaltests",
)
}
}
}

// copies the openAPI specifications from the api folder into a resource
// folder so that they are packaged and deployed with the model-server
tasks.register<Copy>("copyApis") {
Expand All @@ -149,7 +122,6 @@ tasks.named("compileKotlin") {
}

tasks.named("build") {
dependsOn("cucumber")
dependsOn("copyApis")
}

Expand Down
56 changes: 4 additions & 52 deletions model-server/src/main/kotlin/org/modelix/model/server/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.engine.embeddedServer
import io.ktor.server.html.respondHtmlTemplate
import io.ktor.server.http.content.staticResources
import io.ktor.server.netty.Netty
import io.ktor.server.netty.NettyApplicationEngine
Expand All @@ -44,12 +43,6 @@ import io.ktor.server.routing.routing
import io.ktor.server.websocket.WebSockets
import io.ktor.server.websocket.pingPeriod
import io.ktor.server.websocket.timeout
import kotlinx.html.a
import kotlinx.html.h1
import kotlinx.html.li
import kotlinx.html.style
import kotlinx.html.ul
import kotlinx.html.unsafe
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.apache.commons.io.FileUtils
Expand All @@ -71,6 +64,7 @@ import org.modelix.model.server.handlers.ModelReplicationServer
import org.modelix.model.server.handlers.RepositoriesManager
import org.modelix.model.server.handlers.ui.ContentExplorer
import org.modelix.model.server.handlers.ui.HistoryHandler
import org.modelix.model.server.handlers.ui.IndexPage
import org.modelix.model.server.handlers.ui.RepositoryOverview
import org.modelix.model.server.store.IgniteStoreClient
import org.modelix.model.server.store.InMemoryStoreClient
Expand All @@ -80,7 +74,6 @@ import org.modelix.model.server.store.forContextRepository
import org.modelix.model.server.store.forGlobalRepository
import org.modelix.model.server.store.loadDump
import org.modelix.model.server.store.writeDump
import org.modelix.model.server.templates.PageWithMenuBar
import org.slf4j.LoggerFactory
import org.springframework.util.ResourceUtils
import java.io.File
Expand Down Expand Up @@ -217,61 +210,20 @@ object Main {
installStatusPages()

modelServer.init(this)
IndexPage().init(this)
historyHandler.init(this)
repositoryOverview.init(this)
contentExplorer.init(this)
jsonModelServer.init(this)
modelReplicationServer.init(this)
metricsApi.init(this)
IdsApiImpl(repositoriesManager, localModelClient).init(this)

routing {
HealthApiImpl(repositoriesManager, globalStoreClient, inMemoryModels).installRoutes(this)

staticResources("/public", "public")
get("/") {
call.respondHtmlTemplate(PageWithMenuBar("root", ".")) {
headContent {
style {
unsafe {
raw(
"""
body {
font-family: sans-serif;
table {
border-collapse: collapse;
}
td, th {
border: 1px solid #888;
padding: 3px 12px;
}
""".trimIndent(),
)
}
}
}
bodyContent {
h1 { +"Model Server" }
ul {
li {
a("repos/") { +"View Repositories on the Model Server" }
}
li {
a("json/") { +"JSON API for JavaScript clients" }
}
li {
a("headers") { +"View HTTP headers" }
}
li {
a("user") { +"View JWT token and permissions" }
}
li {
a("swagger") { +"SwaggerUI" }
}
}
}
}
call.respondText("Model Server")
}

if (cmdLineArgs.noSwaggerUi) {
get("swagger") {
call.respondText("SwaggerUI is disabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ class HealthApiImpl(
}

companion object {
private const val HEALTH_KEY = PROTECTED_PREFIX + "health2"
internal const val HEALTH_KEY = PROTECTED_PREFIX + "health2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.ui

import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.html.respondHtmlTemplate
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
import kotlinx.html.a
import kotlinx.html.h1
import kotlinx.html.li
import kotlinx.html.style
import kotlinx.html.ul
import kotlinx.html.unsafe
import org.modelix.model.server.templates.PageWithMenuBar

/**
* Landing page of the model-server with links to other pages.
*/
class IndexPage {

fun init(application: Application) {
application.routing {
get("/") {
call.respondHtmlTemplate(PageWithMenuBar("root", ".")) {
headContent {
style {
unsafe {
raw(
"""
body {
font-family: sans-serif;
table {
border-collapse: collapse;
}
td, th {
border: 1px solid #888;
padding: 3px 12px;
}
""".trimIndent(),
)
}
}
}
bodyContent {
h1 { +"Model Server" }
ul {
li {
a("repos/") { +"View Repositories on the Model Server" }
}
li {
a("json/") { +"JSON API for JavaScript clients" }
}
li {
a("headers") { +"View HTTP headers" }
}
li {
a("user") { +"View JWT token and permissions" }
}
li {
a("swagger") { +"SwaggerUI" }
}
}
}
}
}
}
}
}
Loading

0 comments on commit 3725bfc

Please sign in to comment.