Skip to content
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

Knot.x 2.0 Stack & Unit tests #39

Merged
merged 9 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ Structure of the stack is following
├── bin
│ └── knotx // shell script used to resolve and run knotx instance
├── conf // contains application and logger configuration files
│ ├── application.conf // defines all modules that Knot.x instance is running, provides configuration for Knot.x Core and global variables for other config files
│ ├── application.conf // defines / includes all modules that Knot.x instance is running
│ ├── bootstrap.json // config retriever options, defines application configuration stores (e.g. points to `application.conf` - the main configuration)
│ ├── default-cluster.xml // basic configuration of Knot.x instance cluster
│ ├── includes // additional modules configuration which are included in `application.conf`
│ │ ├── actionKnot.conf
│ │ ├── hbsKnot.conf
│ │ ├── httpRepo.conf
│ │ ├── server.conf
│ │ ├── serviceAdapter.conf
│ │ └── serviceKnot.conf
│ ├── openapi.yaml // Open API 3.0 configuration that is loaded via Knot.x HTTP Server
│ ├── server.conf // Knot.x HTTP server configuration which is included in `application.conf`
│ ├── routes // server routes configurations
│ │ ├── operation-get.conf
│ │ └── handlers // handlers used in API operations definitions
| │ │ ├── knotEngineHandler.conf
| │ │ └── httpRepoConnectorHandler.conf
│ ├── knots // Knot modules configurations which are included in `application.conf`
│ │ ├── dataBridgeStack.conf
│ │ ├── dataBridgeKnot.conf
│ │ ├── dataBridgeSourceHttp.conf
│ │ ├── templateEngineStack.conf
│ │ └── templateEngineKnot.conf
│ └── logback.xml // logger configuration
├── knotx-stack.json // stack descriptor, defines instance libraries and dependencies
├── lib // contains instance libraries and dependencies, instance classpath
Expand Down
42 changes: 28 additions & 14 deletions knotx-it-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,48 @@
<name>Knot.x - Integration Tests</name>

<dependencies>
<!-- Knot.x core -->
<!-- Knot.x Launcher -->
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-core</artifactId>
<artifactId>knotx-launcher</artifactId>
</dependency>
<!-- Knot.x Server -->
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-databridge-api</artifactId>
<artifactId>knotx-server-http-core</artifactId>
</dependency>
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-databridge-core</artifactId>
<artifactId>knotx-splitter-html</artifactId>
</dependency>
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-databridge-adapter-http</artifactId>
<artifactId>knotx-assembler</artifactId>
</dependency>
<!-- Knot.x Repositories -->
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-repository-connector-http</artifactId>
</dependency>
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-forms-api</artifactId>
<artifactId>knotx-repository-connector-fs</artifactId>
</dependency>
<!-- Knot.x Knot Engine -->
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-forms-core</artifactId>
<artifactId>knotx-knot-engine-handler</artifactId>
</dependency>
<!-- Knot.x Data Bridge -->
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-template-engine-api</artifactId>
<artifactId>knotx-databridge-core</artifactId>
</dependency>
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-databridge-adapter-http</artifactId>
</dependency>
<!-- Knot.x Template Engine -->
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-template-engine-core</artifactId>
Expand All @@ -66,6 +79,8 @@
<groupId>io.knotx</groupId>
<artifactId>knotx-template-engine-handlebars</artifactId>
</dependency>

<!-- Vert.x -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
Expand Down Expand Up @@ -122,12 +137,6 @@
<artifactId>vertx-config</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.knotx</groupId>
<artifactId>knotx-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -144,6 +153,11 @@
<configuration>
<source>8</source>
<target>8</target>
<compilerArgs>
<arg>-verbose</arg>
<arg>-Xlint:all</arg>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ final class KnotxServerTester {
this.serverPort = serverPort;
}

