From 58219d717c51c9802f6f896492b38984f8ae9860 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Mon, 23 May 2016 16:11:25 -0400 Subject: [PATCH] lib/popcorn: add example and test for default_file Signed-off-by: Alexandre Terrasa --- .../static_files/example_static_default.nit | 21 +++++ .../examples/static_files/public/default.html | 13 +++ .../tests/res/test_example_static_default.res | 88 ++++++++++++++++++++ lib/popcorn/tests/test_example_static_default.nit | 52 ++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 lib/popcorn/examples/static_files/example_static_default.nit create mode 100644 lib/popcorn/examples/static_files/public/default.html create mode 100644 lib/popcorn/tests/res/test_example_static_default.res create mode 100644 lib/popcorn/tests/test_example_static_default.nit diff --git a/lib/popcorn/examples/static_files/example_static_default.nit b/lib/popcorn/examples/static_files/example_static_default.nit new file mode 100644 index 0000000..6aa5b34 --- /dev/null +++ b/lib/popcorn/examples/static_files/example_static_default.nit @@ -0,0 +1,21 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2016 Alexandre Terrasa +# +# 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. + +import popcorn + +var app = new App +app.use("/", new StaticHandler("public/", "default.html")) +app.listen("localhost", 3000) diff --git a/lib/popcorn/examples/static_files/public/default.html b/lib/popcorn/examples/static_files/public/default.html new file mode 100644 index 0000000..2abb789 --- /dev/null +++ b/lib/popcorn/examples/static_files/public/default.html @@ -0,0 +1,13 @@ + + + + + + Some Popcorn love + + + + +

Default Page

+ + diff --git a/lib/popcorn/tests/res/test_example_static_default.res b/lib/popcorn/tests/res/test_example_static_default.res new file mode 100644 index 0000000..59392f6 --- /dev/null +++ b/lib/popcorn/tests/res/test_example_static_default.res @@ -0,0 +1,88 @@ + +[Client] curl -s localhost:*****/css/style.css +body { + color: blue; + padding: 20px; +} + +[Client] curl -s localhost:*****/js/app.js +alert("Hello World!"); + +[Client] curl -s localhost:*****/hello.html + + + + + + Some Popcorn love + + + + +

Hello Popcorn!

+ + maybe it's a kitten? + + + + + +[Client] curl -s localhost:*****/ + + + + + + Some Popcorn love + + + + +

Default Page

+ + + +[Client] curl -s localhost:*****/css/not_found.nit + + + + + + Some Popcorn love + + + + +

Default Page

+ + + +[Client] curl -s localhost:*****/static/css/not_found.nit + + + + + + Some Popcorn love + + + + +

Default Page

+ + + +[Client] curl -s localhost:*****/not_found.nit + + + + + + Some Popcorn love + + + + +

Default Page

+ + diff --git a/lib/popcorn/tests/test_example_static_default.nit b/lib/popcorn/tests/test_example_static_default.nit new file mode 100644 index 0000000..ced04e2 --- /dev/null +++ b/lib/popcorn/tests/test_example_static_default.nit @@ -0,0 +1,52 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2016 Alexandre Terrasa +# +# 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. + +import base_tests +import example_static_default + +class TestClient + super ClientThread + + redef fun main do + system "curl -s {host}:{port}/css/style.css" + system "curl -s {host}:{port}/js/app.js" + system "curl -s {host}:{port}/hello.html" + system "curl -s {host}:{port}/" + + system "curl -s {host}:{port}/css/not_found.nit" + system "curl -s {host}:{port}/static/css/not_found.nit" + system "curl -s {host}:{port}/not_found.nit" + + return null + end +end + +var app = new App +app.use("/", new StaticHandler("../examples/static_files/public/", "default.html")) + +var host = test_host +var port = test_port + +var server = new AppThread(host, port, app) +server.start +0.1.sleep + +var client = new TestClient(host, port) +client.start +client.join +0.1.sleep + +exit 0 -- 1.7.9.5