17 changed files with 356 additions and 14 deletions
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.importingconfigurationinterfaces; |
||||
|
||||
import org.testcontainers.containers.MongoDBContainer; |
||||
import org.testcontainers.containers.Neo4jContainer; |
||||
import org.testcontainers.junit.jupiter.Container; |
||||
|
||||
interface MyContainers { |
||||
|
||||
@Container |
||||
MongoDBContainer mongoContainer = new MongoDBContainer("mongo:5.0"); |
||||
|
||||
@Container |
||||
Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:5"); |
||||
|
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.importingconfigurationinterfaces; |
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration; |
||||
import org.springframework.boot.testcontainers.context.ImportTestcontainers; |
||||
|
||||
@TestConfiguration(proxyBeanMethods = false) |
||||
@ImportTestcontainers(MyContainers.class) |
||||
class MyTestConfiguration { |
||||
|
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.springbeans; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.testcontainers.containers.MongoDBContainer; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.context.annotation.Import; |
||||
|
||||
@SpringBootTest |
||||
@Import(MyTestConfiguration.class) |
||||
class MyIntegrationTests { |
||||
|
||||
@Autowired |
||||
private MongoDBContainer mongo; |
||||
|
||||
@Test |
||||
void myTest() { |
||||
/**/ System.out.println(this.mongo); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.springbeans; |
||||
|
||||
import org.testcontainers.containers.MongoDBContainer; |
||||
import org.testcontainers.utility.DockerImageName; |
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration; |
||||
import org.springframework.context.annotation.Bean; |
||||
|
||||
@TestConfiguration(proxyBeanMethods = false) |
||||
class MyTestConfiguration { |
||||
|
||||
@Bean |
||||
MongoDBContainer mongoDbContainer() { |
||||
return new MongoDBContainer(DockerImageName.parse("mongo:5.0")); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.importingconfigurationinterfaces |
||||
|
||||
import org.testcontainers.containers.MongoDBContainer |
||||
import org.testcontainers.containers.Neo4jContainer |
||||
import org.testcontainers.junit.jupiter.Container |
||||
|
||||
interface MyContainers { |
||||
|
||||
companion object { |
||||
|
||||
@Container |
||||
val mongoContainer: MongoDBContainer = MongoDBContainer("mongo:5.0") |
||||
|
||||
@Container |
||||
val neo4jContainer: Neo4jContainer<*> = Neo4jContainer("neo4j:5") |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.importingconfigurationinterfaces |
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration |
||||
import org.springframework.boot.testcontainers.context.ImportTestcontainers |
||||
|
||||
@TestConfiguration(proxyBeanMethods = false) |
||||
@ImportTestcontainers(MyContainers::class) |
||||
class MyTestConfiguration { |
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.springbeans |
||||
|
||||
import org.junit.jupiter.api.Test |
||||
import org.springframework.beans.factory.annotation.Autowired |
||||
import org.springframework.boot.test.context.SpringBootTest |
||||
import org.springframework.context.annotation.Import |
||||
import org.testcontainers.containers.MongoDBContainer |
||||
|
||||
@SpringBootTest |
||||
@Import(MyTestConfiguration::class) |
||||
class MyIntegrationTests { |
||||
|
||||
@Autowired |
||||
private val mongo: MongoDBContainer? = null |
||||
|
||||
@Test |
||||
fun myTest() { |
||||
/**/ println() |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* Copyright 2012-2025 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.testing.testcontainers.springbeans |
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration |
||||
import org.springframework.context.annotation.Bean |
||||
import org.testcontainers.containers.MongoDBContainer |
||||
import org.testcontainers.utility.DockerImageName |
||||
|
||||
@TestConfiguration(proxyBeanMethods = false) |
||||
class MyTestConfiguration { |
||||
|
||||
@Bean |
||||
fun mongoDbContainer(): MongoDBContainer { |
||||
return MongoDBContainer(DockerImageName.parse("mongo:5.0")) |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue