mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish "Add support for Oracle R2DBC Service Connection"
See gh-34852
This commit is contained in:
parent
6d893b2fe2
commit
0da209db08
@ -971,7 +971,7 @@ The following service connection factories are provided in the `spring-boot-test
|
||||
| Containers of type `Neo4jContainer`
|
||||
|
||||
| `R2dbcConnectionDetails`
|
||||
| Containers of type `MariaDBContainer`, `MSSQLServerContainer`, `MySQLContainer` or `PostgreSQLContainer`
|
||||
| Containers of type `MariaDBContainer`, `MSSQLServerContainer`, `MySQLContainer`, `OracleContainer`, or `PostgreSQLContainer`
|
||||
|
||||
| `RabbitConnectionDetails`
|
||||
| Containers of type `RabbitMQContainer`
|
||||
|
@ -42,8 +42,11 @@ dependencies {
|
||||
testImplementation("org.mockito:mockito-core")
|
||||
testImplementation("org.mockito:mockito-junit-jupiter")
|
||||
testImplementation("org.springframework:spring-core-test")
|
||||
testImplementation("org.springframework:spring-r2dbc")
|
||||
testImplementation("org.springframework.amqp:spring-rabbit")
|
||||
testImplementation("org.springframework.kafka:spring-kafka")
|
||||
testImplementation("org.testcontainers:junit-jupiter")
|
||||
|
||||
testRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
|
||||
}
|
||||
|
||||
|
@ -40,18 +40,20 @@ class OracleR2dbcContainerConnectionDetailsFactory
|
||||
|
||||
@Override
|
||||
public R2dbcConnectionDetails getContainerConnectionDetails(ContainerConnectionSource<OracleContainer> source) {
|
||||
return new R2dbcDatabaseContainerConnectionDetails(source.getContainer());
|
||||
return new R2dbcDatabaseContainerConnectionDetails(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link R2dbcConnectionDetails} backed by a {@link ContainerConnectionSource}.
|
||||
*/
|
||||
private static final class R2dbcDatabaseContainerConnectionDetails implements R2dbcConnectionDetails {
|
||||
private static final class R2dbcDatabaseContainerConnectionDetails extends ContainerConnectionDetails
|
||||
implements R2dbcConnectionDetails {
|
||||
|
||||
private final OracleContainer container;
|
||||
|
||||
private R2dbcDatabaseContainerConnectionDetails(OracleContainer container) {
|
||||
this.container = container;
|
||||
private R2dbcDatabaseContainerConnectionDetails(ContainerConnectionSource<OracleContainer> source) {
|
||||
super(source);
|
||||
this.container = source.getContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2012-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.boot.testcontainers.service.connection.r2dbc;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.OracleContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
|
||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link OracleR2dbcContainerConnectionDetailsFactory}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
class OracleR2dbcContainerConnectionDetailsFactoryTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
static final OracleContainer oracle = new OracleContainer(DockerImageNames.oracleXe());
|
||||
|
||||
@Autowired
|
||||
ConnectionFactory connectionFactory;
|
||||
|
||||
@Test
|
||||
void connectionCanBeMadeToOracleContainer() {
|
||||
Object result = DatabaseClient.create(this.connectionFactory)
|
||||
.sql(DatabaseDriver.ORACLE.getValidationQuery())
|
||||
.map((row, metadata) -> row.get(0))
|
||||
.first()
|
||||
.block();
|
||||
assertThat(result).isEqualTo("Hello");
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportAutoConfiguration(R2dbcAutoConfiguration.class)
|
||||
static class TestConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -41,6 +41,8 @@ public final class DockerImageNames {
|
||||
|
||||
private static final String NEO4J_VERSION = "4.4.11";
|
||||
|
||||
private static final String ORACLE_XE_VERSION = "18.4.0-slim";
|
||||
|
||||
private static final String POSTGRESQL_VERSION = "14.0";
|
||||
|
||||
private static final String RABBIT_VERSION = "3.11-alpine";
|
||||
@ -110,6 +112,10 @@ public final class DockerImageNames {
|
||||
return DockerImageName.parse("neo4j").withTag(NEO4J_VERSION);
|
||||
}
|
||||
|
||||
public static DockerImageName oracleXe() {
|
||||
return DockerImageName.parse("gvenzl/oracle-xe").withTag(ORACLE_XE_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link DockerImageName} suitable for running PostgreSQL.
|
||||
* @return a docker image name for running postgresql
|
||||
|
Loading…
Reference in New Issue
Block a user