static KnotxServerTester defatultInstance() {
return new KnotxServerTester(KNOTX_TESTS_SERVER_ADDRESS_DEFAULT,
KNOTX_TESTS_SERVER_PORT_DEFAULT);
static KnotxServerTester defaultInstance() {
return defaultInstance(KNOTX_TESTS_SERVER_PORT_DEFAULT);
}

static KnotxServerTester defaultInstance(int port) {
return new KnotxServerTester(KNOTX_TESTS_SERVER_ADDRESS_DEFAULT, port);
}

void testPostRequest(VertxTestContext context, Vertx vertx, String url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.github.tomakehurst.wiremock.WireMockServer;
import io.knotx.junit5.KnotxApplyConfiguration;
import io.knotx.junit5.KnotxExtension;
import io.knotx.junit5.wiremock.KnotxWiremock;
import io.knotx.junit5.wiremock.ClasspathResourcesMockServer;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.junit5.VertxTestContext;
import io.vertx.reactivex.core.Vertx;
Expand All @@ -19,14 +19,15 @@
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;

@Disabled("Fallbacks need to be reimplemented.")
@ExtendWith(KnotxExtension.class)
@TestInstance(Lifecycle.PER_CLASS)
public class SampleApplicationFallbackSupportIntegrationTest {
class SampleApplicationFallbackSupportIntegrationTest {

@KnotxWiremock
@ClasspathResourcesMockServer
private WireMockServer mockService;

@KnotxWiremock
@ClasspathResourcesMockServer
private WireMockServer mockRepository;

private KnotxServerTester knotxServerTester;
Expand All @@ -51,89 +52,89 @@ void initMocks() {
.withHeader("X-Server", "Knot.x")
));

knotxServerTester = KnotxServerTester.defatultInstance();
knotxServerTester = KnotxServerTester.defaultInstance();
}

@Test
@KnotxApplyConfiguration("conf/integrationTestsStack.conf")
public void requestPageWhenFormsProcessingFails_expectServerError(
@KnotxApplyConfiguration("conf/application.conf")
void requestPageWhenFormsProcessingFails_expectServerError(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetServerError(context, vertx, "/content/local/notExistingFormsAdapter.html",
HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
}

@Test
@KnotxApplyConfiguration("conf/integrationTestsStack.conf")
@KnotxApplyConfiguration("conf/application.conf")
@Disabled("Bug in forms - when using undefined data adapter fallback is not applied")
public void requestPageWhenFormsProcessingFailsAndFallbackDefined(
void requestPageWhenFormsProcessingFailsAndFallbackDefined(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetRequest(context, vertx, "/content/local/notExistingFormsAdapterWithFallback.html",
"results/pageWithFallback.html");
}

@Test
@KnotxApplyConfiguration({"conf/integrationTestsStack.conf",
"conf/overrides/defaultFallback.conf"})
@KnotxApplyConfiguration({"conf/application.conf",
"conf/overrides/defaultFallback.conf" })
@Disabled("Bug in forms - when using undefined data adapter fallback is not applied")
public void requestPageWhenFormsProcessingFailsAndGlobalFallbackDefined(
void requestPageWhenFormsProcessingFailsAndGlobalFallbackDefined(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetRequest(context, vertx, "/content/local/notExistingFormsAdapter.html",
"results/pageWithGlobalFallback.html");
}

@Test
@KnotxApplyConfiguration("conf/integrationTestsStack.conf")
public void requestPageWhenDatabridgeProcessingFails_expectServerError(
@KnotxApplyConfiguration("conf/application.conf")
void requestPageWhenDatabridgeProcessingFails_expectServerError(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetServerError(context, vertx, "/content/local/notExistingDataDefinition.html",
HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
}

@Test
@KnotxApplyConfiguration("conf/integrationTestsStack.conf")
public void requestPageWhenDatabridgeProcessingFailsAndFallbackDefined(
@KnotxApplyConfiguration("conf/application.conf")
void requestPageWhenDatabridgeProcessingFailsAndFallbackDefined(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetRequest(context, vertx, "/content/local/notExistingDataDefinitionWithFallback.html",
"results/pageWithFallback.html");
}

@Test
@KnotxApplyConfiguration({"conf/integrationTestsStack.conf",
"conf/overrides/defaultFallback.conf"})
public void requestPageWhenDatabridgeProcessingFailsAndGlobalFallbackDefined(
@KnotxApplyConfiguration({"conf/application.conf",
"conf/overrides/defaultFallback.conf" })
void requestPageWhenDatabridgeProcessingFailsAndGlobalFallbackDefined(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetRequest(context, vertx, "/content/local/notExistingDataDefinition.html",
"results/pageWithGlobalFallback.html");
}

@Test
@KnotxApplyConfiguration("conf/integrationTestsStack.conf")
public void requestPageWhenTemplateEngineProcessingFails_expectServerError(
@KnotxApplyConfiguration("conf/application.conf")
void requestPageWhenTemplateEngineProcessingFails_expectServerError(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetServerError(context, vertx, "/content/local/notExistingTemplateEngine.html",
HttpResponseStatus.INTERNAL_SERVER_ERROR.code());
}

@Test
@KnotxApplyConfiguration("conf/integrationTestsStack.conf")
public void requestPageWhenTemplateEngineProcessingFailsAndFallbackDefined(
@KnotxApplyConfiguration("conf/application.conf")
void requestPageWhenTemplateEngineProcessingFailsAndFallbackDefined(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetRequest(context, vertx, "/content/local/notExistingTemplateEngineWithFallback.html",
"results/pageWithFallback.html");
}

@Test
@KnotxApplyConfiguration({"conf/integrationTestsStack.conf",
"conf/overrides/defaultFallback.conf"})
public void requestPageWhenTemplateEngineProcessingFailsAndGlobalFallbackDefined(
@KnotxApplyConfiguration({"conf/application.conf",
"conf/overrides/defaultFallback.conf" })
void requestPageWhenTemplateEngineProcessingFailsAndGlobalFallbackDefined(
VertxTestContext context, Vertx vertx) {
knotxServerTester
.testGetRequest(context, vertx, "/content/local/notExistingTemplateEngine.html",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import com.github.tomakehurst.wiremock.WireMockServer;
import io.knotx.junit5.KnotxApplyConfiguration;
import io.knotx.junit5.KnotxExtension;
import io.knotx.junit5.wiremock.KnotxWiremock;
import io.knotx.junit5.RandomPort;
import io.knotx.junit5.wiremock.ClasspathResourcesMockServer;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.junit5.VertxTestContext;
import io.vertx.reactivex.core.MultiMap;
Expand All @@ -35,20 +36,18 @@
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(KnotxExtension.class)
public class SampleApplicationHeadersIntegrationTest {
class SampleApplicationHeadersIntegrationTest {

private MultiMap expectedHeaders = MultiMap.caseInsensitiveMultiMap();

@KnotxWiremock
protected WireMockServer mockService;
@ClasspathResourcesMockServer
private WireMockServer mockService;

@KnotxWiremock
protected WireMockServer mockRepository;

private KnotxServerTester knotxServerTester;
@ClasspathResourcesMockServer
private WireMockServer mockRepository;

@BeforeEach
public void before() {
void before() {
stubForServer(mockService,
get(urlMatching("/service/mock/.*"))
.willReturn(
Expand All @@ -64,21 +63,20 @@ public void before() {
aResponse()
.withHeader("Cache-control", "no-cache, no-store, must-revalidate")
.withHeader("Content-Type", "text/html; charset=UTF-8")
.withHeader("X-Server", "Knot.x")
.withHeader("X-Server", "Knot.x-Custom-Header")
));

expectedHeaders.clear();
expectedHeaders.add("Content-Type", "text/html; charset=UTF-8");
expectedHeaders.add("X-Server", "Knot.x-Custom-Header");

knotxServerTester = KnotxServerTester.defatultInstance();
}

@Test
@KnotxApplyConfiguration("conf/integrationTestsStack.conf")
public void whenRequestingRemoteRepository_expectOnlyAllowedResponseHeaders(
VertxTestContext context, Vertx vertx) {
knotxServerTester.testGet(context, vertx, "/content/remote/fullPage.html", resp -> {
@KnotxApplyConfiguration("conf/application.conf")
void whenRequestingRemoteRepository_expectOnlyAllowedResponseHeaders(VertxTestContext context,
Vertx vertx, @RandomPort Integer globalServerPort) {
KnotxServerTester serverTester = KnotxServerTester.defaultInstance(globalServerPort);
serverTester.testGet(context, vertx, "/content/remote/fullPage.html", resp -> {
MultiMap headers = resp.headers();
expectedHeaders.names().forEach(name -> {
assertTrue(headers.contains(name), "Header " + name + " is expected to be present.");
Expand Down
Loading