Create service connections from Testcontainers-managed containers
Building upon the auto-configuration support for service connections, this commit adds support for deriving connection details from a Testcontainers-managed container. Several service-specific annotations have been introduced. These annotations can be used on a container field to indicate that it is a source of the details for a service connection. See gh-34658 Co-Authored-By: Phillip Webb <pwebb@vmware.com> Co-Authored-By: Mortitz Halbritter <mkammerer@vmware.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.docs.howto.testing.testcontainers.serviceconnections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.Neo4jContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.neo4j.Neo4jServiceConnection;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@Testcontainers
|
||||
class MyIntegrationTests {
|
||||
|
||||
@Container
|
||||
@Neo4jServiceConnection
|
||||
static Neo4jContainer<?> neo4j = new Neo4jContainer<>("neo4j:4.2");
|
||||
|
||||
@Test
|
||||
void myTest() {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.docs.howto.testing.testcontainers.serviceconnection
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.autoconfigure.neo4j.Neo4jServiceConnection;
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.test.context.DynamicPropertyRegistry
|
||||
import org.springframework.test.context.DynamicPropertySource
|
||||
import org.testcontainers.containers.Neo4jContainer
|
||||
import org.testcontainers.junit.jupiter.Container
|
||||
import org.testcontainers.junit.jupiter.Testcontainers
|
||||
|
||||
@SpringBootTest
|
||||
@Testcontainers
|
||||
internal class MyIntegrationTests {
|
||||
|
||||
@Test
|
||||
fun myTest() {
|
||||
// ...
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@Container
|
||||
@Neo4jServiceConnection
|
||||
var neo4j: Neo4jContainer<*> = Neo4jContainer<Nothing>("neo4j:4.2")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user