Polish "Add support for Spring Data Couchbase custom type key"
See gh-19789
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -41,8 +41,8 @@ public class CouchbaseDataProperties {
|
||||
private Consistency consistency = Consistency.READ_YOUR_OWN_WRITES;
|
||||
|
||||
/**
|
||||
* Name of the field that will store the type information for complex types when using
|
||||
* MappingCouchbaseConverter.
|
||||
* Name of the field that stores the type information for complex types when using
|
||||
* "MappingCouchbaseConverter".
|
||||
*/
|
||||
private String typeKey = DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -73,6 +73,11 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
|
||||
return new EntityScanner(this.applicationContext).scan(Document.class, Persistent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeKey() {
|
||||
return this.properties.getTypeKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ConditionalOnMissingBean(name = BeanNames.COUCHBASE_TEMPLATE)
|
||||
@Bean(name = BeanNames.COUCHBASE_TEMPLATE)
|
||||
@@ -97,9 +102,4 @@ class SpringBootCouchbaseDataConfiguration extends AbstractCouchbaseDataConfigur
|
||||
return new IndexManager(false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeKey() {
|
||||
return this.properties.getTypeKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -120,6 +120,19 @@ class CouchbaseDataAutoConfigurationTests {
|
||||
assertThat(initialEntitySet).containsOnly(City.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void typeKeyDefault() {
|
||||
load(CouchbaseTestConfigurer.class);
|
||||
assertThat(this.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customConversions() {
|
||||
load(CustomConversionsConfig.class);
|
||||
@@ -128,22 +141,6 @@ class CouchbaseDataAutoConfigurationTests {
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void typeKeyIsClassByDefault() {
|
||||
load(CouchbaseTestConfigurer.class);
|
||||
AbstractCouchbaseDataConfiguration couchbaseDataConfiguration = this.context
|
||||
.getBean(AbstractCouchbaseDataConfiguration.class);
|
||||
assertThat(couchbaseDataConfiguration.typeKey()).isEqualTo(DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customTypeKey() {
|
||||
load(CouchbaseTestConfigurer.class, "spring.data.couchbase.type-key=custom");
|
||||
AbstractCouchbaseDataConfiguration couchbaseDataConfiguration = this.context
|
||||
.getBean(AbstractCouchbaseDataConfiguration.class);
|
||||
assertThat(couchbaseDataConfiguration.typeKey()).isEqualTo("custom");
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of(environment).applyTo(context);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user