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
a0b99747
Commit
a0b99747
authored
Mar 15, 2018
by
Brian Clozel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish Couchbase tests
parent
ac644416
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
68 deletions
+107
-68
AbstractCouchbaseAutoConfigurationTests.java
...re/couchbase/AbstractCouchbaseAutoConfigurationTests.java
+1
-1
CouchbaseAutoConfigurationIntegrationTests.java
...couchbase/CouchbaseAutoConfigurationIntegrationTests.java
+26
-13
CouchbaseAutoConfigurationTests.java
...oconfigure/couchbase/CouchbaseAutoConfigurationTests.java
+80
-54
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/AbstractCouchbaseAutoConfigurationTests.java
View file @
a0b99747
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationIntegrationTests.java
View file @
a0b99747
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -24,6 +24,9 @@ import com.couchbase.client.java.env.CouchbaseEnvironment;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -35,28 +38,38 @@ import static org.mockito.Mockito.mock;
*
* @author Stephane Nicoll
*/
public
class
CouchbaseAutoConfigurationIntegrationTests
extends
AbstractCouchbaseAutoConfigurationTests
{
public
class
CouchbaseAutoConfigurationIntegrationTests
{
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
PropertyPlaceholderAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
));
@Rule
public
final
CouchbaseTestServer
couchbase
=
new
CouchbaseTestServer
();
@Test
public
void
defaultConfiguration
()
{
load
(
null
,
"spring.couchbase.bootstrapHosts=localhost"
);
assertThat
(
this
.
context
.
getBeansOfType
(
Cluster
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
ClusterInfo
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseEnvironment
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
Bucket
.
class
)).
hasSize
(
1
);
this
.
contextRunner
.
withPropertyValues
(
"spring.couchbase.bootstrapHosts=localhost"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
Cluster
.
class
)
.
hasSingleBean
(
ClusterInfo
.
class
)
.
hasSingleBean
(
CouchbaseEnvironment
.
class
)
.
hasSingleBean
(
Bucket
.
class
);
});
}
@Test
public
void
customConfiguration
()
{
load
(
CustomConfiguration
.
class
,
"spring.couchbase.bootstrapHosts=localhost"
);
assertThat
(
this
.
context
.
getBeansOfType
(
Cluster
.
class
)).
hasSize
(
2
);
assertThat
(
this
.
context
.
getBeansOfType
(
ClusterInfo
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseEnvironment
.
class
)).
hasSize
(
1
);
assertThat
(
this
.
context
.
getBeansOfType
(
Bucket
.
class
)).
hasSize
(
2
);
this
.
contextRunner
.
withUserConfiguration
(
CustomConfiguration
.
class
)
.
withPropertyValues
(
"spring.couchbase.bootstrapHosts=localhost"
)
.
run
((
context
)
->
{
assertThat
(
context
.
getBeansOfType
(
Cluster
.
class
)).
hasSize
(
2
);
assertThat
(
context
.
getBeansOfType
(
ClusterInfo
.
class
)).
hasSize
(
1
);
assertThat
(
context
.
getBeansOfType
(
CouchbaseEnvironment
.
class
)).
hasSize
(
1
);
assertThat
(
context
.
getBeansOfType
(
Bucket
.
class
)).
hasSize
(
2
);
});
}
@Configuration
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java
View file @
a0b99747
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
couchbase
;
import
java.util.function.Consumer
;
import
com.couchbase.client.java.Bucket
;
import
com.couchbase.client.java.Cluster
;
import
com.couchbase.client.java.CouchbaseBucket
;
...
...
@@ -24,8 +26,12 @@ import com.couchbase.client.java.env.CouchbaseEnvironment;
import
com.couchbase.client.java.env.DefaultCouchbaseEnvironment
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration.CouchbaseConfiguration
;
import
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -38,102 +44,122 @@ import static org.mockito.Mockito.mock;
* @author Eddú Meléndez
* @author Stephane Nicoll
*/
public
class
CouchbaseAutoConfigurationTests
extends
AbstractCouchbaseAutoConfigurationTests
{
public
class
CouchbaseAutoConfigurationTests
{
private
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
PropertyPlaceholderAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
));
@Test
public
void
bootstrapHostsIsRequired
()
{
load
(
null
);
assertNoCouchbaseBeans
();
this
.
contextRunner
.
run
((
context
)
->
{
assertNoCouchbaseBeans
(
context
);
});
}
@Test
public
void
bootstrapHostsNotRequiredIfCouchbaseConfigurerIsSet
()
{
load
(
CouchbaseTestConfigurer
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseTestConfigurer
.
class
)).
hasSize
(
1
);
// No beans are going to be created
assertNoCouchbaseBeans
();
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
CouchbaseTestConfigurer
.
class
);
// No beans are going to be created
assertNoCouchbaseBeans
(
context
);
});
}
@Test
public
void
bootstrapHostsIgnoredIfCouchbaseConfigurerIsSet
()
{
load
(
CouchbaseTestConfigurer
.
class
,
"spring.couchbase.bootstrapHosts=localhost"
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseTestConfigurer
.
class
)).
hasSize
(
1
);
assertNoCouchbaseBeans
();
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
withPropertyValues
(
"spring.couchbase.bootstrapHosts=localhost"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
CouchbaseTestConfigurer
.
class
);
assertNoCouchbaseBeans
(
context
);
});
}
private
void
assertNoCouchbaseBeans
()
{
private
void
assertNoCouchbaseBeans
(
AssertableApplicationContext
context
)
{
// No beans are going to be created
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseEnvironment
.
class
)).
isEmpty
();
assertThat
(
this
.
context
.
getBeansOfType
(
ClusterInfo
.
class
)).
isEmpty
();
assertThat
(
this
.
context
.
getBeansOfType
(
Cluster
.
class
)).
isEmpty
();
assertThat
(
this
.
context
.
getBeansOfType
(
Bucket
.
class
)).
isEmpty
(
);
assertThat
(
context
).
doesNotHaveBean
(
CouchbaseEnvironment
.
class
)
.
doesNotHaveBean
(
ClusterInfo
.
class
)
.
doesNotHaveBean
(
Cluster
.
class
)
.
doesNotHaveBean
(
Bucket
.
class
);
}
@Test
public
void
customizeEnvEndpoints
()
throws
Exception
{
DefaultCouchbaseEnvironment
env
=
customizeEnv
(
public
void
customizeEnvEndpoints
()
{
testCouchbaseEnv
(
env
->
{
assertThat
(
env
.
kvEndpoints
()).
isEqualTo
(
4
);
assertThat
(
env
.
queryEndpoints
()).
isEqualTo
(
5
);
assertThat
(
env
.
viewEndpoints
()).
isEqualTo
(
6
);
},
"spring.couchbase.env.endpoints.keyValue=4"
,
"spring.couchbase.env.endpoints.query=5"
,
"spring.couchbase.env.endpoints.view=6"
);
assertThat
(
env
.
kvEndpoints
()).
isEqualTo
(
4
);
assertThat
(
env
.
queryEndpoints
()).
isEqualTo
(
5
);
assertThat
(
env
.
viewEndpoints
()).
isEqualTo
(
6
);
}
@Test
public
void
customizeEnvTimeouts
()
throws
Exception
{
DefaultCouchbaseEnvironment
env
=
customizeEnv
(
public
void
customizeEnvTimeouts
()
{
testCouchbaseEnv
(
env
->
{
assertThat
(
env
.
connectTimeout
()).
isEqualTo
(
100
);
assertThat
(
env
.
kvTimeout
()).
isEqualTo
(
200
);
assertThat
(
env
.
queryTimeout
()).
isEqualTo
(
300
);
assertThat
(
env
.
socketConnectTimeout
()).
isEqualTo
(
400
);
assertThat
(
env
.
viewTimeout
()).
isEqualTo
(
500
);
},
"spring.couchbase.env.timeouts.connect=100"
,
"spring.couchbase.env.timeouts.keyValue=200"
,
"spring.couchbase.env.timeouts.query=300"
,
"spring.couchbase.env.timeouts.socket-connect=400"
,
"spring.couchbase.env.timeouts.view=500"
);
assertThat
(
env
.
connectTimeout
()).
isEqualTo
(
100
);
assertThat
(
env
.
kvTimeout
()).
isEqualTo
(
200
);
assertThat
(
env
.
queryTimeout
()).
isEqualTo
(
300
);
assertThat
(
env
.
socketConnectTimeout
()).
isEqualTo
(
400
);
assertThat
(
env
.
viewTimeout
()).
isEqualTo
(
500
);
}
@Test
public
void
enableSslNoEnabledFlag
()
throws
Exception
{
DefaultCouchbaseEnvironment
env
=
customizeEnv
(
public
void
enableSslNoEnabledFlag
()
{
testCouchbaseEnv
(
env
->
{
assertThat
(
env
.
sslEnabled
()).
isTrue
();
assertThat
(
env
.
sslKeystoreFile
()).
isEqualTo
(
"foo"
);
assertThat
(
env
.
sslKeystorePassword
()).
isEqualTo
(
"secret"
);
},
"spring.couchbase.env.ssl.keyStore=foo"
,
"spring.couchbase.env.ssl.keyStorePassword=secret"
);
assertThat
(
env
.
sslEnabled
()).
isTrue
();
assertThat
(
env
.
sslKeystoreFile
()).
isEqualTo
(
"foo"
);
assertThat
(
env
.
sslKeystorePassword
()).
isEqualTo
(
"secret"
);
}
@Test
public
void
disableSslEvenWithKeyStore
()
throws
Exception
{
DefaultCouchbaseEnvironment
env
=
customizeEnv
(
public
void
disableSslEvenWithKeyStore
()
{
testCouchbaseEnv
(
env
->
{
assertThat
(
env
.
sslEnabled
()).
isFalse
();
assertThat
(
env
.
sslKeystoreFile
()).
isNull
();
assertThat
(
env
.
sslKeystorePassword
()).
isNull
();
},
"spring.couchbase.env.ssl.enabled=false"
,
"spring.couchbase.env.ssl.keyStore=foo"
,
"spring.couchbase.env.ssl.keyStorePassword=secret"
);
assertThat
(
env
.
sslEnabled
()).
isFalse
();
assertThat
(
env
.
sslKeystoreFile
()).
isNull
();
assertThat
(
env
.
sslKeystorePassword
()).
isNull
();
}
@Test
public
void
customizeEnvWithCustomCouchbaseConfiguration
(
)
{
load
(
CustomCouchbaseConfiguration
.
class
,
"spring.couchbase.bootstrap-hosts=localhost"
,
"spring.couchbase.env.timeouts.connect=100"
);
assertThat
(
this
.
context
.
getBeansOfType
(
CouchbaseConfiguration
.
class
)).
hasSize
(
1
);
DefaultCouchbaseEnvironment
env
=
this
.
context
.
getBean
(
DefaultCouchbaseEnvironment
.
class
);
assertThat
(
env
.
socketConnectTimeout
()).
isEqualTo
(
5000
);
assertThat
(
env
.
connectTimeout
()).
isEqualTo
(
2000
);
private
void
testCouchbaseEnv
(
Consumer
<
DefaultCouchbaseEnvironment
>
environmentConsumer
,
String
...
environment
)
{
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
withPropertyValues
(
environment
)
.
run
((
context
)
->
{
CouchbaseProperties
properties
=
context
.
getBean
(
CouchbaseProperties
.
class
);
DefaultCouchbaseEnvironment
env
=
new
CouchbaseConfiguration
(
properties
)
.
couchbaseEnvironment
(
);
environmentConsumer
.
accept
(
env
);
}
);
}
private
DefaultCouchbaseEnvironment
customizeEnv
(
String
...
environment
)
throws
Exception
{
load
(
CouchbaseTestConfigurer
.
class
,
environment
);
CouchbaseProperties
properties
=
this
.
context
.
getBean
(
CouchbaseProperties
.
class
);
return
new
CouchbaseConfiguration
(
properties
).
couchbaseEnvironment
();
@Test
public
void
customizeEnvWithCustomCouchbaseConfiguration
()
{
this
.
contextRunner
.
withUserConfiguration
(
CustomCouchbaseConfiguration
.
class
)
.
withPropertyValues
(
"spring.couchbase.bootstrap-hosts=localhost"
,
"spring.couchbase.env.timeouts.connect=100"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
CouchbaseConfiguration
.
class
);
DefaultCouchbaseEnvironment
env
=
context
.
getBean
(
DefaultCouchbaseEnvironment
.
class
);
assertThat
(
env
.
socketConnectTimeout
()).
isEqualTo
(
5000
);
assertThat
(
env
.
connectTimeout
()).
isEqualTo
(
2000
);
});
}
@Configuration
...
...
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