From 6f7d1841d1aeaeec942b73b48a6ff8ad3250bd0d Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Thu, 3 Aug 2023 17:15:32 -0700 Subject: [PATCH] http (internal): Add StaticContent server test for Netty backend --- .../src/test/resources/static/index.html | 15 +++++++ .../http/netty/StaticContentTest.scala | 44 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 airframe-http-netty/src/test/resources/static/index.html create mode 100644 airframe-http-netty/src/test/scala/wvlet/airframe/http/netty/StaticContentTest.scala diff --git a/airframe-http-netty/src/test/resources/static/index.html b/airframe-http-netty/src/test/resources/static/index.html new file mode 100644 index 0000000000..ebaa0a078e --- /dev/null +++ b/airframe-http-netty/src/test/resources/static/index.html @@ -0,0 +1,15 @@ + + + diff --git a/airframe-http-netty/src/test/scala/wvlet/airframe/http/netty/StaticContentTest.scala b/airframe-http-netty/src/test/scala/wvlet/airframe/http/netty/StaticContentTest.scala new file mode 100644 index 0000000000..7246edb755 --- /dev/null +++ b/airframe-http-netty/src/test/scala/wvlet/airframe/http/netty/StaticContentTest.scala @@ -0,0 +1,44 @@ +/* + * 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 wvlet.airframe.http.netty + +import wvlet.airframe.http.client.SyncClient +import wvlet.airframe.http.{Endpoint, Http, HttpHeader, HttpMessage, RxRouter, StaticContent} +import wvlet.airspec.AirSpec + +object StaticContentTest extends AirSpec { + class StaticContentServer { + private val content: StaticContent = StaticContent.fromDirectory("./airframe-http-netty/src/test/resources/static") + + @Endpoint(path = "/*path") + def staticContent(path: String): HttpMessage.Response = { + if (path.isEmpty) { + content("index.html") + } else + content(path) + } + } + + override protected def design = { + Netty.server + .withRouter(RxRouter.of[StaticContentServer]) + .designWithSyncClient + } + + test("read index.html") { (client: SyncClient) => + val resp = client.send(Http.GET("/")) + resp.contentString shouldContain "" + resp.contentType shouldBe Some("text/html") + } +}