-
Notifications
You must be signed in to change notification settings - Fork 12
Add functional tests #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mateusz512
wants to merge
9
commits into
Knotx:master
Choose a base branch
from
Mateusz512:feature/api-gateway-caching-func-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a3cfaef
Add functional tests
d5dd3b5
re-invoke CI/CD
4fcfa1d
TEST add network=host to test container
3975662
implement multi-OS host network configuration
562b352
Remove commented line
Mateusz512 a1b5bcc
use new tasks instead of `if`
eb768ce
Merge remote-tracking branch 'origin/feature/api-gateway-caching-func…
3849e37
Merge remote-tracking branch 'knotx/master' into feature/api-gateway-…
d6052d9
#65 fix failing build
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to copy this file?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've overriden some configs that allow dockerized Knot.x to reach localhost's wiremock server. |
||
| * 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. | ||
| */ | ||
| import com.bmuschko.gradle.docker.shaded.io.netty.util.internal.PlatformDependent.isWindows | ||
| import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer | ||
| import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer | ||
| import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer | ||
| import com.bmuschko.gradle.docker.tasks.container.extras.DockerWaitHealthyContainer | ||
| import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage | ||
| import com.bmuschko.gradle.docker.tasks.image.DockerRemoveImage | ||
| import org.apache.tools.ant.taskdefs.condition.Os.FAMILY_UNIX | ||
| import org.apache.tools.ant.taskdefs.condition.Os.isFamily | ||
|
|
||
| val dockerImageRef = "$buildDir/.docker/buildImage-imageId.txt" | ||
|
|
||
| tasks.register<Copy>("copyDockerfile") { | ||
| group = "docker" | ||
| from("docker") | ||
| into("$buildDir") | ||
| expand("knotx_version" to project.property("knotx.version")) | ||
| mustRunAfter("cleanDistribution") | ||
| } | ||
|
|
||
| tasks.register<DockerRemoveImage>("removeImage") { | ||
| group = "docker" | ||
| val spec = object : Spec<Task> { | ||
| override fun isSatisfiedBy(task: Task): Boolean { | ||
| return File(dockerImageRef).exists() | ||
| } | ||
| } | ||
| onlyIf(spec) | ||
|
|
||
| targetImageId(if (File(dockerImageRef).exists()) File(dockerImageRef).readText() else "") | ||
| onError { | ||
| if (!this.message!!.contains("No such image")) | ||
| throw this | ||
| } | ||
| } | ||
|
|
||
| tasks.register<DockerBuildImage> ("buildImage") { | ||
| group = "docker" | ||
| inputDir.set(file("$buildDir")) | ||
| tags.add("${project.property("docker.image.name")}:latest") | ||
| dependsOn("removeImage", "prepareDocker") | ||
| } | ||
| val buildImage = tasks.named<DockerBuildImage>("buildImage") | ||
|
|
||
| // FUNCTIONAL TESTS | ||
|
|
||
| tasks.register<DockerCreateContainer>("createContainer") { | ||
| group = "docker-functional-tests" | ||
| dependsOn(buildImage) | ||
| targetImageId(buildImage.get().imageId) | ||
| portBindings.set(listOf("8092:8092", "18092:18092")) | ||
| exposePorts("tcp", listOf(8092, 18092)) | ||
| autoRemove.set(true) | ||
| // allow container to access host's network | ||
| dependsOn("configureUnix", "configureNonUnix") | ||
| } | ||
|
|
||
| tasks.register("configureUnix"){ | ||
| doLast { | ||
| createContainer { | ||
| network.set("host") | ||
| withEnvVar("EXTERNAL_API_DOMAIN", "localhost") | ||
| } | ||
| } | ||
| onlyIf { isFamily(FAMILY_UNIX) } | ||
| } | ||
|
|
||
| tasks.register("configureNonUnix"){ | ||
| doLast { | ||
| createContainer { | ||
| withEnvVar("EXTERNAL_API_DOMAIN", "host.docker.internal") | ||
| } | ||
| } | ||
| onlyIf { !isFamily(FAMILY_UNIX) } | ||
| } | ||
|
|
||
| val createContainer = tasks.named<DockerCreateContainer>("createContainer") | ||
|
|
||
| tasks.register<DockerStartContainer>("startContainer") { | ||
| group = "docker-functional-tests" | ||
| dependsOn(createContainer) | ||
| targetContainerId(createContainer.get().containerId) | ||
| } | ||
|
|
||
| tasks.register<DockerWaitHealthyContainer>("waitContainer") { | ||
| group = "docker-functional-tests" | ||
| dependsOn(tasks.named("startContainer")) | ||
| targetContainerId(createContainer.get().containerId) | ||
| } | ||
|
|
||
| tasks.register<DockerStopContainer>("stopContainer") { | ||
| group = "docker-functional-tests" | ||
| targetContainerId(createContainer.get().containerId) | ||
| } | ||
|
|
||
| /** Deprecated */ | ||
| tasks.register("runTest", Test::class) { | ||
| dependsOn(tasks.named("runFunctionalTest")) | ||
| } | ||
|
|
||
| tasks.register("runFunctionalTest", Test::class) { | ||
| group = "docker-functional-tests" | ||
| dependsOn(tasks.named("waitContainer")) | ||
| finalizedBy(tasks.named("stopContainer")) | ||
| include("**/*ITCase*") | ||
| } | ||
|
|
||
| tasks.register("prepareDocker") { | ||
| dependsOn("cleanDistribution", "overwriteCustomFiles", "copyDockerfile") | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
api-gateway/caching/functional/src/test/java/com/project/test/functional/CacheITCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.project.test.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.core.WireMockConfiguration.options; | ||
| import static io.restassured.RestAssured.given; | ||
|
|
||
| import com.github.tomakehurst.wiremock.WireMockServer; | ||
| import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; | ||
| import org.junit.Assert; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
|
|
||
| class CacheITCase { | ||
|
|
||
| private WireMockServer wireMockServer = new WireMockServer(options() | ||
| .port(8080) | ||
| .usingFilesUnderDirectory("../../common-services/webapi") | ||
| .extensions(new ResponseTemplateTransformer(true))); | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| wireMockServer.start(); | ||
| wireMockServer.stubFor(get(urlEqualTo("/product/id")) | ||
| .willReturn(aResponse().withStatus(200) | ||
| .withTransformers("response-template") | ||
| .withBodyFile("product.json"))); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Expect the same response when invoking API twice.") | ||
| void callProxyApiAndExpectCachedResponse() { | ||
| // @formatter:off | ||
| String firstReponse = | ||
| given() | ||
| .port(8092) | ||
| .when() | ||
| .get("/product/id") | ||
| .then() | ||
| .statusCode(200) | ||
| .extract() | ||
| .asString(); | ||
|
|
||
| String secondRespone = | ||
| given() | ||
| .port(8092) | ||
| .when() | ||
| .get("/product/id") | ||
| .then() | ||
| .statusCode(200) | ||
| .extract() | ||
| .asString(); | ||
|
|
||
| Assert.assertEquals(firstReponse, secondRespone); | ||
| // @formatter:on | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <configuration> | ||
| <property name="LOG_PATH" value="/var/log/knotx"/> | ||
|
|
||
| <include resource="io/knotx/logging/logback/defaults.xml"/> | ||
| <include resource="io/knotx/logging/logback/file-appender.xml"/> | ||
| <include resource="io/knotx/logging/logback/access.xml"/> | ||
|
|
||
| <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <layout class="ch.qos.logback.classic.PatternLayout"> | ||
| <Pattern> | ||
| %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n | ||
| </Pattern> | ||
| </layout> | ||
| </appender> | ||
|
|
||
| <logger name="io.knotx" level="TRACE"/> | ||
| <logger name="io.vertx" level="TRACE"/> | ||
|
|
||
| <root level="INFO"> | ||
| <appender-ref ref="CONSOLE"/> | ||
| </root> | ||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this for functional tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, removed