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

chore: Add Testcontainers connector module #1251

Merged
merged 1 commit into from
Nov 4, 2024
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
10 changes: 10 additions & 0 deletions catalog/citrus-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@
<artifactId>citrus-kubernetes</artifactId>
<version>4.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-knative</artifactId>
<version>4.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-testcontainers</artifactId>
<version>4.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-sql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
xmlns:citrus-k8s="http://www.citrusframework.org/schema/kubernetes/config"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd
http://www.citrusframework.org/schema/kubernetes/config http://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config.xsd">
http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd">

<context:property-placeholder location="classpath:citrus.properties"
ignore-unresolvable="true"/>
Expand Down
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
Loading