From f92f93fee69b9c05b16d222fa9a1fe9005a1e2a2 Mon Sep 17 00:00:00 2001 From: Voycawojka Date: Tue, 14 Jul 2020 09:51:11 +0200 Subject: [PATCH 1/4] #146 Adjust tests for transitions alias --- .github/PULL_REQUEST_TEMPLATE.md | 58 +-- CODE_OF_CONDUCT.md | 2 +- CONTRIBUTING.md | 2 +- conf/application.conf | 11 + conf/knots/hbsTemplateEngineKnot.conf | 26 ++ conf/knots/pebbleTemplateEngineKnot.conf | 22 ++ conf/knots/templateEngineStack.conf | 19 + conf/routes/handlers/fragmentsHandler.conf | 56 +++ .../handlers/httpRepoConnectorHandler.conf | 62 ++++ conf/routes/te-get.conf | 21 ++ conf/routes/web-api-get.conf | 23 ++ conf/server.conf | 101 ++++++ conf/tasks/task-with-fallback-action.conf | 89 +++++ .../knotx-fragments-debug-data/mocks.conf | 8 + .../knotx-fragments-debug-data/pebble.conf | 1 + .../knotx-fragments-debug-data/tasks.conf | 211 +++++++++++ ...BreakerTimesOutAndRetriesScenarioTest.java | 174 ++++----- ...pServicesWithFallbacksIntegrationTest.java | 146 ++++---- ...viceWithCircuitBreakerIntegrationTest.java | 160 ++++----- .../PebbleTemplateEngineIntegrationTest.java | 96 ++--- ...yConnectorRedirectPassedToEndUserTest.java | 194 +++++----- .../TemplateEnginesIntegrationTest.java | 90 ++--- .../resources/common/api/fragments.conf | 12 +- .../resources/common/api/routing.conf | 46 +-- .../common/templating/fragments.conf | 42 +-- .../resources/common/templating/routing.conf | 56 +-- .../routes/handlers/fragmentsHandler.conf | 86 ++--- .../handlers/httpRepoConnectorHandler.conf | 120 +++---- src/functionalTest/resources/conf/server.conf | 206 +++++------ .../conf/tasks/task-with-fallback-action.conf | 6 +- .../resources/content/failedFragment.html | 58 +-- src/functionalTest/resources/openapi.yaml | 84 ++--- .../mocks.conf | 14 +- .../tasks.conf | 126 +++---- .../circuit-breaker-times-out/mocks.conf | 14 +- .../circuit-breaker-times-out/tasks.conf | 146 ++++---- .../mocks.conf | 16 +- .../tasks.conf | 98 ++--- .../failed-knotx-fragment/mocks.conf | 14 +- .../failed-knotx-fragment/tasks.conf | 50 +-- .../mocks.conf | 8 +- .../tasks.conf | 228 ++++++------ .../fragments-debug-data/debugHtml.conf | 24 +- .../fragments-debug-data/debugJson.conf | 26 +- .../scenarios/fragments-debug-data/tasks.conf | 336 +++++++++--------- .../mocks.conf | 6 +- .../tasks.conf | 134 +++---- .../mocks.conf | 14 +- .../tasks.conf | 196 +++++----- .../pebble-template-engine/mocks.conf | 6 +- .../pebble-template-engine/tasks.conf | 142 ++++---- .../httpRepoConnectorHandler.conf | 62 ++-- .../mocks.conf | 6 +- .../template-engines-integration/mocks.conf | 6 +- .../template-engines-integration/tasks.conf | 118 +++--- .../mocks.conf | 14 +- .../tasks.conf | 226 ++++++------ src/main/packaging/conf/server.conf | 190 +++++----- .../io/knotx/stack/KnotxServerTester.java | 194 +++++----- 59 files changed, 2676 insertions(+), 2026 deletions(-) create mode 100644 conf/application.conf create mode 100644 conf/knots/hbsTemplateEngineKnot.conf create mode 100644 conf/knots/pebbleTemplateEngineKnot.conf create mode 100644 conf/knots/templateEngineStack.conf create mode 100644 conf/routes/handlers/fragmentsHandler.conf create mode 100644 conf/routes/handlers/httpRepoConnectorHandler.conf create mode 100644 conf/routes/te-get.conf create mode 100644 conf/routes/web-api-get.conf create mode 100644 conf/server.conf create mode 100644 conf/tasks/task-with-fallback-action.conf create mode 100644 scenarios/knotx-fragments-debug-data/mocks.conf create mode 100644 scenarios/knotx-fragments-debug-data/pebble.conf create mode 100644 scenarios/knotx-fragments-debug-data/tasks.conf diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 1e941626..be16ddd2 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,29 +1,29 @@ - - -## Description - - -## Motivation and Context - - - -## Screenshots (if appropriate) - -## Upgrade notes (if appropriate) - - -## Types of changes - -- [ ] Bug fix (non-breaking change which fixes an issue) -- [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - -## Checklist: - - -- [ ] I have read the [CONTRIBUTING](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md) document. -- [ ] My change requires a change to the documentation. -- [ ] I have updated the documentation accordingly. - ---- -I hereby agree to the terms of the Knot.x Contributor License Agreement. + + +## Description + + +## Motivation and Context + + + +## Screenshots (if appropriate) + +## Upgrade notes (if appropriate) + + +## Types of changes + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) + +## Checklist: + + +- [ ] I have read the [CONTRIBUTING](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md) document. +- [ ] My change requires a change to the documentation. +- [ ] I have updated the documentation accordingly. + +--- +I hereby agree to the terms of the Knot.x Contributor License Agreement. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b7c9bebc..936a18e2 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1 +1 @@ -Please refer to the main [Knot.x Code of Conduct](https://github.com/Knotx/knotx/blob/master/CODE_OF_CONDUCT.md). +Please refer to the main [Knot.x Code of Conduct](https://github.com/Knotx/knotx/blob/master/CODE_OF_CONDUCT.md). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e85eef88..0ca7425f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1 +1 @@ -Please refer to the main [Knot.x contributing guide](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md). +Please refer to the main [Knot.x contributing guide](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md). diff --git a/conf/application.conf b/conf/application.conf new file mode 100644 index 00000000..f080eeb6 --- /dev/null +++ b/conf/application.conf @@ -0,0 +1,11 @@ +########### Modules to start ########### +# Modules map specify a list of verticles to be started by Knot.x. +# Each line should have a form of = +# where alias is just a name that you can use later in order to define configuration for the module +# verticle-class-name is a fully qualified class name of the verticle. +# +# This JSON object is filled in included files. +modules {} + +include required(classpath("conf/server.conf")) +include required(classpath("conf/knots/templateEngineStack.conf")) diff --git a/conf/knots/hbsTemplateEngineKnot.conf b/conf/knots/hbsTemplateEngineKnot.conf new file mode 100644 index 00000000..c8624e70 --- /dev/null +++ b/conf/knots/hbsTemplateEngineKnot.conf @@ -0,0 +1,26 @@ +# Vert.x event bus delivery options used when communicating with other verticles +address = knotx.knot.te.handlebars + +engine { + factory = handlebars + config = { + # Algorithm used to build a hash key of the compiled handlebars snippets. + # The hash is computed for the snippet handlebars 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 + + # Symbol used as a start delimiter of handlebars expression. If not use, a default '{{' is used + # + # startDelimiter = + + # Symbol used as a end delimiter of handlebars expression. If not use, a default '}}' is used + # + # endDelimiter = + } +} + diff --git a/conf/knots/pebbleTemplateEngineKnot.conf b/conf/knots/pebbleTemplateEngineKnot.conf new file mode 100644 index 00000000..440660a6 --- /dev/null +++ b/conf/knots/pebbleTemplateEngineKnot.conf @@ -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 + } + } +} + diff --git a/conf/knots/templateEngineStack.conf b/conf/knots/templateEngineStack.conf new file mode 100644 index 00000000..78a74314 --- /dev/null +++ b/conf/knots/templateEngineStack.conf @@ -0,0 +1,19 @@ +########### Template Engine Stack ########### +modules { + hbsTemplateEngine = "io.knotx.te.core.TemplateEngineKnot" + pebbleTemplateEngine = "io.knotx.te.core.TemplateEngineKnot" +} + +########### Modules configurations ########### +config.hbsTemplateEngine { + options.config { + include required(classpath("conf/knots/hbsTemplateEngineKnot.conf")) + } +} + +########### Modules configurations ########### +config.pebbleTemplateEngine { + options.config { + include required(classpath("conf/knots/pebbleTemplateEngineKnot.conf")) + } +} diff --git a/conf/routes/handlers/fragmentsHandler.conf b/conf/routes/handlers/fragmentsHandler.conf new file mode 100644 index 00000000..b8c5464b --- /dev/null +++ b/conf/routes/handlers/fragmentsHandler.conf @@ -0,0 +1,56 @@ +########### This configuration is overloaded in integration tests! ########### +tasks { + # will be extended per unit tests +} + +actions { + # will be extended per unit tests + te-hbs { + factory = knot + config { + address = knotx.knot.te.handlebars + deliveryOptions { + sendTimeout = 3000 + } + } + } + te-pebble { + factory = knot + config { + address = knotx.knot.te.pebble + deliveryOptions { + sendTimeout = 3000 + } + } + } +} + +taskFactories = [ + { + factory = default + config { + tasks = ${global.handler.fragmentsHandler.config.tasks} + nodeFactories = [ + { + factory = action + config.actions = ${global.handler.fragmentsHandler.config.actions} + } + { + factory = subtasks + } + ] + } + } +] + +consumerFactories = [ + { + factory = fragmentHtmlBodyWriter + config { + condition { + param = debug + } + fragmentTypes = [ "snippet" ] + } + } +] diff --git a/conf/routes/handlers/httpRepoConnectorHandler.conf b/conf/routes/handlers/httpRepoConnectorHandler.conf new file mode 100644 index 00000000..b1791c19 --- /dev/null +++ b/conf/routes/handlers/httpRepoConnectorHandler.conf @@ -0,0 +1,62 @@ +# Vert.x event bus delivery options used when communicating with other verticles +# see http://vertx.io/docs/vertx-core/dataobjects.html#HttpClientOptions for the details what can be configured +# +clientOptions { + maxPoolSize = 1000 + idleTimeout = 120 # seconds + tryUseCompression = true + + # If you're going to use SSL (clientDestination.scheme='https') then here you'd need to configure + # some aspects related to the SSL negotiation and validation. + # + # Whether all server certificated should be trusted or not (e.g. self-signed certificates) + # trustAll = true + # + # Hostname verification + # verifyHost = false + # + # It will force SSL SNI (Server Name Indication). The SNI will be set to the same value as 'hostHeader' (set in ClientDestination) + # forceSni = true +} + +# HTTP Repository connection details +clientDestination { + # Connection scheme: http or https + scheme = http + + # domain or the IP of the host: e.g. localhost, 10.0.11.2 + domain = localhost + + ## Port on which the host listens, e.g. 8080, 3001, etc. + port = ${test.wiremock.mockRepository.port} + + # Host header override to be used with a communication to the repository. If it's set, it overrides any value in the 'Host' header, and sets the SNI SSL to the same value. + # hostHeader = +} + +# List of allowed request headers that will be send to HTTP repository. +# Each item is a string that defines regex, e.g. to match any char use `.*` +# +allowedRequestHeaders = [ + Host + "Accept.*" + Authorization + Connection + Cookie + Date + "Edge.*" + "If.*" + Origin + Pragma + Proxy-Authorization + "Surrogate.*" + User-Agent + Via + "X-.*" +] + +# Statically defined HTTP request header sent in every request to the repository +customHttpHeader = { + name = X-User-Agent + value = Knot.x +} diff --git a/conf/routes/te-get.conf b/conf/routes/te-get.conf new file mode 100644 index 00000000..21496d8d --- /dev/null +++ b/conf/routes/te-get.conf @@ -0,0 +1,21 @@ +routingOperations = ${routingOperations} [ + { + operationId = te-get + handlers = ${config.server.handlers.common.request} [ + { + name = httpRepoConnectorHandler + config = ${global.handler.httpRepoConnectorHandler.config} + }, + { + name = htmlFragmentsSupplier + }, + { + name = fragmentsHandler + config = ${global.handler.fragmentsHandler.config} + }, + { + name = fragmentsAssembler + } + ] ${config.server.handlers.common.response} + } +] diff --git a/conf/routes/web-api-get.conf b/conf/routes/web-api-get.conf new file mode 100644 index 00000000..11468083 --- /dev/null +++ b/conf/routes/web-api-get.conf @@ -0,0 +1,23 @@ +routingOperations = ${routingOperations} [ + { + operationId = web-api-get + handlers = ${config.server.handlers.common.request} [ + { + name = singleFragmentSupplier + config = { + type = json + configuration { + data-knotx-task = web-api-test + } + } + }, + { + name = fragmentsHandler + config = ${global.handler.fragmentsHandler.config} + }, + { + name = fragmentsAssembler + } + ] ${config.server.handlers.common.response} + } +] diff --git a/conf/server.conf b/conf/server.conf new file mode 100644 index 00000000..d558f987 --- /dev/null +++ b/conf/server.conf @@ -0,0 +1,101 @@ +########### Knot.x JUnit5 config ########### +test { + random { + globalServer.port = 0 + } +} + +########### Knot.x Server ########### +modules { + server = "io.knotx.server.KnotxServerVerticle" +} + +########### Modules configurations ########### +config.server { + handlers.common { + request = [ + { + name = bodyHandler + }, + { + name = requestContextHandler + } + ], + response = [ + { + name = headerHandler + # Statically defined HTTP response header returned to the client in every HTTP response + config { + name = X-Server + value = Knot.x-Custom-Header + } + }, + { + name = writerHandler + # List of HTTP response headers Knot.x can return to the client + config.allowedResponseHeaders = [ + Access-Control-Allow-Origin + Content-Type + Content-Length + X-Server + ] + } + ] + } + options.config { + # Configuraiton of HTTP server + serverOptions { + # Knot.x server HTTP port + port = ${test.random.globalServer.port} + + # If you want a server to serve SSL connections you can configure it here + # + # Enable SSL + # ssl = true + # + # Path on the server the keystore.jks file is located + # keyStoreOptions.path = + # + # Keystore password + # keyStoreOptions.password = + } + + # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). + routingSpecificationLocation = /openapi.yaml + + displayExceptionDetails = true + + dropRequestOptions { + # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details + enabled = false + + # Status code that is served if the response is dropped, default is 429, "Too Many Requests" + # dropRequestResponseCode = + + # Number of request that single Server insance can support concurrently. Default value is 1000. + # backpressureBufferCapacity + + # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. + # backpressureStrategy = + } + + routingOperations = [] + include required(classpath("conf/routes/te-get.conf")) + include required(classpath("conf/routes/web-api-get.conf")) + } + + # The options object carries-on configuration called DeploymentOptions for a given verticle. + # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. + # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions + # + # options {} +} + +########### Globals ########### +global { + handler { + httpRepoConnectorHandler.config = { include required(classpath("conf/routes/handlers/httpRepoConnectorHandler.conf")) } + # This value is overloaded in test + fragmentsHandler.config = { include required(classpath("conf/routes/handlers/fragmentsHandler.conf")) } + } +} diff --git a/conf/tasks/task-with-fallback-action.conf b/conf/tasks/task-with-fallback-action.conf new file mode 100644 index 00000000..220765dd --- /dev/null +++ b/conf/tasks/task-with-fallback-action.conf @@ -0,0 +1,89 @@ +global.handler.fragmentsHandler.config { + tasks { + tags-listing { + action = tags + onTransitions { + _success { + action = te-hbs + } + _error { + action = tags-fallback + } + } + } + authors-listing { + action = author + onTransitions { + _success { + action = te-hbs + } + } + } + books-and-authors-listing { + actions = [ + { + action = book + }, + { + action = author + } + ] + onTransitions { + _success { + action = te-hbs + } + } + } + } + + actions { + tags { + factory = http + config { + endpointOptions { + path = /service/broken/500.json + domain = localhost + port = ${test.wiremock.mockBrokenService.port} + allowedRequestHeaders = [ "Content-Type" ] + } + } + } + tags-fallback { + factory = inline-body + config { + body = """

Tags are unavailable at the moment

""" + } + } + 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" ] + } + } + } + te-hbs { + factory = "knot" + config { + address = "knotx.knot.te.handlebars" + deliveryOptions { + sendTimeout = 3000 + } + } + } + } +} \ No newline at end of file diff --git a/scenarios/knotx-fragments-debug-data/mocks.conf b/scenarios/knotx-fragments-debug-data/mocks.conf new file mode 100644 index 00000000..c21efc94 --- /dev/null +++ b/scenarios/knotx-fragments-debug-data/mocks.conf @@ -0,0 +1,8 @@ +########### Knot.x JUnit5 config ########### +test.wiremock { + mockRepository.port = 0 + mockService.port = 0 +} +test.random { + delayedService.port = 0 +} diff --git a/scenarios/knotx-fragments-debug-data/pebble.conf b/scenarios/knotx-fragments-debug-data/pebble.conf new file mode 100644 index 00000000..946bd33d --- /dev/null +++ b/scenarios/knotx-fragments-debug-data/pebble.conf @@ -0,0 +1 @@ +config.pebbleTemplateEngine.options.config.engine.config.syntax.wrappingRootNodeName = root \ No newline at end of file diff --git a/scenarios/knotx-fragments-debug-data/tasks.conf b/scenarios/knotx-fragments-debug-data/tasks.conf new file mode 100644 index 00000000..6efea299 --- /dev/null +++ b/scenarios/knotx-fragments-debug-data/tasks.conf @@ -0,0 +1,211 @@ +global.handler.fragmentsHandler.config { + tasks { + user-task { + action = fetch-user-info // _success + onTransitions._success { + action = te-hbs + } + } + payments-task { + action = fetch-user-info // _success + onTransitions._success { + actions = [ + { + action = fetch-payment-providers // _success + onTransitions._error { + action = fetch-payment-providers-fallback + } + } + { + action = fetch-offers // _error + onTransitions._error { + action = fetch-offers-fallback // _success + } + } + { + action = fetch-delivery-options-cb // _fallback + onTransitions._fallback { + action = fetch-delivery-timeout // _success + } + } + ] + onTransitions._success { + action = te-pebble // _success + } + } + onTransitions._error { + action = fetch-user-info-fallback + onTransitions._success { + action = fetch-user-info-fallback-success + } + onTransitions._error { + action = fetch-user-info-fallback-error + } + } + onTransitions._custom { + action = fetch-user-info-custom-fallback + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.xml + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions { + forceJson = true + predicates = [] + } + } + fetch-delivery { + factory = http + config.endpointOptions { + path = /mock/scenario/delayed + domain = localhost + port = ${test.random.delayedService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-delivery-options-cb { + factory = cb + config { + circuitBreakerName = delivery-cb + circuitBreakerOptions { + maxRetries = 1 + timeout = 50 + } + } + doAction = fetch-delivery + } + fetch-offers-fallback { + factory = inline-payload + config { + alias = fetch-offers + payload { + _result { + fallback = "json-syntax-error" + } + } + } + } + fetch-delivery-timeout { + factory = inline-payload + config { + alias = fetch-delivery + payload { + _result { + fallback = "action ended with _timeout" + } + } + } + } + create-response { + factory = payload-to-body + } + te-hbs { + factory = knot + config { + address = knotx.knot.te.handlebars + deliveryOptions { + sendTimeout = 3000 + } + } + } + te-pebble { + factory = knot + config { + address = knotx.knot.te.pebble + deliveryOptions { + sendTimeout = 3000 + } + } + } + fetch-payment-providers-fallback { + factory = http + config.endpointOptions { + path = /service/mock/placeholderFallback.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-user-info-fallback { + factory = http + config.endpointOptions { + path = /service/mock/placeholderFallback.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-user-info-fallback-success { + factory = http + config.endpointOptions { + path = /service/mock/placeholderFallback.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-user-info-fallback-error { + factory = http + config.endpointOptions { + path = /service/mock/placeholderFallback.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-user-info-custom-fallback { + factory = http + config.endpointOptions { + path = /service/mock/placeholderFallback.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} + config.logLevel = info + } + { + factory = subtasks + } + ] + } + } + ] +} \ No newline at end of file diff --git a/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java b/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java index 7e496e06..77a1a8ea 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java @@ -1,87 +1,87 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.junit5.util.FileReader; -import io.knotx.stack.KnotxServerTester; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.vertx.core.json.JsonObject; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class CircuitBreakerTimesOutAndRetriesScenarioTest { - - private static final String SCENARIO_NAME = "Circuit breaker times out HTTP Action and retries."; - private static final String RETRY_SCENARIO_STATE = "RETRY"; - - private WireMockServer scenarioMockService; - - @Test - @DisplayName("Expect offers from second service invocation (retry) following the first attempt timeout.") - @KnotxApplyConfiguration({"conf/application.conf", - "common/api/routing.conf", - "common/api/fragments.conf", - "scenarios/circuit-breaker-times-out-and-retries/mocks.conf", - "scenarios/circuit-breaker-times-out-and-retries/tasks.conf"}) - void requestApi(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer scenarioServicePort, @RandomPort Integer globalServerPort) { - scenarioMockService = new WireMockServer(scenarioServicePort); - scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) - .whenScenarioStateIs(STARTED) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withFixedDelay(100) - .withBody(FileReader.readTextSafe("service/mock/emptyOffers.json"))) - .willSetStateTo(RETRY_SCENARIO_STATE)); - scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) - .whenScenarioStateIs(RETRY_SCENARIO_STATE) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(FileReader.readTextSafe("service/mock/specialOffers.json")))); - scenarioMockService.start(); - - KnotxServerTester.defaultInstance(globalServerPort) - .testGet(testContext, vertx, "/api/user", resp -> { - assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); - JsonObject response = resp.body().toJsonObject(); - assertNotNull(response); - assertEquals(5, response.getJsonObject("fetch-offers").getJsonArray("_result").size()); - }); - } - - @AfterEach - void tearDown() { - scenarioMockService.stop(); - } -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.junit5.util.FileReader; +import io.knotx.stack.KnotxServerTester; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.json.JsonObject; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class CircuitBreakerTimesOutAndRetriesScenarioTest { + + private static final String SCENARIO_NAME = "Circuit breaker times out HTTP Action and retries."; + private static final String RETRY_SCENARIO_STATE = "RETRY"; + + private WireMockServer scenarioMockService; + + @Test + @DisplayName("Expect offers from second service invocation (retry) following the first attempt timeout.") + @KnotxApplyConfiguration({"conf/application.conf", + "common/api/routing.conf", + "common/api/fragments.conf", + "scenarios/circuit-breaker-times-out-and-retries/mocks.conf", + "scenarios/circuit-breaker-times-out-and-retries/tasks.conf"}) + void requestApi(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer scenarioServicePort, @RandomPort Integer globalServerPort) { + scenarioMockService = new WireMockServer(scenarioServicePort); + scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) + .whenScenarioStateIs(STARTED) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withFixedDelay(100) + .withBody(FileReader.readTextSafe("service/mock/emptyOffers.json"))) + .willSetStateTo(RETRY_SCENARIO_STATE)); + scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) + .whenScenarioStateIs(RETRY_SCENARIO_STATE) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(FileReader.readTextSafe("service/mock/specialOffers.json")))); + scenarioMockService.start(); + + KnotxServerTester.defaultInstance(globalServerPort) + .testGet(testContext, vertx, "/api/user", resp -> { + assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); + JsonObject response = resp.body().toJsonObject(); + assertNotNull(response); + assertEquals(5, response.getJsonObject("fetch-offers").getJsonArray("_result").size()); + }); + } + + @AfterEach + void tearDown() { + scenarioMockService.stop(); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java index 13331618..fbfa83ac 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java @@ -1,73 +1,73 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; -import io.knotx.stack.KnotxServerTester; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class FailingHttpServicesWithFallbacksIntegrationTest { - - @ClasspathResourcesMockServer - private WireMockServer mockRepository; - - private WireMockServer mockBrokenService; - - @AfterEach - void tearDown() { - mockBrokenService.stop(); - } - - @Test - @DisplayName("Expect page containing data from services and fallback data for broken service.") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/failing-http-services-with-fallbacks/mocks.conf", - "scenarios/failing-http-services-with-fallbacks/tasks.conf"}) - void requestPage(VertxTestContext context, Vertx vertx, @RandomPort Integer mockBrokenServicePort, - @RandomPort Integer globalServerPort) { - // when - mockBrokenService = new WireMockServer(mockBrokenServicePort); - mockBrokenService.stubFor(get(urlMatching("/service/broken/500.json")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) - )); - mockBrokenService.start(); - - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester - .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", - "scenarios/failing-http-services-with-fallbacks/result/fullPage.html"); - } -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; +import io.knotx.stack.KnotxServerTester; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class FailingHttpServicesWithFallbacksIntegrationTest { + + @ClasspathResourcesMockServer + private WireMockServer mockRepository; + + private WireMockServer mockBrokenService; + + @AfterEach + void tearDown() { + mockBrokenService.stop(); + } + + @Test + @DisplayName("Expect page containing data from services and fallback data for broken service.") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/failing-http-services-with-fallbacks/mocks.conf", + "scenarios/failing-http-services-with-fallbacks/tasks.conf"}) + void requestPage(VertxTestContext context, Vertx vertx, @RandomPort Integer mockBrokenServicePort, + @RandomPort Integer globalServerPort) { + // when + mockBrokenService = new WireMockServer(mockBrokenServicePort); + mockBrokenService.stubFor(get(urlMatching("/service/broken/500.json")) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) + )); + mockBrokenService.start(); + + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester + .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", + "scenarios/failing-http-services-with-fallbacks/result/fullPage.html"); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java index 1586cd7c..8bb423e8 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java @@ -1,80 +1,80 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; -import io.knotx.stack.KnotxServerTester; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -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 LongRunningHttpServiceWithCircuitBreakerIntegrationTest { - - @ClasspathResourcesMockServer - private WireMockServer mockService; - - @ClasspathResourcesMockServer - private WireMockServer mockRepository; - - private WireMockServer delayedServiceServer; - - @AfterEach - void tearDown() { - delayedServiceServer.stop(); - } - - @Test - @DisplayName("Expect page containing data from services and fallback data for broken service.") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/long-running-http-service-with-circuit-breaker/mocks.conf", - "scenarios/long-running-http-service-with-circuit-breaker/tasks.conf"}) - void taskWithCircuitBreaker(VertxTestContext context, Vertx vertx, - @RandomPort Integer delayedServicePort, - @RandomPort Integer globalServerPort) { - // given - delayedServiceServer = new WireMockServer(delayedServicePort); - delayedServiceServer.stubFor(get(urlEqualTo("/service/mock/delayed")).willReturn( - aResponse() - .withStatus(200) - .withFixedDelay(2000))); - delayedServiceServer.start(); - - // when - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester - .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", - "scenarios/long-running-http-service-with-circuit-breaker/result/fullPage.html"); - } - -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; +import io.knotx.stack.KnotxServerTester; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +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 LongRunningHttpServiceWithCircuitBreakerIntegrationTest { + + @ClasspathResourcesMockServer + private WireMockServer mockService; + + @ClasspathResourcesMockServer + private WireMockServer mockRepository; + + private WireMockServer delayedServiceServer; + + @AfterEach + void tearDown() { + delayedServiceServer.stop(); + } + + @Test + @DisplayName("Expect page containing data from services and fallback data for broken service.") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/long-running-http-service-with-circuit-breaker/mocks.conf", + "scenarios/long-running-http-service-with-circuit-breaker/tasks.conf"}) + void taskWithCircuitBreaker(VertxTestContext context, Vertx vertx, + @RandomPort Integer delayedServicePort, + @RandomPort Integer globalServerPort) { + // given + delayedServiceServer = new WireMockServer(delayedServicePort); + delayedServiceServer.stubFor(get(urlEqualTo("/service/mock/delayed")).willReturn( + aResponse() + .withStatus(200) + .withFixedDelay(2000))); + delayedServiceServer.start(); + + // when + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester + .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", + "scenarios/long-running-http-service-with-circuit-breaker/result/fullPage.html"); + } + +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java index 2523a019..a6a0a68e 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java @@ -1,48 +1,48 @@ -/* - * 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", - "common/templating/routing.conf", - "common/templating/fragments.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.testGetWithExpectedResponse(context, vertx, - "/content/fullPebblePage.html", "results/fullPage.html"); - } -} +/* + * 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", + "common/templating/routing.conf", + "common/templating/fragments.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.testGetWithExpectedResponse(context, vertx, + "/content/fullPebblePage.html", "results/fullPage.html"); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java b/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java index 2b769b67..21316a94 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java @@ -1,97 +1,97 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.stack.KnotxServerTester; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.vertx.ext.web.client.WebClientOptions; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class RepositoryConnectorRedirectPassedToEndUserTest { - - private WireMockServer httpRepositoryServer; - - - - @Test - @DisplayName("Should return redirect response when Http Repository returns redirect with empty body (AEM author login redirect case)") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) - void requestAemAuthorResourceLoginRedirect(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { - httpRepositoryServer = new WireMockServer(httpRepositoryPort); - httpRepositoryServer.stubFor(get(urlEqualTo("/admin-panel.html")).willReturn( - aResponse() - .withStatus(HttpResponseStatus.FOUND.code()) - .withHeader("location", "/login.html"))); - httpRepositoryServer.start(); - - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester - .withClientOptions(new WebClientOptions().setFollowRedirects(false)) - .testGet(testContext, vertx, "/admin-panel.html", - resp -> { - assertEquals(HttpResponseStatus.FOUND.code(), resp.statusCode()); - assertEquals("/login.html", resp.getHeader("location")); - }); - } - - @Test - @DisplayName("Should return not-found response when Http Repository returns 404 with empty body (AEM author login redirect case)") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) - void requestRepositoryGetNotFound(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { - httpRepositoryServer = new WireMockServer(httpRepositoryPort); - httpRepositoryServer.stubFor(get(urlEqualTo("/not-existing.html")).willReturn( - aResponse() - .withStatus(HttpResponseStatus.NOT_FOUND.code())) - ); - httpRepositoryServer.start(); - - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester.testGet(testContext, vertx, "/not-existing.html", - resp -> { - assertEquals(HttpResponseStatus.NOT_FOUND.code(), resp.statusCode()); - }); - } - - @AfterEach - void tearDown() { - httpRepositoryServer.stop(); - } -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.stack.KnotxServerTester; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.ext.web.client.WebClientOptions; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class RepositoryConnectorRedirectPassedToEndUserTest { + + private WireMockServer httpRepositoryServer; + + + + @Test + @DisplayName("Should return redirect response when Http Repository returns redirect with empty body (AEM author login redirect case)") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) + void requestAemAuthorResourceLoginRedirect(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { + httpRepositoryServer = new WireMockServer(httpRepositoryPort); + httpRepositoryServer.stubFor(get(urlEqualTo("/admin-panel.html")).willReturn( + aResponse() + .withStatus(HttpResponseStatus.FOUND.code()) + .withHeader("location", "/login.html"))); + httpRepositoryServer.start(); + + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester + .withClientOptions(new WebClientOptions().setFollowRedirects(false)) + .testGet(testContext, vertx, "/admin-panel.html", + resp -> { + assertEquals(HttpResponseStatus.FOUND.code(), resp.statusCode()); + assertEquals("/login.html", resp.getHeader("location")); + }); + } + + @Test + @DisplayName("Should return not-found response when Http Repository returns 404 with empty body (AEM author login redirect case)") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) + void requestRepositoryGetNotFound(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { + httpRepositoryServer = new WireMockServer(httpRepositoryPort); + httpRepositoryServer.stubFor(get(urlEqualTo("/not-existing.html")).willReturn( + aResponse() + .withStatus(HttpResponseStatus.NOT_FOUND.code())) + ); + httpRepositoryServer.start(); + + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester.testGet(testContext, vertx, "/not-existing.html", + resp -> { + assertEquals(HttpResponseStatus.NOT_FOUND.code(), resp.statusCode()); + }); + } + + @AfterEach + void tearDown() { + httpRepositoryServer.stop(); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java index d8c6d0d2..cefd8c9f 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java @@ -1,45 +1,45 @@ -/* - * 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.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class TemplateEnginesIntegrationTest { - - @Test - @DisplayName("Should return page properly processed by handlebars") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/template-engines-integration/mocks.conf", - "scenarios/template-engines-integration/tasks.conf", - "scenarios/template-engines-integration/pebble.conf"}) - void requestPage(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer globalServerPort) { - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester.testGetWithExpectedResponse(testContext, vertx, "/content/payments.html", - "scenarios/template-engines-integration/resultPage.html"); - } -} +/* + * 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.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class TemplateEnginesIntegrationTest { + + @Test + @DisplayName("Should return page properly processed by handlebars") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/template-engines-integration/mocks.conf", + "scenarios/template-engines-integration/tasks.conf", + "scenarios/template-engines-integration/pebble.conf"}) + void requestPage(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer globalServerPort) { + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester.testGetWithExpectedResponse(testContext, vertx, "/content/payments.html", + "scenarios/template-engines-integration/resultPage.html"); + } +} diff --git a/src/functionalTest/resources/common/api/fragments.conf b/src/functionalTest/resources/common/api/fragments.conf index b04676d6..e26e6bc4 100644 --- a/src/functionalTest/resources/common/api/fragments.conf +++ b/src/functionalTest/resources/common/api/fragments.conf @@ -1,7 +1,7 @@ -global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} - -global.handler.fragmentsHandler.config.actions { - create-response { - factory = payload-to-body - } +global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} + +global.handler.fragmentsHandler.config.actions { + create-response { + factory = payload-to-body + } } \ No newline at end of file diff --git a/src/functionalTest/resources/common/api/routing.conf b/src/functionalTest/resources/common/api/routing.conf index ca57022a..c8c1ddcf 100644 --- a/src/functionalTest/resources/common/api/routing.conf +++ b/src/functionalTest/resources/common/api/routing.conf @@ -1,23 +1,23 @@ -config.server.options.config.routingOperations = [ - { - operationId = scenario-operation - handlers = ${config.server.handlers.common.request} [ - { - name = singleFragmentSupplier - config = { - type = json - configuration { - data-knotx-task = web-api-test - } - } - }, - { - name = fragmentsHandler - config = ${global.handler.fragmentsHandler.config} - }, - { - name = fragmentsAssembler - } - ] ${config.server.handlers.common.response} - } -] +config.server.options.config.routingOperations = [ + { + operationId = scenario-operation + handlers = ${config.server.handlers.common.request} [ + { + name = singleFragmentSupplier + config = { + type = json + configuration { + data-knotx-task = web-api-test + } + } + }, + { + name = fragmentsHandler + config = ${global.handler.fragmentsHandler.config} + }, + { + name = fragmentsAssembler + } + ] ${config.server.handlers.common.response} + } +] diff --git a/src/functionalTest/resources/common/templating/fragments.conf b/src/functionalTest/resources/common/templating/fragments.conf index 56894df7..a8b3adeb 100644 --- a/src/functionalTest/resources/common/templating/fragments.conf +++ b/src/functionalTest/resources/common/templating/fragments.conf @@ -1,22 +1,22 @@ -global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} - -global.handler.fragmentsHandler.config.actions { - te-hbs { - factory = knot - config { - address = knotx.knot.te.handlebars - deliveryOptions { - sendTimeout = 3000 - } - } - } - te-pebble { - factory = knot - config { - address = knotx.knot.te.pebble - deliveryOptions { - sendTimeout = 3000 - } - } - } +global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} + +global.handler.fragmentsHandler.config.actions { + te-hbs { + factory = knot + config { + address = knotx.knot.te.handlebars + deliveryOptions { + sendTimeout = 3000 + } + } + } + te-pebble { + factory = knot + config { + address = knotx.knot.te.pebble + deliveryOptions { + sendTimeout = 3000 + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/common/templating/routing.conf b/src/functionalTest/resources/common/templating/routing.conf index d19dfe6f..27c079ed 100644 --- a/src/functionalTest/resources/common/templating/routing.conf +++ b/src/functionalTest/resources/common/templating/routing.conf @@ -1,28 +1,28 @@ -test.wiremock { - mockRepository.port = 0 -} - -config.server.options.config.routingOperations = [ - { - operationId = scenario-operation - handlers = ${config.server.handlers.common.request} [ - { - name = httpRepoConnectorHandler - config = ${global.handler.httpRepoConnectorHandler.config} - }, - { - name = htmlFragmentsSupplier - }, - { - name = fragmentsHandler - config = ${global.handler.fragmentsHandler.config} - }, - { - name = fragmentsAssembler - } - ] ${config.server.handlers.common.response} - } -] - -global.handler.httpRepoConnectorHandler.config = {include required(classpath("conf/routes/handlers/httpRepoConnectorHandler.conf"))} -global.handler.httpRepoConnectorHandler.config.clientDestination.port = ${test.wiremock.mockRepository.port} +test.wiremock { + mockRepository.port = 0 +} + +config.server.options.config.routingOperations = [ + { + operationId = scenario-operation + handlers = ${config.server.handlers.common.request} [ + { + name = httpRepoConnectorHandler + config = ${global.handler.httpRepoConnectorHandler.config} + }, + { + name = htmlFragmentsSupplier + }, + { + name = fragmentsHandler + config = ${global.handler.fragmentsHandler.config} + }, + { + name = fragmentsAssembler + } + ] ${config.server.handlers.common.response} + } +] + +global.handler.httpRepoConnectorHandler.config = {include required(classpath("conf/routes/handlers/httpRepoConnectorHandler.conf"))} +global.handler.httpRepoConnectorHandler.config.clientDestination.port = ${test.wiremock.mockRepository.port} diff --git a/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf b/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf index 8bbe59c2..069b1bb2 100644 --- a/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf +++ b/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf @@ -1,44 +1,44 @@ -########### This configuration is overloaded in integration tests! ########### -tasks { - # will be extended per unit tests -} - -actions { - # will be extended per unit tests - te-hbs { - factory = knot - config { - address = knotx.knot.te.handlebars - deliveryOptions { - sendTimeout = 3000 - } - } - } - te-pebble { - factory = knot - config { - address = knotx.knot.te.pebble - deliveryOptions { - sendTimeout = 3000 - } - } - } -} - -taskFactories = [ - { - factory = default - config { - tasks = ${global.handler.fragmentsHandler.config.tasks} - nodeFactories = [ - { - factory = action - config.actions = ${global.handler.fragmentsHandler.config.actions} - } - { - factory = subtasks - } - ] - } - } +########### This configuration is overloaded in integration tests! ########### +tasks { + # will be extended per unit tests +} + +actions { + # will be extended per unit tests + te-hbs { + factory = knot + config { + address = knotx.knot.te.handlebars + deliveryOptions { + sendTimeout = 3000 + } + } + } + te-pebble { + factory = knot + config { + address = knotx.knot.te.pebble + deliveryOptions { + sendTimeout = 3000 + } + } + } +} + +taskFactories = [ + { + factory = default + config { + tasks = ${global.handler.fragmentsHandler.config.tasks} + nodeFactories = [ + { + factory = action + config.actions = ${global.handler.fragmentsHandler.config.actions} + } + { + factory = subtasks + } + ] + } + } ] \ No newline at end of file diff --git a/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf b/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf index eb0c0b35..ed1359c2 100644 --- a/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf +++ b/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf @@ -1,61 +1,61 @@ -# Vert.x event bus delivery options used when communicating with other verticles -# see http://vertx.io/docs/vertx-core/dataobjects.html#HttpClientOptions for the details what can be configured -# -clientOptions { - maxPoolSize = 1000 - idleTimeout = 120 # seconds - tryUseCompression = true - - # If you're going to use SSL (clientDestination.scheme='https') then here you'd need to configure - # some aspects related to the SSL negotiation and validation. - # - # Whether all server certificated should be trusted or not (e.g. self-signed certificates) - # trustAll = true - # - # Hostname verification - # verifyHost = false - # - # It will force SSL SNI (Server Name Indication). The SNI will be set to the same value as 'hostHeader' (set in ClientDestination) - # forceSni = true -} - -# HTTP Repository connection details -clientDestination { - # Connection scheme: http or https - scheme = http - - # domain or the IP of the host: e.g. localhost, 10.0.11.2 - domain = localhost - - ## Port on which the host listens, e.g. 8080, 3001, etc. - port = 80 - - # Host header override to be used with a communication to the repository. If it's set, it overrides any value in the 'Host' header, and sets the SNI SSL to the same value. - # hostHeader = -} - -# List of allowed request headers that will be send to HTTP repository. -# Each item is a string that defines regex, e.g. to match any char use `.*` -# -allowedRequestHeaders = [ - "Accept.*" - Authorization - Connection - Cookie - Date - "Edge.*" - "If.*" - Origin - Pragma - Proxy-Authorization - "Surrogate.*" - User-Agent - Via - "X-.*" -] - -# Statically defined HTTP request header sent in every request to the repository -customHttpHeader = { - name = X-User-Agent - value = Knot.x +# Vert.x event bus delivery options used when communicating with other verticles +# see http://vertx.io/docs/vertx-core/dataobjects.html#HttpClientOptions for the details what can be configured +# +clientOptions { + maxPoolSize = 1000 + idleTimeout = 120 # seconds + tryUseCompression = true + + # If you're going to use SSL (clientDestination.scheme='https') then here you'd need to configure + # some aspects related to the SSL negotiation and validation. + # + # Whether all server certificated should be trusted or not (e.g. self-signed certificates) + # trustAll = true + # + # Hostname verification + # verifyHost = false + # + # It will force SSL SNI (Server Name Indication). The SNI will be set to the same value as 'hostHeader' (set in ClientDestination) + # forceSni = true +} + +# HTTP Repository connection details +clientDestination { + # Connection scheme: http or https + scheme = http + + # domain or the IP of the host: e.g. localhost, 10.0.11.2 + domain = localhost + + ## Port on which the host listens, e.g. 8080, 3001, etc. + port = 80 + + # Host header override to be used with a communication to the repository. If it's set, it overrides any value in the 'Host' header, and sets the SNI SSL to the same value. + # hostHeader = +} + +# List of allowed request headers that will be send to HTTP repository. +# Each item is a string that defines regex, e.g. to match any char use `.*` +# +allowedRequestHeaders = [ + "Accept.*" + Authorization + Connection + Cookie + Date + "Edge.*" + "If.*" + Origin + Pragma + Proxy-Authorization + "Surrogate.*" + User-Agent + Via + "X-.*" +] + +# Statically defined HTTP request header sent in every request to the repository +customHttpHeader = { + name = X-User-Agent + value = Knot.x } \ No newline at end of file diff --git a/src/functionalTest/resources/conf/server.conf b/src/functionalTest/resources/conf/server.conf index 9a516f14..670efbbc 100644 --- a/src/functionalTest/resources/conf/server.conf +++ b/src/functionalTest/resources/conf/server.conf @@ -1,103 +1,103 @@ -########### Knot.x JUnit5 config ########### -test { - random { - globalServer.port = 0 - } -} - -########### Knot.x Server ########### -modules { - server = "io.knotx.server.KnotxServerVerticle" -} - -########### Modules configurations ########### -config.server { - handlers.common { - request = [ - { - name = bodyHandler - }, - { - name = requestContextHandler - } - ], - response = [ - { - name = headerHandler - # Statically defined HTTP response header returned to the client in every HTTP response - config { - name = X-Server - value = Knot.x-Custom-Header - } - }, - { - name = writerHandler - # List of HTTP response headers Knot.x can return to the client - config.allowedResponseHeaders = [ - Access-Control-Allow-Origin - Content-Type - Content-Length - X-Server - Location - ] - } - ] - } - options.config { - # Configuraiton of HTTP server - serverOptions { - # Knot.x server HTTP port - port = ${test.random.globalServer.port} - - # If you want a server to serve SSL connections you can configure it here - # - # Enable SSL - # ssl = true - # - # Path on the server the keystore.jks file is located - # keyStoreOptions.path = - # - # Keystore password - # keyStoreOptions.password = - } - - # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). - routingSpecificationLocation = /openapi.yaml - - displayExceptionDetails = true - - dropRequestOptions { - # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details - enabled = false - - # Status code that is served if the response is dropped, default is 429, "Too Many Requests" - # dropRequestResponseCode = - - # Number of request that single Server insance can support concurrently. Default value is 1000. - # backpressureBufferCapacity - - # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. - # backpressureStrategy = - } - - routingOperations = [] - - # Global handlers section - globalHandlers = [ - # access log, by default logged to the knotx-access.log in the logs directory - { - name = loggerHandler - config { - immediate = true - format = DEFAULT - } - } - ] - } - - # The options object carries-on configuration called DeploymentOptions for a given verticle. - # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. - # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions - # - # options {} -} +########### Knot.x JUnit5 config ########### +test { + random { + globalServer.port = 0 + } +} + +########### Knot.x Server ########### +modules { + server = "io.knotx.server.KnotxServerVerticle" +} + +########### Modules configurations ########### +config.server { + handlers.common { + request = [ + { + name = bodyHandler + }, + { + name = requestContextHandler + } + ], + response = [ + { + name = headerHandler + # Statically defined HTTP response header returned to the client in every HTTP response + config { + name = X-Server + value = Knot.x-Custom-Header + } + }, + { + name = writerHandler + # List of HTTP response headers Knot.x can return to the client + config.allowedResponseHeaders = [ + Access-Control-Allow-Origin + Content-Type + Content-Length + X-Server + Location + ] + } + ] + } + options.config { + # Configuraiton of HTTP server + serverOptions { + # Knot.x server HTTP port + port = ${test.random.globalServer.port} + + # If you want a server to serve SSL connections you can configure it here + # + # Enable SSL + # ssl = true + # + # Path on the server the keystore.jks file is located + # keyStoreOptions.path = + # + # Keystore password + # keyStoreOptions.password = + } + + # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). + routingSpecificationLocation = /openapi.yaml + + displayExceptionDetails = true + + dropRequestOptions { + # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details + enabled = false + + # Status code that is served if the response is dropped, default is 429, "Too Many Requests" + # dropRequestResponseCode = + + # Number of request that single Server insance can support concurrently. Default value is 1000. + # backpressureBufferCapacity + + # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. + # backpressureStrategy = + } + + routingOperations = [] + + # Global handlers section + globalHandlers = [ + # access log, by default logged to the knotx-access.log in the logs directory + { + name = loggerHandler + config { + immediate = true + format = DEFAULT + } + } + ] + } + + # The options object carries-on configuration called DeploymentOptions for a given verticle. + # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. + # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions + # + # options {} +} diff --git a/src/functionalTest/resources/conf/tasks/task-with-fallback-action.conf b/src/functionalTest/resources/conf/tasks/task-with-fallback-action.conf index 220765dd..b2a9315d 100644 --- a/src/functionalTest/resources/conf/tasks/task-with-fallback-action.conf +++ b/src/functionalTest/resources/conf/tasks/task-with-fallback-action.conf @@ -2,7 +2,7 @@ global.handler.fragmentsHandler.config { tasks { tags-listing { action = tags - onTransitions { + on { _success { action = te-hbs } @@ -13,7 +13,7 @@ global.handler.fragmentsHandler.config { } authors-listing { action = author - onTransitions { + on { _success { action = te-hbs } @@ -28,7 +28,7 @@ global.handler.fragmentsHandler.config { action = author } ] - onTransitions { + on { _success { action = te-hbs } diff --git a/src/functionalTest/resources/content/failedFragment.html b/src/functionalTest/resources/content/failedFragment.html index 7ef24e53..dd1a0771 100644 --- a/src/functionalTest/resources/content/failedFragment.html +++ b/src/functionalTest/resources/content/failedFragment.html @@ -1,29 +1,29 @@ - - - - - - Broken service - - -
- -

This fragment should fail/h2> - -

- - + + + + + + Broken service + + +
+ +

This fragment should fail/h2> + +

+ + diff --git a/src/functionalTest/resources/openapi.yaml b/src/functionalTest/resources/openapi.yaml index 59923f2b..9eee8beb 100644 --- a/src/functionalTest/resources/openapi.yaml +++ b/src/functionalTest/resources/openapi.yaml @@ -1,43 +1,43 @@ -# 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. - -openapi: "3.0.0" -info: - version: 1.0.0 - title: Knot.x Stack OAS - description: This is a full flow server used during integration tests. - license: - name: Apache 2.0 - url: http://www.apache.org/licenses/LICENSE-2.0.html - -servers: -- url: https://{domain}:{port} - description: The local API server - variables: - domain: - default: localhost - description: api domain - port: - enum: - - '8092' - - '443' - default: '8092' - -paths: - /*: - get: - operationId: scenario-operation - responses: - default: +# 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. + +openapi: "3.0.0" +info: + version: 1.0.0 + title: Knot.x Stack OAS + description: This is a full flow server used during integration tests. + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + +servers: +- url: https://{domain}:{port} + description: The local API server + variables: + domain: + default: localhost + description: api domain + port: + enum: + - '8092' + - '443' + default: '8092' + +paths: + /*: + get: + operationId: scenario-operation + responses: + default: description: scenario specific operation \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf index 373c5b6b..62df6d4f 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - scenarioService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + scenarioService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf index 731fe411..84298080 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf @@ -1,64 +1,64 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = fetch-user-info - onTransitions._success { - actions = [ - { - action = fetch-payment-providers - } - { - action = fetch-offers-with-cb - } - ] - onTransitions { - _success { - action = create-response - } - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/scenario - domain = localhost - port = ${test.random.scenarioService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions.predicates = [ JSON ] - } - fetch-offers-with-cb { - factory = cb - config { - circuitBreakerName = offers-cb - circuitBreakerOptions { - maxRetries = 1 - timeout = 50 - } - } - doAction = fetch-offers - } - } +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = fetch-user-info + on._success { + actions = [ + { + action = fetch-payment-providers + } + { + action = fetch-offers-with-cb + } + ] + on { + _success { + action = create-response + } + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/scenario + domain = localhost + port = ${test.random.scenarioService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions.predicates = [ JSON ] + } + fetch-offers-with-cb { + factory = cb + config { + circuitBreakerName = offers-cb + circuitBreakerOptions { + maxRetries = 1 + timeout = 50 + } + } + doAction = fetch-offers + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf index bf284a45..a07c0fd1 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - delayedService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + delayedService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf index e6862659..0457dcd2 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf @@ -1,74 +1,74 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = fetch-user-info - onTransitions._success { - actions = [ - { - action = fetch-payment-providers - } - { - action = fetch-offers-with-cb - onTransitions._fallback { - action = fetch-offers-fallback - } - } - ] - onTransitions._success { - action = create-response - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/delayed - domain = localhost - port = ${test.random.delayedService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers-with-cb { - factory = cb - config { - circuitBreakerName = offers-cb - circuitBreakerOptions { - timeout = 50 - } - } - doAction = fetch-offers - } - fetch-offers-fallback { - factory = inline-payload - config { - alias = fetch-offers - payload { - _result { - fallback = "timeout" - } - } - } - } - } +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = fetch-user-info + on._success { + actions = [ + { + action = fetch-payment-providers + } + { + action = fetch-offers-with-cb + on._fallback { + action = fetch-offers-fallback + } + } + ] + on._success { + action = create-response + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/delayed + domain = localhost + port = ${test.random.delayedService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers-with-cb { + factory = cb + config { + circuitBreakerName = offers-cb + circuitBreakerOptions { + timeout = 50 + } + } + doAction = fetch-offers + } + fetch-offers-fallback { + factory = inline-payload + config { + alias = fetch-offers + payload { + _result { + fallback = "timeout" + } + } + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf index ec15f0e1..1cc8cbde 100644 --- a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf +++ b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf @@ -1,8 +1,8 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - authService.port = 0 - databaseService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + authService.port = 0 + databaseService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf index 71010dcd..7d5c4e20 100644 --- a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf +++ b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf @@ -1,49 +1,49 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = obtain-auth-token - onTransitions._success { - action = reload-database - onTransitions { - _success { - action = create-response - } - } - } - } - } - - actions { - obtain-auth-token { - factory = http - config { - endpointOptions { - path = "/auth/login?id={param.id}&apiKey={param.key}" - domain = localhost - port = ${test.random.authService.port} - allowedRequestHeaders = ["Content-Type"] - } - responseOptions.predicates = [ JSON ] - } - } - reload-database { - factory = http - config { - httpMethod = POST - endpointOptions { - path = /database/manage - domain = localhost - port = ${test.random.databaseService.port} - interpolateBody = true - bodyJson { - id = "{param.id}" - authToken = "{payload.obtain-auth-token._result.token}" - operation = reloadFromPermanentStorage - } - allowedRequestHeaders = ["Content-Type"] - } - responseOptions.predicates = [ JSON ] - } - } - } -} +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = obtain-auth-token + on._success { + action = reload-database + on { + _success { + action = create-response + } + } + } + } + } + + actions { + obtain-auth-token { + factory = http + config { + endpointOptions { + path = "/auth/login?id={param.id}&apiKey={param.key}" + domain = localhost + port = ${test.random.authService.port} + allowedRequestHeaders = ["Content-Type"] + } + responseOptions.predicates = [ JSON ] + } + } + reload-database { + factory = http + config { + httpMethod = POST + endpointOptions { + path = /database/manage + domain = localhost + port = ${test.random.databaseService.port} + interpolateBody = true + bodyJson { + id = "{param.id}" + authToken = "{payload.obtain-auth-token._result.token}" + operation = reloadFromPermanentStorage + } + allowedRequestHeaders = ["Content-Type"] + } + responseOptions.predicates = [ JSON ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf b/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf index bf284a45..a07c0fd1 100644 --- a/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf +++ b/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - delayedService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + delayedService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf b/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf index f3a40122..01f43853 100644 --- a/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf +++ b/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf @@ -1,26 +1,26 @@ -global.handler.fragmentsHandler.config { - tasks { - error-task { - action = fetch-incorrect-data - onTransitions._success { - action = te-pebble - } - } - } - - actions { - fetch-incorrect-data { - factory = http - config.endpointOptions { - path = /service/broken/500.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - forceJson = true - } - } - } - - allowInvalidFragmentsHeader = "Allow-Invalid-Fragments" - allowInvalidFragmentsParam = "allowInvalidFragments" +global.handler.fragmentsHandler.config { + tasks { + error-task { + action = fetch-incorrect-data + on._success { + action = te-pebble + } + } + } + + actions { + fetch-incorrect-data { + factory = http + config.endpointOptions { + path = /service/broken/500.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + forceJson = true + } + } + } + + allowInvalidFragmentsHeader = "Allow-Invalid-Fragments" + allowInvalidFragmentsParam = "allowInvalidFragments" } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf index eeddde05..eb63baeb 100644 --- a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf +++ b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.random { - mockBrokenService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.random { + mockBrokenService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf index ecec3e2b..363351e6 100644 --- a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf +++ b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf @@ -1,115 +1,115 @@ -global.handler.fragmentsHandler.config { - tasks { - books-listing { - action = book - onTransitions { - _error { - action = book-inline-body-fallback - } - } - } - authors-listing { - action = author - onTransitions { - _error { - action = author-inline-payload-fallback - onTransitions._success { - action = te-hbs - } - } - } - } - books-and-authors-listing { - subtasks = [ - { - action = book - onTransitions._error { - action = book-inline-payload-fallback - } - }, - { - action = author - } - ] - onTransitions { - _error { - action = author-inline-payload-fallback - onTransitions._success { - action = te-hbs - } - } - } - } - } - - actions { - book { - factory = http - config.endpointOptions { - path = /service/broken/500.json - domain = localhost - port = ${test.random.mockBrokenService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - author { - factory = http - config.endpointOptions { - path = /service/broken/500.json - domain = localhost - port = ${test.random.mockBrokenService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - // fallbacks - author-inline-payload-fallback { - factory = inline-payload - config { - alias = author - payload { - _result { - name = "Knot X", - info { - portfolio = [ - "tutorials", - "blogs", - "books" - ], - bio = "Aliquam cursus fermentum mi, vel tempus mi pellentesque vel. Nunc in feugiat lorem. Etiam placerat ante eget sem euismod, sit amet dictum sapien vulputate. Morbi pellentesque arcu a mauris ornare eleifend." - } - } - _response { - metadata { - statusCode = 500 - } - } - } - } - } - book-inline-payload-fallback { - factory = inline-payload - config { - alias = book - payload { - _result { - title = "Knot.x Integration Tests in Practice" - info { - authors = "Knot.x Team" - } - } - _response { - metadata { - statusCode = 500 - } - } - } - } - } - book-inline-body-fallback { - factory = inline-body - config { - body = "

Tags are unavailable at the moment

" - } - } - } +global.handler.fragmentsHandler.config { + tasks { + books-listing { + action = book + on { + _error { + action = book-inline-body-fallback + } + } + } + authors-listing { + action = author + on { + _error { + action = author-inline-payload-fallback + on._success { + action = te-hbs + } + } + } + } + books-and-authors-listing { + subtasks = [ + { + action = book + on._error { + action = book-inline-payload-fallback + } + }, + { + action = author + } + ] + on { + _error { + action = author-inline-payload-fallback + on._success { + action = te-hbs + } + } + } + } + } + + actions { + book { + factory = http + config.endpointOptions { + path = /service/broken/500.json + domain = localhost + port = ${test.random.mockBrokenService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + author { + factory = http + config.endpointOptions { + path = /service/broken/500.json + domain = localhost + port = ${test.random.mockBrokenService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + // fallbacks + author-inline-payload-fallback { + factory = inline-payload + config { + alias = author + payload { + _result { + name = "Knot X", + info { + portfolio = [ + "tutorials", + "blogs", + "books" + ], + bio = "Aliquam cursus fermentum mi, vel tempus mi pellentesque vel. Nunc in feugiat lorem. Etiam placerat ante eget sem euismod, sit amet dictum sapien vulputate. Morbi pellentesque arcu a mauris ornare eleifend." + } + } + _response { + metadata { + statusCode = 500 + } + } + } + } + } + book-inline-payload-fallback { + factory = inline-payload + config { + alias = book + payload { + _result { + title = "Knot.x Integration Tests in Practice" + info { + authors = "Knot.x Team" + } + } + _response { + metadata { + statusCode = 500 + } + } + } + } + } + book-inline-body-fallback { + factory = inline-body + config { + body = "

Tags are unavailable at the moment

" + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf b/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf index c728bbaf..6cc876e3 100644 --- a/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf +++ b/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf @@ -1,13 +1,13 @@ -global.handler.fragmentsHandler.config { - consumerFactories = [ - { - factory = fragmentHtmlBodyWriter - config { - condition { - param = debug - } - fragmentTypes = ["snippet"] - } - } - ] +global.handler.fragmentsHandler.config { + consumerFactories = [ + { + factory = fragmentHtmlBodyWriter + config { + condition { + param = debug + } + fragmentTypes = ["snippet"] + } + } + ] } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf b/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf index 07aa29e2..6dd46f38 100644 --- a/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf +++ b/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf @@ -1,14 +1,14 @@ -global.handler.fragmentsHandler.config { - consumerFactories = [ - { - factory = fragmentJsonBodyWriter - config { - condition { - param = debug - header = x-knotx-debug - } - fragmentTypes = ["json"] - } - } - ] +global.handler.fragmentsHandler.config { + consumerFactories = [ + { + factory = fragmentJsonBodyWriter + config { + condition { + param = debug + header = x-knotx-debug + } + fragmentTypes = ["json"] + } + } + ] } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf b/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf index 10299254..f5fbfcc5 100644 --- a/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf +++ b/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf @@ -1,169 +1,169 @@ -global.handler.fragmentsHandler.config { - tasks { - # HTML Templating Scenario - user-task { - action = fetch-user-info // _success - onTransitions._success { - action = te-hbs - } - } - # HTML Templating Scenario - payments-task { - action = fetch-user-info // _success - onTransitions._success { - actions = [ - { - action = fetch-payment-providers // _success - onTransitions._error { - action = fetch-payment-providers-fallback - } - } - { - action = fetch-offers // _error - onTransitions._error { - action = fetch-offers-fallback // _success - } - } - { - action = fetch-delivery-options-cb // 2 x 500 -> _fallback - onTransitions._fallback { - action = fetch-delivery-fallback // _success - } - } - { - action = notify-analytics-cb // 2 x timeout -> _fallback - onTransitions._fallback { - action = notify-analytics-fallback // _success - } - } - ] - onTransitions._success { - action = te-pebble // _success - } - } - onTransitions._error { - action = fetch-user-info-fallback - } - onTransitions._custom { - action = fetch-user-info-custom - } - } - # Web API Scenario - web-api-test = ${global.handler.fragmentsHandler.config.tasks.payments-task} - web-api-test.onTransitions._success.onTransitions._success.action = create-response // _success - } - - actions { - common-fallback-action { - factory = http - config.endpointOptions { - path = /service/mock/placeholderFallback.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.xml - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions { - forceJson = true - predicates = [] - } - } - fetch-offers-fallback { - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-delivery-options-cb { - factory = cb - config { - circuitBreakerName = delivery-cb - circuitBreakerOptions { - maxRetries = 1 - timeout = 50 - } - } - doAction = fetch-delivery - } - fetch-delivery { - factory = http - config.endpointOptions { - path = /mock/scenario/delayed - domain = localhost - port = ${test.random.delayedService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-delivery-fallback { - factory = inline-payload - config { - alias = fetch-delivery - payload { - _result { - fallback = "action ended with _timeout" - } - } - } - } - - notify-analytics-cb { - factory = cb - config { - circuitBreakerName = delivery-cb - } - doAction = notify-analytics - } - notify-analytics { - factory = http - config.httpMethod = POST - config.endpointOptions { - path = /mock/scenario/analytics - domain = localhost - port = ${test.random.brokenService.port} - bodyJson = { - user-data-id = "{payload.fetch-user-info._result.id}" - } - interpolateBody = true - allowedRequestHeaders = ["Content-Type"] - } - } - notify-analytics-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - - fetch-payment-providers-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - fetch-user-info-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - fetch-user-info-custom = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - } +global.handler.fragmentsHandler.config { + tasks { + # HTML Templating Scenario + user-task { + action = fetch-user-info // _success + on._success { + action = te-hbs + } + } + # HTML Templating Scenario + payments-task { + action = fetch-user-info // _success + on._success { + actions = [ + { + action = fetch-payment-providers // _success + on._error { + action = fetch-payment-providers-fallback + } + } + { + action = fetch-offers // _error + on._error { + action = fetch-offers-fallback // _success + } + } + { + action = fetch-delivery-options-cb // 2 x 500 -> _fallback + on._fallback { + action = fetch-delivery-fallback // _success + } + } + { + action = notify-analytics-cb // 2 x timeout -> _fallback + on._fallback { + action = notify-analytics-fallback // _success + } + } + ] + on._success { + action = te-pebble // _success + } + } + on._error { + action = fetch-user-info-fallback + } + on._custom { + action = fetch-user-info-custom + } + } + # Web API Scenario + web-api-test = ${global.handler.fragmentsHandler.config.tasks.payments-task} + web-api-test.onTransitions._success.onTransitions._success.action = create-response // _success + } + + actions { + common-fallback-action { + factory = http + config.endpointOptions { + path = /service/mock/placeholderFallback.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.xml + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions { + forceJson = true + predicates = [] + } + } + fetch-offers-fallback { + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-delivery-options-cb { + factory = cb + config { + circuitBreakerName = delivery-cb + circuitBreakerOptions { + maxRetries = 1 + timeout = 50 + } + } + doAction = fetch-delivery + } + fetch-delivery { + factory = http + config.endpointOptions { + path = /mock/scenario/delayed + domain = localhost + port = ${test.random.delayedService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-delivery-fallback { + factory = inline-payload + config { + alias = fetch-delivery + payload { + _result { + fallback = "action ended with _timeout" + } + } + } + } + + notify-analytics-cb { + factory = cb + config { + circuitBreakerName = delivery-cb + } + doAction = notify-analytics + } + notify-analytics { + factory = http + config.httpMethod = POST + config.endpointOptions { + path = /mock/scenario/analytics + domain = localhost + port = ${test.random.brokenService.port} + bodyJson = { + user-data-id = "{payload.fetch-user-info._result.id}" + } + interpolateBody = true + allowedRequestHeaders = ["Content-Type"] + } + } + notify-analytics-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + + fetch-payment-providers-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + fetch-user-info-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + fetch-user-info-custom = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf index 90739f4f..11a65af1 100644 --- a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf +++ b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf index 2b3fed83..ef3cf2c3 100644 --- a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf +++ b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf @@ -1,68 +1,68 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = fetch-user-info - onTransitions._success { - actions = [ - { - action = fetch-payment-providers - } - { - action = fetch-offers - onTransitions._error { - action = fetch-offers-fallback - } - } - ] - onTransitions._success { - action = create-response - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = "/service/mock/paymentProviders.{param.group}.json" - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { // invalid format - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.xml - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions { - forceJson = true - predicates = [] - } - } - fetch-offers-fallback { - factory = inline-payload - config { - alias = fetch-offers - payload { - _result { - fallback = "json-syntax-error" - } - } - } - } - } +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = fetch-user-info + on._success { + actions = [ + { + action = fetch-payment-providers + } + { + action = fetch-offers + on._error { + action = fetch-offers-fallback + } + } + ] + on._success { + action = create-response + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = "/service/mock/paymentProviders.{param.group}.json" + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { // invalid format + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.xml + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions { + forceJson = true + predicates = [] + } + } + fetch-offers-fallback { + factory = inline-payload + config { + alias = fetch-offers + payload { + _result { + fallback = "json-syntax-error" + } + } + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf index bf284a45..a07c0fd1 100644 --- a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf +++ b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - delayedService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + delayedService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf index f69bc586..65ae7873 100644 --- a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf +++ b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf @@ -1,99 +1,99 @@ -global.handler.fragmentsHandler.config { - tasks { - books-listing { - action = book-with-circuit-breaker - onTransitions._fallback { - action = book-inline-body-fallback - } - } - authors-listing { - action = author - onTransitions { - _success { - action = te-hbs - } - } - } - books-and-authors-listing { - actions = [ - { - action = book-with-circuit-breaker - onTransitions._fallback { - action = book-inline-payload-fallback - } - }, - { - action = author - } - ] - onTransitions { - _success { - action = te-hbs - } - } - } - } - - actions { - book-with-circuit-breaker { - factory = cb - config { - circuitBreakerName = "Circuit Breaker: book service" - circuitBreakerOptions { - timeout = 1000 - maxFailures = 1 - resetTimeout = 10000 - } - } - doAction = book - } - book { - factory = http - config { - endpointOptions { - path = /service/mock/delayed - domain = localhost - port = ${test.random.delayedService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - author { - factory = http - config { - endpointOptions { - path = /service/mock/author.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - // fallbacks - book-inline-payload-fallback { - factory = inline-payload - config { - alias = book - payload { - _result { - title = "Knot.x Integration Tests in Practice" - info { - authors = "Knot.x Team" - } - } - _response { - metadata { - statusCode = 500 - } - } - } - } - } - book-inline-body-fallback { - factory = inline-body - config { - body = "

Tags are unavailable at the moment

" - } - } - } +global.handler.fragmentsHandler.config { + tasks { + books-listing { + action = book-with-circuit-breaker + on._fallback { + action = book-inline-body-fallback + } + } + authors-listing { + action = author + on { + _success { + action = te-hbs + } + } + } + books-and-authors-listing { + actions = [ + { + action = book-with-circuit-breaker + on._fallback { + action = book-inline-payload-fallback + } + }, + { + action = author + } + ] + on { + _success { + action = te-hbs + } + } + } + } + + actions { + book-with-circuit-breaker { + factory = cb + config { + circuitBreakerName = "Circuit Breaker: book service" + circuitBreakerOptions { + timeout = 1000 + maxFailures = 1 + resetTimeout = 10000 + } + } + doAction = book + } + book { + factory = http + config { + endpointOptions { + path = /service/mock/delayed + domain = localhost + port = ${test.random.delayedService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + author { + factory = http + config { + endpointOptions { + path = /service/mock/author.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + // fallbacks + book-inline-payload-fallback { + factory = inline-payload + config { + alias = book + payload { + _result { + title = "Knot.x Integration Tests in Practice" + info { + authors = "Knot.x Team" + } + } + _response { + metadata { + statusCode = 500 + } + } + } + } + } + book-inline-body-fallback { + factory = inline-body + config { + body = "

Tags are unavailable at the moment

" + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf b/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf index 90739f4f..11a65af1 100644 --- a/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf +++ b/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf b/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf index ba9ab1e5..b72d8e44 100644 --- a/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf +++ b/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf @@ -1,71 +1,71 @@ -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" ] - } - } - } - } -} +global.handler.fragmentsHandler.config { + tasks { + tags-listing { + action = tags + on { + _success { + action = te-pebble + } + _error { + action = tags-fallback + } + } + } + books-listing { + action = book + on { + _success { + action = te-pebble + } + } + } + authors-listing { + action = author + on { + _success { + action = te-pebble + } + } + } + books-and-authors-listing { + actions = [ + { + action = book + }, + { + action = author + } + ] + on { + _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" ] + } + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf index e9a7d994..88eb554d 100644 --- a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf +++ b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf @@ -1,32 +1,32 @@ -global.handler.httpRepoConnectorHandler.config { - clientOptions { - maxPoolSize = 1000 - idleTimeout = 120 - tryUseCompression = true - # do not follow redirects to pass it to the end user - followRedirects = false - } - - clientDestination { - scheme = http - domain = localhost - port = ${test.random.httpRepository.port} - } - - allowedRequestHeaders = [ - "Accept.*" - Authorization - Connection - Cookie - Date - "Edge.*" - "If.*" - Origin - Pragma - Proxy-Authorization - "Surrogate.*" - User-Agent - Via - "X-.*" - ] +global.handler.httpRepoConnectorHandler.config { + clientOptions { + maxPoolSize = 1000 + idleTimeout = 120 + tryUseCompression = true + # do not follow redirects to pass it to the end user + followRedirects = false + } + + clientDestination { + scheme = http + domain = localhost + port = ${test.random.httpRepository.port} + } + + allowedRequestHeaders = [ + "Accept.*" + Authorization + Connection + Cookie + Date + "Edge.*" + "If.*" + Origin + Pragma + Proxy-Authorization + "Surrogate.*" + User-Agent + Via + "X-.*" + ] } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf index 3e6c99eb..75fa9313 100644 --- a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf +++ b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.random { - httpRepository.port = 0 +########### Knot.x JUnit5 config ########### +test.random { + httpRepository.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf b/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf index 90739f4f..11a65af1 100644 --- a/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf +++ b/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf b/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf index 743d374e..a3aac467 100644 --- a/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf +++ b/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf @@ -1,60 +1,60 @@ -global.handler.fragmentsHandler.config { - tasks { - user-task { - action = fetch-user-info // _success - onTransitions._success { - action = te-hbs - } - } - payments-task { - action = fetch-user-info // _success - onTransitions._success { - actions = [ - { - action = fetch-payment-providers // _success - } - { - action = fetch-offers // _success - } - ] - onTransitions._success { - action = te-pebble // _success - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions { - forceJson = true - predicates = [] - } - } - } +global.handler.fragmentsHandler.config { + tasks { + user-task { + action = fetch-user-info // _success + on._success { + action = te-hbs + } + } + payments-task { + action = fetch-user-info // _success + on._success { + actions = [ + { + action = fetch-payment-providers // _success + } + { + action = fetch-offers // _success + } + ] + on._success { + action = te-pebble // _success + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions { + forceJson = true + predicates = [] + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf b/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf index 8969461c..48ae0dc9 100644 --- a/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf +++ b/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - service.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + service.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf b/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf index a92dc3ae..f678d203 100644 --- a/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf +++ b/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf @@ -1,113 +1,113 @@ -global.handler.fragmentsHandler.config { - tasks { - various-methods-for-http-action { - actions = [ - { - action = get - } - { - action = post - } - { - action = put - } - { - action = patch - } - { - action = delete - } - { - action = head - } - ] - onTransitions._success { - action = te-hbs - } - } - } - - actions { - get { - factory = http - config { - httpMethod = get - endpointOptions { - path = /service/mock/get.json - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - responseOptions { - forceJson = true - } - } - } - post { - factory = http - config { - httpMethod = post - endpointOptions { - path = /service/mock/post.json - body = "{\"password\": \"pazzword\"}" - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - put { - factory = http - config { - httpMethod = put - endpointOptions { - path = /service/mock/put.json - interpolateBody = true - bodyJson { - password = pazzword - } - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - patch { - factory = http - config { - httpMethod = patch - endpointOptions { - path = /service/mock/patch.json - body = "{\"password\": \"pazzword\"}" - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - delete { - factory = http - config { - httpMethod = delete - endpointOptions { - path = /service/mock/delete.json - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - head { - factory = http - config { - httpMethod = head - endpointOptions { - path = /service/mock/head.json - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - } -} +global.handler.fragmentsHandler.config { + tasks { + various-methods-for-http-action { + actions = [ + { + action = get + } + { + action = post + } + { + action = put + } + { + action = patch + } + { + action = delete + } + { + action = head + } + ] + on._success { + action = te-hbs + } + } + } + + actions { + get { + factory = http + config { + httpMethod = get + endpointOptions { + path = /service/mock/get.json + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + responseOptions { + forceJson = true + } + } + } + post { + factory = http + config { + httpMethod = post + endpointOptions { + path = /service/mock/post.json + body = "{\"password\": \"pazzword\"}" + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + put { + factory = http + config { + httpMethod = put + endpointOptions { + path = /service/mock/put.json + interpolateBody = true + bodyJson { + password = pazzword + } + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + patch { + factory = http + config { + httpMethod = patch + endpointOptions { + path = /service/mock/patch.json + body = "{\"password\": \"pazzword\"}" + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + delete { + factory = http + config { + httpMethod = delete + endpointOptions { + path = /service/mock/delete.json + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + head { + factory = http + config { + httpMethod = head + endpointOptions { + path = /service/mock/head.json + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + } +} diff --git a/src/main/packaging/conf/server.conf b/src/main/packaging/conf/server.conf index 08967e30..4cc2532f 100644 --- a/src/main/packaging/conf/server.conf +++ b/src/main/packaging/conf/server.conf @@ -1,95 +1,95 @@ -########### Knot.x Server ########### -modules { - server = "io.knotx.server.KnotxServerVerticle" -} - -########### Modules configurations ########### -config.server { - handlers.common { - request = [ - { - name = bodyHandler - }, - { - name = requestContextHandler - } - ], - response = [ - { - name = headerHandler - # Statically defined HTTP response header returned to the client in every HTTP response - config { - name = X-Server - value = Knot.x-Custom-Header - } - }, - { - name = writerHandler - # List of HTTP response headers Knot.x can return to the client - config.allowedResponseHeaders = [ - Access-Control-Allow-Origin - Content-Type - Content-Length - Location - ] - } - ] - } - options.config { - # Configuraiton of HTTP server - serverOptions { - # Knot.x server HTTP port - port = 8092 - - # If you want a server to serve SSL connections you can configure it here - # - # Enable SSL - # ssl = true - # - # Path on the server the keystore.jks file is located - # keyStoreOptions.path = - # - # Keystore password - # keyStoreOptions.password = - } - - # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). - routingSpecificationLocation = /openapi.yaml - - displayExceptionDetails = true - dropRequestOptions { - # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details - enabled = false - - # Status code that is served if the response is dropped, default is 429, "Too Many Requests" - # dropRequestResponseCode = - - # Number of request that single Server insance can support concurrently. Default value is 1000. - # backpressureBufferCapacity - - # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. - # backpressureStrategy = - } - - routingOperations = [] - include required(classpath("routes/operations.conf")) - - # Global handlers section - globalHandlers = [ - # access log, by default logged to the knotx-access.log in the logs directory - { - name = loggerHandler - config { - immediate = true - format = DEFAULT - } - } - ] - } - - # The options object carries-on configuration called DeploymentOptions for a given verticle. - # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. - # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions - # - # options {} -} +########### Knot.x Server ########### +modules { + server = "io.knotx.server.KnotxServerVerticle" +} + +########### Modules configurations ########### +config.server { + handlers.common { + request = [ + { + name = bodyHandler + }, + { + name = requestContextHandler + } + ], + response = [ + { + name = headerHandler + # Statically defined HTTP response header returned to the client in every HTTP response + config { + name = X-Server + value = Knot.x-Custom-Header + } + }, + { + name = writerHandler + # List of HTTP response headers Knot.x can return to the client + config.allowedResponseHeaders = [ + Access-Control-Allow-Origin + Content-Type + Content-Length + Location + ] + } + ] + } + options.config { + # Configuraiton of HTTP server + serverOptions { + # Knot.x server HTTP port + port = 8092 + + # If you want a server to serve SSL connections you can configure it here + # + # Enable SSL + # ssl = true + # + # Path on the server the keystore.jks file is located + # keyStoreOptions.path = + # + # Keystore password + # keyStoreOptions.password = + } + + # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). + routingSpecificationLocation = /openapi.yaml + + displayExceptionDetails = true + dropRequestOptions { + # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details + enabled = false + + # Status code that is served if the response is dropped, default is 429, "Too Many Requests" + # dropRequestResponseCode = + + # Number of request that single Server insance can support concurrently. Default value is 1000. + # backpressureBufferCapacity + + # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. + # backpressureStrategy = + } + + routingOperations = [] + include required(classpath("routes/operations.conf")) + + # Global handlers section + globalHandlers = [ + # access log, by default logged to the knotx-access.log in the logs directory + { + name = loggerHandler + config { + immediate = true + format = DEFAULT + } + } + ] + } + + # The options object carries-on configuration called DeploymentOptions for a given verticle. + # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. + # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions + # + # options {} +} diff --git a/src/test/java/io/knotx/stack/KnotxServerTester.java b/src/test/java/io/knotx/stack/KnotxServerTester.java index 5c4036df..8cbe894a 100644 --- a/src/test/java/io/knotx/stack/KnotxServerTester.java +++ b/src/test/java/io/knotx/stack/KnotxServerTester.java @@ -1,97 +1,97 @@ -/* - * 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; - -import static io.knotx.junit5.util.RequestUtil.subscribeToResult_shouldSucceed; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import io.knotx.junit5.assertions.HtmlMarkupAssertions; -import io.knotx.junit5.util.FileReader; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.reactivex.Single; -import io.reactivex.functions.Consumer; -import io.vertx.ext.web.client.WebClientOptions; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.MultiMap; -import io.vertx.reactivex.core.Vertx; -import io.vertx.reactivex.core.buffer.Buffer; -import io.vertx.reactivex.ext.web.client.HttpResponse; -import io.vertx.reactivex.ext.web.client.WebClient; -import java.util.Collections; -import java.util.Map; - -public final class KnotxServerTester { - - private static final int KNOTX_TESTS_SERVER_PORT_DEFAULT = 8092; - private static final String KNOTX_TESTS_SERVER_ADDRESS_DEFAULT = "localhost"; - - private final String serverHost; - private final int serverPort; - - private WebClientOptions clientOptions = new WebClientOptions(); - private Map headers = Collections.emptyMap(); - - private KnotxServerTester(String serverHost, int serverPort) { - this.serverHost = serverHost; - this.serverPort = serverPort; - } - - public static KnotxServerTester defaultInstance() { - return defaultInstance(KNOTX_TESTS_SERVER_PORT_DEFAULT); - } - - public static KnotxServerTester defaultInstance(int port) { - return new KnotxServerTester(KNOTX_TESTS_SERVER_ADDRESS_DEFAULT, port); - } - - public KnotxServerTester withClientOptions(WebClientOptions clientOptions) { - this.clientOptions = clientOptions; - return this; - } - - public KnotxServerTester withRequestHeaders(Map headers) { - this.headers = headers; - return this; - } - - public void testGetWithExpectedResponse(VertxTestContext context, Vertx vertx, String url, - String expectedResponseFile) { - testGet(context, vertx, url, resp -> { - assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); - HtmlMarkupAssertions.assertHtmlBodyMarkupsEqual(FileReader.readTextSafe(expectedResponseFile), - resp.body().toString()); - }); - } - - public void testGet(VertxTestContext context, Vertx vertx, String url, - Consumer> assertions) { - MultiMap headersMultiMap = MultiMap.caseInsensitiveMultiMap(); - headersMultiMap.addAll(headers); - - WebClient client = WebClient.create(vertx, clientOptions); - Single> httpResponseSingle = client - .get(serverPort, serverHost, url) - .putHeaders(headersMultiMap) - .rxSend(); - - subscribeToResult_shouldSucceed(context, httpResponseSingle, - resp -> { - assertions.accept(resp); - client.close(); - }); - } - -} +/* + * 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; + +import static io.knotx.junit5.util.RequestUtil.subscribeToResult_shouldSucceed; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.knotx.junit5.assertions.HtmlMarkupAssertions; +import io.knotx.junit5.util.FileReader; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.reactivex.Single; +import io.reactivex.functions.Consumer; +import io.vertx.ext.web.client.WebClientOptions; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.MultiMap; +import io.vertx.reactivex.core.Vertx; +import io.vertx.reactivex.core.buffer.Buffer; +import io.vertx.reactivex.ext.web.client.HttpResponse; +import io.vertx.reactivex.ext.web.client.WebClient; +import java.util.Collections; +import java.util.Map; + +public final class KnotxServerTester { + + private static final int KNOTX_TESTS_SERVER_PORT_DEFAULT = 8092; + private static final String KNOTX_TESTS_SERVER_ADDRESS_DEFAULT = "localhost"; + + private final String serverHost; + private final int serverPort; + + private WebClientOptions clientOptions = new WebClientOptions(); + private Map headers = Collections.emptyMap(); + + private KnotxServerTester(String serverHost, int serverPort) { + this.serverHost = serverHost; + this.serverPort = serverPort; + } + + public static KnotxServerTester defaultInstance() { + return defaultInstance(KNOTX_TESTS_SERVER_PORT_DEFAULT); + } + + public static KnotxServerTester defaultInstance(int port) { + return new KnotxServerTester(KNOTX_TESTS_SERVER_ADDRESS_DEFAULT, port); + } + + public KnotxServerTester withClientOptions(WebClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + public KnotxServerTester withRequestHeaders(Map headers) { + this.headers = headers; + return this; + } + + public void testGetWithExpectedResponse(VertxTestContext context, Vertx vertx, String url, + String expectedResponseFile) { + testGet(context, vertx, url, resp -> { + assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); + HtmlMarkupAssertions.assertHtmlBodyMarkupsEqual(FileReader.readTextSafe(expectedResponseFile), + resp.body().toString()); + }); + } + + public void testGet(VertxTestContext context, Vertx vertx, String url, + Consumer> assertions) { + MultiMap headersMultiMap = MultiMap.caseInsensitiveMultiMap(); + headersMultiMap.addAll(headers); + + WebClient client = WebClient.create(vertx, clientOptions); + Single> httpResponseSingle = client + .get(serverPort, serverHost, url) + .putHeaders(headersMultiMap) + .rxSend(); + + subscribeToResult_shouldSucceed(context, httpResponseSingle, + resp -> { + assertions.accept(resp); + client.close(); + }); + } + +} From 7b8894ea4c0b7942c84940e4eabcd9096020db74 Mon Sep 17 00:00:00 2001 From: "filip.kowalski" Date: Wed, 15 Jul 2020 15:44:39 +0200 Subject: [PATCH 2/4] #146 Fix line endings --- .github/PULL_REQUEST_TEMPLATE.md | 58 ++--- CODE_OF_CONDUCT.md | 2 +- CONTRIBUTING.md | 2 +- ...BreakerTimesOutAndRetriesScenarioTest.java | 174 +++++++-------- ...pServicesWithFallbacksIntegrationTest.java | 146 ++++++------- ...viceWithCircuitBreakerIntegrationTest.java | 160 +++++++------- .../PebbleTemplateEngineIntegrationTest.java | 96 ++++---- ...yConnectorRedirectPassedToEndUserTest.java | 194 ++++++++--------- .../TemplateEnginesIntegrationTest.java | 90 ++++---- .../resources/common/api/fragments.conf | 12 +- .../resources/common/api/routing.conf | 46 ++-- .../common/templating/fragments.conf | 42 ++-- .../resources/common/templating/routing.conf | 56 ++--- .../routes/handlers/fragmentsHandler.conf | 86 ++++---- .../handlers/httpRepoConnectorHandler.conf | 120 +++++----- src/functionalTest/resources/conf/server.conf | 206 +++++++++--------- .../resources/content/failedFragment.html | 58 ++--- src/functionalTest/resources/openapi.yaml | 84 +++---- .../mocks.conf | 14 +- .../circuit-breaker-times-out/mocks.conf | 14 +- .../mocks.conf | 16 +- .../failed-knotx-fragment/mocks.conf | 14 +- .../mocks.conf | 8 +- .../fragments-debug-data/debugHtml.conf | 24 +- .../fragments-debug-data/debugJson.conf | 26 +-- .../mocks.conf | 6 +- .../mocks.conf | 14 +- .../pebble-template-engine/mocks.conf | 6 +- .../httpRepoConnectorHandler.conf | 62 +++--- .../mocks.conf | 6 +- .../template-engines-integration/mocks.conf | 6 +- .../mocks.conf | 14 +- src/main/packaging/conf/server.conf | 190 ++++++++-------- .../io/knotx/stack/KnotxServerTester.java | 194 ++++++++--------- 34 files changed, 1123 insertions(+), 1123 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index be16ddd2..1e941626 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,29 +1,29 @@ - - -## Description - - -## Motivation and Context - - - -## Screenshots (if appropriate) - -## Upgrade notes (if appropriate) - - -## Types of changes - -- [ ] Bug fix (non-breaking change which fixes an issue) -- [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - -## Checklist: - - -- [ ] I have read the [CONTRIBUTING](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md) document. -- [ ] My change requires a change to the documentation. -- [ ] I have updated the documentation accordingly. - ---- -I hereby agree to the terms of the Knot.x Contributor License Agreement. + + +## Description + + +## Motivation and Context + + + +## Screenshots (if appropriate) + +## Upgrade notes (if appropriate) + + +## Types of changes + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) + +## Checklist: + + +- [ ] I have read the [CONTRIBUTING](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md) document. +- [ ] My change requires a change to the documentation. +- [ ] I have updated the documentation accordingly. + +--- +I hereby agree to the terms of the Knot.x Contributor License Agreement. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 936a18e2..b7c9bebc 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1 +1 @@ -Please refer to the main [Knot.x Code of Conduct](https://github.com/Knotx/knotx/blob/master/CODE_OF_CONDUCT.md). +Please refer to the main [Knot.x Code of Conduct](https://github.com/Knotx/knotx/blob/master/CODE_OF_CONDUCT.md). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ca7425f..e85eef88 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1 +1 @@ -Please refer to the main [Knot.x contributing guide](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md). +Please refer to the main [Knot.x contributing guide](https://github.com/Knotx/knotx/blob/master/CONTRIBUTING.md). diff --git a/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java b/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java index 77a1a8ea..7e496e06 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/CircuitBreakerTimesOutAndRetriesScenarioTest.java @@ -1,87 +1,87 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.junit5.util.FileReader; -import io.knotx.stack.KnotxServerTester; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.vertx.core.json.JsonObject; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class CircuitBreakerTimesOutAndRetriesScenarioTest { - - private static final String SCENARIO_NAME = "Circuit breaker times out HTTP Action and retries."; - private static final String RETRY_SCENARIO_STATE = "RETRY"; - - private WireMockServer scenarioMockService; - - @Test - @DisplayName("Expect offers from second service invocation (retry) following the first attempt timeout.") - @KnotxApplyConfiguration({"conf/application.conf", - "common/api/routing.conf", - "common/api/fragments.conf", - "scenarios/circuit-breaker-times-out-and-retries/mocks.conf", - "scenarios/circuit-breaker-times-out-and-retries/tasks.conf"}) - void requestApi(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer scenarioServicePort, @RandomPort Integer globalServerPort) { - scenarioMockService = new WireMockServer(scenarioServicePort); - scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) - .whenScenarioStateIs(STARTED) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withFixedDelay(100) - .withBody(FileReader.readTextSafe("service/mock/emptyOffers.json"))) - .willSetStateTo(RETRY_SCENARIO_STATE)); - scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) - .whenScenarioStateIs(RETRY_SCENARIO_STATE) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBody(FileReader.readTextSafe("service/mock/specialOffers.json")))); - scenarioMockService.start(); - - KnotxServerTester.defaultInstance(globalServerPort) - .testGet(testContext, vertx, "/api/user", resp -> { - assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); - JsonObject response = resp.body().toJsonObject(); - assertNotNull(response); - assertEquals(5, response.getJsonObject("fetch-offers").getJsonArray("_result").size()); - }); - } - - @AfterEach - void tearDown() { - scenarioMockService.stop(); - } -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.junit5.util.FileReader; +import io.knotx.stack.KnotxServerTester; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.json.JsonObject; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class CircuitBreakerTimesOutAndRetriesScenarioTest { + + private static final String SCENARIO_NAME = "Circuit breaker times out HTTP Action and retries."; + private static final String RETRY_SCENARIO_STATE = "RETRY"; + + private WireMockServer scenarioMockService; + + @Test + @DisplayName("Expect offers from second service invocation (retry) following the first attempt timeout.") + @KnotxApplyConfiguration({"conf/application.conf", + "common/api/routing.conf", + "common/api/fragments.conf", + "scenarios/circuit-breaker-times-out-and-retries/mocks.conf", + "scenarios/circuit-breaker-times-out-and-retries/tasks.conf"}) + void requestApi(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer scenarioServicePort, @RandomPort Integer globalServerPort) { + scenarioMockService = new WireMockServer(scenarioServicePort); + scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) + .whenScenarioStateIs(STARTED) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withFixedDelay(100) + .withBody(FileReader.readTextSafe("service/mock/emptyOffers.json"))) + .willSetStateTo(RETRY_SCENARIO_STATE)); + scenarioMockService.stubFor(get(urlEqualTo("/service/mock/scenario")).inScenario(SCENARIO_NAME) + .whenScenarioStateIs(RETRY_SCENARIO_STATE) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(FileReader.readTextSafe("service/mock/specialOffers.json")))); + scenarioMockService.start(); + + KnotxServerTester.defaultInstance(globalServerPort) + .testGet(testContext, vertx, "/api/user", resp -> { + assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); + JsonObject response = resp.body().toJsonObject(); + assertNotNull(response); + assertEquals(5, response.getJsonObject("fetch-offers").getJsonArray("_result").size()); + }); + } + + @AfterEach + void tearDown() { + scenarioMockService.stop(); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java index fbfa83ac..13331618 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/FailingHttpServicesWithFallbacksIntegrationTest.java @@ -1,73 +1,73 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; -import io.knotx.stack.KnotxServerTester; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class FailingHttpServicesWithFallbacksIntegrationTest { - - @ClasspathResourcesMockServer - private WireMockServer mockRepository; - - private WireMockServer mockBrokenService; - - @AfterEach - void tearDown() { - mockBrokenService.stop(); - } - - @Test - @DisplayName("Expect page containing data from services and fallback data for broken service.") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/failing-http-services-with-fallbacks/mocks.conf", - "scenarios/failing-http-services-with-fallbacks/tasks.conf"}) - void requestPage(VertxTestContext context, Vertx vertx, @RandomPort Integer mockBrokenServicePort, - @RandomPort Integer globalServerPort) { - // when - mockBrokenService = new WireMockServer(mockBrokenServicePort); - mockBrokenService.stubFor(get(urlMatching("/service/broken/500.json")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) - )); - mockBrokenService.start(); - - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester - .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", - "scenarios/failing-http-services-with-fallbacks/result/fullPage.html"); - } -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; +import io.knotx.stack.KnotxServerTester; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class FailingHttpServicesWithFallbacksIntegrationTest { + + @ClasspathResourcesMockServer + private WireMockServer mockRepository; + + private WireMockServer mockBrokenService; + + @AfterEach + void tearDown() { + mockBrokenService.stop(); + } + + @Test + @DisplayName("Expect page containing data from services and fallback data for broken service.") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/failing-http-services-with-fallbacks/mocks.conf", + "scenarios/failing-http-services-with-fallbacks/tasks.conf"}) + void requestPage(VertxTestContext context, Vertx vertx, @RandomPort Integer mockBrokenServicePort, + @RandomPort Integer globalServerPort) { + // when + mockBrokenService = new WireMockServer(mockBrokenServicePort); + mockBrokenService.stubFor(get(urlMatching("/service/broken/500.json")) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) + )); + mockBrokenService.start(); + + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester + .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", + "scenarios/failing-http-services-with-fallbacks/result/fullPage.html"); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java index 8bb423e8..1586cd7c 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/LongRunningHttpServiceWithCircuitBreakerIntegrationTest.java @@ -1,80 +1,80 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; -import io.knotx.stack.KnotxServerTester; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -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 LongRunningHttpServiceWithCircuitBreakerIntegrationTest { - - @ClasspathResourcesMockServer - private WireMockServer mockService; - - @ClasspathResourcesMockServer - private WireMockServer mockRepository; - - private WireMockServer delayedServiceServer; - - @AfterEach - void tearDown() { - delayedServiceServer.stop(); - } - - @Test - @DisplayName("Expect page containing data from services and fallback data for broken service.") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/long-running-http-service-with-circuit-breaker/mocks.conf", - "scenarios/long-running-http-service-with-circuit-breaker/tasks.conf"}) - void taskWithCircuitBreaker(VertxTestContext context, Vertx vertx, - @RandomPort Integer delayedServicePort, - @RandomPort Integer globalServerPort) { - // given - delayedServiceServer = new WireMockServer(delayedServicePort); - delayedServiceServer.stubFor(get(urlEqualTo("/service/mock/delayed")).willReturn( - aResponse() - .withStatus(200) - .withFixedDelay(2000))); - delayedServiceServer.start(); - - // when - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester - .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", - "scenarios/long-running-http-service-with-circuit-breaker/result/fullPage.html"); - } - -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.junit5.wiremock.ClasspathResourcesMockServer; +import io.knotx.stack.KnotxServerTester; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +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 LongRunningHttpServiceWithCircuitBreakerIntegrationTest { + + @ClasspathResourcesMockServer + private WireMockServer mockService; + + @ClasspathResourcesMockServer + private WireMockServer mockRepository; + + private WireMockServer delayedServiceServer; + + @AfterEach + void tearDown() { + delayedServiceServer.stop(); + } + + @Test + @DisplayName("Expect page containing data from services and fallback data for broken service.") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/long-running-http-service-with-circuit-breaker/mocks.conf", + "scenarios/long-running-http-service-with-circuit-breaker/tasks.conf"}) + void taskWithCircuitBreaker(VertxTestContext context, Vertx vertx, + @RandomPort Integer delayedServicePort, + @RandomPort Integer globalServerPort) { + // given + delayedServiceServer = new WireMockServer(delayedServicePort); + delayedServiceServer.stubFor(get(urlEqualTo("/service/mock/delayed")).willReturn( + aResponse() + .withStatus(200) + .withFixedDelay(2000))); + delayedServiceServer.start(); + + // when + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester + .testGetWithExpectedResponse(context, vertx, "/content/fullPage.html", + "scenarios/long-running-http-service-with-circuit-breaker/result/fullPage.html"); + } + +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java index a6a0a68e..2523a019 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/PebbleTemplateEngineIntegrationTest.java @@ -1,48 +1,48 @@ -/* - * 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", - "common/templating/routing.conf", - "common/templating/fragments.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.testGetWithExpectedResponse(context, vertx, - "/content/fullPebblePage.html", "results/fullPage.html"); - } -} +/* + * 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", + "common/templating/routing.conf", + "common/templating/fragments.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.testGetWithExpectedResponse(context, vertx, + "/content/fullPebblePage.html", "results/fullPage.html"); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java b/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java index 21316a94..2b769b67 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/RepositoryConnectorRedirectPassedToEndUserTest.java @@ -1,97 +1,97 @@ -/* - * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.github.tomakehurst.wiremock.WireMockServer; -import io.knotx.junit5.KnotxApplyConfiguration; -import io.knotx.junit5.KnotxExtension; -import io.knotx.junit5.RandomPort; -import io.knotx.stack.KnotxServerTester; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.vertx.ext.web.client.WebClientOptions; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.Vertx; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class RepositoryConnectorRedirectPassedToEndUserTest { - - private WireMockServer httpRepositoryServer; - - - - @Test - @DisplayName("Should return redirect response when Http Repository returns redirect with empty body (AEM author login redirect case)") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) - void requestAemAuthorResourceLoginRedirect(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { - httpRepositoryServer = new WireMockServer(httpRepositoryPort); - httpRepositoryServer.stubFor(get(urlEqualTo("/admin-panel.html")).willReturn( - aResponse() - .withStatus(HttpResponseStatus.FOUND.code()) - .withHeader("location", "/login.html"))); - httpRepositoryServer.start(); - - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester - .withClientOptions(new WebClientOptions().setFollowRedirects(false)) - .testGet(testContext, vertx, "/admin-panel.html", - resp -> { - assertEquals(HttpResponseStatus.FOUND.code(), resp.statusCode()); - assertEquals("/login.html", resp.getHeader("location")); - }); - } - - @Test - @DisplayName("Should return not-found response when Http Repository returns 404 with empty body (AEM author login redirect case)") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", - "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) - void requestRepositoryGetNotFound(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { - httpRepositoryServer = new WireMockServer(httpRepositoryPort); - httpRepositoryServer.stubFor(get(urlEqualTo("/not-existing.html")).willReturn( - aResponse() - .withStatus(HttpResponseStatus.NOT_FOUND.code())) - ); - httpRepositoryServer.start(); - - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester.testGet(testContext, vertx, "/not-existing.html", - resp -> { - assertEquals(HttpResponseStatus.NOT_FOUND.code(), resp.statusCode()); - }); - } - - @AfterEach - void tearDown() { - httpRepositoryServer.stop(); - } -} +/* + * 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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.github.tomakehurst.wiremock.WireMockServer; +import io.knotx.junit5.KnotxApplyConfiguration; +import io.knotx.junit5.KnotxExtension; +import io.knotx.junit5.RandomPort; +import io.knotx.stack.KnotxServerTester; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.ext.web.client.WebClientOptions; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.Vertx; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class RepositoryConnectorRedirectPassedToEndUserTest { + + private WireMockServer httpRepositoryServer; + + + + @Test + @DisplayName("Should return redirect response when Http Repository returns redirect with empty body (AEM author login redirect case)") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) + void requestAemAuthorResourceLoginRedirect(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { + httpRepositoryServer = new WireMockServer(httpRepositoryPort); + httpRepositoryServer.stubFor(get(urlEqualTo("/admin-panel.html")).willReturn( + aResponse() + .withStatus(HttpResponseStatus.FOUND.code()) + .withHeader("location", "/login.html"))); + httpRepositoryServer.start(); + + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester + .withClientOptions(new WebClientOptions().setFollowRedirects(false)) + .testGet(testContext, vertx, "/admin-panel.html", + resp -> { + assertEquals(HttpResponseStatus.FOUND.code(), resp.statusCode()); + assertEquals("/login.html", resp.getHeader("location")); + }); + } + + @Test + @DisplayName("Should return not-found response when Http Repository returns 404 with empty body (AEM author login redirect case)") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf", + "scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf"}) + void requestRepositoryGetNotFound(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer httpRepositoryPort, @RandomPort Integer globalServerPort) { + httpRepositoryServer = new WireMockServer(httpRepositoryPort); + httpRepositoryServer.stubFor(get(urlEqualTo("/not-existing.html")).willReturn( + aResponse() + .withStatus(HttpResponseStatus.NOT_FOUND.code())) + ); + httpRepositoryServer.start(); + + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester.testGet(testContext, vertx, "/not-existing.html", + resp -> { + assertEquals(HttpResponseStatus.NOT_FOUND.code(), resp.statusCode()); + }); + } + + @AfterEach + void tearDown() { + httpRepositoryServer.stop(); + } +} diff --git a/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java b/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java index cefd8c9f..d8c6d0d2 100644 --- a/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java +++ b/src/functionalTest/java/io/knotx/stack/functional/TemplateEnginesIntegrationTest.java @@ -1,45 +1,45 @@ -/* - * 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.extension.ExtendWith; - -@ExtendWith(KnotxExtension.class) -class TemplateEnginesIntegrationTest { - - @Test - @DisplayName("Should return page properly processed by handlebars") - @KnotxApplyConfiguration({"conf/application.conf", - "common/templating/routing.conf", - "common/templating/fragments.conf", - "scenarios/template-engines-integration/mocks.conf", - "scenarios/template-engines-integration/tasks.conf", - "scenarios/template-engines-integration/pebble.conf"}) - void requestPage(VertxTestContext testContext, Vertx vertx, - @RandomPort Integer globalServerPort) { - KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); - serverTester.testGetWithExpectedResponse(testContext, vertx, "/content/payments.html", - "scenarios/template-engines-integration/resultPage.html"); - } -} +/* + * 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.extension.ExtendWith; + +@ExtendWith(KnotxExtension.class) +class TemplateEnginesIntegrationTest { + + @Test + @DisplayName("Should return page properly processed by handlebars") + @KnotxApplyConfiguration({"conf/application.conf", + "common/templating/routing.conf", + "common/templating/fragments.conf", + "scenarios/template-engines-integration/mocks.conf", + "scenarios/template-engines-integration/tasks.conf", + "scenarios/template-engines-integration/pebble.conf"}) + void requestPage(VertxTestContext testContext, Vertx vertx, + @RandomPort Integer globalServerPort) { + KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort); + serverTester.testGetWithExpectedResponse(testContext, vertx, "/content/payments.html", + "scenarios/template-engines-integration/resultPage.html"); + } +} diff --git a/src/functionalTest/resources/common/api/fragments.conf b/src/functionalTest/resources/common/api/fragments.conf index e26e6bc4..b04676d6 100644 --- a/src/functionalTest/resources/common/api/fragments.conf +++ b/src/functionalTest/resources/common/api/fragments.conf @@ -1,7 +1,7 @@ -global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} - -global.handler.fragmentsHandler.config.actions { - create-response { - factory = payload-to-body - } +global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} + +global.handler.fragmentsHandler.config.actions { + create-response { + factory = payload-to-body + } } \ No newline at end of file diff --git a/src/functionalTest/resources/common/api/routing.conf b/src/functionalTest/resources/common/api/routing.conf index c8c1ddcf..ca57022a 100644 --- a/src/functionalTest/resources/common/api/routing.conf +++ b/src/functionalTest/resources/common/api/routing.conf @@ -1,23 +1,23 @@ -config.server.options.config.routingOperations = [ - { - operationId = scenario-operation - handlers = ${config.server.handlers.common.request} [ - { - name = singleFragmentSupplier - config = { - type = json - configuration { - data-knotx-task = web-api-test - } - } - }, - { - name = fragmentsHandler - config = ${global.handler.fragmentsHandler.config} - }, - { - name = fragmentsAssembler - } - ] ${config.server.handlers.common.response} - } -] +config.server.options.config.routingOperations = [ + { + operationId = scenario-operation + handlers = ${config.server.handlers.common.request} [ + { + name = singleFragmentSupplier + config = { + type = json + configuration { + data-knotx-task = web-api-test + } + } + }, + { + name = fragmentsHandler + config = ${global.handler.fragmentsHandler.config} + }, + { + name = fragmentsAssembler + } + ] ${config.server.handlers.common.response} + } +] diff --git a/src/functionalTest/resources/common/templating/fragments.conf b/src/functionalTest/resources/common/templating/fragments.conf index a8b3adeb..56894df7 100644 --- a/src/functionalTest/resources/common/templating/fragments.conf +++ b/src/functionalTest/resources/common/templating/fragments.conf @@ -1,22 +1,22 @@ -global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} - -global.handler.fragmentsHandler.config.actions { - te-hbs { - factory = knot - config { - address = knotx.knot.te.handlebars - deliveryOptions { - sendTimeout = 3000 - } - } - } - te-pebble { - factory = knot - config { - address = knotx.knot.te.pebble - deliveryOptions { - sendTimeout = 3000 - } - } - } +global.handler.fragmentsHandler.config = {include required(classpath("conf/routes/handlers/fragmentsHandler.conf"))} + +global.handler.fragmentsHandler.config.actions { + te-hbs { + factory = knot + config { + address = knotx.knot.te.handlebars + deliveryOptions { + sendTimeout = 3000 + } + } + } + te-pebble { + factory = knot + config { + address = knotx.knot.te.pebble + deliveryOptions { + sendTimeout = 3000 + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/common/templating/routing.conf b/src/functionalTest/resources/common/templating/routing.conf index 27c079ed..d19dfe6f 100644 --- a/src/functionalTest/resources/common/templating/routing.conf +++ b/src/functionalTest/resources/common/templating/routing.conf @@ -1,28 +1,28 @@ -test.wiremock { - mockRepository.port = 0 -} - -config.server.options.config.routingOperations = [ - { - operationId = scenario-operation - handlers = ${config.server.handlers.common.request} [ - { - name = httpRepoConnectorHandler - config = ${global.handler.httpRepoConnectorHandler.config} - }, - { - name = htmlFragmentsSupplier - }, - { - name = fragmentsHandler - config = ${global.handler.fragmentsHandler.config} - }, - { - name = fragmentsAssembler - } - ] ${config.server.handlers.common.response} - } -] - -global.handler.httpRepoConnectorHandler.config = {include required(classpath("conf/routes/handlers/httpRepoConnectorHandler.conf"))} -global.handler.httpRepoConnectorHandler.config.clientDestination.port = ${test.wiremock.mockRepository.port} +test.wiremock { + mockRepository.port = 0 +} + +config.server.options.config.routingOperations = [ + { + operationId = scenario-operation + handlers = ${config.server.handlers.common.request} [ + { + name = httpRepoConnectorHandler + config = ${global.handler.httpRepoConnectorHandler.config} + }, + { + name = htmlFragmentsSupplier + }, + { + name = fragmentsHandler + config = ${global.handler.fragmentsHandler.config} + }, + { + name = fragmentsAssembler + } + ] ${config.server.handlers.common.response} + } +] + +global.handler.httpRepoConnectorHandler.config = {include required(classpath("conf/routes/handlers/httpRepoConnectorHandler.conf"))} +global.handler.httpRepoConnectorHandler.config.clientDestination.port = ${test.wiremock.mockRepository.port} diff --git a/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf b/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf index 069b1bb2..8bbe59c2 100644 --- a/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf +++ b/src/functionalTest/resources/conf/routes/handlers/fragmentsHandler.conf @@ -1,44 +1,44 @@ -########### This configuration is overloaded in integration tests! ########### -tasks { - # will be extended per unit tests -} - -actions { - # will be extended per unit tests - te-hbs { - factory = knot - config { - address = knotx.knot.te.handlebars - deliveryOptions { - sendTimeout = 3000 - } - } - } - te-pebble { - factory = knot - config { - address = knotx.knot.te.pebble - deliveryOptions { - sendTimeout = 3000 - } - } - } -} - -taskFactories = [ - { - factory = default - config { - tasks = ${global.handler.fragmentsHandler.config.tasks} - nodeFactories = [ - { - factory = action - config.actions = ${global.handler.fragmentsHandler.config.actions} - } - { - factory = subtasks - } - ] - } - } +########### This configuration is overloaded in integration tests! ########### +tasks { + # will be extended per unit tests +} + +actions { + # will be extended per unit tests + te-hbs { + factory = knot + config { + address = knotx.knot.te.handlebars + deliveryOptions { + sendTimeout = 3000 + } + } + } + te-pebble { + factory = knot + config { + address = knotx.knot.te.pebble + deliveryOptions { + sendTimeout = 3000 + } + } + } +} + +taskFactories = [ + { + factory = default + config { + tasks = ${global.handler.fragmentsHandler.config.tasks} + nodeFactories = [ + { + factory = action + config.actions = ${global.handler.fragmentsHandler.config.actions} + } + { + factory = subtasks + } + ] + } + } ] \ No newline at end of file diff --git a/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf b/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf index ed1359c2..eb0c0b35 100644 --- a/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf +++ b/src/functionalTest/resources/conf/routes/handlers/httpRepoConnectorHandler.conf @@ -1,61 +1,61 @@ -# Vert.x event bus delivery options used when communicating with other verticles -# see http://vertx.io/docs/vertx-core/dataobjects.html#HttpClientOptions for the details what can be configured -# -clientOptions { - maxPoolSize = 1000 - idleTimeout = 120 # seconds - tryUseCompression = true - - # If you're going to use SSL (clientDestination.scheme='https') then here you'd need to configure - # some aspects related to the SSL negotiation and validation. - # - # Whether all server certificated should be trusted or not (e.g. self-signed certificates) - # trustAll = true - # - # Hostname verification - # verifyHost = false - # - # It will force SSL SNI (Server Name Indication). The SNI will be set to the same value as 'hostHeader' (set in ClientDestination) - # forceSni = true -} - -# HTTP Repository connection details -clientDestination { - # Connection scheme: http or https - scheme = http - - # domain or the IP of the host: e.g. localhost, 10.0.11.2 - domain = localhost - - ## Port on which the host listens, e.g. 8080, 3001, etc. - port = 80 - - # Host header override to be used with a communication to the repository. If it's set, it overrides any value in the 'Host' header, and sets the SNI SSL to the same value. - # hostHeader = -} - -# List of allowed request headers that will be send to HTTP repository. -# Each item is a string that defines regex, e.g. to match any char use `.*` -# -allowedRequestHeaders = [ - "Accept.*" - Authorization - Connection - Cookie - Date - "Edge.*" - "If.*" - Origin - Pragma - Proxy-Authorization - "Surrogate.*" - User-Agent - Via - "X-.*" -] - -# Statically defined HTTP request header sent in every request to the repository -customHttpHeader = { - name = X-User-Agent - value = Knot.x +# Vert.x event bus delivery options used when communicating with other verticles +# see http://vertx.io/docs/vertx-core/dataobjects.html#HttpClientOptions for the details what can be configured +# +clientOptions { + maxPoolSize = 1000 + idleTimeout = 120 # seconds + tryUseCompression = true + + # If you're going to use SSL (clientDestination.scheme='https') then here you'd need to configure + # some aspects related to the SSL negotiation and validation. + # + # Whether all server certificated should be trusted or not (e.g. self-signed certificates) + # trustAll = true + # + # Hostname verification + # verifyHost = false + # + # It will force SSL SNI (Server Name Indication). The SNI will be set to the same value as 'hostHeader' (set in ClientDestination) + # forceSni = true +} + +# HTTP Repository connection details +clientDestination { + # Connection scheme: http or https + scheme = http + + # domain or the IP of the host: e.g. localhost, 10.0.11.2 + domain = localhost + + ## Port on which the host listens, e.g. 8080, 3001, etc. + port = 80 + + # Host header override to be used with a communication to the repository. If it's set, it overrides any value in the 'Host' header, and sets the SNI SSL to the same value. + # hostHeader = +} + +# List of allowed request headers that will be send to HTTP repository. +# Each item is a string that defines regex, e.g. to match any char use `.*` +# +allowedRequestHeaders = [ + "Accept.*" + Authorization + Connection + Cookie + Date + "Edge.*" + "If.*" + Origin + Pragma + Proxy-Authorization + "Surrogate.*" + User-Agent + Via + "X-.*" +] + +# Statically defined HTTP request header sent in every request to the repository +customHttpHeader = { + name = X-User-Agent + value = Knot.x } \ No newline at end of file diff --git a/src/functionalTest/resources/conf/server.conf b/src/functionalTest/resources/conf/server.conf index 670efbbc..9a516f14 100644 --- a/src/functionalTest/resources/conf/server.conf +++ b/src/functionalTest/resources/conf/server.conf @@ -1,103 +1,103 @@ -########### Knot.x JUnit5 config ########### -test { - random { - globalServer.port = 0 - } -} - -########### Knot.x Server ########### -modules { - server = "io.knotx.server.KnotxServerVerticle" -} - -########### Modules configurations ########### -config.server { - handlers.common { - request = [ - { - name = bodyHandler - }, - { - name = requestContextHandler - } - ], - response = [ - { - name = headerHandler - # Statically defined HTTP response header returned to the client in every HTTP response - config { - name = X-Server - value = Knot.x-Custom-Header - } - }, - { - name = writerHandler - # List of HTTP response headers Knot.x can return to the client - config.allowedResponseHeaders = [ - Access-Control-Allow-Origin - Content-Type - Content-Length - X-Server - Location - ] - } - ] - } - options.config { - # Configuraiton of HTTP server - serverOptions { - # Knot.x server HTTP port - port = ${test.random.globalServer.port} - - # If you want a server to serve SSL connections you can configure it here - # - # Enable SSL - # ssl = true - # - # Path on the server the keystore.jks file is located - # keyStoreOptions.path = - # - # Keystore password - # keyStoreOptions.password = - } - - # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). - routingSpecificationLocation = /openapi.yaml - - displayExceptionDetails = true - - dropRequestOptions { - # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details - enabled = false - - # Status code that is served if the response is dropped, default is 429, "Too Many Requests" - # dropRequestResponseCode = - - # Number of request that single Server insance can support concurrently. Default value is 1000. - # backpressureBufferCapacity - - # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. - # backpressureStrategy = - } - - routingOperations = [] - - # Global handlers section - globalHandlers = [ - # access log, by default logged to the knotx-access.log in the logs directory - { - name = loggerHandler - config { - immediate = true - format = DEFAULT - } - } - ] - } - - # The options object carries-on configuration called DeploymentOptions for a given verticle. - # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. - # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions - # - # options {} -} +########### Knot.x JUnit5 config ########### +test { + random { + globalServer.port = 0 + } +} + +########### Knot.x Server ########### +modules { + server = "io.knotx.server.KnotxServerVerticle" +} + +########### Modules configurations ########### +config.server { + handlers.common { + request = [ + { + name = bodyHandler + }, + { + name = requestContextHandler + } + ], + response = [ + { + name = headerHandler + # Statically defined HTTP response header returned to the client in every HTTP response + config { + name = X-Server + value = Knot.x-Custom-Header + } + }, + { + name = writerHandler + # List of HTTP response headers Knot.x can return to the client + config.allowedResponseHeaders = [ + Access-Control-Allow-Origin + Content-Type + Content-Length + X-Server + Location + ] + } + ] + } + options.config { + # Configuraiton of HTTP server + serverOptions { + # Knot.x server HTTP port + port = ${test.random.globalServer.port} + + # If you want a server to serve SSL connections you can configure it here + # + # Enable SSL + # ssl = true + # + # Path on the server the keystore.jks file is located + # keyStoreOptions.path = + # + # Keystore password + # keyStoreOptions.password = + } + + # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). + routingSpecificationLocation = /openapi.yaml + + displayExceptionDetails = true + + dropRequestOptions { + # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details + enabled = false + + # Status code that is served if the response is dropped, default is 429, "Too Many Requests" + # dropRequestResponseCode = + + # Number of request that single Server insance can support concurrently. Default value is 1000. + # backpressureBufferCapacity + + # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. + # backpressureStrategy = + } + + routingOperations = [] + + # Global handlers section + globalHandlers = [ + # access log, by default logged to the knotx-access.log in the logs directory + { + name = loggerHandler + config { + immediate = true + format = DEFAULT + } + } + ] + } + + # The options object carries-on configuration called DeploymentOptions for a given verticle. + # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. + # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions + # + # options {} +} diff --git a/src/functionalTest/resources/content/failedFragment.html b/src/functionalTest/resources/content/failedFragment.html index dd1a0771..7ef24e53 100644 --- a/src/functionalTest/resources/content/failedFragment.html +++ b/src/functionalTest/resources/content/failedFragment.html @@ -1,29 +1,29 @@ - - - - - - Broken service - - -
- -

This fragment should fail/h2> - -

- - + + + + + + Broken service + + +
+ +

This fragment should fail/h2> + +

+ + diff --git a/src/functionalTest/resources/openapi.yaml b/src/functionalTest/resources/openapi.yaml index 9eee8beb..59923f2b 100644 --- a/src/functionalTest/resources/openapi.yaml +++ b/src/functionalTest/resources/openapi.yaml @@ -1,43 +1,43 @@ -# 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. - -openapi: "3.0.0" -info: - version: 1.0.0 - title: Knot.x Stack OAS - description: This is a full flow server used during integration tests. - license: - name: Apache 2.0 - url: http://www.apache.org/licenses/LICENSE-2.0.html - -servers: -- url: https://{domain}:{port} - description: The local API server - variables: - domain: - default: localhost - description: api domain - port: - enum: - - '8092' - - '443' - default: '8092' - -paths: - /*: - get: - operationId: scenario-operation - responses: - default: +# 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. + +openapi: "3.0.0" +info: + version: 1.0.0 + title: Knot.x Stack OAS + description: This is a full flow server used during integration tests. + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + +servers: +- url: https://{domain}:{port} + description: The local API server + variables: + domain: + default: localhost + description: api domain + port: + enum: + - '8092' + - '443' + default: '8092' + +paths: + /*: + get: + operationId: scenario-operation + responses: + default: description: scenario specific operation \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf index 62df6d4f..373c5b6b 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - scenarioService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + scenarioService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf index a07c0fd1..bf284a45 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - delayedService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + delayedService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf index 1cc8cbde..ec15f0e1 100644 --- a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf +++ b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/mocks.conf @@ -1,8 +1,8 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - authService.port = 0 - databaseService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + authService.port = 0 + databaseService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf b/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf index a07c0fd1..bf284a45 100644 --- a/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf +++ b/src/functionalTest/resources/scenarios/failed-knotx-fragment/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - delayedService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + delayedService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf index eb63baeb..eeddde05 100644 --- a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf +++ b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.random { - mockBrokenService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.random { + mockBrokenService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf b/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf index 6cc876e3..c728bbaf 100644 --- a/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf +++ b/src/functionalTest/resources/scenarios/fragments-debug-data/debugHtml.conf @@ -1,13 +1,13 @@ -global.handler.fragmentsHandler.config { - consumerFactories = [ - { - factory = fragmentHtmlBodyWriter - config { - condition { - param = debug - } - fragmentTypes = ["snippet"] - } - } - ] +global.handler.fragmentsHandler.config { + consumerFactories = [ + { + factory = fragmentHtmlBodyWriter + config { + condition { + param = debug + } + fragmentTypes = ["snippet"] + } + } + ] } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf b/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf index 6dd46f38..07aa29e2 100644 --- a/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf +++ b/src/functionalTest/resources/scenarios/fragments-debug-data/debugJson.conf @@ -1,14 +1,14 @@ -global.handler.fragmentsHandler.config { - consumerFactories = [ - { - factory = fragmentJsonBodyWriter - config { - condition { - param = debug - header = x-knotx-debug - } - fragmentTypes = ["json"] - } - } - ] +global.handler.fragmentsHandler.config { + consumerFactories = [ + { + factory = fragmentJsonBodyWriter + config { + condition { + param = debug + header = x-knotx-debug + } + fragmentTypes = ["json"] + } + } + ] } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf index 11a65af1..90739f4f 100644 --- a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf +++ b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf index a07c0fd1..bf284a45 100644 --- a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf +++ b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - delayedService.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + delayedService.port = 0 +} diff --git a/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf b/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf index 11a65af1..90739f4f 100644 --- a/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf +++ b/src/functionalTest/resources/scenarios/pebble-template-engine/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf index 88eb554d..e9a7d994 100644 --- a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf +++ b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/httpRepoConnectorHandler.conf @@ -1,32 +1,32 @@ -global.handler.httpRepoConnectorHandler.config { - clientOptions { - maxPoolSize = 1000 - idleTimeout = 120 - tryUseCompression = true - # do not follow redirects to pass it to the end user - followRedirects = false - } - - clientDestination { - scheme = http - domain = localhost - port = ${test.random.httpRepository.port} - } - - allowedRequestHeaders = [ - "Accept.*" - Authorization - Connection - Cookie - Date - "Edge.*" - "If.*" - Origin - Pragma - Proxy-Authorization - "Surrogate.*" - User-Agent - Via - "X-.*" - ] +global.handler.httpRepoConnectorHandler.config { + clientOptions { + maxPoolSize = 1000 + idleTimeout = 120 + tryUseCompression = true + # do not follow redirects to pass it to the end user + followRedirects = false + } + + clientDestination { + scheme = http + domain = localhost + port = ${test.random.httpRepository.port} + } + + allowedRequestHeaders = [ + "Accept.*" + Authorization + Connection + Cookie + Date + "Edge.*" + "If.*" + Origin + Pragma + Proxy-Authorization + "Surrogate.*" + User-Agent + Via + "X-.*" + ] } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf index 75fa9313..3e6c99eb 100644 --- a/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf +++ b/src/functionalTest/resources/scenarios/repository-connector-redirect-passed-to-end-user/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.random { - httpRepository.port = 0 +########### Knot.x JUnit5 config ########### +test.random { + httpRepository.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf b/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf index 11a65af1..90739f4f 100644 --- a/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf +++ b/src/functionalTest/resources/scenarios/template-engines-integration/mocks.conf @@ -1,4 +1,4 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf b/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf index 48ae0dc9..8969461c 100644 --- a/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf +++ b/src/functionalTest/resources/scenarios/various-methods-for-http-action/mocks.conf @@ -1,7 +1,7 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockService.port = 0 -} -test.random { - service.port = 0 -} +########### Knot.x JUnit5 config ########### +test.wiremock { + mockService.port = 0 +} +test.random { + service.port = 0 +} diff --git a/src/main/packaging/conf/server.conf b/src/main/packaging/conf/server.conf index 4cc2532f..08967e30 100644 --- a/src/main/packaging/conf/server.conf +++ b/src/main/packaging/conf/server.conf @@ -1,95 +1,95 @@ -########### Knot.x Server ########### -modules { - server = "io.knotx.server.KnotxServerVerticle" -} - -########### Modules configurations ########### -config.server { - handlers.common { - request = [ - { - name = bodyHandler - }, - { - name = requestContextHandler - } - ], - response = [ - { - name = headerHandler - # Statically defined HTTP response header returned to the client in every HTTP response - config { - name = X-Server - value = Knot.x-Custom-Header - } - }, - { - name = writerHandler - # List of HTTP response headers Knot.x can return to the client - config.allowedResponseHeaders = [ - Access-Control-Allow-Origin - Content-Type - Content-Length - Location - ] - } - ] - } - options.config { - # Configuraiton of HTTP server - serverOptions { - # Knot.x server HTTP port - port = 8092 - - # If you want a server to serve SSL connections you can configure it here - # - # Enable SSL - # ssl = true - # - # Path on the server the keystore.jks file is located - # keyStoreOptions.path = - # - # Keystore password - # keyStoreOptions.password = - } - - # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). - routingSpecificationLocation = /openapi.yaml - - displayExceptionDetails = true - dropRequestOptions { - # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details - enabled = false - - # Status code that is served if the response is dropped, default is 429, "Too Many Requests" - # dropRequestResponseCode = - - # Number of request that single Server insance can support concurrently. Default value is 1000. - # backpressureBufferCapacity - - # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. - # backpressureStrategy = - } - - routingOperations = [] - include required(classpath("routes/operations.conf")) - - # Global handlers section - globalHandlers = [ - # access log, by default logged to the knotx-access.log in the logs directory - { - name = loggerHandler - config { - immediate = true - format = DEFAULT - } - } - ] - } - - # The options object carries-on configuration called DeploymentOptions for a given verticle. - # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. - # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions - # - # options {} -} +########### Knot.x Server ########### +modules { + server = "io.knotx.server.KnotxServerVerticle" +} + +########### Modules configurations ########### +config.server { + handlers.common { + request = [ + { + name = bodyHandler + }, + { + name = requestContextHandler + } + ], + response = [ + { + name = headerHandler + # Statically defined HTTP response header returned to the client in every HTTP response + config { + name = X-Server + value = Knot.x-Custom-Header + } + }, + { + name = writerHandler + # List of HTTP response headers Knot.x can return to the client + config.allowedResponseHeaders = [ + Access-Control-Allow-Origin + Content-Type + Content-Length + Location + ] + } + ] + } + options.config { + # Configuraiton of HTTP server + serverOptions { + # Knot.x server HTTP port + port = 8092 + + # If you want a server to serve SSL connections you can configure it here + # + # Enable SSL + # ssl = true + # + # Path on the server the keystore.jks file is located + # keyStoreOptions.path = + # + # Keystore password + # keyStoreOptions.password = + } + + # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). + routingSpecificationLocation = /openapi.yaml + + displayExceptionDetails = true + dropRequestOptions { + # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details + enabled = false + + # Status code that is served if the response is dropped, default is 429, "Too Many Requests" + # dropRequestResponseCode = + + # Number of request that single Server insance can support concurrently. Default value is 1000. + # backpressureBufferCapacity + + # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. + # backpressureStrategy = + } + + routingOperations = [] + include required(classpath("routes/operations.conf")) + + # Global handlers section + globalHandlers = [ + # access log, by default logged to the knotx-access.log in the logs directory + { + name = loggerHandler + config { + immediate = true + format = DEFAULT + } + } + ] + } + + # The options object carries-on configuration called DeploymentOptions for a given verticle. + # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. + # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions + # + # options {} +} diff --git a/src/test/java/io/knotx/stack/KnotxServerTester.java b/src/test/java/io/knotx/stack/KnotxServerTester.java index 8cbe894a..5c4036df 100644 --- a/src/test/java/io/knotx/stack/KnotxServerTester.java +++ b/src/test/java/io/knotx/stack/KnotxServerTester.java @@ -1,97 +1,97 @@ -/* - * 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; - -import static io.knotx.junit5.util.RequestUtil.subscribeToResult_shouldSucceed; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import io.knotx.junit5.assertions.HtmlMarkupAssertions; -import io.knotx.junit5.util.FileReader; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.reactivex.Single; -import io.reactivex.functions.Consumer; -import io.vertx.ext.web.client.WebClientOptions; -import io.vertx.junit5.VertxTestContext; -import io.vertx.reactivex.core.MultiMap; -import io.vertx.reactivex.core.Vertx; -import io.vertx.reactivex.core.buffer.Buffer; -import io.vertx.reactivex.ext.web.client.HttpResponse; -import io.vertx.reactivex.ext.web.client.WebClient; -import java.util.Collections; -import java.util.Map; - -public final class KnotxServerTester { - - private static final int KNOTX_TESTS_SERVER_PORT_DEFAULT = 8092; - private static final String KNOTX_TESTS_SERVER_ADDRESS_DEFAULT = "localhost"; - - private final String serverHost; - private final int serverPort; - - private WebClientOptions clientOptions = new WebClientOptions(); - private Map headers = Collections.emptyMap(); - - private KnotxServerTester(String serverHost, int serverPort) { - this.serverHost = serverHost; - this.serverPort = serverPort; - } - - public static KnotxServerTester defaultInstance() { - return defaultInstance(KNOTX_TESTS_SERVER_PORT_DEFAULT); - } - - public static KnotxServerTester defaultInstance(int port) { - return new KnotxServerTester(KNOTX_TESTS_SERVER_ADDRESS_DEFAULT, port); - } - - public KnotxServerTester withClientOptions(WebClientOptions clientOptions) { - this.clientOptions = clientOptions; - return this; - } - - public KnotxServerTester withRequestHeaders(Map headers) { - this.headers = headers; - return this; - } - - public void testGetWithExpectedResponse(VertxTestContext context, Vertx vertx, String url, - String expectedResponseFile) { - testGet(context, vertx, url, resp -> { - assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); - HtmlMarkupAssertions.assertHtmlBodyMarkupsEqual(FileReader.readTextSafe(expectedResponseFile), - resp.body().toString()); - }); - } - - public void testGet(VertxTestContext context, Vertx vertx, String url, - Consumer> assertions) { - MultiMap headersMultiMap = MultiMap.caseInsensitiveMultiMap(); - headersMultiMap.addAll(headers); - - WebClient client = WebClient.create(vertx, clientOptions); - Single> httpResponseSingle = client - .get(serverPort, serverHost, url) - .putHeaders(headersMultiMap) - .rxSend(); - - subscribeToResult_shouldSucceed(context, httpResponseSingle, - resp -> { - assertions.accept(resp); - client.close(); - }); - } - -} +/* + * 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; + +import static io.knotx.junit5.util.RequestUtil.subscribeToResult_shouldSucceed; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.knotx.junit5.assertions.HtmlMarkupAssertions; +import io.knotx.junit5.util.FileReader; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.reactivex.Single; +import io.reactivex.functions.Consumer; +import io.vertx.ext.web.client.WebClientOptions; +import io.vertx.junit5.VertxTestContext; +import io.vertx.reactivex.core.MultiMap; +import io.vertx.reactivex.core.Vertx; +import io.vertx.reactivex.core.buffer.Buffer; +import io.vertx.reactivex.ext.web.client.HttpResponse; +import io.vertx.reactivex.ext.web.client.WebClient; +import java.util.Collections; +import java.util.Map; + +public final class KnotxServerTester { + + private static final int KNOTX_TESTS_SERVER_PORT_DEFAULT = 8092; + private static final String KNOTX_TESTS_SERVER_ADDRESS_DEFAULT = "localhost"; + + private final String serverHost; + private final int serverPort; + + private WebClientOptions clientOptions = new WebClientOptions(); + private Map headers = Collections.emptyMap(); + + private KnotxServerTester(String serverHost, int serverPort) { + this.serverHost = serverHost; + this.serverPort = serverPort; + } + + public static KnotxServerTester defaultInstance() { + return defaultInstance(KNOTX_TESTS_SERVER_PORT_DEFAULT); + } + + public static KnotxServerTester defaultInstance(int port) { + return new KnotxServerTester(KNOTX_TESTS_SERVER_ADDRESS_DEFAULT, port); + } + + public KnotxServerTester withClientOptions(WebClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + public KnotxServerTester withRequestHeaders(Map headers) { + this.headers = headers; + return this; + } + + public void testGetWithExpectedResponse(VertxTestContext context, Vertx vertx, String url, + String expectedResponseFile) { + testGet(context, vertx, url, resp -> { + assertEquals(HttpResponseStatus.OK.code(), resp.statusCode()); + HtmlMarkupAssertions.assertHtmlBodyMarkupsEqual(FileReader.readTextSafe(expectedResponseFile), + resp.body().toString()); + }); + } + + public void testGet(VertxTestContext context, Vertx vertx, String url, + Consumer> assertions) { + MultiMap headersMultiMap = MultiMap.caseInsensitiveMultiMap(); + headersMultiMap.addAll(headers); + + WebClient client = WebClient.create(vertx, clientOptions); + Single> httpResponseSingle = client + .get(serverPort, serverHost, url) + .putHeaders(headersMultiMap) + .rxSend(); + + subscribeToResult_shouldSucceed(context, httpResponseSingle, + resp -> { + assertions.accept(resp); + client.close(); + }); + } + +} From 5d802cc8db3f1cec9e4b3f0b988984f65af68d25 Mon Sep 17 00:00:00 2001 From: "filip.kowalski" Date: Wed, 15 Jul 2020 15:56:50 +0200 Subject: [PATCH 3/4] #146 Fix line endings --- .../tasks.conf | 126 +++---- .../circuit-breaker-times-out/tasks.conf | 146 ++++---- .../tasks.conf | 98 ++--- .../failed-knotx-fragment/tasks.conf | 50 +-- .../tasks.conf | 228 ++++++------ .../scenarios/fragments-debug-data/tasks.conf | 336 +++++++++--------- .../tasks.conf | 134 +++---- .../tasks.conf | 196 +++++----- .../pebble-template-engine/tasks.conf | 142 ++++---- .../template-engines-integration/tasks.conf | 118 +++--- .../tasks.conf | 226 ++++++------ 11 files changed, 900 insertions(+), 900 deletions(-) diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf index 84298080..2145141e 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out-and-retries/tasks.conf @@ -1,64 +1,64 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = fetch-user-info - on._success { - actions = [ - { - action = fetch-payment-providers - } - { - action = fetch-offers-with-cb - } - ] - on { - _success { - action = create-response - } - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/scenario - domain = localhost - port = ${test.random.scenarioService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions.predicates = [ JSON ] - } - fetch-offers-with-cb { - factory = cb - config { - circuitBreakerName = offers-cb - circuitBreakerOptions { - maxRetries = 1 - timeout = 50 - } - } - doAction = fetch-offers - } - } +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = fetch-user-info + on._success { + actions = [ + { + action = fetch-payment-providers + } + { + action = fetch-offers-with-cb + } + ] + on { + _success { + action = create-response + } + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/scenario + domain = localhost + port = ${test.random.scenarioService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions.predicates = [ JSON ] + } + fetch-offers-with-cb { + factory = cb + config { + circuitBreakerName = offers-cb + circuitBreakerOptions { + maxRetries = 1 + timeout = 50 + } + } + doAction = fetch-offers + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf index 0457dcd2..ef19dbae 100644 --- a/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf +++ b/src/functionalTest/resources/scenarios/circuit-breaker-times-out/tasks.conf @@ -1,74 +1,74 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = fetch-user-info - on._success { - actions = [ - { - action = fetch-payment-providers - } - { - action = fetch-offers-with-cb - on._fallback { - action = fetch-offers-fallback - } - } - ] - on._success { - action = create-response - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/delayed - domain = localhost - port = ${test.random.delayedService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers-with-cb { - factory = cb - config { - circuitBreakerName = offers-cb - circuitBreakerOptions { - timeout = 50 - } - } - doAction = fetch-offers - } - fetch-offers-fallback { - factory = inline-payload - config { - alias = fetch-offers - payload { - _result { - fallback = "timeout" - } - } - } - } - } +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = fetch-user-info + on._success { + actions = [ + { + action = fetch-payment-providers + } + { + action = fetch-offers-with-cb + on._fallback { + action = fetch-offers-fallback + } + } + ] + on._success { + action = create-response + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/delayed + domain = localhost + port = ${test.random.delayedService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers-with-cb { + factory = cb + config { + circuitBreakerName = offers-cb + circuitBreakerOptions { + timeout = 50 + } + } + doAction = fetch-offers + } + fetch-offers-fallback { + factory = inline-payload + config { + alias = fetch-offers + payload { + _result { + fallback = "timeout" + } + } + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf index 7d5c4e20..017d9f14 100644 --- a/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf +++ b/src/functionalTest/resources/scenarios/dependent-http-actions-scenario-test/tasks.conf @@ -1,49 +1,49 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = obtain-auth-token - on._success { - action = reload-database - on { - _success { - action = create-response - } - } - } - } - } - - actions { - obtain-auth-token { - factory = http - config { - endpointOptions { - path = "/auth/login?id={param.id}&apiKey={param.key}" - domain = localhost - port = ${test.random.authService.port} - allowedRequestHeaders = ["Content-Type"] - } - responseOptions.predicates = [ JSON ] - } - } - reload-database { - factory = http - config { - httpMethod = POST - endpointOptions { - path = /database/manage - domain = localhost - port = ${test.random.databaseService.port} - interpolateBody = true - bodyJson { - id = "{param.id}" - authToken = "{payload.obtain-auth-token._result.token}" - operation = reloadFromPermanentStorage - } - allowedRequestHeaders = ["Content-Type"] - } - responseOptions.predicates = [ JSON ] - } - } - } -} +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = obtain-auth-token + on._success { + action = reload-database + on { + _success { + action = create-response + } + } + } + } + } + + actions { + obtain-auth-token { + factory = http + config { + endpointOptions { + path = "/auth/login?id={param.id}&apiKey={param.key}" + domain = localhost + port = ${test.random.authService.port} + allowedRequestHeaders = ["Content-Type"] + } + responseOptions.predicates = [ JSON ] + } + } + reload-database { + factory = http + config { + httpMethod = POST + endpointOptions { + path = /database/manage + domain = localhost + port = ${test.random.databaseService.port} + interpolateBody = true + bodyJson { + id = "{param.id}" + authToken = "{payload.obtain-auth-token._result.token}" + operation = reloadFromPermanentStorage + } + allowedRequestHeaders = ["Content-Type"] + } + responseOptions.predicates = [ JSON ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf b/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf index 01f43853..377edf0a 100644 --- a/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf +++ b/src/functionalTest/resources/scenarios/failed-knotx-fragment/tasks.conf @@ -1,26 +1,26 @@ -global.handler.fragmentsHandler.config { - tasks { - error-task { - action = fetch-incorrect-data - on._success { - action = te-pebble - } - } - } - - actions { - fetch-incorrect-data { - factory = http - config.endpointOptions { - path = /service/broken/500.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - forceJson = true - } - } - } - - allowInvalidFragmentsHeader = "Allow-Invalid-Fragments" - allowInvalidFragmentsParam = "allowInvalidFragments" +global.handler.fragmentsHandler.config { + tasks { + error-task { + action = fetch-incorrect-data + on._success { + action = te-pebble + } + } + } + + actions { + fetch-incorrect-data { + factory = http + config.endpointOptions { + path = /service/broken/500.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + forceJson = true + } + } + } + + allowInvalidFragmentsHeader = "Allow-Invalid-Fragments" + allowInvalidFragmentsParam = "allowInvalidFragments" } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf index 363351e6..3e65cb2e 100644 --- a/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf +++ b/src/functionalTest/resources/scenarios/failing-http-services-with-fallbacks/tasks.conf @@ -1,115 +1,115 @@ -global.handler.fragmentsHandler.config { - tasks { - books-listing { - action = book - on { - _error { - action = book-inline-body-fallback - } - } - } - authors-listing { - action = author - on { - _error { - action = author-inline-payload-fallback - on._success { - action = te-hbs - } - } - } - } - books-and-authors-listing { - subtasks = [ - { - action = book - on._error { - action = book-inline-payload-fallback - } - }, - { - action = author - } - ] - on { - _error { - action = author-inline-payload-fallback - on._success { - action = te-hbs - } - } - } - } - } - - actions { - book { - factory = http - config.endpointOptions { - path = /service/broken/500.json - domain = localhost - port = ${test.random.mockBrokenService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - author { - factory = http - config.endpointOptions { - path = /service/broken/500.json - domain = localhost - port = ${test.random.mockBrokenService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - // fallbacks - author-inline-payload-fallback { - factory = inline-payload - config { - alias = author - payload { - _result { - name = "Knot X", - info { - portfolio = [ - "tutorials", - "blogs", - "books" - ], - bio = "Aliquam cursus fermentum mi, vel tempus mi pellentesque vel. Nunc in feugiat lorem. Etiam placerat ante eget sem euismod, sit amet dictum sapien vulputate. Morbi pellentesque arcu a mauris ornare eleifend." - } - } - _response { - metadata { - statusCode = 500 - } - } - } - } - } - book-inline-payload-fallback { - factory = inline-payload - config { - alias = book - payload { - _result { - title = "Knot.x Integration Tests in Practice" - info { - authors = "Knot.x Team" - } - } - _response { - metadata { - statusCode = 500 - } - } - } - } - } - book-inline-body-fallback { - factory = inline-body - config { - body = "

Tags are unavailable at the moment

" - } - } - } +global.handler.fragmentsHandler.config { + tasks { + books-listing { + action = book + on { + _error { + action = book-inline-body-fallback + } + } + } + authors-listing { + action = author + on { + _error { + action = author-inline-payload-fallback + on._success { + action = te-hbs + } + } + } + } + books-and-authors-listing { + subtasks = [ + { + action = book + on._error { + action = book-inline-payload-fallback + } + }, + { + action = author + } + ] + on { + _error { + action = author-inline-payload-fallback + on._success { + action = te-hbs + } + } + } + } + } + + actions { + book { + factory = http + config.endpointOptions { + path = /service/broken/500.json + domain = localhost + port = ${test.random.mockBrokenService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + author { + factory = http + config.endpointOptions { + path = /service/broken/500.json + domain = localhost + port = ${test.random.mockBrokenService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + // fallbacks + author-inline-payload-fallback { + factory = inline-payload + config { + alias = author + payload { + _result { + name = "Knot X", + info { + portfolio = [ + "tutorials", + "blogs", + "books" + ], + bio = "Aliquam cursus fermentum mi, vel tempus mi pellentesque vel. Nunc in feugiat lorem. Etiam placerat ante eget sem euismod, sit amet dictum sapien vulputate. Morbi pellentesque arcu a mauris ornare eleifend." + } + } + _response { + metadata { + statusCode = 500 + } + } + } + } + } + book-inline-payload-fallback { + factory = inline-payload + config { + alias = book + payload { + _result { + title = "Knot.x Integration Tests in Practice" + info { + authors = "Knot.x Team" + } + } + _response { + metadata { + statusCode = 500 + } + } + } + } + } + book-inline-body-fallback { + factory = inline-body + config { + body = "

Tags are unavailable at the moment

" + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf b/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf index f5fbfcc5..1d9d2099 100644 --- a/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf +++ b/src/functionalTest/resources/scenarios/fragments-debug-data/tasks.conf @@ -1,169 +1,169 @@ -global.handler.fragmentsHandler.config { - tasks { - # HTML Templating Scenario - user-task { - action = fetch-user-info // _success - on._success { - action = te-hbs - } - } - # HTML Templating Scenario - payments-task { - action = fetch-user-info // _success - on._success { - actions = [ - { - action = fetch-payment-providers // _success - on._error { - action = fetch-payment-providers-fallback - } - } - { - action = fetch-offers // _error - on._error { - action = fetch-offers-fallback // _success - } - } - { - action = fetch-delivery-options-cb // 2 x 500 -> _fallback - on._fallback { - action = fetch-delivery-fallback // _success - } - } - { - action = notify-analytics-cb // 2 x timeout -> _fallback - on._fallback { - action = notify-analytics-fallback // _success - } - } - ] - on._success { - action = te-pebble // _success - } - } - on._error { - action = fetch-user-info-fallback - } - on._custom { - action = fetch-user-info-custom - } - } - # Web API Scenario - web-api-test = ${global.handler.fragmentsHandler.config.tasks.payments-task} - web-api-test.onTransitions._success.onTransitions._success.action = create-response // _success - } - - actions { - common-fallback-action { - factory = http - config.endpointOptions { - path = /service/mock/placeholderFallback.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.xml - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions { - forceJson = true - predicates = [] - } - } - fetch-offers-fallback { - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - - fetch-delivery-options-cb { - factory = cb - config { - circuitBreakerName = delivery-cb - circuitBreakerOptions { - maxRetries = 1 - timeout = 50 - } - } - doAction = fetch-delivery - } - fetch-delivery { - factory = http - config.endpointOptions { - path = /mock/scenario/delayed - domain = localhost - port = ${test.random.delayedService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-delivery-fallback { - factory = inline-payload - config { - alias = fetch-delivery - payload { - _result { - fallback = "action ended with _timeout" - } - } - } - } - - notify-analytics-cb { - factory = cb - config { - circuitBreakerName = delivery-cb - } - doAction = notify-analytics - } - notify-analytics { - factory = http - config.httpMethod = POST - config.endpointOptions { - path = /mock/scenario/analytics - domain = localhost - port = ${test.random.brokenService.port} - bodyJson = { - user-data-id = "{payload.fetch-user-info._result.id}" - } - interpolateBody = true - allowedRequestHeaders = ["Content-Type"] - } - } - notify-analytics-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - - fetch-payment-providers-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - fetch-user-info-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - fetch-user-info-custom = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} - } +global.handler.fragmentsHandler.config { + tasks { + # HTML Templating Scenario + user-task { + action = fetch-user-info // _success + on._success { + action = te-hbs + } + } + # HTML Templating Scenario + payments-task { + action = fetch-user-info // _success + on._success { + actions = [ + { + action = fetch-payment-providers // _success + on._error { + action = fetch-payment-providers-fallback + } + } + { + action = fetch-offers // _error + on._error { + action = fetch-offers-fallback // _success + } + } + { + action = fetch-delivery-options-cb // 2 x 500 -> _fallback + on._fallback { + action = fetch-delivery-fallback // _success + } + } + { + action = notify-analytics-cb // 2 x timeout -> _fallback + on._fallback { + action = notify-analytics-fallback // _success + } + } + ] + on._success { + action = te-pebble // _success + } + } + on._error { + action = fetch-user-info-fallback + } + on._custom { + action = fetch-user-info-custom + } + } + # Web API Scenario + web-api-test = ${global.handler.fragmentsHandler.config.tasks.payments-task} + web-api-test.onTransitions._success.onTransitions._success.action = create-response // _success + } + + actions { + common-fallback-action { + factory = http + config.endpointOptions { + path = /service/mock/placeholderFallback.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.xml + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions { + forceJson = true + predicates = [] + } + } + fetch-offers-fallback { + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + + fetch-delivery-options-cb { + factory = cb + config { + circuitBreakerName = delivery-cb + circuitBreakerOptions { + maxRetries = 1 + timeout = 50 + } + } + doAction = fetch-delivery + } + fetch-delivery { + factory = http + config.endpointOptions { + path = /mock/scenario/delayed + domain = localhost + port = ${test.random.delayedService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-delivery-fallback { + factory = inline-payload + config { + alias = fetch-delivery + payload { + _result { + fallback = "action ended with _timeout" + } + } + } + } + + notify-analytics-cb { + factory = cb + config { + circuitBreakerName = delivery-cb + } + doAction = notify-analytics + } + notify-analytics { + factory = http + config.httpMethod = POST + config.endpointOptions { + path = /mock/scenario/analytics + domain = localhost + port = ${test.random.brokenService.port} + bodyJson = { + user-data-id = "{payload.fetch-user-info._result.id}" + } + interpolateBody = true + allowedRequestHeaders = ["Content-Type"] + } + } + notify-analytics-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + + fetch-payment-providers-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + fetch-user-info-fallback = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + fetch-user-info-custom = ${global.handler.fragmentsHandler.config.actions.common-fallback-action} + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf index ef3cf2c3..0bcd368b 100644 --- a/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf +++ b/src/functionalTest/resources/scenarios/http-service-responds-with-invalid-json/tasks.conf @@ -1,68 +1,68 @@ -global.handler.fragmentsHandler.config { - tasks { - web-api-test { - action = fetch-user-info - on._success { - actions = [ - { - action = fetch-payment-providers - } - { - action = fetch-offers - on._error { - action = fetch-offers-fallback - } - } - ] - on._success { - action = create-response - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = "/service/mock/paymentProviders.{param.group}.json" - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { // invalid format - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.xml - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions { - forceJson = true - predicates = [] - } - } - fetch-offers-fallback { - factory = inline-payload - config { - alias = fetch-offers - payload { - _result { - fallback = "json-syntax-error" - } - } - } - } - } +global.handler.fragmentsHandler.config { + tasks { + web-api-test { + action = fetch-user-info + on._success { + actions = [ + { + action = fetch-payment-providers + } + { + action = fetch-offers + on._error { + action = fetch-offers-fallback + } + } + ] + on._success { + action = create-response + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = "/service/mock/paymentProviders.{param.group}.json" + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { // invalid format + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.xml + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions { + forceJson = true + predicates = [] + } + } + fetch-offers-fallback { + factory = inline-payload + config { + alias = fetch-offers + payload { + _result { + fallback = "json-syntax-error" + } + } + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf index 65ae7873..71c55d5d 100644 --- a/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf +++ b/src/functionalTest/resources/scenarios/long-running-http-service-with-circuit-breaker/tasks.conf @@ -1,99 +1,99 @@ -global.handler.fragmentsHandler.config { - tasks { - books-listing { - action = book-with-circuit-breaker - on._fallback { - action = book-inline-body-fallback - } - } - authors-listing { - action = author - on { - _success { - action = te-hbs - } - } - } - books-and-authors-listing { - actions = [ - { - action = book-with-circuit-breaker - on._fallback { - action = book-inline-payload-fallback - } - }, - { - action = author - } - ] - on { - _success { - action = te-hbs - } - } - } - } - - actions { - book-with-circuit-breaker { - factory = cb - config { - circuitBreakerName = "Circuit Breaker: book service" - circuitBreakerOptions { - timeout = 1000 - maxFailures = 1 - resetTimeout = 10000 - } - } - doAction = book - } - book { - factory = http - config { - endpointOptions { - path = /service/mock/delayed - domain = localhost - port = ${test.random.delayedService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - author { - factory = http - config { - endpointOptions { - path = /service/mock/author.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - // fallbacks - book-inline-payload-fallback { - factory = inline-payload - config { - alias = book - payload { - _result { - title = "Knot.x Integration Tests in Practice" - info { - authors = "Knot.x Team" - } - } - _response { - metadata { - statusCode = 500 - } - } - } - } - } - book-inline-body-fallback { - factory = inline-body - config { - body = "

Tags are unavailable at the moment

" - } - } - } +global.handler.fragmentsHandler.config { + tasks { + books-listing { + action = book-with-circuit-breaker + on._fallback { + action = book-inline-body-fallback + } + } + authors-listing { + action = author + on { + _success { + action = te-hbs + } + } + } + books-and-authors-listing { + actions = [ + { + action = book-with-circuit-breaker + on._fallback { + action = book-inline-payload-fallback + } + }, + { + action = author + } + ] + on { + _success { + action = te-hbs + } + } + } + } + + actions { + book-with-circuit-breaker { + factory = cb + config { + circuitBreakerName = "Circuit Breaker: book service" + circuitBreakerOptions { + timeout = 1000 + maxFailures = 1 + resetTimeout = 10000 + } + } + doAction = book + } + book { + factory = http + config { + endpointOptions { + path = /service/mock/delayed + domain = localhost + port = ${test.random.delayedService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + author { + factory = http + config { + endpointOptions { + path = /service/mock/author.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + // fallbacks + book-inline-payload-fallback { + factory = inline-payload + config { + alias = book + payload { + _result { + title = "Knot.x Integration Tests in Practice" + info { + authors = "Knot.x Team" + } + } + _response { + metadata { + statusCode = 500 + } + } + } + } + } + book-inline-body-fallback { + factory = inline-body + config { + body = "

Tags are unavailable at the moment

" + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf b/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf index b72d8e44..d28f20ab 100644 --- a/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf +++ b/src/functionalTest/resources/scenarios/pebble-template-engine/tasks.conf @@ -1,71 +1,71 @@ -global.handler.fragmentsHandler.config { - tasks { - tags-listing { - action = tags - on { - _success { - action = te-pebble - } - _error { - action = tags-fallback - } - } - } - books-listing { - action = book - on { - _success { - action = te-pebble - } - } - } - authors-listing { - action = author - on { - _success { - action = te-pebble - } - } - } - books-and-authors-listing { - actions = [ - { - action = book - }, - { - action = author - } - ] - on { - _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" ] - } - } - } - } -} +global.handler.fragmentsHandler.config { + tasks { + tags-listing { + action = tags + on { + _success { + action = te-pebble + } + _error { + action = tags-fallback + } + } + } + books-listing { + action = book + on { + _success { + action = te-pebble + } + } + } + authors-listing { + action = author + on { + _success { + action = te-pebble + } + } + } + books-and-authors-listing { + actions = [ + { + action = book + }, + { + action = author + } + ] + on { + _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" ] + } + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf b/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf index a3aac467..acc1b130 100644 --- a/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf +++ b/src/functionalTest/resources/scenarios/template-engines-integration/tasks.conf @@ -1,60 +1,60 @@ -global.handler.fragmentsHandler.config { - tasks { - user-task { - action = fetch-user-info // _success - on._success { - action = te-hbs - } - } - payments-task { - action = fetch-user-info // _success - on._success { - actions = [ - { - action = fetch-payment-providers // _success - } - { - action = fetch-offers // _success - } - ] - on._success { - action = te-pebble // _success - } - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions { - forceJson = true - predicates = [] - } - } - } +global.handler.fragmentsHandler.config { + tasks { + user-task { + action = fetch-user-info // _success + on._success { + action = te-hbs + } + } + payments-task { + action = fetch-user-info // _success + on._success { + actions = [ + { + action = fetch-payment-providers // _success + } + { + action = fetch-offers // _success + } + ] + on._success { + action = te-pebble // _success + } + } + } + } + + actions { + fetch-user-info { + factory = http + config.endpointOptions { + path = /service/mock/userInfo.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-payment-providers { + factory = http + config.endpointOptions { + path = /service/mock/paymentProviders.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + } + fetch-offers { + factory = http + config.endpointOptions { + path = /service/mock/specialOffers.json + domain = localhost + port = ${test.wiremock.mockService.port} + allowedRequestHeaders = ["Content-Type"] + } + config.responseOptions { + forceJson = true + predicates = [] + } + } + } } \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf b/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf index f678d203..d1562c0a 100644 --- a/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf +++ b/src/functionalTest/resources/scenarios/various-methods-for-http-action/tasks.conf @@ -1,113 +1,113 @@ -global.handler.fragmentsHandler.config { - tasks { - various-methods-for-http-action { - actions = [ - { - action = get - } - { - action = post - } - { - action = put - } - { - action = patch - } - { - action = delete - } - { - action = head - } - ] - on._success { - action = te-hbs - } - } - } - - actions { - get { - factory = http - config { - httpMethod = get - endpointOptions { - path = /service/mock/get.json - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - responseOptions { - forceJson = true - } - } - } - post { - factory = http - config { - httpMethod = post - endpointOptions { - path = /service/mock/post.json - body = "{\"password\": \"pazzword\"}" - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - put { - factory = http - config { - httpMethod = put - endpointOptions { - path = /service/mock/put.json - interpolateBody = true - bodyJson { - password = pazzword - } - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - patch { - factory = http - config { - httpMethod = patch - endpointOptions { - path = /service/mock/patch.json - body = "{\"password\": \"pazzword\"}" - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - delete { - factory = http - config { - httpMethod = delete - endpointOptions { - path = /service/mock/delete.json - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - head { - factory = http - config { - httpMethod = head - endpointOptions { - path = /service/mock/head.json - domain = localhost - port = ${test.random.service.port} - allowedRequestHeaders = ["Content-Type"] - } - } - } - } -} +global.handler.fragmentsHandler.config { + tasks { + various-methods-for-http-action { + actions = [ + { + action = get + } + { + action = post + } + { + action = put + } + { + action = patch + } + { + action = delete + } + { + action = head + } + ] + on._success { + action = te-hbs + } + } + } + + actions { + get { + factory = http + config { + httpMethod = get + endpointOptions { + path = /service/mock/get.json + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + responseOptions { + forceJson = true + } + } + } + post { + factory = http + config { + httpMethod = post + endpointOptions { + path = /service/mock/post.json + body = "{\"password\": \"pazzword\"}" + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + put { + factory = http + config { + httpMethod = put + endpointOptions { + path = /service/mock/put.json + interpolateBody = true + bodyJson { + password = pazzword + } + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + patch { + factory = http + config { + httpMethod = patch + endpointOptions { + path = /service/mock/patch.json + body = "{\"password\": \"pazzword\"}" + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + delete { + factory = http + config { + httpMethod = delete + endpointOptions { + path = /service/mock/delete.json + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + head { + factory = http + config { + httpMethod = head + endpointOptions { + path = /service/mock/head.json + domain = localhost + port = ${test.random.service.port} + allowedRequestHeaders = ["Content-Type"] + } + } + } + } +} From b684c260bc5091a4dd271639dedd7f5331db2c36 Mon Sep 17 00:00:00 2001 From: "filip.kowalski" Date: Wed, 15 Jul 2020 15:59:45 +0200 Subject: [PATCH 4/4] #146 Remove duplicated files --- conf/application.conf | 11 - conf/knots/hbsTemplateEngineKnot.conf | 26 --- conf/knots/pebbleTemplateEngineKnot.conf | 22 -- conf/knots/templateEngineStack.conf | 19 -- conf/routes/handlers/fragmentsHandler.conf | 56 ----- .../handlers/httpRepoConnectorHandler.conf | 62 ----- conf/routes/te-get.conf | 21 -- conf/routes/web-api-get.conf | 23 -- conf/server.conf | 101 --------- conf/tasks/task-with-fallback-action.conf | 89 -------- .../knotx-fragments-debug-data/mocks.conf | 8 - .../knotx-fragments-debug-data/pebble.conf | 1 - .../knotx-fragments-debug-data/tasks.conf | 211 ------------------ 13 files changed, 650 deletions(-) delete mode 100644 conf/application.conf delete mode 100644 conf/knots/hbsTemplateEngineKnot.conf delete mode 100644 conf/knots/pebbleTemplateEngineKnot.conf delete mode 100644 conf/knots/templateEngineStack.conf delete mode 100644 conf/routes/handlers/fragmentsHandler.conf delete mode 100644 conf/routes/handlers/httpRepoConnectorHandler.conf delete mode 100644 conf/routes/te-get.conf delete mode 100644 conf/routes/web-api-get.conf delete mode 100644 conf/server.conf delete mode 100644 conf/tasks/task-with-fallback-action.conf delete mode 100644 scenarios/knotx-fragments-debug-data/mocks.conf delete mode 100644 scenarios/knotx-fragments-debug-data/pebble.conf delete mode 100644 scenarios/knotx-fragments-debug-data/tasks.conf diff --git a/conf/application.conf b/conf/application.conf deleted file mode 100644 index f080eeb6..00000000 --- a/conf/application.conf +++ /dev/null @@ -1,11 +0,0 @@ -########### Modules to start ########### -# Modules map specify a list of verticles to be started by Knot.x. -# Each line should have a form of = -# where alias is just a name that you can use later in order to define configuration for the module -# verticle-class-name is a fully qualified class name of the verticle. -# -# This JSON object is filled in included files. -modules {} - -include required(classpath("conf/server.conf")) -include required(classpath("conf/knots/templateEngineStack.conf")) diff --git a/conf/knots/hbsTemplateEngineKnot.conf b/conf/knots/hbsTemplateEngineKnot.conf deleted file mode 100644 index c8624e70..00000000 --- a/conf/knots/hbsTemplateEngineKnot.conf +++ /dev/null @@ -1,26 +0,0 @@ -# Vert.x event bus delivery options used when communicating with other verticles -address = knotx.knot.te.handlebars - -engine { - factory = handlebars - config = { - # Algorithm used to build a hash key of the compiled handlebars snippets. - # The hash is computed for the snippet handlebars 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 - - # Symbol used as a start delimiter of handlebars expression. If not use, a default '{{' is used - # - # startDelimiter = - - # Symbol used as a end delimiter of handlebars expression. If not use, a default '}}' is used - # - # endDelimiter = - } -} - diff --git a/conf/knots/pebbleTemplateEngineKnot.conf b/conf/knots/pebbleTemplateEngineKnot.conf deleted file mode 100644 index 440660a6..00000000 --- a/conf/knots/pebbleTemplateEngineKnot.conf +++ /dev/null @@ -1,22 +0,0 @@ -# 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 - } - } -} - diff --git a/conf/knots/templateEngineStack.conf b/conf/knots/templateEngineStack.conf deleted file mode 100644 index 78a74314..00000000 --- a/conf/knots/templateEngineStack.conf +++ /dev/null @@ -1,19 +0,0 @@ -########### Template Engine Stack ########### -modules { - hbsTemplateEngine = "io.knotx.te.core.TemplateEngineKnot" - pebbleTemplateEngine = "io.knotx.te.core.TemplateEngineKnot" -} - -########### Modules configurations ########### -config.hbsTemplateEngine { - options.config { - include required(classpath("conf/knots/hbsTemplateEngineKnot.conf")) - } -} - -########### Modules configurations ########### -config.pebbleTemplateEngine { - options.config { - include required(classpath("conf/knots/pebbleTemplateEngineKnot.conf")) - } -} diff --git a/conf/routes/handlers/fragmentsHandler.conf b/conf/routes/handlers/fragmentsHandler.conf deleted file mode 100644 index b8c5464b..00000000 --- a/conf/routes/handlers/fragmentsHandler.conf +++ /dev/null @@ -1,56 +0,0 @@ -########### This configuration is overloaded in integration tests! ########### -tasks { - # will be extended per unit tests -} - -actions { - # will be extended per unit tests - te-hbs { - factory = knot - config { - address = knotx.knot.te.handlebars - deliveryOptions { - sendTimeout = 3000 - } - } - } - te-pebble { - factory = knot - config { - address = knotx.knot.te.pebble - deliveryOptions { - sendTimeout = 3000 - } - } - } -} - -taskFactories = [ - { - factory = default - config { - tasks = ${global.handler.fragmentsHandler.config.tasks} - nodeFactories = [ - { - factory = action - config.actions = ${global.handler.fragmentsHandler.config.actions} - } - { - factory = subtasks - } - ] - } - } -] - -consumerFactories = [ - { - factory = fragmentHtmlBodyWriter - config { - condition { - param = debug - } - fragmentTypes = [ "snippet" ] - } - } -] diff --git a/conf/routes/handlers/httpRepoConnectorHandler.conf b/conf/routes/handlers/httpRepoConnectorHandler.conf deleted file mode 100644 index b1791c19..00000000 --- a/conf/routes/handlers/httpRepoConnectorHandler.conf +++ /dev/null @@ -1,62 +0,0 @@ -# Vert.x event bus delivery options used when communicating with other verticles -# see http://vertx.io/docs/vertx-core/dataobjects.html#HttpClientOptions for the details what can be configured -# -clientOptions { - maxPoolSize = 1000 - idleTimeout = 120 # seconds - tryUseCompression = true - - # If you're going to use SSL (clientDestination.scheme='https') then here you'd need to configure - # some aspects related to the SSL negotiation and validation. - # - # Whether all server certificated should be trusted or not (e.g. self-signed certificates) - # trustAll = true - # - # Hostname verification - # verifyHost = false - # - # It will force SSL SNI (Server Name Indication). The SNI will be set to the same value as 'hostHeader' (set in ClientDestination) - # forceSni = true -} - -# HTTP Repository connection details -clientDestination { - # Connection scheme: http or https - scheme = http - - # domain or the IP of the host: e.g. localhost, 10.0.11.2 - domain = localhost - - ## Port on which the host listens, e.g. 8080, 3001, etc. - port = ${test.wiremock.mockRepository.port} - - # Host header override to be used with a communication to the repository. If it's set, it overrides any value in the 'Host' header, and sets the SNI SSL to the same value. - # hostHeader = -} - -# List of allowed request headers that will be send to HTTP repository. -# Each item is a string that defines regex, e.g. to match any char use `.*` -# -allowedRequestHeaders = [ - Host - "Accept.*" - Authorization - Connection - Cookie - Date - "Edge.*" - "If.*" - Origin - Pragma - Proxy-Authorization - "Surrogate.*" - User-Agent - Via - "X-.*" -] - -# Statically defined HTTP request header sent in every request to the repository -customHttpHeader = { - name = X-User-Agent - value = Knot.x -} diff --git a/conf/routes/te-get.conf b/conf/routes/te-get.conf deleted file mode 100644 index 21496d8d..00000000 --- a/conf/routes/te-get.conf +++ /dev/null @@ -1,21 +0,0 @@ -routingOperations = ${routingOperations} [ - { - operationId = te-get - handlers = ${config.server.handlers.common.request} [ - { - name = httpRepoConnectorHandler - config = ${global.handler.httpRepoConnectorHandler.config} - }, - { - name = htmlFragmentsSupplier - }, - { - name = fragmentsHandler - config = ${global.handler.fragmentsHandler.config} - }, - { - name = fragmentsAssembler - } - ] ${config.server.handlers.common.response} - } -] diff --git a/conf/routes/web-api-get.conf b/conf/routes/web-api-get.conf deleted file mode 100644 index 11468083..00000000 --- a/conf/routes/web-api-get.conf +++ /dev/null @@ -1,23 +0,0 @@ -routingOperations = ${routingOperations} [ - { - operationId = web-api-get - handlers = ${config.server.handlers.common.request} [ - { - name = singleFragmentSupplier - config = { - type = json - configuration { - data-knotx-task = web-api-test - } - } - }, - { - name = fragmentsHandler - config = ${global.handler.fragmentsHandler.config} - }, - { - name = fragmentsAssembler - } - ] ${config.server.handlers.common.response} - } -] diff --git a/conf/server.conf b/conf/server.conf deleted file mode 100644 index d558f987..00000000 --- a/conf/server.conf +++ /dev/null @@ -1,101 +0,0 @@ -########### Knot.x JUnit5 config ########### -test { - random { - globalServer.port = 0 - } -} - -########### Knot.x Server ########### -modules { - server = "io.knotx.server.KnotxServerVerticle" -} - -########### Modules configurations ########### -config.server { - handlers.common { - request = [ - { - name = bodyHandler - }, - { - name = requestContextHandler - } - ], - response = [ - { - name = headerHandler - # Statically defined HTTP response header returned to the client in every HTTP response - config { - name = X-Server - value = Knot.x-Custom-Header - } - }, - { - name = writerHandler - # List of HTTP response headers Knot.x can return to the client - config.allowedResponseHeaders = [ - Access-Control-Allow-Origin - Content-Type - Content-Length - X-Server - ] - } - ] - } - options.config { - # Configuraiton of HTTP server - serverOptions { - # Knot.x server HTTP port - port = ${test.random.globalServer.port} - - # If you want a server to serve SSL connections you can configure it here - # - # Enable SSL - # ssl = true - # - # Path on the server the keystore.jks file is located - # keyStoreOptions.path = - # - # Keystore password - # keyStoreOptions.password = - } - - # Location of your Open API spec. It can be an absolute path, a local path or remote url (with HTTP protocol). - routingSpecificationLocation = /openapi.yaml - - displayExceptionDetails = true - - dropRequestOptions { - # FixMe this should be enabled by default, see https://github.com/Knotx/knotx-server-http/issues/20 for details - enabled = false - - # Status code that is served if the response is dropped, default is 429, "Too Many Requests" - # dropRequestResponseCode = - - # Number of request that single Server insance can support concurrently. Default value is 1000. - # backpressureBufferCapacity - - # Strategy how to deal with backpressure buffer overflow. Default is DROP_LATEST. - # backpressureStrategy = - } - - routingOperations = [] - include required(classpath("conf/routes/te-get.conf")) - include required(classpath("conf/routes/web-api-get.conf")) - } - - # The options object carries-on configuration called DeploymentOptions for a given verticle. - # It allows you to control the verticle behaviour, such as how many instances, classpath isolation, workers, etc. - # See available options http://vertx.io/docs/vertx-core/dataobjects.html#DeploymentOptions - # - # options {} -} - -########### Globals ########### -global { - handler { - httpRepoConnectorHandler.config = { include required(classpath("conf/routes/handlers/httpRepoConnectorHandler.conf")) } - # This value is overloaded in test - fragmentsHandler.config = { include required(classpath("conf/routes/handlers/fragmentsHandler.conf")) } - } -} diff --git a/conf/tasks/task-with-fallback-action.conf b/conf/tasks/task-with-fallback-action.conf deleted file mode 100644 index 220765dd..00000000 --- a/conf/tasks/task-with-fallback-action.conf +++ /dev/null @@ -1,89 +0,0 @@ -global.handler.fragmentsHandler.config { - tasks { - tags-listing { - action = tags - onTransitions { - _success { - action = te-hbs - } - _error { - action = tags-fallback - } - } - } - authors-listing { - action = author - onTransitions { - _success { - action = te-hbs - } - } - } - books-and-authors-listing { - actions = [ - { - action = book - }, - { - action = author - } - ] - onTransitions { - _success { - action = te-hbs - } - } - } - } - - actions { - tags { - factory = http - config { - endpointOptions { - path = /service/broken/500.json - domain = localhost - port = ${test.wiremock.mockBrokenService.port} - allowedRequestHeaders = [ "Content-Type" ] - } - } - } - tags-fallback { - factory = inline-body - config { - body = """

