|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.docker.compose.service.connection.oracle; |
| 18 | + |
| 19 | +import java.sql.Driver; |
| 20 | +import java.time.Duration; |
| 21 | + |
| 22 | +import org.awaitility.Awaitility; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | +import org.junit.jupiter.api.condition.OS; |
| 25 | + |
| 26 | +import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails; |
| 27 | +import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests; |
| 28 | +import org.springframework.boot.jdbc.DatabaseDriver; |
| 29 | +import org.springframework.boot.testsupport.junit.DisabledOnOs; |
| 30 | +import org.springframework.boot.testsupport.testcontainers.DockerImageNames; |
| 31 | +import org.springframework.jdbc.core.JdbcTemplate; |
| 32 | +import org.springframework.jdbc.datasource.SimpleDriverDataSource; |
| 33 | +import org.springframework.util.ClassUtils; |
| 34 | + |
| 35 | +import static org.assertj.core.api.Assertions.assertThat; |
| 36 | + |
| 37 | +/** |
| 38 | + * Integration tests for {@link OracleJdbcDockerComposeConnectionDetailsFactory} |
| 39 | + * |
| 40 | + * @author Andy Wilkinson |
| 41 | + */ |
| 42 | +@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64", |
| 43 | + disabledReason = "The Oracle image has no ARM support") |
| 44 | +class OracleFreeJdbcDockerComposeConnectionDetailsFactoryIntegrationTests |
| 45 | + extends AbstractDockerComposeIntegrationTests { |
| 46 | + |
| 47 | + OracleFreeJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() { |
| 48 | + super("oracle-compose.yaml", DockerImageNames.oracleFree()); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + @SuppressWarnings("unchecked") |
| 53 | + void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase() throws Exception { |
| 54 | + JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class); |
| 55 | + assertThat(connectionDetails.getUsername()).isEqualTo("app_user"); |
| 56 | + assertThat(connectionDetails.getPassword()).isEqualTo("app_user_secret"); |
| 57 | + assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/xepdb1"); |
| 58 | + SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); |
| 59 | + dataSource.setUrl(connectionDetails.getJdbcUrl()); |
| 60 | + dataSource.setUsername(connectionDetails.getUsername()); |
| 61 | + dataSource.setPassword(connectionDetails.getPassword()); |
| 62 | + dataSource.setDriverClass((Class<? extends Driver>) ClassUtils.forName(connectionDetails.getDriverClassName(), |
| 63 | + getClass().getClassLoader())); |
| 64 | + Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().untilAsserted(() -> { |
| 65 | + JdbcTemplate template = new JdbcTemplate(dataSource); |
| 66 | + assertThat(template.queryForObject(DatabaseDriver.ORACLE.getValidationQuery(), String.class)) |
| 67 | + .isEqualTo("Hello"); |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments