http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java deleted file mode 100644 index 1f1a2a9..0000000 --- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java +++ /dev/null @@ -1,469 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.ServiceContextManager; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.Type; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Manager that deals with {@link PropertyConverter} instances. - * This class is thread-safe. - */ -public class PropertyConverterManager { - /** - * The logger used. - */ - private static final Logger LOG = Logger.getLogger(PropertyConverterManager.class.getName()); - /** - * The registered converters. - */ - private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>(); - /** - * The transitive converters. - */ - private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> transitiveConverters = new ConcurrentHashMap<>(); - /** - * The lock used. - */ - private final ReadWriteLock lock = new ReentrantReadWriteLock(); - - private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() { - - @Override - public int compare(Object o1, Object o2) { - int prio = PriorityServiceComparator.getPriority(o1) - PriorityServiceComparator.getPriority(o2); - if (prio < 0) { - return 1; - } else if (prio > 0) { - return -1; - } else { - return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); - } - } - }; - - /** - * Constructor. - */ - public PropertyConverterManager() { - this(true); - } - - public PropertyConverterManager(boolean init) { - if (init) { - initConverters(); - } - } - - /** - * Registers the default converters provided out of the box. - */ - protected void initConverters() { - for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) { - Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0]; - register(TypeLiteral.of(type), conv); - } - } - - /** - * Registers a ew converter instance. - * - * @param targetType the target type, not null. - * @param converter the converter, not null. - * @param <T> the type. - */ - public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) { - Objects.requireNonNull(converter); - Lock writeLock = lock.writeLock(); - try { - writeLock.lock(); - List converters = List.class.cast(this.converters.get(targetType)); - if(converters!=null && converters.contains(converter)){ - return; - } - List<PropertyConverter<?>> newConverters = new ArrayList<>(); - if (converters != null) { - newConverters.addAll(converters); - } - if(!newConverters.contains(converter)) { - newConverters.add(converter); - } - Collections.sort(newConverters, PRIORITY_COMPARATOR); - this.converters.put(targetType, Collections.unmodifiableList(newConverters)); - // evaluate transitive closure for all inherited supertypes and implemented interfaces - // direct implemented interfaces - for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) { - converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType))); - newConverters = new ArrayList<>(); - if (converters != null) { - newConverters.addAll(converters); - } - newConverters.add(converter); - Collections.sort(newConverters, PRIORITY_COMPARATOR); - this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters)); - } - Class<?> superClass = targetType.getRawType().getSuperclass(); - while (superClass != null && !superClass.equals(Object.class)) { - converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass))); - newConverters = new ArrayList<>(); - if (converters != null) { - newConverters.addAll(converters); - } - newConverters.add(converter); - Collections.sort(newConverters, PRIORITY_COMPARATOR); - this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters)); - for (Class<?> ifaceType : superClass.getInterfaces()) { - converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType))); - newConverters = new ArrayList<>(); - if (converters != null) { - newConverters.addAll(converters); - } - newConverters.add(converter); - Collections.sort(newConverters, PRIORITY_COMPARATOR); - this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters)); - } - superClass = superClass.getSuperclass(); - } - } finally { - writeLock.unlock(); - } - } - - /** - * Allows to evaluate if a given target type is supported. - * - * @param targetType the target type, not null. - * @return true, if a converter for the given type is registered, or a default one can be created. - */ - public boolean isTargetTypeSupported(TypeLiteral<?> targetType) { - return converters.containsKey(targetType) || transitiveConverters.containsKey(targetType) || createDefaultPropertyConverter(targetType) != null; - } - - /** - * Get a map of all property converters currently registered. This will not contain the converters that - * may be created, when an instance is adapted, which provides a String constructor or compatible - * factory methods taking a single String instance. - * - * @return the current map of instantiated and registered converters. - * @see #createDefaultPropertyConverter(TypeLiteral) - */ - public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() { - Lock readLock = lock.readLock(); - try { - readLock.lock(); - return new HashMap<>(this.converters); - } finally { - readLock.unlock(); - } - } - - /** - * Get the list of all current registered converters for the given target type. - * If not converters are registered, they component tries to create and register a dynamic - * converter based on String costructor or static factory methods available. - * The converters provided are of the following type and returned in the following order: - * <ul> - * <li>Converters mapped explicitly to the required target type are returned first, ordered - * by decreasing priority. This means, if explicit converters are registered these are used - * primarly for converting a value.</li> - * <li>The target type of each explicitly registered converter also can be transitively mapped to - * 1) all directly implemented interfaces, 2) all its superclasses (except Object), 3) all the interfaces - * implemented by its superclasses. These groups of transitive converters is returned similarly in the - * order as mentioned, whereas also here a priority based decreasing ordering is applied.</li> - * <li>java.lang wrapper classes and native types are automatically mapped.</li> - * <li>If no explicit converters are registered, for Enum types a default implementation is provided that - * compares the configuration values with the different enum members defined (cases sensitive mapping).</li> - * </ul> - * <p> - * So given that list above directly registered mappings always are tried first, before any transitive mapping - * should be used. Also in all cases @Priority annotations are honored for ordering of the converters in place. - * Transitive conversion is supported for all directly implemented interfaces (including inherited ones) and - * the inheritance hierarchy (exception Object). Superinterfaces of implemented interfaces are ignored. - * - * @param targetType the target type, not null. - * @param <T> the type class - * @return the ordered list of converters (may be empty for not convertible types). - * @see #createDefaultPropertyConverter(TypeLiteral) - */ - public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) { - Lock readLock = lock.readLock(); - List<PropertyConverter<T>> converterList = new ArrayList<>(); - List<PropertyConverter<T>> converters; - // direct mapped converters - try { - readLock.lock(); - addConvertersToList(List.class.cast(this.converters.get(targetType)), converterList); - addConvertersToList(List.class.cast(this.transitiveConverters.get(targetType)), converterList); - } finally { - readLock.unlock(); - } - // handling of java.lang wrapper classes - TypeLiteral<T> boxedType = mapBoxedType(targetType); - if (boxedType != null) { - try { - readLock.lock(); - addConvertersToList(List.class.cast(this.converters.get(boxedType)), converterList); - } finally { - readLock.unlock(); - } - } - if (converterList.isEmpty() && !TypeLiteral.of(String.class).equals(targetType)) { - // adding any converters created on the fly, e.g. for enum types. - PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType); - if (defaultConverter != null) { - register(targetType, defaultConverter); - try { - readLock.lock(); - addConvertersToList(List.class.cast(this.converters.get(targetType)), converterList); - } finally { - readLock.unlock(); - } - } - } - // check for parametrized types, ignoring param type - // direct mapped converters - if(targetType.getType()!=null) { - try { - readLock.lock(); - addConvertersToList(List.class.cast(this.converters.get( - TypeLiteral.of(targetType.getRawType()))), converterList); - } finally { - readLock.unlock(); - } - } - return converterList; - } - - private <T> void addConvertersToList(Collection<PropertyConverter<T>> converters, List<PropertyConverter<T>> converterList) { - if (converters != null) { - for(PropertyConverter<T> conv:converters) { - if(!converterList.contains(conv)) { - converterList.add(conv); - } - } - } - } - - /** - * Maps native types to the corresponding boxed types. - * - * @param targetType the native type. - * @param <T> the type - * @return the boxed type, or null. - */ - private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) { - Type parameterType = targetType.getType(); - if (parameterType == int.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Integer.class)); - } - if (parameterType == short.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Short.class)); - } - if (parameterType == byte.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Byte.class)); - } - if (parameterType == long.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Long.class)); - } - if (parameterType == boolean.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class)); - } - if (parameterType == char.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Character.class)); - } - if (parameterType == float.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Float.class)); - } - if (parameterType == double.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Double.class)); - } - if (parameterType == int[].class) { - return TypeLiteral.class.cast(TypeLiteral.of(Integer[].class)); - } - if (parameterType == short[].class) { - return TypeLiteral.class.cast(TypeLiteral.of(Short[].class)); - } - if (parameterType == byte[].class) { - return TypeLiteral.class.cast(TypeLiteral.of(Byte[].class)); - } - if (parameterType == long[].class) { - return TypeLiteral.class.cast(TypeLiteral.of(Long[].class)); - } - if (parameterType == boolean.class) { - return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class)); - } - if (parameterType == char[].class) { - return TypeLiteral.class.cast(TypeLiteral.of(Character[].class)); - } - if (parameterType == float[].class) { - return TypeLiteral.class.cast(TypeLiteral.of(Float[].class)); - } - if (parameterType == double[].class) { - return TypeLiteral.class.cast(TypeLiteral.of(Double[].class)); - } - return null; - } - - /** - * Creates a dynamic PropertyConverter for the given target type. - * - * @param targetType the target type - * @param <T> the type class - * @return a new converter, or null. - */ - protected <T> PropertyConverter<T> createDefaultPropertyConverter(final TypeLiteral<T> targetType) { - if (Enum.class.isAssignableFrom(targetType.getRawType())) { - return new EnumConverter<>(targetType.getRawType()); - } - PropertyConverter<T> converter = null; - final Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse"); - if (factoryMethod != null) { - converter = new DefaultPropertyConverter<>(factoryMethod, targetType.getRawType()); - } - if (converter == null) { - final Constructor<T> constr; - try { - constr = targetType.getRawType().getDeclaredConstructor(String.class); - } catch (NoSuchMethodException e) { - LOG.log(Level.FINEST, "No matching constrctor for " + targetType, e); - return null; - } - converter = new PropertyConverter<T>() { - @Override - public T convert(String value, ConversionContext context) { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - constr.setAccessible(true); - return null; - } - }); - return null; - } - }); - try { - return constr.newInstance(value); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e); - } - return null; - } - }; - } - return converter; - } - - /** - * Tries to evaluate a factory method that can be used to create an instance based on a String. - * - * @param type the target type - * @param methodNames the possible static method names - * @return the first method found, or null. - */ - private Method getFactoryMethod(Class<?> type, String... methodNames) { - Method m; - for (String name : methodNames) { - try { - m = type.getDeclaredMethod(name, String.class); - return m; - } catch (NoSuchMethodException | RuntimeException e) { - LOG.finest("No such factory method found on type: " + type.getName() + ", methodName: " + name); - } - } - return null; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof PropertyConverterManager)) { - return false; - } - PropertyConverterManager that = (PropertyConverterManager) o; - return converters.equals(that.converters); - - } - - @Override - public int hashCode() { - return converters.hashCode(); - } - - /** - * Default converter imüöementation perfoming several lookups for String converion - * option. - * @param <T> - */ - private static class DefaultPropertyConverter<T> implements PropertyConverter<T> { - - private final Method factoryMethod; - private final Class<T> targetType; - - DefaultPropertyConverter(Method factoryMethod, Class<T> targetType){ - this.factoryMethod = Objects.requireNonNull(factoryMethod); - this.targetType = Objects.requireNonNull(targetType); - } - - @Override - public T convert(String value, ConversionContext context) { - context.addSupportedFormats(getClass(), "<String -> "+factoryMethod.toGenericString()); - - if (!Modifier.isStatic(factoryMethod.getModifiers())) { - throw new ConfigException(factoryMethod.toGenericString() + - " is not a static method. Only static " + - "methods can be used as factory methods."); - } - try { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - @Override - public Object run() { - factoryMethod.setAccessible(true); - return null; - } - }); - Object invoke = factoryMethod.invoke(null, value); - return targetType.cast(invoke); - } catch (Exception e) { - throw new ConfigException("Failed to decode '" + value + "'", e); - } - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java deleted file mode 100644 index 20eef63..0000000 --- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.spi.PropertyFilter; - -import javax.annotation.Priority; -import java.io.Serializable; -import java.util.Comparator; - -/** - * Comparator for PropertyFilters based on their priority annotations. - */ -public final class PropertyFilterComparator implements Comparator<PropertyFilter>, Serializable { - - private static final long serialVersionUID = 1L; - - private static final PropertyFilterComparator INSTANCE = new PropertyFilterComparator(); - - /** - * Get the shared instance of the comparator. - * @return the shared instance, never null. - */ - public static PropertyFilterComparator getInstance(){ - return INSTANCE; - } - - private PropertyFilterComparator(){} - - /** - * Compare 2 filters for ordering the filter chain. - * - * @param filter1 the first filter - * @param filter2 the second filter - * @return the comparison result - */ - private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) { - Priority prio1 = filter1.getClass().getAnnotation(Priority.class); - Priority prio2 = filter2.getClass().getAnnotation(Priority.class); - int ord1 = prio1 != null ? prio1.value() : 0; - int ord2 = prio2 != null ? prio2.value() : 0; - - if (ord1 < ord2) { - return -1; - } else if (ord1 > ord2) { - return 1; - } else { - return filter1.getClass().getName().compareTo(filter2.getClass().getName()); - } - } - - @Override - public int compare(PropertyFilter filter1, PropertyFilter filter2) { - return comparePropertyFilters(filter1, filter2); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java deleted file mode 100644 index ee76623..0000000 --- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.FilterContext; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertyValue; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the - * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link PropertyFilter} - * instance to evaluate the current Configuration. - */ -public final class PropertyFiltering{ - /** - * The logger. - */ - private static final Logger LOG = Logger.getLogger(PropertyFiltering.class.getName()); - /** - * The maximal number of filter cycles performed before aborting. - */ - private static final int MAX_FILTER_LOOPS = 10; - - /** - * Private singleton constructor. - */ - private PropertyFiltering(){} - - /** - * Filters a single value. - * @param value the raw value, not null. - * @param context the context - * @return the filtered value, inclusing null. - */ - public static PropertyValue applyFilter(PropertyValue value, ConfigurationContext context) { - FilterContext filterContext = new FilterContext(value, context); - return filterValue(filterContext); - } - - /** - * Filters all properties. - * @param rawProperties the unfiltered properties, not null. - * @param context the context - * @return the filtered value, inclusing null. - */ - public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> rawProperties, ConfigurationContext context) { - Map<String, PropertyValue> result = new HashMap<>(); - // Apply filters to values, prevent values filtered to null! - for (Map.Entry<String, PropertyValue> entry : rawProperties.entrySet()) { - FilterContext filterContext = new FilterContext(entry.getValue(), rawProperties, context); - PropertyValue filtered = filterValue(filterContext); - if(filtered!=null){ - result.put(filtered.getKey(), filtered); - } - } - return result; - } - - /** - * Basic filter logic. - * @param context the filter context, not null. - * @return the filtered value. - */ - private static PropertyValue filterValue(FilterContext context) { - PropertyValue inputValue = context.getProperty(); - PropertyValue filteredValue = inputValue; - - for (int i = 0; i < MAX_FILTER_LOOPS; i++) { - int changes = 0; - for (PropertyFilter filter : context.getContext().getPropertyFilters()) { - filteredValue = filter.filterProperty(inputValue, context); - if (filteredValue != null && !filteredValue.equals(inputValue)) { - changes++; - LOG.finest("Filter - " + inputValue + " -> " + filteredValue + " by " + filter); - } - if(filteredValue==null){ - LOG.finest("Filter removed entry - " + inputValue + ": " + filter); - break; - }else{ - inputValue = filteredValue; - } - } - if (changes == 0) { - LOG.finest("Finishing filter loop, no changes detected."); - break; - } else if (filteredValue == null) { - break; - } else { - if (i == (MAX_FILTER_LOOPS - 1)) { - if (LOG.isLoggable(Level.WARNING)) { - LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i); - } - } else { - LOG.finest("Repeating filter loop, changes detected: " + changes); - } - } - } - return filteredValue; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java deleted file mode 100644 index 6799e4e..0000000 --- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - -import javax.annotation.Priority; -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.Comparator; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Comparator for ordering of PropertySources based on their ordinal method and class name. - */ -public class PropertySourceComparator implements Comparator<PropertySource>, Serializable { - /** serial version UID. */ - private static final long serialVersionUID = 1L; - - private static final Logger LOG = Logger.getLogger(PropertySourceComparator.class.getName()); - - private static final PropertySourceComparator INSTANCE = new PropertySourceComparator(); - - private String alternativeOrdinalKey; - - private PropertySourceComparator(){} - - /** - * Get the shared instance of the comparator. - * @return the shared instance, never null. - */ - public static PropertySourceComparator getInstance(){ - return INSTANCE; - } - - - /** - * Order property source reversely, the most important come first. - * - * @param source1 the first PropertySource - * @param source2 the second PropertySource - * @return the comparison result. - */ - private int comparePropertySources(PropertySource source1, PropertySource source2) { - if (getOrdinal(source1, alternativeOrdinalKey) < getOrdinal(source2, alternativeOrdinalKey)) { - return -1; - } else if (getOrdinal(source1, alternativeOrdinalKey) > getOrdinal(source2, alternativeOrdinalKey)) { - return 1; - } else { - return source1.getClass().getName().compareTo(source2.getClass().getName()); - } - } - - public static int getOrdinal(PropertySource propertySource) { - return getOrdinal(propertySource, null); - } - - public static int getOrdinal(PropertySource propertySource, String alternativeOrdinalKey) { - if(alternativeOrdinalKey!=null) { - PropertyValue ordinalValue = propertySource.get(alternativeOrdinalKey); - if (ordinalValue != null) { - try { - return Integer.parseInt(ordinalValue.getValue().trim()); - } catch (Exception e) { - LOG.finest("Failed to parse ordinal from " + alternativeOrdinalKey + - " in " + propertySource.getName() + ": " + ordinalValue.getValue()); - } - } - } - return propertySource.getOrdinal(); - } - - /** - * Overrides/adds the key to evaluate/override a property sources ordinal. - * @param ordinalKey sets the alternative ordinal key, if null default - * behaviour will be active. - * @return the instance for chaining. - */ - public PropertySourceComparator setOrdinalKey(String ordinalKey) { - this.alternativeOrdinalKey = ordinalKey; - return this; - } - - @Override - public int compare(PropertySource source1, PropertySource source2) { - return comparePropertySources(source1, source2); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java deleted file mode 100644 index 1f8cce9..0000000 --- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.spi.FilterContext; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertyValue; - -import java.util.Arrays; -import java.util.List; - -/** - * Predicate filtering using a regex expression operating on the key. It allows either - * to define the target keys to be selected (includes), or to be excluded (excludes). - */ -public final class RegexPropertyFilter implements PropertyFilter{ - /** The expression used to include entries that match. */ - private List<String> includes; - /** The expression used to exclude entries that match. */ - private List<String> excludes; - - /** - * Sets the regex expression to be applied on the key to filter the corresponding entry - * if matching. - * @param expressions the regular expression for inclusion, not null. - */ - public void setIncludes(String... expressions){ - this.includes = Arrays.asList(expressions); - } - - /** - * Sets the regex expression to be applied on the key to remove the corresponding entries - * if matching. - * @param expressions the regular expressions for exclusion, not null. - */ - public void setExcludes(String... expressions){ - this.excludes= Arrays.asList(expressions); - } - - @Override - public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { - if(includes!=null){ - for(String expression:includes){ - if(context.getProperty().getKey().matches(expression)){ - return valueToBeFiltered; - } - } - return null; - } - if(excludes!=null){ - for(String expression:excludes){ - if(context.getProperty().getKey().matches(expression)){ - return null; - } - } - } - return valueToBeFiltered; - } - - @Override - public String toString() { - return "RegexPropertyFilter{" + - "includes='" + includes + '\'' + - "excludes='" + excludes + '\'' + - '}'; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java deleted file mode 100644 index f1a5a57..0000000 --- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.spi.PropertyValue; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.UUID; -import java.util.logging.Logger; - -/** - * Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for - * simple property files and XML property files. - */ -public class SimplePropertySource extends BasePropertySource { - - private static final Logger LOG = Logger.getLogger(SimplePropertySource.class.getName()); - - /** - * The current properties. - */ - private Map<String, PropertyValue> properties = new HashMap<>(); - - /** - * Creates a new Properties based PropertySource based on the given URL. - * - * @param propertiesLocation the URL encoded location, not null. - */ - public SimplePropertySource(File propertiesLocation) { - super(propertiesLocation.toString(), 0); - try { - this.properties = load(propertiesLocation.toURI().toURL()); - } catch (IOException e) { - throw new ConfigException("Failed to load properties from " + propertiesLocation, e); - } - } - - /** - * Creates a new Properties based PropertySource based on the given URL. - * - * @param propertiesLocation the URL encoded location, not null. - */ - public SimplePropertySource(URL propertiesLocation) { - super(propertiesLocation.toString(), 0); - this.properties = load(Objects.requireNonNull(propertiesLocation)); - } - - /** - * Creates a new Properties based PropertySource. - * - * @param name the property source name, not null. - * @param properties the properties, not null - * @param defaultOrdinal the default ordinal - */ - public SimplePropertySource(String name, Map<String, String> properties, int defaultOrdinal){ - super(name, defaultOrdinal); - for(Map.Entry<String,String> en: properties.entrySet()) { - this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); - } - } - - /** - * Creates a new Properties based PropertySource based on the given properties map. - * - * @param name the name, not null. - * @param properties the properties, not null. - */ - public SimplePropertySource(String name, Map<String, String> properties) { - this(name, properties, 0); - } - - /** - * Creates a new Properties based PropertySource based on the given URL. - * - * @param name The property source name - * @param propertiesLocation the URL encoded location, not null. - */ - public SimplePropertySource(String name, URL propertiesLocation) { - super(name, 0); - this.properties = load(propertiesLocation); - } - - private SimplePropertySource(Builder builder) { - properties = builder.properties; - if(builder.defaultOrdinal!=null){ - setDefaultOrdinal(builder.defaultOrdinal); - } - if(builder.ordinal!=null){ - setOrdinal(builder.ordinal); - } - setName(builder.name); - } - - public static Builder newBuilder() { - return new Builder(); - } - - @Override - public Map<String, PropertyValue> getProperties() { - return this.properties; - } - - /** - * loads the Properties from the given URL - * - * @param propertiesFile {@link URL} to load Properties from - * @return loaded {@link Properties} - * @throws IllegalStateException in case of an error while reading properties-file - */ - private static Map<String, PropertyValue> load(URL propertiesFile) { - boolean isXML = isXMLPropertieFiles(propertiesFile); - - Map<String, PropertyValue> properties = new HashMap<>(); - try (InputStream stream = propertiesFile.openStream()) { - Properties props = new Properties(); - if (stream != null) { - if (isXML) { - props.loadFromXML(stream); - } else { - props.load(stream); - } - } - String source = propertiesFile.toString(); - for (String key : props.stringPropertyNames()) { - properties.put(key, PropertyValue.of(key, props.getProperty(key), source)); - } - } catch (IOException e) { - throw new ConfigException("Error loading properties from " + propertiesFile, e); - } - - return properties; - } - - private static boolean isXMLPropertieFiles(URL url) { - return url.getFile().endsWith(".xml"); - } - - - /** - * {@code SimplePropertySource} builder static inner class. - */ - public static final class Builder { - private String name; - private Integer defaultOrdinal; - private Integer ordinal; - private Map<String, PropertyValue> properties = new HashMap<>(); - - private Builder() { - } - - /** - * Sets the {@code name} to a new UUID and returns a reference to this Builder so that the methods - * can be chained together. - * - * @return a reference to this Builder - */ - public Builder withUuidName() { - this.name = UUID.randomUUID().toString(); - return this; - } - - /** - * Sets the {@code name} and returns a reference to this Builder so that the methods - * can be chained together. - * - * @param val the {@code name} to set, not null. - * @return a reference to this Builder - */ - public Builder withName(String val) { - this.name = Objects.requireNonNull(name); - return this; - } - - /** - * Sets the {@code ordinal} and returns a reference to this Builder so that the methods - * can be chained together. - * - * @param val the {@code ordinal} to set - * @return a reference to this Builder - */ - public Builder withOrdinal(int val) { - this.ordinal = val; - return this; - } - - /** - * Sets the {@code defaultOrdinal} and returns a reference to this Builder so that the methods - * can be chained together. - * - * @param val the {@code defaultOrdinal} to set - * @return a reference to this Builder - */ - public Builder withDefaultOrdinal(int val) { - this.defaultOrdinal = val; - return this; - } - - /** - * Reads the {@code properties} from the given resource and returns a reference - * to this Builder so that the methods can be chained together. - * - * @param resource the {@code resource} to read - * @return a reference to this Builder - */ - public Builder withProperties(URL resource) { - this.properties.putAll(load(resource)); - return this; - } - - /** - * Reads the {@code properties} from the given resource and returns a reference - * to this Builder so that the methods can be chained together. - * - * @param file the {@code file} to read from (xml or properties format). - * @return a reference to this Builder - */ - public Builder withProperties(File file) { - try { - this.properties.putAll(load(file.toURI().toURL())); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("Failed to read file: " + file, e); - } - return this; - } - - /** - * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together. - * - * @param val the {@code properties} to set - * @return a reference to this Builder - */ - public Builder withProperties(Map<String, String> val) { - for(Map.Entry<String,String> en: val.entrySet()) { - this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); - } - return this; - } - - /** - * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together. - * - * @param val the {@code properties} to set - * @return a reference to this Builder - */ - public Builder withProperty(String key, String val) { - this.properties.put(key, PropertyValue.of(key, val, name)); - return this; - } - - /** - * Returns a {@code SimplePropertySource} built from the parameters previously set. - * - * @return a {@code SimplePropertySource} built with parameters of this {@code SimplePropertySource.Builder} - */ - public SimplePropertySource build() { - return new SimplePropertySource(this); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java deleted file mode 100644 index bc5f99e..0000000 --- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.spi.PropertyValue; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties. You can disable this feature by - * setting {@code tamaya.envprops.disable} or {@code tamaya.defaults.disable}. - */ -public class SystemPropertySource extends BasePropertySource { - - /** - * default ordinal used. - */ - public static final int DEFAULT_ORDINAL = 1000; - - private volatile Map<String,PropertyValue> cachedProperties; - - /** - * previous System.getProperties().hashCode() - * so we can check if we need to reload - */ - private volatile int previousHash; - - /** - * Prefix that allows system properties to virtually be mapped on specified sub section. - */ - private String prefix; - - /** - * If true, this property source does not return any properties. This is useful since this - * property source is applied by default, but can be switched off by setting the - * {@code tamaya.envprops.disable} system/environment property to {@code true}. - */ - private boolean disabled = false; - - /** - * Creates a new instance. Also initializes the {@code prefix} and {@code disabled} properties - * from the system-/ environment properties: - * <pre> - * tamaya.envprops.prefix - * tamaya.envprops.disable - * </pre> - */ - public SystemPropertySource(){ - super("system-properties", DEFAULT_ORDINAL); - initFromSystemProperties(); - if(!disabled){ - cachedProperties = Collections.unmodifiableMap(loadProperties()); - } - } - - /** - * Initializes the {@code prefix} and {@code disabled} properties from the system-/ - * environment properties: - * <pre> - * tamaya.envprops.prefix - * tamaya.envprops.disable - * </pre> - */ - private void initFromSystemProperties() { - String value = System.getProperty("tamaya.sysprops.prefix"); - if(value==null){ - prefix = System.getenv("tamaya.sysprops.prefix"); - } - value = System.getProperty("tamaya.sysprops.disable"); - if(value==null){ - value = System.getenv("tamaya.sysprops.disable"); - } - if(value==null){ - value = System.getProperty("tamaya.defaults.disable"); - } - if(value==null){ - value = System.getenv("tamaya.defaults.disable"); - } - if(value!=null && !value.isEmpty()) { - this.disabled = Boolean.parseBoolean(value); - } - } - - /** - * Creates a new instance using a fixed ordinal value. - * @param ordinal the ordinal number. - */ - public SystemPropertySource(int ordinal){ - this(null, ordinal); - } - - /** - * Creates a new instance. - * @param prefix the prefix to be used, or null. - * @param ordinal the ordinal to be used. - */ - public SystemPropertySource(String prefix, int ordinal){ - this.prefix = prefix; - setOrdinal(ordinal); - } - - /** - * Creates a new instance. - * @param prefix the prefix to be used, or null. - */ - public SystemPropertySource(String prefix){ - this.prefix = prefix; - } - - - private Map<String, PropertyValue> loadProperties() { - Properties sysProps = System.getProperties(); - previousHash = System.getProperties().hashCode(); - final String prefix = this.prefix; - Map<String, PropertyValue> entries = new HashMap<>(); - for (Map.Entry<Object,Object> entry : sysProps.entrySet()) { - if(entry.getKey() instanceof String && entry.getValue() instanceof String) { - if (prefix == null) { - entries.put((String) entry.getKey(), - PropertyValue.of((String) entry.getKey(), - (String) entry.getValue(), - getName())); - } else { - entries.put(prefix + entry.getKey(), - PropertyValue.of(prefix + entry.getKey(), - (String) entry.getValue(), - getName())); - } - } - } - return entries; - } - - @Override - public String getName() { - if(disabled){ - return super.getName() + "(disabled)"; - } - return super.getName(); - } - - @Override - public PropertyValue get(String key) { - if(disabled){ - return null; - } - String prefix = this.prefix; - if(prefix==null) { - return PropertyValue.of(key, System.getProperty(key), getName()); - } - return PropertyValue.of(key, System.getProperty(key.substring(prefix.length())), getName()); - } - - @Override - public Map<String, PropertyValue> getProperties() { - if(disabled){ - return Collections.emptyMap(); - } - // only need to reload and fill our map if something has changed - // synchronization was removed, Instance was marked as volatile. In the worst case it - // is reloaded twice, but the values will be the same. - if (previousHash != System.getProperties().hashCode()) { - Map<String, PropertyValue> properties = loadProperties(); - this.cachedProperties = Collections.unmodifiableMap(properties); - } - return this.cachedProperties; - } - - @Override - public boolean isScannable() { - return true; - } - - @Override - protected String toStringValues() { - return super.toStringValues() + - " prefix=" + prefix + '\n' + - " disabled=" + disabled + '\n'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java deleted file mode 100644 index 4101f1e..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -/** - * Test class for testing transitively evaluated property converters. - */ -class A implements AutoCloseable{ - @Override - public void close() throws Exception { - - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java deleted file mode 100644 index 584b923..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -/** - * Test class for testing transitively evaluated property converters. - */ -public class B extends A implements Runnable{ - @Override - public void run() { - - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java deleted file mode 100644 index a986b7b..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; -import org.junit.Assert; -import org.junit.Test; - -import java.util.*; - -public class BasePropertySourceTest { - - @Test - public void testGetOrdinal() { - - PropertySource defaultPropertySource = new BasePropertySource("testWithDefault", 56) { - - @Override - public PropertyValue get(String key) { - return null; - } - - @Override - public Map<String, PropertyValue> getProperties() { - return Collections.emptyMap(); - } - }; - - Assert.assertEquals(56, PropertySourceComparator.getOrdinal(defaultPropertySource)); - Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal()); - - // propertySource with invalid ordinal - Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal()); - } - - @Test - public void testGet() { - Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal()); - } - - private static class OverriddenOrdinalPropertySource extends BasePropertySource { - - private OverriddenOrdinalPropertySource() { - super("overriddenOrdinal", 250); - } - - @Override - public Map<String, PropertyValue> getProperties() { - Map<String,PropertyValue> props = new HashMap<>(1); - props.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "1000", getName())); - return props; - } - } - - private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource { - - private OverriddenInvalidOrdinalPropertySource() { - super("overriddenInvalidOrdinal", 1); - } - - @Override - public Map<String, PropertyValue> getProperties() { - Map<String,PropertyValue> props = new HashMap<>(1); - props.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "invalid", getName())); - return props; - } - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java deleted file mode 100644 index cab05d2..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class BuildablePropertySourceProviderTest { - - @Test - public void getPropertySources() throws Exception { - BuildablePropertySource ps = BuildablePropertySource.builder() - .withName("test1").build(); - BuildablePropertySourceProvider prov = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps).build(); - assertNotNull(prov); - assertEquals(prov.getPropertySources().iterator().next(), ps); - } - - @Test - public void equals() throws Exception { - BuildablePropertySource ps = BuildablePropertySource.builder() - .withName("test1").build(); - BuildablePropertySourceProvider prov1 = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps).build(); - BuildablePropertySourceProvider prov2 = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps).build(); - assertEquals(prov1, prov2); - BuildablePropertySource ps2 = BuildablePropertySource.builder() - .withName("test12").build(); - prov2 = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps2).build(); - assertNotEquals(prov1, prov2); - } - - @Test - public void testHashCode() throws Exception { - BuildablePropertySource ps = BuildablePropertySource.builder() - .withName("test1").build(); - BuildablePropertySourceProvider prov1 = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps).build(); - BuildablePropertySourceProvider prov2 = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps).build(); - assertEquals(prov1.hashCode(), prov2.hashCode()); - BuildablePropertySource ps2 = BuildablePropertySource.builder() - .withName("test12").build(); - prov2 = BuildablePropertySourceProvider.builder() - .withPropertySourcs(ps2).build(); - assertNotEquals(prov1.hashCode(), prov2.hashCode()); - } - - - @Test - public void builder() throws Exception { - assertNotNull(BuildablePropertySource.builder()); - assertNotEquals(BuildablePropertySource.builder(), BuildablePropertySource.builder()); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java deleted file mode 100644 index 721216d..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class BuildablePropertySourceTest { - @Test - public void getOrdinal() throws Exception { - BuildablePropertySource ps1 = BuildablePropertySource.builder() - .withOrdinal(55).build(); - assertEquals(55, ps1.getOrdinal()); - } - - @Test - public void getName() throws Exception { - BuildablePropertySource ps1 = BuildablePropertySource.builder() - .withName("test1").build(); - assertEquals("test1", ps1.getName()); - ps1 = BuildablePropertySource.builder().build(); - assertNotNull(ps1.getName()); - } - - @Test - public void get() throws Exception { - BuildablePropertySource ps1 = BuildablePropertySource.builder() - .withSimpleProperty("a", "b").build(); - assertEquals("b", ps1.get("a").getValue()); - } - - @Test - public void getProperties() throws Exception { - BuildablePropertySource ps1 = BuildablePropertySource.builder() - .withSimpleProperty("a", "b").build(); - assertNotNull(ps1.getProperties()); - assertEquals(1, ps1.getProperties().size()); - assertEquals("b", ps1.getProperties().get("a").getValue()); - } - - @Test - public void equals() throws Exception { - BuildablePropertySource ps1 = BuildablePropertySource.builder() - .withName("test1").build(); - BuildablePropertySource ps2 = BuildablePropertySource.builder() - .withName("test1").build(); - assertEquals(ps1, ps2); - ps2 = BuildablePropertySource.builder() - .withName("test2").build(); - assertNotEquals(ps1, ps2); - } - - @Test - public void testHashCode() throws Exception { - BuildablePropertySource ps1 = BuildablePropertySource.builder() - .withName("test1").build(); - BuildablePropertySource ps2 = BuildablePropertySource.builder() - .withName("test1").build(); - assertEquals(ps1.hashCode(), ps2.hashCode()); - ps2 = BuildablePropertySource.builder() - .withName("test2").build(); - assertNotEquals(ps1.hashCode(), ps2.hashCode()); - } - - @Test - public void builder() throws Exception { - assertNotNull(BuildablePropertySource.builder()); - assertNotEquals(BuildablePropertySource.builder(), BuildablePropertySource.builder()); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java deleted file mode 100644 index da581e6..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import java.io.IOException; -import java.nio.CharBuffer; - -/** - * Test class for testing transitively evaluated property converters. - */ -public class C extends B implements Readable{ - - private final String inValue; - - public C(String inValue){ - this.inValue = inValue; - } - - @Override - public int read(CharBuffer cb) throws IOException { - return 0; - } - - /** - * Returns the input value, set on creation. Used for test assertion. - * @return the in value. - */ - public String getInValue() { - return inValue; - } - - @Override - public String toString() { - return "C{" + - "inValue='" + inValue + '\'' + - '}'; - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java deleted file mode 100644 index e08bf80..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.core.propertysource.CLIPropertySource; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests for PropertySource for reading main arguments as configuration. - */ -public class CLIPropertySourceTest { - - @Test - public void setCLIProps() throws Exception { - System.clearProperty("main.args"); - CLIPropertySource ps = new CLIPropertySource(); - assertTrue(ps.getProperties().isEmpty()); - CLIPropertySource.initMainArgs("-a", "b"); - assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("a").getValue(), "b"); - CLIPropertySource.initMainArgs("--c"); - assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("c").getValue(), "c"); - CLIPropertySource.initMainArgs("sss"); - assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("sss").getValue(), "sss"); - CLIPropertySource.initMainArgs("-a", "b", "--c", "sss", "--val=vvv"); - assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("a").getValue(), "b"); - assertEquals(ps.getProperties().get("c").getValue(), "c"); - assertEquals(ps.getProperties().get("sss").getValue(), "sss"); - // getProperties() throws Exception { - System.setProperty("main.args", "-a b\t--c sss "); - ps = new CLIPropertySource(); - assertFalse(ps.getProperties().isEmpty()); - System.clearProperty("main.args"); - assertEquals(ps.getProperties().get("a").getValue(), "b"); - assertEquals(ps.getProperties().get("c").getValue(), "c"); - assertEquals(ps.getProperties().get("sss").getValue(), "sss"); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java deleted file mode 100644 index dce8121..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - -/** - * Created by Anatole on 13.06.2015. - */ -public class CTestConverter implements PropertyConverter<C>{ - @Override - public C convert(String value, ConversionContext context) { - return new C(value); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java deleted file mode 100644 index 5e748ce..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - - -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.*; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Simple tests for {@link DefaultConfigurationContext} by atsticks on 16.08.16. - */ -public class DefaultConfigurationContextTest { - - @Test - public void addPropertySources() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - PropertySource def = new TestPropertyDefaultSource(); - assertFalse(ctx.getPropertySources().contains(def)); - ctx.addPropertySources(def); - assertTrue(ctx.getPropertySources().contains(def)); - } - - @Test - public void testToString() throws Exception { - String toString = ConfigurationProvider.getConfiguration().getContext().toString(); - System.out.println(toString); - } - - @Test - public void getPropertySources() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - assertNotNull(ctx.getPropertySources()); - assertEquals(ctx.getPropertySources().size(), 0); - ctx = new DefaultConfigurationContextBuilder().addDefaultPropertySources().build(); - assertNotNull(ctx.getPropertySources()); - assertEquals(4, ctx.getPropertySources().size()); - } - - @Test - public void getPropertySource() throws Exception { - PropertySource ps = new TestPropertyDefaultSource(); - ConfigurationContext ctx = new DefaultConfigurationContextBuilder() - .addPropertySources(ps).build(); - assertNotNull(ctx.getPropertySources()); - assertEquals(ctx.getPropertySources().size(), 1); - assertNotNull(((DefaultConfigurationContext)ctx).getPropertySource(ps.getName())); - assertEquals(ps.getName(), ((DefaultConfigurationContext)ctx).getPropertySource(ps.getName()).getName()); - assertNull(((DefaultConfigurationContext)ctx).getPropertySource("huhu")); - - } - - @Test - public void testHashCode() throws Exception { - PropertySource ps = new TestPropertyDefaultSource(); - ConfigurationContext ctx1 = new DefaultConfigurationContextBuilder() - .addPropertySources(ps).build(); - ConfigurationContext ctx2 = new DefaultConfigurationContextBuilder() - .addPropertySources(ps).build(); - assertEquals(ctx1.hashCode(), ctx2.hashCode()); - ctx2 = new DefaultConfigurationContextBuilder() - .build(); - assertNotEquals(ctx1.hashCode(), ctx2.hashCode()); - - } - - @Test - public void addPropertyConverter() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - PropertyConverter testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return ""; - } - }; - assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)); - ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)); - } - - @Test - public void getPropertyConverters() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - PropertyConverter testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return ""; - } - }; - ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter); - assertNotNull(ctx.getPropertyConverters()); - assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(String.class))); - assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(String.class)).contains(testConverter)); - testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return Integer.valueOf(5); - } - }; - ctx.addPropertyConverter(TypeLiteral.of(Integer.class), testConverter); - assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(Integer.class))); - assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(Integer.class)).contains(testConverter)); - } - - @Test - public void getPropertyConverters1() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - PropertyConverter testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return ""; - } - }; - assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class))); - assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),0); - ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter); - assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class))); - assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),1); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)); - - } - - @Test - public void getPropertyFilters() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - PropertyFilter testFilter = new PropertyFilter() { - - @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - return value; - } - }; - assertNotNull(ctx.getPropertyFilters()); - assertFalse(ctx.getPropertyFilters().contains(testFilter)); - ctx = ctx.toBuilder().addPropertyFilters(testFilter).build(); - assertTrue(ctx.getPropertyFilters().contains(testFilter)); - } - - @Test - public void getPropertyValueCombinationPolicy() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - assertNotNull(ctx.getPropertyValueCombinationPolicy()); - assertEquals(ctx.getPropertyValueCombinationPolicy(), - PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR); - } - - @Test - public void toBuilder() throws Exception { - assertNotNull(new DefaultConfigurationContextBuilder().build().toBuilder()); - } - - @Test - public void testRoundTrip() throws Exception { - ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build(); - assertEquals(ctx.toBuilder().build(), ctx); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java deleted file mode 100644 index c846e81..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tamaya.spisupport; - -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; -import org.junit.Test; - -import java.math.RoundingMode; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * Test class testing the {@link EnumConverter} class. - */ -public class EnumConverterTest { - - private final EnumConverter testConverter = new EnumConverter(RoundingMode.class); - - private final ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder("someKey", TypeLiteral.of(Enum.class)).build(); - - @Test - public void testConvert() { - assertEquals(testConverter.convert(RoundingMode.CEILING.toString(), - DUMMY_CONTEXT), RoundingMode.CEILING); - } - - @Test - public void testConvert_LowerCase() { - assertEquals(testConverter.convert("ceiling", DUMMY_CONTEXT), RoundingMode.CEILING); - } - - @Test - public void testConvert_MixedCase() { - assertEquals(testConverter.convert("CeiLinG", DUMMY_CONTEXT), RoundingMode.CEILING); - } - - @Test - public void testConvert_OtherValue() { - assertNull(testConverter.convert("fooBars", DUMMY_CONTEXT)); - } -} \ No newline at end of file
