diff --git a/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java b/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java index 5441dae5..ab2ea1bd 100644 --- a/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/config/CouchbaseConfigurationSupport.java @@ -26,7 +26,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.data.annotation.Persistent; -import org.springframework.data.couchbase.core.convert.CustomConversions; +import org.springframework.data.convert.CustomConversions; +import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions; import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService; import org.springframework.data.couchbase.core.convert.translation.TranslationService; @@ -49,6 +50,7 @@ import org.springframework.util.StringUtils; * * @author Simon Baslé * @author Subhashni Balakrishnan + * @author Mark Paluch */ public class CouchbaseConfigurationSupport { /** @@ -130,7 +132,7 @@ public class CouchbaseConfigurationSupport { */ @Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS) public CustomConversions customConversions() { - return new CustomConversions(Collections.emptyList()); + return new CouchbaseCustomConversions(Collections.emptyList()); } /** diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java index 38ae47df..b242ac88 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors + * Copyright 2012-2017 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. @@ -20,11 +20,15 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.GenericConversionService; import org.springframework.data.convert.EntityInstantiators; +import org.springframework.data.convert.CustomConversions; + +import java.util.Collections; /** * An abstract {@link CouchbaseConverter} that provides the basics for the {@link MappingCouchbaseConverter}. * * @author Michael Nitschinger + * @author Mark Paluch */ public abstract class AbstractCouchbaseConverter implements CouchbaseConverter, InitializingBean { @@ -41,7 +45,7 @@ public abstract class AbstractCouchbaseConverter implements CouchbaseConverter, /** * Holds the custom conversions. */ - protected CustomConversions conversions = new CustomConversions(); + protected CustomConversions conversions = new CouchbaseCustomConversions(Collections.emptyList()); /** * Create a new converter and hand it over the {@link ConversionService} @@ -94,16 +98,13 @@ public abstract class AbstractCouchbaseConverter implements CouchbaseConverter, return null; } - Class targetType = this.conversions.getCustomWriteTarget(value.getClass()); - if (targetType != null) { - return this.conversionService.convert(value, targetType); - } - return value; + return this.conversions.getCustomWriteTarget(value.getClass()) // + .map(it -> (Object) this.conversionService.convert(value, it)) // + .orElse(value); } @Override public Class getWriteClassFor(Class clazz) { - Class targetType = this.conversions.getCustomWriteTarget(clazz); - return targetType != null ? targetType : clazz; + return this.conversions.getCustomWriteTarget(clazz).orElse(clazz); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseCustomConversions.java b/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseCustomConversions.java new file mode 100644 index 00000000..269b1ea5 --- /dev/null +++ b/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseCustomConversions.java @@ -0,0 +1,64 @@ +/* + * Copyright 2017 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.data.couchbase.core.convert; + +import org.springframework.data.mapping.model.SimpleTypeHolder; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Value object to capture custom conversion. + *

+ *

Types that can be mapped directly onto JSON are considered simple ones, because they neither need deeper + * inspection nor nested conversion.

+ * + * @author Michael Nitschinger + * @author Oliver Gierke + * @author Mark Paluch + * @author Subhashni Balakrishnan + * @see org.springframework.data.convert.CustomConversions + * @see SimpleTypeHolder + * @since 2.0 + */ +public class CouchbaseCustomConversions extends org.springframework.data.convert.CustomConversions { + + private static final StoreConversions STORE_CONVERSIONS; + + private static final List STORE_CONVERTERS; + + static { + + List converters = new ArrayList<>(); + + converters.addAll(DateConverters.getConvertersToRegister()); + converters.addAll(CouchbaseJsr310Converters.getConvertersToRegister()); + + STORE_CONVERTERS = Collections.unmodifiableList(converters); + STORE_CONVERSIONS = StoreConversions.of(SimpleTypeHolder.DEFAULT, STORE_CONVERTERS); + } + + /** + * Create a new instance with a given list of converters. + * + * @param converters the list of custom converters. + */ + public CouchbaseCustomConversions(final List converters) { + super(STORE_CONVERSIONS, converters); + } +} diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java b/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java index a006d827..45f51fd4 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java @@ -16,26 +16,7 @@ package org.springframework.data.couchbase.core.convert; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.core.GenericTypeResolver; -import org.springframework.core.convert.converter.Converter; -import org.springframework.core.convert.converter.ConverterFactory; -import org.springframework.core.convert.converter.GenericConverter; -import org.springframework.core.convert.support.GenericConversionService; -import org.springframework.data.convert.ReadingConverter; -import org.springframework.data.convert.WritingConverter; -import org.springframework.data.mapping.model.SimpleTypeHolder; -import org.springframework.util.Assert; /** * Value object to capture custom conversion. @@ -47,31 +28,10 @@ import org.springframework.util.Assert; * @author Oliver Gierke * @author Mark Paluch * @author Subhashni Balakrishnan + * @deprecated since 2.0, use {@link CouchbaseCustomConversions}. */ -public class CustomConversions { - - private static final Logger LOG = LoggerFactory.getLogger(CustomConversions.class); - private static final String READ_CONVERTER_NOT_SIMPLE = "Registering converter from %s to %s as reading converter although it doesn't convert from a Couchbase supported type! You might wanna check you annotation setup at the converter implementation."; - private static final String WRITE_CONVERTER_NOT_SIMPLE = "Registering converter from %s to %s as writing converter although it doesn't convert to a Couchbase supported type! You might wanna check you annotation setup at the converter implementation."; - - /** - * Contains the simple type holder. - */ - private final SimpleTypeHolder simpleTypeHolder; - - private final List converters; - - private final Set readingPairs; - private final Set writingPairs; - private final Set> customSimpleTypes; - private final ConcurrentMap customReadTargetTypes; - - /** - * Create a new instance with no converters. - */ - CustomConversions() { - this(new ArrayList()); - } +@Deprecated +public class CustomConversions extends CouchbaseCustomConversions { /** * Create a new instance with a given list of conversers. @@ -79,265 +39,6 @@ public class CustomConversions { * @param converters the list of custom converters. */ public CustomConversions(final List converters) { - Assert.notNull(converters, "List of Converters must not be null!"); - - readingPairs = new LinkedHashSet(); - writingPairs = new LinkedHashSet(); - customSimpleTypes = new HashSet>(); - customReadTargetTypes = new ConcurrentHashMap(); - - this.converters = new ArrayList(); - this.converters.addAll(converters); - this.converters.addAll(DateConverters.getConvertersToRegister()); - this.converters.addAll(CouchbaseJsr310Converters.getConvertersToRegister()); - - for (Object converter : this.converters) { - registerConversion(converter); - } - - simpleTypeHolder = new SimpleTypeHolder(customSimpleTypes, true); - } - - /** - * Check that the given type is of "simple type". - * - * @param type the type to check. - * @return if its simple type or not. - */ - public boolean isSimpleType(final Class type) { - return simpleTypeHolder.isSimpleType(type); - } - - /** - * Returns the simple type holder. - * - * @return the simple type holder. - */ - public SimpleTypeHolder getSimpleTypeHolder() { - return simpleTypeHolder; - } - - /** - * Populates the given {@link GenericConversionService} with the convertes registered. - * - * @param conversionService the service to register. - */ - public void registerConvertersIn(final GenericConversionService conversionService) { - for (Object converter : converters) { - boolean added = false; - - if (converter instanceof Converter) { - conversionService.addConverter((Converter) converter); - added = true; - } - - if (converter instanceof ConverterFactory) { - conversionService.addConverterFactory((ConverterFactory) converter); - added = true; - } - - if (converter instanceof GenericConverter) { - conversionService.addConverter((GenericConverter) converter); - added = true; - } - - if (!added) { - throw new IllegalArgumentException("Given set contains element that is neither Converter nor ConverterFactory!"); - } - } - } - - /** - * Registers a conversion for the given converter. Inspects either generics or the convertible pairs returned - * by a {@link GenericConverter}. - * - * @param converter the converter to register. - */ - private void registerConversion(final Object converter) { - Class type = converter.getClass(); - boolean isWriting = type.isAnnotationPresent(WritingConverter.class); - boolean isReading = type.isAnnotationPresent(ReadingConverter.class); - - if (converter instanceof GenericConverter) { - GenericConverter genericConverter = (GenericConverter) converter; - for (GenericConverter.ConvertiblePair pair : genericConverter.getConvertibleTypes()) { - register(new ConverterRegistration(pair, isReading, isWriting)); - } - } - else if (converter instanceof Converter) { - Class[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class); - register(new ConverterRegistration(arguments[0], arguments[1], isReading, isWriting)); - } - else { - throw new IllegalArgumentException("Unsupported Converter type!"); - } - } - - /** - * Registers the given {@link ConverterRegistration} as reading or writing pair depending on the type sides being basic - * Couchbase types. - * - * @param registration the registration. - */ - private void register(final ConverterRegistration registration) { - GenericConverter.ConvertiblePair pair = registration.getConvertiblePair(); - - if (registration.isReading()) { - readingPairs.add(pair); - if (LOG.isWarnEnabled() && !registration.isSimpleSourceType()) { - LOG.warn(String.format(READ_CONVERTER_NOT_SIMPLE, pair.getSourceType(), pair.getTargetType())); - } - } - - if (registration.isWriting()) { - writingPairs.add(pair); - customSimpleTypes.add(pair.getSourceType()); - if (LOG.isWarnEnabled() && !registration.isSimpleTargetType()) { - LOG.warn(String.format(WRITE_CONVERTER_NOT_SIMPLE, pair.getSourceType(), pair.getTargetType())); - } - } - } - - /** - * Returns the target type to convert to in case we have a custom conversion registered to convert the given source - * type into a Couchbase native one. - * - * @param sourceType must not be {@literal null} - * @return - */ - public Class getCustomWriteTarget(Class sourceType) { - return getCustomWriteTarget(sourceType, null); - } - - /** - * Returns the target type we can write an object of the given source type to. The returned type might be a subclass - * oth the given expected type though. If {@code expectedTargetType} is {@literal null} we will simply return the - * first target type matching or {@literal null} if no conversion can be found. - * - * @param sourceType must not be {@literal null} - * @param requestedTargetType - * @return - */ - public Class getCustomWriteTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType, "Source type must not be null!"); - return getCustomTarget(sourceType, requestedTargetType, writingPairs); - } - - /** - * Returns whether we have a custom conversion registered to write into a Couchbase native type. The returned type might - * be a subclass of the given expected type though. - * - * @param sourceType must not be {@literal null} - * @return - */ - public boolean hasCustomWriteTarget(Class sourceType) { - Assert.notNull(sourceType, "Source type must not be null!"); - return hasCustomWriteTarget(sourceType, null); - } - - /** - * Returns whether we have a custom conversion registered to write an object of the given source type into an object - * of the given Couchbase native target type. - * - * @param sourceType must not be {@literal null}. - * @param requestedTargetType - * @return - */ - public boolean hasCustomWriteTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType, "Source type must not be null!"); - return getCustomWriteTarget(sourceType, requestedTargetType) != null; - } - - /** - * Returns whether we have a custom conversion registered to read the given source into the given target type. - * - * @param sourceType must not be {@literal null} - * @param requestedTargetType must not be {@literal null} - * @return - */ - public boolean hasCustomReadTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType, "Source type must not be null!"); - Assert.notNull(requestedTargetType, "Requested target type must not be null!"); - return getCustomReadTarget(sourceType, requestedTargetType) != null; - } - - /** - * Returns the actual target type for the given {@code sourceType} and {@code requestedTargetType}. Note that the - * returned {@link Class} could be an assignable type to the given {@code requestedTargetType}. - * - * @param sourceType must not be {@literal null}. - * @param requestedTargetType can be {@literal null}. - * @return - */ - private Class getCustomReadTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType, "Source type must not be null!"); - if (requestedTargetType == null) { - return null; - } - - GenericConverter.ConvertiblePair lookupKey = new GenericConverter.ConvertiblePair(sourceType, requestedTargetType); - CacheValue readTargetTypeValue = customReadTargetTypes.get(lookupKey); - - if (readTargetTypeValue != null) { - return readTargetTypeValue.getType(); - } - - readTargetTypeValue = CacheValue.of(getCustomTarget(sourceType, requestedTargetType, readingPairs)); - CacheValue cacheValue = customReadTargetTypes.putIfAbsent(lookupKey, readTargetTypeValue); - - return cacheValue != null ? cacheValue.getType() : readTargetTypeValue.getType(); - } - - /** - * Inspects the given {@link GenericConverter.ConvertiblePair} for ones - * that have a source compatible type as source. Additionally checks assignability of the target type if one is - * given. - * - * @param sourceType must not be {@literal null}. - * @param requestedTargetType can be {@literal null}. - * @param pairs must not be {@literal null}. - * @return - */ - private static Class getCustomTarget(Class sourceType, Class requestedTargetType, - Iterable pairs) { - Assert.notNull(sourceType, "Source type must not be null!"); - Assert.notNull(pairs, "Pairs must not be null!"); - - for (GenericConverter.ConvertiblePair typePair : pairs) { - if (typePair.getSourceType().isAssignableFrom(sourceType)) { - Class targetType = typePair.getTargetType(); - if (requestedTargetType == null || targetType.isAssignableFrom(requestedTargetType)) { - return targetType; - } - } - } - - return null; - } - - /** - * Wrapper to safely store {@literal null} values in the type cache. - * - * @author Patryk Wasik - * @author Oliver Gierke - * @author Thomas Darimont - */ - private static class CacheValue { - - private static final CacheValue ABSENT = new CacheValue(null); - - private final Class type; - - public CacheValue(Class type) { - this.type = type; - } - - public Class getType() { - return type; - } - - static CacheValue of(Class type) { - return type == null ? ABSENT : new CacheValue(type); - } + super(converters); } } diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java index 57955235..40ce22f6 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java @@ -368,7 +368,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter return; } - boolean isCustom = conversions.getCustomWriteTarget(source.getClass(), CouchbaseDocument.class) != null; + boolean isCustom = conversions.getCustomWriteTarget(source.getClass(), CouchbaseDocument.class).isPresent(); TypeInformation type = ClassTypeInformation.from(source.getClass()); if (!isCustom) { @@ -394,8 +394,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter return; } - Class customTarget = conversions.getCustomWriteTarget(source.getClass(), CouchbaseDocument.class); - if (customTarget != null) { + Optional> customTarget = conversions.getCustomWriteTarget(source.getClass(), CouchbaseDocument.class); + if (customTarget.isPresent()) { copyCouchbaseDocument(conversionService.convert(source, CouchbaseDocument.class), target); return; } @@ -568,9 +568,13 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter return; } - Class basicTargetType = conversions.getCustomWriteTarget(source.getClass(), null); - if (basicTargetType != null) { - target.put(name, conversionService.convert(source, basicTargetType)); + Optional> basicTargetType = conversions.getCustomWriteTarget(source.getClass()); + if (basicTargetType.isPresent()) { + + basicTargetType.ifPresent(it -> { + target.put(name, conversionService.convert(source, it)); + }); + return; } @@ -756,12 +760,10 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter return null; } - Class customTarget = conversions.getCustomWriteTarget(value.getClass(), null); - if (customTarget != null) { - return conversionService.convert(value, customTarget); - } else { - return Enum.class.isAssignableFrom(value.getClass()) ? ((Enum) value).name() : value; - } + Optional> customTarget = conversions.getCustomWriteTarget(value.getClass()); + + return customTarget.map(it -> (Object) conversionService.convert(value, it)) + .orElseGet(() -> Enum.class.isAssignableFrom(value.getClass()) ? ((Enum) value).name() : value); } /** diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/translation/JacksonTranslationService.java b/src/main/java/org/springframework/data/couchbase/core/convert/translation/JacksonTranslationService.java index 187eaaf5..4f8d7aad 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/translation/JacksonTranslationService.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/translation/JacksonTranslationService.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors + * Copyright 2012-2017 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. @@ -40,6 +40,7 @@ import org.springframework.data.mapping.model.SimpleTypeHolder; * @author Michael Nitschinger * @author Simon Baslé * @author Anastasiia Smirnova + * @author Mark Paluch */ public class JacksonTranslationService implements TranslationService, InitializingBean { @@ -51,7 +52,7 @@ public class JacksonTranslationService implements TranslationService, Initializi /** * Type holder to help easily identify simple types. */ - private SimpleTypeHolder simpleTypeHolder = new SimpleTypeHolder(); + private SimpleTypeHolder simpleTypeHolder = SimpleTypeHolder.DEFAULT; /** * JSON factory for Jackson. diff --git a/src/test/java/org/springframework/data/couchbase/core/mapping/BasicCouchbasePersistentPropertyTests.java b/src/test/java/org/springframework/data/couchbase/core/mapping/BasicCouchbasePersistentPropertyTests.java index dc140948..b98a0b35 100644 --- a/src/test/java/org/springframework/data/couchbase/core/mapping/BasicCouchbasePersistentPropertyTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/mapping/BasicCouchbasePersistentPropertyTests.java @@ -145,7 +145,7 @@ public class BasicCouchbasePersistentPropertyTests { * @return the actual BasicCouchbasePersistentProperty instance. */ private CouchbasePersistentProperty getPropertyFor(Field field) { - return new BasicCouchbasePersistentProperty(Property.of(field), entity, new SimpleTypeHolder(), + return new BasicCouchbasePersistentProperty(Property.of(field), entity, SimpleTypeHolder.DEFAULT, PropertyNameFieldNamingStrategy.INSTANCE); } diff --git a/src/test/java/org/springframework/data/couchbase/core/mapping/CustomConvertersTests.java b/src/test/java/org/springframework/data/couchbase/core/mapping/CustomConvertersTests.java index 9313cdfb..b668b575 100644 --- a/src/test/java/org/springframework/data/couchbase/core/mapping/CustomConvertersTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/mapping/CustomConvertersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 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. @@ -33,7 +33,7 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; import org.springframework.data.convert.WritingConverter; import org.springframework.data.couchbase.UnitTestApplicationConfig; -import org.springframework.data.couchbase.core.convert.CustomConversions; +import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions; import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -45,6 +45,7 @@ import com.couchbase.client.java.repository.annotation.Id; * Tests to verify custom mapping logic. * * @author Michael Nitschinger + * @author Mark Paluch */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = UnitTestApplicationConfig.class) @@ -55,14 +56,14 @@ public class CustomConvertersTests { @After public void cleanup() { - converter.setCustomConversions(new CustomConversions(Collections.emptyList())); + converter.setCustomConversions(new CouchbaseCustomConversions(Collections.emptyList())); } @Test public void shouldWriteWithCustomConverter() { List converters = new ArrayList(); converters.add(DateToStringConverter.INSTANCE); - converter.setCustomConversions(new CustomConversions(converters)); + converter.setCustomConversions(new CouchbaseCustomConversions(converters)); converter.afterPropertiesSet(); Date date = new Date(); @@ -79,7 +80,7 @@ public class CustomConvertersTests { public void shouldReadWithCustomConverter() { List converters = new ArrayList(); converters.add(IntegerToStringConverter.INSTANCE); - converter.setCustomConversions(new CustomConversions(converters)); + converter.setCustomConversions(new CouchbaseCustomConversions(converters)); converter.afterPropertiesSet(); CouchbaseDocument doc = new CouchbaseDocument(); @@ -92,7 +93,7 @@ public class CustomConvertersTests { public void shouldWriteConvertFullDocument() { List converters = new ArrayList(); converters.add(BlogPostToCouchbaseDocumentConverter.INSTANCE); - converter.setCustomConversions(new CustomConversions(converters)); + converter.setCustomConversions(new CouchbaseCustomConversions(converters)); converter.afterPropertiesSet(); BlogPost post = new BlogPost(); @@ -110,7 +111,7 @@ public class CustomConvertersTests { public void shouldReadConvertFullDocument() { List converters = new ArrayList(); converters.add(CouchbaseDocumentToBlogPostConverter.INSTANCE); - converter.setCustomConversions(new CustomConversions(converters)); + converter.setCustomConversions(new CouchbaseCustomConversions(converters)); converter.afterPropertiesSet(); CouchbaseDocument doc = new CouchbaseDocument(); diff --git a/src/test/java/org/springframework/data/couchbase/core/mapping/MappingCouchbaseConverterTests.java b/src/test/java/org/springframework/data/couchbase/core/mapping/MappingCouchbaseConverterTests.java index 9068acbb..94efcd9b 100644 --- a/src/test/java/org/springframework/data/couchbase/core/mapping/MappingCouchbaseConverterTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/mapping/MappingCouchbaseConverterTests.java @@ -43,8 +43,8 @@ import org.springframework.data.annotation.Id; import org.springframework.data.convert.ReadingConverter; import org.springframework.data.convert.WritingConverter; import org.springframework.data.couchbase.UnitTestApplicationConfig; +import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions; import org.springframework.data.couchbase.core.convert.CouchbaseJsr310Converters.LocalDateTimeToLongConverter; -import org.springframework.data.couchbase.core.convert.CustomConversions; import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter; import org.springframework.data.mapping.model.MappingException; import org.springframework.test.context.ContextConfiguration; @@ -56,6 +56,7 @@ import com.couchbase.client.java.repository.annotation.Field; * @author Michael Nitschinger * @author Geoffrey Mina * @author Subhashni Balakrishnan + * @author Mark Paluch */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = UnitTestApplicationConfig.class) @@ -386,7 +387,7 @@ public class MappingCouchbaseConverterTests { List converters = new ArrayList(); converters.add(BigDecimalToStringConverter.INSTANCE); converters.add(StringToBigDecimalConverter.INSTANCE); - converter.setCustomConversions(new CustomConversions(converters)); + converter.setCustomConversions(new CouchbaseCustomConversions(converters)); converter.afterPropertiesSet(); CouchbaseDocument converted = new CouchbaseDocument(); @@ -431,7 +432,7 @@ public class MappingCouchbaseConverterTests { List converters = new ArrayList(); converters.add(BigDecimalToStringConverter.INSTANCE); converters.add(StringToBigDecimalConverter.INSTANCE); - converter.setCustomConversions(new CustomConversions(converters)); + converter.setCustomConversions(new CouchbaseCustomConversions(converters)); converter.afterPropertiesSet(); CouchbaseDocument converted = new CouchbaseDocument(); diff --git a/src/test/java/org/springframework/data/couchbase/repository/query/PartTreeN1qBasedQueryTest.java b/src/test/java/org/springframework/data/couchbase/repository/query/PartTreeN1qBasedQueryTest.java index 0ba895a2..8979ba12 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/query/PartTreeN1qBasedQueryTest.java +++ b/src/test/java/org/springframework/data/couchbase/repository/query/PartTreeN1qBasedQueryTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2017 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.data.couchbase.repository.query; import static org.junit.Assert.*; @@ -39,6 +55,9 @@ import org.springframework.data.repository.query.ResultProcessor; import com.couchbase.client.java.CouchbaseBucket; import com.couchbase.client.java.query.Statement; +/** + * @author Mark Paluch + */ public class PartTreeN1qBasedQueryTest { @Test @@ -75,6 +94,7 @@ public class PartTreeN1qBasedQueryTest { when(accessor.iterator()).thenReturn(Arrays.asList((Object) "value", pr).iterator()); when(couchbaseConverter.getTypeKey()).thenReturn("_class"); when(couchbaseConverter.convertForWriteIfNeeded(eq("value"))).thenReturn("value"); + when(accessor.getPageable()).thenReturn(pr); PartTreeN1qlBasedQuery query = new PartTreeN1qlBasedQuery(queryMethod, couchbaseOperations); Statement statement = query.getCount(accessor, new Object[] { "value", pr }); @@ -119,6 +139,7 @@ public class PartTreeN1qBasedQueryTest { when(accessor.getSort()).thenReturn(sort); when(couchbaseConverter.getTypeKey()).thenReturn("_class"); when(couchbaseConverter.convertForWriteIfNeeded(eq("value"))).thenReturn("value"); + when(accessor.getPageable()).thenReturn(pr); PartTreeN1qlBasedQuery query = new PartTreeN1qlBasedQuery(queryMethod, couchbaseOperations); Statement statement = query.getCount(accessor, new Object[] { "value", pr });