Skip to content

Commit

Permalink
Merge pull request #716 from hexagontk/develop
Browse files Browse the repository at this point in the history
Update CI
  • Loading branch information
jaguililla committed Aug 21, 2024
2 parents 9fcad79 + 7cde87b commit 96beb6e
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

on:
push:
branches-ignore: [ master ]
branches-ignore: [ master, release/** ]

permissions:
contents: read
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
run: |
export REMOTE="https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.git"
git remote set-url origin "$REMOTE"
git clone "$REMOTE" --branch gh-pages build/gh-pages
./gradlew build
./gradlew -x build buildSite
ls -AlF site/build/site
Expand All @@ -43,10 +42,3 @@ jobs:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew --no-daemon -x test release

- run: |
cp -rf site/build/site/* build/gh-pages/
cd build/gh-pages
git add --all
git commit -m "Publishing to gh-pages"
git push origin gh-pages
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.warning.mode=all
org.gradle.console=plain

# Gradle
version=3.6.3
version=3.6.4
group=com.hexagonkt
description=The atoms of your platform

Expand Down
6 changes: 2 additions & 4 deletions http/http_server/api/http_server.api
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ public final class com/hexagonkt/http/server/callbacks/UrlCallback : kotlin/jvm/
}

public final class com/hexagonkt/http/server/handlers/CorsHandler : com/hexagonkt/http/handlers/HttpHandler {
public fun <init> ()V
public fun <init> (Lcom/hexagonkt/http/server/callbacks/CorsCallback;)V
public fun <init> (Ljava/lang/String;Lcom/hexagonkt/http/server/callbacks/CorsCallback;)V
public synthetic fun <init> (Ljava/lang/String;Lcom/hexagonkt/http/server/callbacks/CorsCallback;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lkotlin/text/Regex;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;ZLcom/hexagonkt/http/model/HttpStatus;J)V
public synthetic fun <init> (Ljava/lang/String;Lkotlin/text/Regex;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;ZLcom/hexagonkt/http/model/HttpStatus;JILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;ZLcom/hexagonkt/http/model/HttpStatus;J)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;ZLcom/hexagonkt/http/model/HttpStatus;JILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun addPrefix (Ljava/lang/String;)Lcom/hexagonkt/http/handlers/HttpHandler;
public fun byMethod ()Ljava/util/Map;
public fun filter (Lcom/hexagonkt/http/model/HttpMethod;)Lcom/hexagonkt/http/handlers/HttpHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import com.hexagonkt.http.model.HttpStatus
import com.hexagonkt.http.model.NO_CONTENT_204
import com.hexagonkt.http.server.callbacks.CorsCallback

// TODO Write tests
class CorsHandler(pattern: String = "*", cors: CorsCallback = CorsCallback()) :
class CorsHandler(pattern: String, cors: CorsCallback) :
HttpHandler by FilterHandler(HttpPredicate(pattern = pattern), cors) {

constructor(cors: CorsCallback) : this("*", cors)

constructor(
pattern: String = "*",
allowedOrigin: Regex,
allowedOrigin: String = "*",
allowedMethods: Set<HttpMethod> = ALL,
allowedHeaders: Set<String> = emptySet(),
exposedHeaders: Set<String> = emptySet(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,18 @@ class HelidonServerAdapter(
setOf(ZIP)

override fun options(): Map<String, *> =
fieldsMapOf<HelidonServerAdapter>()
fieldsMapOf(
HelidonServerAdapter::backlog to backlog,
HelidonServerAdapter::writeQueueLength to writeQueueLength,
HelidonServerAdapter::readTimeout to readTimeout,
HelidonServerAdapter::connectTimeout to connectTimeout,
HelidonServerAdapter::tcpNoDelay to tcpNoDelay,
HelidonServerAdapter::receiveLog to receiveLog,
HelidonServerAdapter::sendLog to sendLog,
HelidonServerAdapter::validatePath to validatePath,
HelidonServerAdapter::validateRequestHeaders to validateRequestHeaders,
HelidonServerAdapter::validateResponseHeaders to validateResponseHeaders,
)

private fun setResponse(
secureRequest: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import com.hexagonkt.http.model.HttpMethod.POST
import com.hexagonkt.http.model.NO_CONTENT_204
import com.hexagonkt.http.model.OK_200
import com.hexagonkt.http.server.*
import com.hexagonkt.http.server.callbacks.CorsCallback
import com.hexagonkt.http.handlers.HandlerBuilder
import com.hexagonkt.http.handlers.PathHandler
import com.hexagonkt.http.handlers.HttpHandler
import com.hexagonkt.http.handlers.path
import com.hexagonkt.http.server.callbacks.CorsCallback
import com.hexagonkt.http.server.handlers.CorsHandler
import com.hexagonkt.http.test.BaseTest
import org.junit.jupiter.api.Test
Expand All @@ -28,19 +28,19 @@ abstract class CorsTest(

// cors
val path: PathHandler = path {
corsPath("/default", CorsCallback())
corsPath("/example/org", CorsCallback("example.org"))
corsPath("/no/credentials", CorsCallback(supportCredentials = false))
corsPath("/only/post", CorsCallback(allowedMethods = setOf(POST)))
corsPath("/cache", CorsCallback(preFlightMaxAge = 10))
corsPath("/exposed/headers", CorsCallback(exposedHeaders = setOf("head")))
corsPath("/allowed/headers", CorsCallback(allowedHeaders = setOf("head")))
corsPath("/default", CorsHandler(CorsCallback()))
corsPath("/example/org", CorsHandler(allowedOrigin = "example.org"))
corsPath("/no/credentials", CorsHandler(supportCredentials = false))
corsPath("/only/post", CorsHandler(allowedMethods = setOf(POST)))
corsPath("/cache", CorsHandler(preFlightMaxAge = 10))
corsPath("/exposed/headers", CorsHandler(exposedHeaders = setOf("head")))
corsPath("/allowed/headers", CorsHandler(allowedHeaders = setOf("head")))
}

private fun HandlerBuilder.corsPath(path: String, cors: CorsCallback) {
private fun HandlerBuilder.corsPath(path: String, cors: CorsHandler) {
path(path) {
// CORS settings can change for different routes
use(CorsHandler(cors))
use(cors)

get("/path") { ok(method.toString()) }
post("/path") { ok(method.toString()) }
Expand Down
4 changes: 4 additions & 0 deletions http/rest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ dependencies {

"testImplementation"(project(":http:http_client_jetty"))
"testImplementation"(project(":http:http_server_jetty"))
"testImplementation"(project(":serialization:serialization_jackson_csv"))
"testImplementation"(project(":serialization:serialization_jackson_json"))
"testImplementation"(project(":serialization:serialization_jackson_toml"))
"testImplementation"(project(":serialization:serialization_jackson_xml"))
"testImplementation"(project(":serialization:serialization_jackson_yaml"))
"testImplementation"("org.slf4j:log4j-over-slf4j:$slf4jVersion")
"testImplementation"("org.slf4j:jcl-over-slf4j:$slf4jVersion")
"testImplementation"("org.slf4j:slf4j-jdk14:$slf4jVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.hexagonkt.http.handlers.HttpContext
import com.hexagonkt.serialization.SerializationManager
import com.hexagonkt.serialization.serialize

// TODO Create SerializeRequestHandler like CorsHandler
class SerializeRequestCallback : HttpCallback {

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.hexagonkt.http.handlers.HttpContext
import com.hexagonkt.serialization.SerializationManager
import com.hexagonkt.serialization.serialize

// TODO Create SerializeResponseHandler like CorsHandler
class SerializeResponseCallback: HttpCallback {

init {
Expand Down
58 changes: 46 additions & 12 deletions http/rest/src/test/kotlin/com/hexagonkt/rest/RestTest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.hexagonkt.rest

import com.hexagonkt.core.media.APPLICATION_JSON
import com.hexagonkt.core.media.APPLICATION_TOML
import com.hexagonkt.core.media.APPLICATION_XML
import com.hexagonkt.core.media.APPLICATION_YAML
import com.hexagonkt.core.media.TEXT_CSV
import com.hexagonkt.core.requireInt
import com.hexagonkt.http.model.HttpResponse
import com.hexagonkt.http.model.ContentType
import com.hexagonkt.http.model.HttpRequest
import com.hexagonkt.serialization.SerializationManager
import com.hexagonkt.serialization.jackson.csv.Csv
import com.hexagonkt.serialization.jackson.json.Json
import com.hexagonkt.serialization.jackson.toml.Toml
import com.hexagonkt.serialization.jackson.xml.Xml
import com.hexagonkt.serialization.jackson.yaml.Yaml
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
Expand All @@ -30,10 +37,8 @@ internal class RestTest {
)
}

private val json: ContentType = ContentType(APPLICATION_JSON)

@BeforeAll fun setUp() {
SerializationManager.formats = setOf(Json)
SerializationManager.formats = setOf(Json, Yaml, Xml, Toml, Csv)
}

@Test fun `Media type is calculated properly`() {
Expand All @@ -48,47 +53,76 @@ internal class RestTest {
}

@Test fun `Body is parsed to list`() {
HttpRequest(body = """[ "a", "b", "c" ]""", contentType = json).apply {
HttpRequest(body = """[ "a", "b", "c" ]""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(listOf("a", "b", "c"), bodyList())
}
HttpResponse(body = """[ "a", "b", "c" ]""", contentType = json).apply {
HttpResponse(body = """[ "a", "b", "c" ]""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(listOf("a", "b", "c"), bodyList())
}
}

@Test fun `Body is parsed to map`() {
HttpRequest(body = """{ "a" : 0, "b" : 1, "c" : 2 }""", contentType = json).apply {
HttpRequest(body = """{"a":0,"b":1,"c":2}""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(mapOf("a" to 0, "b" to 1, "c" to 2), bodyMap())
}
HttpResponse(body = """{ "a" : 0, "b" : 1, "c" : 2 }""", contentType = json).apply {
HttpResponse(body = """{"a":0,"b":1,"c":2}""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(mapOf("a" to 0, "b" to 1, "c" to 2), bodyMap())
}
}

@Test fun `Body is parsed to objects`() {
HttpRequest(body = """{ "a" : 0, "b" : 1, "c" : 2 }""", contentType = json).apply {
HttpRequest(body = """{"a":0,"b":1,"c":2}""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(Record(mapOf("a" to 0, "b" to 1, "c" to 2)), bodyObject(::Record))
}
HttpResponse(body = """{ "a" : 0, "b" : 1, "c" : 2 }""", contentType = json).apply {
HttpResponse(body = """{"a":0,"b":1,"c":2}""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(Record(mapOf("a" to 0, "b" to 1, "c" to 2)), bodyObject(::Record))
}
HttpRequest(body = """[ { "a" : 0, "b" : 1, "c" : 2 } ]""", contentType = json).apply {
HttpRequest(body = """[{"a":0,"b":1,"c":2}]""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(listOf(Record(0, 1, 2)), bodyObjects(::Record))
}
HttpResponse(body = """[ { "a" : 0, "b" : 1, "c" : 2 } ]""", contentType = json).apply {
HttpResponse(body = """[{"a":0,"b":1,"c":2}]""", contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
assertEquals(listOf(Record(0, 1, 2)), bodyObjects(::Record))
}
}

// TODO Test serialization with predefined content types
@Test fun `Body is serialized`() {
val body1 = mapOf("a" to 0, "b" to 1, "c" to 2)
HttpResponse(body = body1, contentType = jsonContentType).apply {
assertEquals(APPLICATION_JSON, mediaType())
val textBody = serializeBody().toString().replace(Regex("(\\s|\\n)*"), "")
assertEquals("""{"a":0,"b":1,"c":2}""", textBody)
}
val body2 = mapOf("a" to 3, "b" to 4, "c" to 5)
HttpResponse(body = body2, contentType = yamlContentType).apply {
assertEquals(APPLICATION_YAML, mediaType())
val textBody = serializeBody().toString().replace(Regex("(\\s|\\n)*"), "")
assertEquals("""a:3b:4c:5""", textBody)
}
val body3 = mapOf("a" to 6, "b" to 7, "c" to 8)
HttpResponse(body = body3, contentType = xmlContentType).apply {
assertEquals(APPLICATION_XML, mediaType())
val textBody = serializeBody().toString().replace(Regex("(\\s|\\n)*"), "")
assertEquals("""<LinkedHashMap><a>6</a><b>7</b><c>8</c></LinkedHashMap>""", textBody)
}
val body4 = mapOf("a" to 9, "b" to 10, "c" to 11)
HttpResponse(body = body4, contentType = tomlContentType).apply {
assertEquals(APPLICATION_TOML, mediaType())
val textBody = serializeBody().toString().replace(Regex("(\\s|\\n)*"), "")
assertEquals("""a=9b=10c=11""", textBody)
}
val body5 = listOf(12, 13, 14)
HttpResponse(body = body5, contentType = csvContentType).apply {
assertEquals(TEXT_CSV, mediaType())
val textBody = serializeBody().toString().replace(Regex("(\\s|\\n)*"), "")
assertEquals("""12,13,14""", textBody)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class HttpClientTool(
val followRedirects: Boolean = false
) {
companion object {
// TODO Use SerializeRequestHandler when created
val serializeHandler: HttpHandler = BeforeHandler("*", SerializeRequestCallback())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class HttpServerTool(

private val server: HttpServer by lazy {
HttpServer(adapter, settings) {
// TODO Use SerializeResponseHandler when created
after("*", SerializeResponseCallback())
after(pattern = "*", status = NOT_FOUND_404) {
send(response = this@HttpServerTool.path.process(request).response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.hexagonkt.rest.tools

import com.hexagonkt.core.media.TEXT_PLAIN
import com.hexagonkt.http.client.jetty.JettyClientAdapter
import com.hexagonkt.http.model.ContentType
import com.hexagonkt.http.model.HttpMethod.POST
import com.hexagonkt.http.model.HttpMethod.PUT
import com.hexagonkt.http.model.HttpResponsePort
import com.hexagonkt.http.model.OK_200
import com.hexagonkt.http.server.jetty.JettyServletAdapter
import com.hexagonkt.rest.textContentType
import com.hexagonkt.serialization.SerializationManager
import com.hexagonkt.serialization.jackson.json.Json
import org.junit.jupiter.api.AfterAll
Expand All @@ -21,7 +21,7 @@ import kotlin.test.assertTrue
@TestInstance(PER_CLASS)
internal class HttpClientToolTest {
private val server: HttpServerTool = HttpServerTool(JettyServletAdapter())
private val text = ContentType(TEXT_PLAIN)
private val text = textContentType

@BeforeAll fun `Set up mock services`() {
SerializationManager.formats = setOf(Json)
Expand Down
Loading

0 comments on commit 96beb6e

Please sign in to comment.