Tags are unavailable at the moment

""" - } - } - 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" ] - } - } - } - te-hbs { - factory = "knot" - config { - address = "knotx.knot.te.handlebars" - deliveryOptions { - sendTimeout = 3000 - } - } - } - } -} \ No newline at end of file diff --git a/scenarios/knotx-fragments-debug-data/mocks.conf b/scenarios/knotx-fragments-debug-data/mocks.conf deleted file mode 100644 index c21efc94..00000000 --- a/scenarios/knotx-fragments-debug-data/mocks.conf +++ /dev/null @@ -1,8 +0,0 @@ -########### Knot.x JUnit5 config ########### -test.wiremock { - mockRepository.port = 0 - mockService.port = 0 -} -test.random { - delayedService.port = 0 -} diff --git a/scenarios/knotx-fragments-debug-data/pebble.conf b/scenarios/knotx-fragments-debug-data/pebble.conf deleted file mode 100644 index 946bd33d..00000000 --- a/scenarios/knotx-fragments-debug-data/pebble.conf +++ /dev/null @@ -1 +0,0 @@ -config.pebbleTemplateEngine.options.config.engine.config.syntax.wrappingRootNodeName = root \ No newline at end of file diff --git a/scenarios/knotx-fragments-debug-data/tasks.conf b/scenarios/knotx-fragments-debug-data/tasks.conf deleted file mode 100644 index 6efea299..00000000 --- a/scenarios/knotx-fragments-debug-data/tasks.conf +++ /dev/null @@ -1,211 +0,0 @@ -global.handler.fragmentsHandler.config { - tasks { - user-task { - action = fetch-user-info // _success - onTransitions._success { - action = te-hbs - } - } - payments-task { - action = fetch-user-info // _success - onTransitions._success { - actions = [ - { - action = fetch-payment-providers // _success - onTransitions._error { - action = fetch-payment-providers-fallback - } - } - { - action = fetch-offers // _error - onTransitions._error { - action = fetch-offers-fallback // _success - } - } - { - action = fetch-delivery-options-cb // _fallback - onTransitions._fallback { - action = fetch-delivery-timeout // _success - } - } - ] - onTransitions._success { - action = te-pebble // _success - } - } - onTransitions._error { - action = fetch-user-info-fallback - onTransitions._success { - action = fetch-user-info-fallback-success - } - onTransitions._error { - action = fetch-user-info-fallback-error - } - } - onTransitions._custom { - action = fetch-user-info-custom-fallback - } - } - } - - actions { - fetch-user-info { - factory = http - config.endpointOptions { - path = /service/mock/userInfo.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-payment-providers { - factory = http - config.endpointOptions { - path = /service/mock/paymentProviders.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-offers { - factory = http - config.endpointOptions { - path = /service/mock/specialOffers.xml - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - config.responseOptions { - forceJson = true - predicates = [] - } - } - fetch-delivery { - factory = http - config.endpointOptions { - path = /mock/scenario/delayed - domain = localhost - port = ${test.random.delayedService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-delivery-options-cb { - factory = cb - config { - circuitBreakerName = delivery-cb - circuitBreakerOptions { - maxRetries = 1 - timeout = 50 - } - } - doAction = fetch-delivery - } - fetch-offers-fallback { - factory = inline-payload - config { - alias = fetch-offers - payload { - _result { - fallback = "json-syntax-error" - } - } - } - } - fetch-delivery-timeout { - factory = inline-payload - config { - alias = fetch-delivery - payload { - _result { - fallback = "action ended with _timeout" - } - } - } - } - create-response { - factory = payload-to-body - } - te-hbs { - factory = knot - config { - address = knotx.knot.te.handlebars - deliveryOptions { - sendTimeout = 3000 - } - } - } - te-pebble { - factory = knot - config { - address = knotx.knot.te.pebble - deliveryOptions { - sendTimeout = 3000 - } - } - } - fetch-payment-providers-fallback { - factory = http - config.endpointOptions { - path = /service/mock/placeholderFallback.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-user-info-fallback { - factory = http - config.endpointOptions { - path = /service/mock/placeholderFallback.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-user-info-fallback-success { - factory = http - config.endpointOptions { - path = /service/mock/placeholderFallback.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-user-info-fallback-error { - factory = http - config.endpointOptions { - path = /service/mock/placeholderFallback.json - domain = localhost - port = ${test.wiremock.mockService.port} - allowedRequestHeaders = ["Content-Type"] - } - } - fetch-user-info-custom-fallback { - factory = http - config.endpointOptions { - path = /service/mock/placeholderFallback.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} - config.logLevel = info - } - { - factory = subtasks - } - ] - } - } - ] -} \ No newline at end of file