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
f0e93f0e
Commit
f0e93f0e
authored
Jan 27, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Couchbase tests to ApplicationContextRunner
parent
a1e6a209
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
191 deletions
+120
-191
CouchbaseDataAutoConfigurationTests.java
...e/data/couchbase/CouchbaseDataAutoConfigurationTests.java
+50
-59
CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests.java
...ctiveAndImperativeRepositoriesAutoConfigurationTests.java
+6
-17
CouchbaseReactiveDataAutoConfigurationTests.java
...ouchbase/CouchbaseReactiveDataAutoConfigurationTests.java
+26
-42
CouchbaseReactiveRepositoriesAutoConfigurationTests.java
.../CouchbaseReactiveRepositoriesAutoConfigurationTests.java
+21
-38
CouchbaseRepositoriesAutoConfigurationTests.java
...ouchbase/CouchbaseRepositoriesAutoConfigurationTests.java
+17
-35
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java
View file @
f0e93f0e
...
...
@@ -19,18 +19,16 @@ package org.springframework.boot.autoconfigure.data.couchbase;
import
java.util.Collections
;
import
java.util.Set
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.
context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.
AutoConfigurations
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer
;
import
org.springframework.boot.autoconfigure.data.couchbase.city.City
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -56,101 +54,94 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class
CouchbaseDataAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@AfterEach
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
ValidationAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
));
@Test
void
disabledIfCouchbaseIsNotConfigured
()
{
load
(
null
);
assertThat
(
this
.
context
.
getBeansOfType
(
IndexManager
.
class
)).
isEmpty
();
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
IndexManager
.
class
));
}
@Test
void
customConfiguration
()
{
load
(
CustomCouchbaseConfiguration
.
class
);
CouchbaseTemplate
couchbaseTemplate
=
this
.
context
.
getBean
(
CouchbaseTemplate
.
class
);
assertThat
(
couchbaseTemplate
.
getDefaultConsistency
()).
isEqualTo
(
Consistency
.
STRONGLY_CONSISTENT
);
this
.
contextRunner
.
withUserConfiguration
(
CustomCouchbaseConfiguration
.
class
).
run
((
context
)
->
{
CouchbaseTemplate
couchbaseTemplate
=
context
.
getBean
(
CouchbaseTemplate
.
class
);
assertThat
(
couchbaseTemplate
.
getDefaultConsistency
()).
isEqualTo
(
Consistency
.
STRONGLY_CONSISTENT
);
});
}
@Test
void
validatorIsPresent
()
{
load
(
CouchbaseTestConfigurer
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
ValidatingCouchbaseEventListener
.
class
)).
hasSize
(
1
);
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
ValidatingCouchbaseEventListener
.
class
)
);
}
@Test
void
autoIndexIsDisabledByDefault
()
{
load
(
CouchbaseTestConfigurer
.
class
);
IndexManager
indexManager
=
this
.
context
.
getBean
(
IndexManager
.
class
);
assertThat
(
indexManager
.
isIgnoreViews
()).
isTrue
();
assertThat
(
indexManager
.
isIgnoreN1qlPrimary
()).
isTrue
();
assertThat
(
indexManager
.
isIgnoreN1qlSecondary
()).
isTrue
();
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
).
run
((
context
)
->
{
IndexManager
indexManager
=
context
.
getBean
(
IndexManager
.
class
);
assertThat
(
indexManager
.
isIgnoreViews
()).
isTrue
();
assertThat
(
indexManager
.
isIgnoreN1qlPrimary
()).
isTrue
();
assertThat
(
indexManager
.
isIgnoreN1qlSecondary
()).
isTrue
();
});
}
@Test
void
enableAutoIndex
()
{
load
(
CouchbaseTestConfigurer
.
class
,
"spring.data.couchbase.auto-index=true"
);
IndexManager
indexManager
=
this
.
context
.
getBean
(
IndexManager
.
class
);
assertThat
(
indexManager
.
isIgnoreViews
()).
isFalse
();
assertThat
(
indexManager
.
isIgnoreN1qlPrimary
()).
isFalse
();
assertThat
(
indexManager
.
isIgnoreN1qlSecondary
()).
isFalse
();
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
withPropertyValues
(
"spring.data.couchbase.auto-index=true"
).
run
((
context
)
->
{
IndexManager
indexManager
=
context
.
getBean
(
IndexManager
.
class
);
assertThat
(
indexManager
.
isIgnoreViews
()).
isFalse
();
assertThat
(
indexManager
.
isIgnoreN1qlPrimary
()).
isFalse
();
assertThat
(
indexManager
.
isIgnoreN1qlSecondary
()).
isFalse
();
});
}
@Test
void
changeConsistency
()
{
load
(
CouchbaseTestConfigurer
.
class
,
"spring.data.couchbase.consistency=eventually-consistent"
);
SpringBootCouchbaseDataConfiguration
configuration
=
this
.
context
.
getBean
(
SpringBootCouchbaseDataConfiguration
.
class
);
assertThat
(
configuration
.
getDefaultConsistency
()).
isEqualTo
(
Consistency
.
EVENTUALLY_CONSISTENT
);
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
withPropertyValues
(
"spring.data.couchbase.consistency=eventually-consistent"
).
run
((
context
)
->
{
SpringBootCouchbaseDataConfiguration
configuration
=
context
.
getBean
(
SpringBootCouchbaseDataConfiguration
.
class
);
assertThat
(
configuration
.
getDefaultConsistency
()).
isEqualTo
(
Consistency
.
EVENTUALLY_CONSISTENT
);
});
}
@Test
@SuppressWarnings
(
"unchecked"
)
void
entityScanShouldSetInitialEntitySet
()
{
load
(
EntityScanConfig
.
class
);
CouchbaseMappingContext
mappingContext
=
this
.
context
.
getBean
(
CouchbaseMappingContext
.
class
);
Set
<
Class
<?>>
initialEntitySet
=
(
Set
<
Class
<?>>)
ReflectionTestUtils
.
getField
(
mappingContext
,
"initialEntitySet"
);
assertThat
(
initialEntitySet
).
containsOnly
(
City
.
class
);
this
.
contextRunner
.
withUserConfiguration
(
EntityScanConfig
.
class
).
run
((
context
)
->
{
CouchbaseMappingContext
mappingContext
=
context
.
getBean
(
CouchbaseMappingContext
.
class
);
Set
<
Class
<?>>
initialEntitySet
=
(
Set
<
Class
<?>>)
ReflectionTestUtils
.
getField
(
mappingContext
,
"initialEntitySet"
);
assertThat
(
initialEntitySet
).
containsOnly
(
City
.
class
);
});
}
@Test
void
typeKeyDefault
()
{
load
(
CouchbaseTestConfigurer
.
class
);
assertThat
(
this
.
context
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
).
typeKey
())
.
isEqualTo
(
DefaultCouchbaseTypeMapper
.
DEFAULT_TYPE_KEY
);
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
).
typeKey
())
.
isEqualTo
(
DefaultCouchbaseTypeMapper
.
DEFAULT_TYPE_KEY
)
);
}
@Test
void
typeKeyCanBeCustomized
()
{
load
(
CouchbaseTestConfigurer
.
class
,
"spring.data.couchbase.type-key=_custom"
);
assertThat
(
this
.
context
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
).
typeKey
()).
isEqualTo
(
"_custom"
);
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
withPropertyValues
(
"spring.data.couchbase.type-key=_custom"
)
.
run
((
context
)
->
assertThat
(
context
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
).
typeKey
())
.
isEqualTo
(
"_custom"
));
}
@Test
void
customConversions
()
{
load
(
CustomConversionsConfig
.
class
);
CouchbaseTemplate
template
=
this
.
context
.
getBean
(
CouchbaseTemplate
.
class
);
assertThat
(
template
.
getConverter
().
getConversionService
().
canConvert
(
CouchbaseProperties
.
class
,
Boolean
.
class
))
.
isTrue
();
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
environment
).
applyTo
(
context
);
if
(
config
!=
null
)
{
context
.
register
(
config
);
}
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
ValidationAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
this
.
contextRunner
.
withUserConfiguration
(
CustomConversionsConfig
.
class
).
run
((
context
)
->
{
CouchbaseTemplate
template
=
context
.
getBean
(
CouchbaseTemplate
.
class
);
assertThat
(
template
.
getConverter
().
getConversionService
().
canConvert
(
CouchbaseProperties
.
class
,
Boolean
.
class
))
.
isTrue
();
});
}
@Configuration
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests.java
View file @
f0e93f0e
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.data.couchbase;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.TestAutoConfigurationPackage
;
...
...
@@ -27,8 +26,7 @@ import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfigurati
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer
;
import
org.springframework.boot.autoconfigure.data.couchbase.city.CityRepository
;
import
org.springframework.boot.autoconfigure.data.couchbase.city.ReactiveCityRepository
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.ImportSelector
;
...
...
@@ -47,21 +45,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class
CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@AfterEach
void
close
()
{
this
.
context
.
close
();
}
@Test
void
shouldCreateInstancesForReactiveAndImperativeRepositories
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
"spring.datasource.initialization-mode:never"
).
applyTo
(
this
.
context
);
this
.
context
.
register
(
ImperativeAndReactiveConfiguration
.
class
,
BaseConfiguration
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
CityRepository
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
ReactiveCityRepository
.
class
)).
isNotNull
();
new
ApplicationContextRunner
()
.
withUserConfiguration
(
ImperativeAndReactiveConfiguration
.
class
,
BaseConfiguration
.
class
)
.
withPropertyValues
(
"spring.datasource.initialization-mode:never"
).
run
((
context
)
->
assertThat
(
context
)
.
hasSingleBean
(
CityRepository
.
class
).
hasSingleBean
(
ReactiveCityRepository
.
class
));
}
@Configuration
(
proxyBeanMethods
=
false
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveDataAutoConfigurationTests.java
View file @
f0e93f0e
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -19,18 +19,16 @@ package org.springframework.boot.autoconfigure.data.couchbase;
import
java.util.Collections
;
import
java.util.Set
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.
context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.
AutoConfigurations
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer
;
import
org.springframework.boot.autoconfigure.data.couchbase.city.City
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -52,66 +50,52 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link CouchbaseReactiveDataAutoConfiguration}.
*
* @author Alex Derkach
* @author Stephane Nicoll
*/
class
CouchbaseReactiveDataAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@AfterEach
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
().
withConfiguration
(
AutoConfigurations
.
of
(
ValidationAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseReactiveDataAutoConfiguration
.
class
));
@Test
void
disabledIfCouchbaseIsNotConfigured
()
{
load
(
null
);
assertThat
(
this
.
context
.
getBeansOfType
(
IndexManager
.
class
)).
isEmpty
();
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
IndexManager
.
class
));
}
@Test
void
customConfiguration
()
{
load
(
CustomCouchbaseConfiguration
.
class
);
RxJavaCouchbaseTemplate
rxJavaCouchbaseTemplate
=
this
.
context
.
getBean
(
RxJavaCouchbaseTemplate
.
class
);
assertThat
(
rxJavaCouchbaseTemplate
.
getDefaultConsistency
()).
isEqualTo
(
Consistency
.
STRONGLY_CONSISTENT
);
this
.
contextRunner
.
withUserConfiguration
(
CustomCouchbaseConfiguration
.
class
).
run
((
context
)
->
{
RxJavaCouchbaseTemplate
rxJavaCouchbaseTemplate
=
context
.
getBean
(
RxJavaCouchbaseTemplate
.
class
);
assertThat
(
rxJavaCouchbaseTemplate
.
getDefaultConsistency
()).
isEqualTo
(
Consistency
.
STRONGLY_CONSISTENT
);
});
}
@Test
void
validatorIsPresent
()
{
load
(
CouchbaseTestConfigurer
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
ValidatingCouchbaseEventListener
.
class
)).
hasSize
(
1
);
this
.
contextRunner
.
withUserConfiguration
(
CouchbaseTestConfigurer
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
ValidatingCouchbaseEventListener
.
class
)
);
}
@Test
@SuppressWarnings
(
"unchecked"
)
void
entityScanShouldSetInitialEntitySet
()
{
load
(
EntityScanConfig
.
class
);
CouchbaseMappingContext
mappingContext
=
this
.
context
.
getBean
(
CouchbaseMappingContext
.
class
);
Set
<
Class
<?>>
initialEntitySet
=
(
Set
<
Class
<?>>)
ReflectionTestUtils
.
getField
(
mappingContext
,
"initialEntitySet"
);
assertThat
(
initialEntitySet
).
containsOnly
(
City
.
class
);
this
.
contextRunner
.
withUserConfiguration
(
EntityScanConfig
.
class
).
run
((
context
)
->
{
CouchbaseMappingContext
mappingContext
=
context
.
getBean
(
CouchbaseMappingContext
.
class
);
Set
<
Class
<?>>
initialEntitySet
=
(
Set
<
Class
<?>>)
ReflectionTestUtils
.
getField
(
mappingContext
,
"initialEntitySet"
);
assertThat
(
initialEntitySet
).
containsOnly
(
City
.
class
);
});
}
@Test
void
customConversions
()
{
load
(
CustomConversionsConfig
.
class
);
RxJavaCouchbaseTemplate
template
=
this
.
context
.
getBean
(
RxJavaCouchbaseTemplate
.
class
);
assertThat
(
template
.
getConverter
().
getConversionService
().
canConvert
(
CouchbaseProperties
.
class
,
Boolean
.
class
))
.
isTrue
();
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
environment
).
applyTo
(
context
);
if
(
config
!=
null
)
{
context
.
register
(
config
);
}
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
ValidationAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseReactiveDataAutoConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
this
.
contextRunner
.
withUserConfiguration
(
CustomConversionsConfig
.
class
).
run
((
context
)
->
{
RxJavaCouchbaseTemplate
template
=
context
.
getBean
(
RxJavaCouchbaseTemplate
.
class
);
assertThat
(
template
.
getConverter
().
getConversionService
().
canConvert
(
CouchbaseProperties
.
class
,
Boolean
.
class
))
.
isTrue
();
});
}
@Configuration
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveRepositoriesAutoConfigurationTests.java
View file @
f0e93f0e
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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,11 +16,10 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
couchbase
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.TestAutoConfigurationPackage
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer
;
import
org.springframework.boot.autoconfigure.data.alt.couchbase.CityCouchbaseRepository
;
...
...
@@ -28,8 +27,7 @@ import org.springframework.boot.autoconfigure.data.alt.couchbase.ReactiveCityCou
import
org.springframework.boot.autoconfigure.data.couchbase.city.City
;
import
org.springframework.boot.autoconfigure.data.couchbase.city.ReactiveCityRepository
;
import
org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories
;
...
...
@@ -40,65 +38,50 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link CouchbaseReactiveRepositoriesAutoConfiguration}.
*
* @author Alex Derkach
* @author Stephane Nicoll
*/
class
CouchbaseReactiveRepositoriesAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@AfterEach
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
().
withConfiguration
(
AutoConfigurations
.
of
(
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseRepositoriesAutoConfiguration
.
class
,
CouchbaseReactiveDataAutoConfiguration
.
class
,
CouchbaseReactiveRepositoriesAutoConfiguration
.
class
));
@Test
void
couchbaseNotAvailable
()
{
load
(
null
);
assertThat
(
this
.
context
.
getBeansOfType
(
ReactiveCityRepository
.
class
)).
hasSize
(
0
);
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
ReactiveCityRepository
.
class
));
}
@Test
void
defaultRepository
()
{
load
(
DefaultConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
ReactiveCityRepository
.
class
)).
hasSize
(
1
);
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
ReactiveCityRepository
.
class
)
);
}
@Test
void
imperativeRepositories
()
{
load
(
DefaultConfiguration
.
class
,
"spring.data.couchbase.repositories.type=imperative"
);
assertThat
(
this
.
context
.
getBeansOfType
(
ReactiveCityRepository
.
class
)).
hasSize
(
0
);
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
)
.
withPropertyValues
(
"spring.data.couchbase.repositories.type=imperative"
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
ReactiveCityRepository
.
class
));
}
@Test
void
disabledRepositories
()
{
load
(
DefaultConfiguration
.
class
,
"spring.data.couchbase.repositories.type=none"
);
assertThat
(
this
.
context
.
getBeansOfType
(
ReactiveCityRepository
.
class
)).
hasSize
(
0
);
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
)
.
withPropertyValues
(
"spring.data.couchbase.repositories.type=none"
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
ReactiveCityRepository
.
class
));
}
@Test
void
noRepositoryAvailable
()
{
load
(
NoRepositoryConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
ReactiveCityRepository
.
class
)).
hasSize
(
0
);
this
.
contextRunner
.
withUserConfiguration
(
NoRepositoryConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
ReactiveCityRepository
.
class
)
);
}
@Test
void
doesNotTriggerDefaultRepositoryDetectionIfCustomized
()
{
load
(
CustomizedConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
ReactiveCityCouchbaseRepository
.
class
)).
isEmpty
();
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
environment
).
applyTo
(
context
);
if
(
config
!=
null
)
{
context
.
register
(
config
);
}
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseRepositoriesAutoConfiguration
.
class
,
CouchbaseReactiveDataAutoConfiguration
.
class
,
CouchbaseReactiveRepositoriesAutoConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
this
.
contextRunner
.
withUserConfiguration
(
CustomizedConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
ReactiveCityCouchbaseRepository
.
class
));
}
@Configuration
(
proxyBeanMethods
=
false
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseRepositoriesAutoConfigurationTests.java
View file @
f0e93f0e
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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,18 +16,16 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
data
.
couchbase
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.TestAutoConfigurationPackage
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer
;
import
org.springframework.boot.autoconfigure.data.couchbase.city.City
;
import
org.springframework.boot.autoconfigure.data.couchbase.city.CityRepository
;
import
org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -41,55 +39,39 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class
CouchbaseRepositoriesAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
@AfterEach
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseRepositoriesAutoConfiguration
.
class
));
@Test
void
couchbaseNotAvailable
()
{
load
(
null
);
assertThat
(
this
.
context
.
getBeansOfType
(
CityRepository
.
class
)).
hasSize
(
0
);
this
.
contextRunner
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
CityRepository
.
class
));
}
@Test
void
defaultRepository
()
{
load
(
DefaultConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
CityRepository
.
class
)).
hasSize
(
1
);
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
CityRepository
.
class
)
);
}
@Test
void
reactiveRepositories
()
{
load
(
DefaultConfiguration
.
class
,
"spring.data.couchbase.repositories.type=reactive"
);
assertThat
(
this
.
context
.
getBeansOfType
(
CityRepository
.
class
)).
hasSize
(
0
);
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
)
.
withPropertyValues
(
"spring.data.couchbase.repositories.type=reactive"
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
CityRepository
.
class
));
}
@Test
void
disabledRepositories
()
{
load
(
DefaultConfiguration
.
class
,
"spring.data.couchbase.repositories.type=none"
);
assertThat
(
this
.
context
.
getBeansOfType
(
CityRepository
.
class
)).
hasSize
(
0
);
this
.
contextRunner
.
withUserConfiguration
(
DefaultConfiguration
.
class
)
.
withPropertyValues
(
"spring.data.couchbase.repositories.type=none"
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
CityRepository
.
class
));
}
@Test
void
noRepositoryAvailable
()
{
load
(
NoRepositoryConfiguration
.
class
);
assertThat
(
this
.
context
.
getBeansOfType
(
CityRepository
.
class
)).
hasSize
(
0
);
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
environment
).
applyTo
(
context
);
if
(
config
!=
null
)
{
context
.
register
(
config
);
}
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseRepositoriesAutoConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
this
.
contextRunner
.
withUserConfiguration
(
NoRepositoryConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
CityRepository
.
class
));
}
@Configuration
(
proxyBeanMethods
=
false
)
...
...
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