Skip to content

Commit

Permalink
chore: Add Testcontainers connector module
Browse files Browse the repository at this point in the history
- Provide test actions to interact with Testcontainers
- Add AWS2 LocalStack container support
- Add PostgreSQL container support
- Add XML DSL support
- Add YAML DSL support
  • Loading branch information
christophd committed Nov 3, 2024
1 parent 188fb53 commit d736fc8
Show file tree
Hide file tree
Showing 83 changed files with 6,753 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public boolean isDisabled() {
logger.warn("Skipping Kubernetes action as no proper Kubernetes environment is available on host system!", e);
connected = new AtomicBoolean(false);
}
} else {
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public static String getNamespace(TestContext context) {
return KubernetesSettings.getNamespace();
}

public static boolean isConnected(TestContext context) {
if (context.getVariables().containsKey(KubernetesVariableNames.CONNECTED.value())) {
return context.getVariable(KubernetesVariableNames.CONNECTED.value(), Boolean.class);
}

return false;
}

public static Yaml yaml() {
Representer representer = new Representer(new DumperOptions()) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

public enum KubernetesVariableNames {

CONNECTED("KUBERNETES_CONNECTED"),
NAMESPACE("KUBERNETES_NAMESPACE"),
SERVICE_CLUSTER_IP("KUBERNETES_SERVICE_CLUSTER_IP");

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright the original author or authors.
*
* 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 org.citrusframework.kubernetes.actions;

import java.util.HashMap;
import java.util.Map;

import org.citrusframework.context.TestContext;
import org.citrusframework.kubernetes.KubernetesVariableNames;

/**
* Connects to a Kubernetes cluster.
*/
public class KubernetesConnectAction extends AbstractKubernetesAction implements KubernetesAction {

public KubernetesConnectAction(Builder builder) {
super("kubernetes-connect", builder);
}

@Override
public void doExecute(TestContext context) {
if (isDisabled(context)) {
return;
}

context.setVariable(KubernetesVariableNames.CONNECTED.value(), true);
}

/**
* Action builder.
*/
public static class Builder extends AbstractKubernetesAction.Builder<KubernetesConnectAction, Builder> {

private String containerImage;
private final Map<String, String> annotations = new HashMap<>();
private final Map<String, String> labels = new HashMap<>();

public Builder image(String containerImage) {
this.containerImage = containerImage;
return this;
}

public Builder annotations(Map<String, String>annotations) {
this.annotations.putAll(annotations);
return this;
}

public Builder annotation(String annotation, String value) {
this.annotations.put(annotation, value);
return this;
}

public Builder labels(Map<String, String>labels) {
this.labels.putAll(labels);
return this;
}

public Builder label(String label, String value) {
this.labels.put(label, value);
return this;
}

@Override
public KubernetesConnectAction doBuild() {
return new KubernetesConnectAction(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.exceptions.InvalidFunctionUsageException;
import org.citrusframework.functions.Function;
import org.citrusframework.kubernetes.KubernetesSettings;
import org.citrusframework.kubernetes.KubernetesSupport;

public class ServiceClusterIpFunction implements Function {

@Override
public String execute(List<String> parameterList, TestContext context) {
if (KubernetesSettings.isLocal()) {
return "127.0.0.1";
}

if (parameterList.isEmpty()) {
throw new InvalidFunctionUsageException("Function parameters must not be empty - please provide a proper service name");
}
Expand Down
102 changes: 102 additions & 0 deletions connectors/citrus-testcontainers/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-connectors</artifactId>
<version>4.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>citrus-testcontainers</artifactId>
<name>Citrus :: Connectors :: Testcontainers</name>

<dependencies>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-kubernetes</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-okhttp</artifactId>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>redpanda</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>kafka</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>

<!-- AWS Localstack -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
</dependency>

<!-- Test scoped dependencies -->
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-test-support</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-testng</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-spring</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-xml</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-yaml</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit d736fc8

Please sign in to comment.