Skip to content

Commit

Permalink
Knotx/knotx-template-engine#20 Pebble Template Engine Integration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin.szymura authored and marcinus committed Jan 30, 2020
1 parent 1187172 commit 3045a39
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies {
implementation("io.knotx:knotx-action-http:${project.version}")
implementation("io.knotx:knotx-template-engine-core:${project.version}")
implementation("io.knotx:knotx-template-engine-handlebars:${project.version}")
implementation("io.knotx:knotx-template-engine-pebble:${project.version}")
implementation("io.netty:netty-tcnative-boringssl-static")

testImplementation("io.knotx:knotx-junit5:${project.version}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2019 Knot.x Project
*
* 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 io.knotx.stack.functional;

import io.knotx.junit5.KnotxApplyConfiguration;
import io.knotx.junit5.KnotxExtension;
import io.knotx.junit5.RandomPort;
import io.knotx.stack.KnotxServerTester;
import io.vertx.junit5.VertxTestContext;
import io.vertx.reactivex.core.Vertx;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(KnotxExtension.class)
@TestInstance(Lifecycle.PER_CLASS)
class PebbleTemplateEngineIntegrationTest {

@Test
@DisplayName("Expect page with markup processed by Pebble Template Engine")
@KnotxApplyConfiguration({"conf/application.conf",
"scenarios/pebble-template-engine/mocks.conf",
"scenarios/pebble-template-engine/tasks.conf"})
void requestPage(VertxTestContext context, Vertx vertx,
@RandomPort Integer globalServerPort) {
// when
KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort);
serverTester.testGetRequest(context, vertx,
"/content/fullPebblePage.html?parameter%20with%20space=value&q=knotx",
"results/fullPage.html");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Vert.x event bus delivery options used when communicating with other verticles
address = knotx.knot.te.pebble

engine {
factory = pebble
config = {
# Algorithm used to build a hash key of the compiled pebble templates.
# The hash is computed for the snippet pebble source code using a selected algorithm.
# The name should be a standard Java Security name (such as "SHA", "MD5", and so on).
# Default value is MD5
#
# cacheKeyAlgorithm = MD5

# Size of the compiled snippets cache. After reaching the max size, new elements will replace the oldest one.
cacheSize = 1000

syntax = {
# strictVariables = true
}
}
}

14 changes: 11 additions & 3 deletions src/functionalTest/resources/conf/knots/templateEngineStack.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
########### Template Engine Stack ###########
modules {
templateEngine = "io.knotx.te.core.TemplateEngineKnot"
hbsTemplateEngine = "io.knotx.te.core.TemplateEngineKnot"
pebbleTemplateEngine = "io.knotx.te.core.TemplateEngineKnot"
}

########### Modules configurations ###########
config.templateEngine {
config.hbsTemplateEngine {
options.config {
include required(classpath("conf/knots/templateEngineKnot.conf"))
include required(classpath("conf/knots/hbsTemplateEngineKnot.conf"))
}
}

########### Modules configurations ###########
config.pebbleTemplateEngine {
options.config {
include required(classpath("conf/knots/pebbleTemplateEngineKnot.conf"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ actions {
}
}
}
te-pebble {
factory = "knot"
config {
address = "knotx.knot.te.pebble"
deliveryOptions {
sendTimeout = 3000
}
}
}
}

taskFactories = [
Expand Down Expand Up @@ -44,4 +53,4 @@ consumerFactories = [
fragmentTypes = [ "snippet" ]
}
}
]
]
84 changes: 84 additions & 0 deletions src/functionalTest/resources/content/fullPebblePage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!--
Copyright (C) 2019 Knot.x Project
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.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="http://cognifide.com/favicon.ico?v=2"/>
<title>Knot.x</title>
<link href="https://bootswatch.com/4/simplex/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="jumbotron">
<h2>
Hello Knot.x - reactive micro-service assembler world!
</h2>
<p>
This template is served from the <strong>local</strong> repository.
</p>
<p>
<a class="btn btn-primary btn-large"
href="https://github.com/Knotx/knotx">Learn more</a>
</p>
</div>
</div>
</div>
<div class="row">
<knotx:snippet data-knotx-task="books-and-authors-listing">
<div class="col-md-4">
<h2>Book</h2>
<p>{{book._result.title}}</p>
<p>Authors: {{book._result.info.authors}}</p>
<div>Success! Status code : {{book._response.metadata.statusCode}}</div>
</div>
<div class="col-md-4">
<h2>Author</h2>
<p>{{author._result.name}}</p>
<p>Bio: {{author._result.info.bio}}</p>
<div>Success! Status code : {{author._response.metadata.statusCode}}</div>
</div>
</knotx:snippet>
</div>
<div class="row">
<div class="col-md-4">
<knotx:snippet data-knotx-task="authors-listing">
<h2>Portfolio: </h2>
<ul>
{% for this in author._result.info.portfolio %}
<li>{{this}}</li>
{% endfor %}
</ul>
</knotx:snippet>
</div>
<div class="col-md-4">
<knotx:snippet data-knotx-task="books-listing">
<h2>Tags: </h2>
<ul>
{% for this in book._result.info.tags %}
<li>{{this}}</li>
{% endfor %}
</ul>
</knotx:snippet>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
########### Knot.x JUnit5 config ###########
test.wiremock {
mockRepository.port = 0
mockService.port = 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
global.handler.fragmentsHandler.config {
tasks {
tags-listing {
action = tags
onTransitions {
_success {
action = te-pebble
}
_error {
action = tags-fallback
}
}
}
books-listing {
action = book
onTransitions {
_success {
action = te-pebble
}
}
}
authors-listing {
action = author
onTransitions {
_success {
action = te-pebble
}
}
}
books-and-authors-listing {
actions = [
{
action = book
},
{
action = author
}
]
onTransitions {
_success {
action = te-pebble
}
}
}
}

actions {
book {
factory = http
config {
endpointOptions {
path = /service/mock/book.json
domain = localhost
port = ${test.wiremock.mockService.port}
allowedRequestHeaders = ["Content-Type"]
}
}
}
author {
factory = http
config {
endpointOptions {
path = /service/mock/author.json
domain = localhost
port = ${test.wiremock.mockService.port}
allowedRequestHeaders = [ "Content-Type" ]
}
}
}
}

taskFactories = [
{
factory = default
config {
tasks = ${global.handler.fragmentsHandler.config.tasks}
nodeFactories = [
{
factory = action
config.actions = ${global.handler.fragmentsHandler.config.actions}
}
{
factory = subtasks
}
]
}
}
]
}

0 comments on commit 3045a39

Please sign in to comment.