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
af4fdf0d
Commit
af4fdf0d
authored
Jan 27, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add support for Spring Data Couchbase custom type key"
See gh-19789
parent
d1a44dfa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
25 deletions
+59
-25
CouchbaseDataProperties.java
...autoconfigure/data/couchbase/CouchbaseDataProperties.java
+3
-3
SpringBootCouchbaseDataConfiguration.java
.../data/couchbase/SpringBootCouchbaseDataConfiguration.java
+6
-6
CouchbaseDataAutoConfigurationTests.java
...e/data/couchbase/CouchbaseDataAutoConfigurationTests.java
+13
-16
CouchbaseDataPropertiesTests.java
...onfigure/data/couchbase/CouchbaseDataPropertiesTests.java
+37
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataProperties.java
View file @
af4fdf0d
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -41,8 +41,8 @@ public class CouchbaseDataProperties {
...
@@ -41,8 +41,8 @@ public class CouchbaseDataProperties {
private
Consistency
consistency
=
Consistency
.
READ_YOUR_OWN_WRITES
;
private
Consistency
consistency
=
Consistency
.
READ_YOUR_OWN_WRITES
;
/**
/**
* Name of the field that
will store
the type information for complex types when using
* Name of the field that
stores
the type information for complex types when using
*
MappingCouchbaseConverter
.
*
"MappingCouchbaseConverter"
.
*/
*/
private
String
typeKey
=
DefaultCouchbaseTypeMapper
.
DEFAULT_TYPE_KEY
;
private
String
typeKey
=
DefaultCouchbaseTypeMapper
.
DEFAULT_TYPE_KEY
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseDataConfiguration.java
View file @
af4fdf0d
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -73,6 +73,11 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
...
@@ -73,6 +73,11 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
return
new
EntityScanner
(
this
.
applicationContext
).
scan
(
Document
.
class
,
Persistent
.
class
);
return
new
EntityScanner
(
this
.
applicationContext
).
scan
(
Document
.
class
,
Persistent
.
class
);
}
}
@Override
public
String
typeKey
()
{
return
this
.
properties
.
getTypeKey
();
}
@Override
@Override
@ConditionalOnMissingBean
(
name
=
BeanNames
.
COUCHBASE_TEMPLATE
)
@ConditionalOnMissingBean
(
name
=
BeanNames
.
COUCHBASE_TEMPLATE
)
@Bean
(
name
=
BeanNames
.
COUCHBASE_TEMPLATE
)
@Bean
(
name
=
BeanNames
.
COUCHBASE_TEMPLATE
)
...
@@ -97,9 +102,4 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
...
@@ -97,9 +102,4 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
return
new
IndexManager
(
false
,
false
,
false
);
return
new
IndexManager
(
false
,
false
,
false
);
}
}
@Override
public
String
typeKey
()
{
return
this
.
properties
.
getTypeKey
();
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataAutoConfigurationTests.java
View file @
af4fdf0d
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -121,27 +121,24 @@ class CouchbaseDataAutoConfigurationTests {
...
@@ -121,27 +121,24 @@ class CouchbaseDataAutoConfigurationTests {
}
}
@Test
@Test
void
customConversions
()
{
void
typeKeyDefault
()
{
load
(
CustomConversionsConfig
.
class
);
load
(
CouchbaseTestConfigurer
.
class
);
CouchbaseTemplate
template
=
this
.
context
.
getBean
(
CouchbaseTemplate
.
class
);
assertThat
(
this
.
context
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
).
typeKey
())
assertThat
(
template
.
getConverter
().
getConversionService
().
canConvert
(
CouchbaseProperties
.
class
,
Boolean
.
class
))
.
isEqualTo
(
DefaultCouchbaseTypeMapper
.
DEFAULT_TYPE_KEY
);
.
isTrue
();
}
}
@Test
@Test
void
typeKeyIsClassByDefault
()
{
void
typeKeyCanBeCustomized
()
{
load
(
CouchbaseTestConfigurer
.
class
);
load
(
CouchbaseTestConfigurer
.
class
,
"spring.data.couchbase.type-key=_custom"
);
AbstractCouchbaseDataConfiguration
couchbaseDataConfiguration
=
this
.
context
assertThat
(
this
.
context
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
).
typeKey
()).
isEqualTo
(
"_custom"
);
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
);
assertThat
(
couchbaseDataConfiguration
.
typeKey
()).
isEqualTo
(
DefaultCouchbaseTypeMapper
.
DEFAULT_TYPE_KEY
);
}
}
@Test
@Test
void
custom
TypeKey
()
{
void
custom
Conversions
()
{
load
(
C
ouchbaseTestConfigurer
.
class
,
"spring.data.couchbase.type-key=custom"
);
load
(
C
ustomConversionsConfig
.
class
);
AbstractCouchbaseDataConfiguration
couchbaseDataConfiguration
=
this
.
context
CouchbaseTemplate
template
=
this
.
context
.
getBean
(
CouchbaseTemplate
.
class
);
.
getBean
(
AbstractCouchbaseDataConfiguration
.
class
);
assertThat
(
template
.
getConverter
().
getConversionService
().
canConvert
(
CouchbaseProperties
.
class
,
Boolean
.
class
))
assertThat
(
couchbaseDataConfiguration
.
typeKey
()).
isEqualTo
(
"custom"
);
.
isTrue
(
);
}
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseDataPropertiesTests.java
0 → 100644
View file @
af4fdf0d
/*
* Copyright 2012-2020 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
.
autoconfigure
.
data
.
couchbase
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.data.couchbase.config.CouchbaseConfigurationSupport
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link CouchbaseDataProperties}.
*
* @author Stephane Nicoll
*/
class
CouchbaseDataPropertiesTests
{
@Test
void
typeKeyHasConsistentDefault
()
{
assertThat
(
new
CouchbaseDataProperties
().
getTypeKey
()).
isEqualTo
(
new
CouchbaseConfigurationSupport
().
typeKey
());
}
}
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