Skip to content

Commit

Permalink
Factor out the OracleContainerSupport to test module
Browse files Browse the repository at this point in the history
  • Loading branch information
onobc committed Nov 7, 2023
1 parent 4eceed3 commit 361e589
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 49 deletions.
18 changes: 7 additions & 11 deletions spring-cloud-dataflow-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@
<artifactId>h2</artifactId>
<version>2.2.222</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -117,7 +124,6 @@
<artifactId>json-unit-assertj</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
Expand All @@ -128,11 +134,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -173,29 +174,24 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.5.8.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>${oracle-driver-ojdbc8.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,20 @@
*/
package org.springframework.cloud.dataflow.server.db.migration;

import java.util.Locale;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.containers.OracleContainer;
import org.testcontainers.utility.DockerImageName;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;

import org.springframework.core.log.LogAccessor;
import org.springframework.cloud.dataflow.server.db.oracle.OracleContainerSupport;

/**
* Basic database schema and JPA tests for Oracle XE.
*
* @author Corneil du Plessis
* @author Chris Bono
*/
@ExtendWith(SystemStubsExtension.class)
public class OracleSmokeTest extends AbstractSmokeTest {

private static final LogAccessor LOG = new LogAccessor(OracleSmokeTest.class);

private static final String WIKI_LINK = "https://github.com/spring-cloud/spring-cloud-dataflow/wiki/Oracle-on-Mac-ARM64";

@SystemStub
private static EnvironmentVariables ENV_VARS;
public class OracleSmokeTest extends AbstractSmokeTest implements OracleContainerSupport {

@BeforeAll
static void startContainer() {
if (runningOnMacArm64()) {
LOG.warn(() -> "You are running on Mac ARM64. If this test fails, make sure Colima is running prior " +
"to test invocation. See " + WIKI_LINK + " for details");
ENV_VARS.set("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock");
ENV_VARS.set("DOCKER_HOST", String.format("unix://%s/.colima/docker.sock", System.getProperty("user.home")));
}
container = new OracleContainer(DockerImageName.parse("gvenzl/oracle-xe")
.withTag("18-slim-faststart"));
container.start();
}

private static boolean runningOnMacArm64() {
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
String osArchitecture = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
return osName.contains("mac") && osArchitecture.equals("aarch64");
container = OracleContainerSupport.startContainer();
}
}
15 changes: 15 additions & 0 deletions spring-cloud-dataflow-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,32 @@
<failIfNoTests>true</failIfNoTests>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-core-dsl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>oracle-xe</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2023-2023 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
*
* https://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.springframework.cloud.dataflow.server.db.oracle;

import java.util.Locale;

import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.containers.OracleContainer;
import org.testcontainers.utility.DockerImageName;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;

import org.springframework.core.log.LogAccessor;

/**
* Provides support for testing against an {@link OracleContainer Oracle testcontainer}.
*
* @author Corneil du Plessis
* @author Chris Bono
*/
@ExtendWith(SystemStubsExtension.class)
public interface OracleContainerSupport {

LogAccessor LOG = new LogAccessor(OracleContainerSupport.class);

@SystemStub
EnvironmentVariables ENV_VARS = new EnvironmentVariables();

static OracleContainer startContainer() {
if (runningOnMacArm64()) {
String wiki = "https://github.com/spring-cloud/spring-cloud-dataflow/wiki/Oracle-on-Mac-ARM64";
LOG.warn(() -> "You are running on Mac ARM64. If this test fails, make sure Colima is running prior " +
"to test invocation. See " + wiki + " for details");
ENV_VARS.set("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", "/var/run/docker.sock");
ENV_VARS.set("DOCKER_HOST", String.format("unix://%s/.colima/docker.sock", System.getProperty("user.home")));
}
OracleContainer oracleContainer = new OracleContainer(DockerImageName.parse("gvenzl/oracle-xe")
.withTag("18-slim-faststart"));
oracleContainer.start();
return oracleContainer;
}

static boolean runningOnMacArm64() {
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
String osArchitecture = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
return osName.contains("mac") && osArchitecture.equals("aarch64");
}
}
7 changes: 7 additions & 0 deletions spring-cloud-skipper/spring-cloud-skipper-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dataflow-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2023 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.
Expand All @@ -16,18 +16,19 @@
package org.springframework.cloud.skipper.server.db.migration;

import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.containers.OracleContainer;

import org.springframework.cloud.dataflow.server.db.oracle.OracleContainerSupport;

/**
* Basic database schema and JPA tests for Oracle XE.
*
* @author Corneil du Plessis
* @author Chris Bono
*/
public class OracleSkipperSmokeTest extends AbstractSkipperSmokeTest {
public class OracleSkipperSmokeTest extends AbstractSkipperSmokeTest implements OracleContainerSupport {

@BeforeAll
static void startContainer() {
container = new OracleContainer();
container.start();
container = OracleContainerSupport.startContainer();
}
}

0 comments on commit 361e589

Please sign in to comment.