Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
747e419d
Commit
747e419d
authored
Feb 13, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
parents
3d6def9f
9fb0b97f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
12 deletions
+111
-12
CassandraDataAutoConfigurationIntegrationTests.java
...andra/CassandraDataAutoConfigurationIntegrationTests.java
+7
-3
DataNeo4jTestIntegrationTests.java
...toconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
+17
-3
DataNeo4jTestPropertiesIntegrationTests.java
...e/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java
+5
-3
DataNeo4jTestWithIncludeFilterIntegrationTests.java
...neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
+5
-3
SkippableContainer.java
...k/boot/testsupport/testcontainers/SkippableContainer.java
+77
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java
View file @
747e419d
...
...
@@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.cassandra.city.City
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.SkippableContainer
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.data.cassandra.config.CassandraSessionFactoryBean
;
import
org.springframework.data.cassandra.config.SchemaAction
;
...
...
@@ -43,7 +44,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
CassandraDataAutoConfigurationIntegrationTests
{
@ClassRule
public
static
CassandraContainer
<?>
cassandra
=
new
CassandraContainer
<>();
public
static
SkippableContainer
<
CassandraContainer
<?>>
cassandra
=
new
SkippableContainer
<>(
CassandraContainer:
:
new
);
private
AnnotationConfigApplicationContext
context
;
...
...
@@ -51,7 +53,8 @@ public class CassandraDataAutoConfigurationIntegrationTests {
public
void
setUp
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
"spring.data.cassandra.port="
+
cassandra
.
getFirstMappedPort
(),
.
of
(
"spring.data.cassandra.port="
+
cassandra
.
getContainer
().
getFirstMappedPort
(),
"spring.data.cassandra.read-timeout=24000"
,
"spring.data.cassandra.connect-timeout=10000"
)
.
applyTo
(
this
.
context
.
getEnvironment
());
...
...
@@ -96,7 +99,8 @@ public class CassandraDataAutoConfigurationIntegrationTests {
private
void
createTestKeyspaceIfNotExists
()
{
Cluster
cluster
=
Cluster
.
builder
().
withoutJMXReporting
()
.
withPort
(
cassandra
.
getFirstMappedPort
()).
addContactPoint
(
"localhost"
)
.
withPort
(
cassandra
.
getContainer
().
getFirstMappedPort
())
.
addContactPoint
(
cassandra
.
getContainer
().
getContainerIpAddress
())
.
build
();
try
(
Session
session
=
cluster
.
connect
())
{
session
.
execute
(
"CREATE KEYSPACE IF NOT EXISTS boot_test"
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestIntegrationTests.java
View file @
747e419d
...
...
@@ -18,13 +18,17 @@ package org.springframework.boot.test.autoconfigure.data.neo4j;
import
org.junit.ClassRule
;
import
org.junit.Test
;
import
org.junit.rules.TestRule
;
import
org.junit.runner.Description
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.model.Statement
;
import
org.neo4j.ogm.session.Session
;
import
org.testcontainers.containers.Neo4jContainer
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.SkippableContainer
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -46,9 +50,18 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@DataNeo4jTest
public
class
DataNeo4jTestIntegrationTests
{
public
static
SkippableContainer
<
Neo4jContainer
<?>>
neo4j
=
new
SkippableContainer
<
Neo4jContainer
<?>>(
()
->
new
Neo4jContainer
<>().
withAdminPassword
(
null
));
@ClassRule
public
static
Neo4jContainer
<?>
neo4j
=
new
Neo4jContainer
<>()
.
withAdminPassword
(
null
);
public
static
TestRule
skippableContainer
=
new
TestRule
()
{
@Override
public
Statement
apply
(
Statement
base
,
Description
description
)
{
return
neo4j
.
apply
(
base
,
description
);
}
};
@Autowired
private
Session
session
;
...
...
@@ -81,7 +94,8 @@ public class DataNeo4jTestIntegrationTests {
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.data.neo4j.uri="
+
neo4j
.
getBoltUrl
())
TestPropertyValues
.
of
(
"spring.data.neo4j.uri="
+
neo4j
.
getContainer
().
getBoltUrl
())
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java
View file @
747e419d
...
...
@@ -23,6 +23,7 @@ import org.testcontainers.containers.Neo4jContainer;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.SkippableContainer
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.core.env.Environment
;
...
...
@@ -43,8 +44,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
DataNeo4jTestPropertiesIntegrationTests
{
@ClassRule
public
static
Neo4jContainer
<?>
neo4j
=
new
Neo4jContainer
<>()
.
withAdminPassword
(
null
);
public
static
SkippableContainer
<
Neo4jContainer
<?>>
neo4j
=
new
SkippableContainer
<
Neo4jContainer
<?>>(
()
->
new
Neo4jContainer
<>().
withAdminPassword
(
null
)
);
@Autowired
private
Environment
environment
;
...
...
@@ -60,7 +61,8 @@ public class DataNeo4jTestPropertiesIntegrationTests {
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.data.neo4j.uri="
+
neo4j
.
getBoltUrl
())
TestPropertyValues
.
of
(
"spring.data.neo4j.uri="
+
neo4j
.
getContainer
().
getBoltUrl
())
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestWithIncludeFilterIntegrationTests.java
View file @
747e419d
...
...
@@ -23,6 +23,7 @@ import org.testcontainers.containers.Neo4jContainer;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.SkippableContainer
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
...
...
@@ -44,8 +45,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public
class
DataNeo4jTestWithIncludeFilterIntegrationTests
{
@ClassRule
public
static
Neo4jContainer
<?>
neo4j
=
new
Neo4jContainer
<>()
.
withAdminPassword
(
null
);
public
static
SkippableContainer
<
Neo4jContainer
<?>>
neo4j
=
new
SkippableContainer
<
Neo4jContainer
<?>>(
()
->
new
Neo4jContainer
<>().
withAdminPassword
(
null
)
);
@Autowired
private
ExampleService
service
;
...
...
@@ -61,7 +62,8 @@ public class DataNeo4jTestWithIncludeFilterIntegrationTests {
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.data.neo4j.uri="
+
neo4j
.
getBoltUrl
())
TestPropertyValues
.
of
(
"spring.data.neo4j.uri="
+
neo4j
.
getContainer
().
getBoltUrl
())
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/SkippableContainer.java
0 → 100644
View file @
747e419d
/*
* Copyright 2012-2019 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
*
* http://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
.
testsupport
.
testcontainers
;
import
java.util.function.Supplier
;
import
org.junit.AssumptionViolatedException
;
import
org.junit.rules.TestRule
;
import
org.junit.runner.Description
;
import
org.junit.runners.model.Statement
;
import
org.testcontainers.DockerClientFactory
;
import
org.testcontainers.containers.FailureDetectingExternalResource
;
import
org.testcontainers.containers.GenericContainer
;
/**
* A {@link GenericContainer} decorator that skips test execution when Docker is not
* available.
*
* @param <T> type of the underlying container
* @author Andy Wilkinson
*/
public
class
SkippableContainer
<
T
>
implements
TestRule
{
private
final
Supplier
<
T
>
containerFactory
;
private
T
container
;
public
SkippableContainer
(
Supplier
<
T
>
containerFactory
)
{
this
.
containerFactory
=
containerFactory
;
}
@Override
public
Statement
apply
(
Statement
base
,
Description
description
)
{
try
{
DockerClientFactory
.
instance
().
client
();
}
catch
(
Throwable
ex
)
{
return
new
SkipStatement
();
}
this
.
container
=
this
.
containerFactory
.
get
();
return
((
FailureDetectingExternalResource
)
this
.
container
).
apply
(
base
,
description
);
}
public
T
getContainer
()
{
if
(
this
.
container
==
null
)
{
throw
new
IllegalStateException
(
"Container cannot be accessed prior to test invocation"
);
}
return
this
.
container
;
}
private
static
class
SkipStatement
extends
Statement
{
@Override
public
void
evaluate
()
{
throw
new
AssumptionViolatedException
(
"Could not find a valid Docker environment."
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment