TAMAYA-145: Added tests, some bugfixes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/d344e732 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/d344e732 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/d344e732 Branch: refs/heads/master Commit: d344e7323db6ec97f3566fd7b893b47093dae771 Parents: bf8c110 Author: anatole <anat...@apache.org> Authored: Tue Apr 18 11:38:52 2017 +0200 Committer: anatole <anat...@apache.org> Committed: Tue Apr 18 11:38:52 2017 +0200 ---------------------------------------------------------------------- .../apache/tamaya/metamodel/CachedFilter.java | 20 ++- .../org/apache/tamaya/metamodel/HideFilter.java | 20 ++- .../tamaya/metamodel/ImmutableFilter.java | 20 ++- .../org/apache/tamaya/metamodel/MapFilter.java | 20 ++- .../org/apache/tamaya/metamodel/MaskFilter.java | 20 ++- .../apache/tamaya/metamodel/SecuredFilter.java | 20 ++- .../internal/ComponentConfigurator.java | 160 ++++++++++++++++--- .../internal/PropertySourceReader.java | 1 + .../internal/factories/CLIArgumentsFactory.java | 1 - .../internal/resolver/JavaResolver.java | 30 +++- .../tamaya/metamodel/ext/IntegrationTest.java | 60 +++++++ .../tamaya/metamodel/ext/MyConverter.java | 36 +++++ .../apache/tamaya/metamodel/ext/MyFilter.java | 37 +++++ .../tamaya/metamodel/ext/MyPropertySource.java | 37 +++++ .../factories/CLIArgumentsFactoryTest.java | 54 +++++++ .../factories/EnvPropertiesFactoryTest.java | 54 +++++++ .../FilePropertySourceFactoryTest.java | 63 ++++++++ .../ResourcePropertySourceFactoryTest.java | 63 ++++++++ ...sourcePropertySourceProviderFactoryTest.java | 64 ++++++++ .../factories/SysPropertiesFactoryTest.java | 54 +++++++ .../factories/URLPropertySourceFactoryTest.java | 63 ++++++++ .../internal/resolver/JavaResolverTest.java | 71 ++++++++ .../resolver/PropertiesResolverTest.java | 52 ++++++ .../propertyconverter-config-test.xml | 32 ++++ .../propertyfilter-config-test.xml | 30 ++++ .../propertysource-config-test.xml | 31 ++++ server/src/main/resources/META-INF/web.xml | 0 27 files changed, 1068 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java index c07e11d..d2a343c 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java @@ -1,6 +1,22 @@ -package org.apache.tamaya.metamodel;/* - * (C) Copyright 2015-2017 Trivadis AG. All rights reserved. +/* + * 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.metamodel; import org.apache.tamaya.metamodel.spi.ItemFactory; import org.apache.tamaya.spi.FilterContext; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java index 2bd701c..6a1e116 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java @@ -1,6 +1,22 @@ -package org.apache.tamaya.metamodel;/* - * (C) Copyright 2015-2017 Trivadis AG. All rights reserved. +/* + * 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.metamodel; import org.apache.tamaya.metamodel.spi.ItemFactory; import org.apache.tamaya.spi.FilterContext; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java index 90c65f5..13f3d0c 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java @@ -1,6 +1,22 @@ -package org.apache.tamaya.metamodel;/* - * (C) Copyright 2015-2017 Trivadis AG. All rights reserved. +/* + * 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.metamodel; import org.apache.tamaya.metamodel.spi.ItemFactory; import org.apache.tamaya.spi.FilterContext; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java index ab521dd..b721780 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MapFilter.java @@ -1,6 +1,22 @@ -package org.apache.tamaya.metamodel;/* - * (C) Copyright 2015-2017 Trivadis AG. All rights reserved. +/* + * 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.metamodel; import org.apache.tamaya.metamodel.spi.ItemFactory; import org.apache.tamaya.spi.FilterContext; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java index d374dc4..a252f96 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java @@ -1,6 +1,22 @@ -package org.apache.tamaya.metamodel;/* - * (C) Copyright 2015-2017 Trivadis AG. All rights reserved. +/* + * 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.metamodel; import org.apache.tamaya.metamodel.spi.ItemFactory; import org.apache.tamaya.spi.FilterContext; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java index 5878106..57171c3 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java @@ -1,6 +1,22 @@ -package org.apache.tamaya.metamodel;/* - * (C) Copyright 2015-2017 Trivadis AG. All rights reserved. +/* + * 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.metamodel; import org.apache.tamaya.ConfigException; import org.apache.tamaya.metamodel.spi.ItemFactory; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java index 8832d98..6e7ea75 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentConfigurator.java @@ -22,7 +22,9 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.lang.reflect.*; import java.util.*; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -40,25 +42,7 @@ public final class ComponentConfigurator<T> { * @param node the node containing any configuration child nodes, not null. */ public static void configure(Object instance, Node node) { - NodeList entryNodes = node.getChildNodes(); - Map<String,String> params = new HashMap<>(); - for(int c=0;c<node.getAttributes().getLength();c++){ - Node attr = node.getAttributes().item(c); - String key = attr.getNodeName(); - String value = attr.getNodeValue(); - params.put(key, value); - } - for(int c=0;c<entryNodes.getLength();c++) { - Node filterNode = entryNodes.item(c); - if(filterNode.getNodeType()!=Node.ELEMENT_NODE){ - continue; - } - if ("param".equals(filterNode.getNodeName())) { - String key = filterNode.getAttributes().getNamedItem("name").getNodeValue(); - String value = filterNode.getTextContent(); - params.put(key, value); - } - } + Map<String,String> params = extractParameters(node); configure(instance, params); } @@ -70,14 +54,140 @@ public final class ComponentConfigurator<T> { public static void configure(Object instance, Map<String,String> params) { LOG.finest("Configuring instance: " + instance + " with " + params); for(Map.Entry<String,String> en:params.entrySet()){ - if(!params.isEmpty()){ - applyParam(instance, en.getKey(), en.getValue()); + applyParam(instance, en.getKey(), en.getValue()); + } + } + + /** + * Apply parameters to instance using reflection ,only if found, as of now only + * String and basic lang types are supported. + * @param instance the instance to configure. + * @param key the parameter name, not null. + * @param value the value to be set, normally not null. + */ + private static void applyParam(Object instance, String key, String value) { + // apply parameters to instance using reflection ,only if found. + Class type = instance.getClass(); + try { + Method[] methods = type.getMethods(); + String methodName = "set" + toUpperCase(key); + for(Method m:methods){ + if(methodName.equals(m.getName()) && m.getParameterTypes().length==1) { + if (applyParam(instance, key, value, m)) { + return; + } + } } + }catch(Exception e){ + LOG.log(Level.FINE, "Reflection issue configuring instance: " + instance, e); + } + try{ + Field field = type.getDeclaredField(key); + applyParam(instance, key, value, field); + }catch(Exception e){ + LOG.log(Level.FINE, "Reflection issue configuring instance: " + instance, e); } } - private static void applyParam(Object instance, String param, String value) { - // TODO apply parameters to instance using reflection ,only if found. + private static String toUpperCase(String value) { + return value.substring(0,1).toUpperCase() + value.substring(1); + } + + /** + * Apply parameters to instance using reflection ,only if found, as of now only + * String and basic lang types are supported. + * @param instance the instance to configure. + * @param key the parameter name, not null. + * @param value the value to be set, normally not null. + * @param setter the setter method, not null. + */ + private static boolean applyParam(Object instance, String key, String value, Method setter) { + if(!Modifier.isPublic(setter.getModifiers())){ + LOG.fine("Setting method as accessible: " + instance.getClass().getSimpleName() + '#' + setter.getName()); + setter.setAccessible(true); + } + try { + Class<?> targetType = setter.getParameterTypes()[0]; + setter.invoke(instance, convert(value, targetType)); + return true; + } catch (Exception e) { + LOG.log(Level.WARNING, "Could not apply parameter (SETTER) '" + key + "' to " + instance, e); + return false; + } + } + + /** + * Apply parameters to instance using reflection ,only if found, as of now only + * String and basic lang types are supported. + * @param instance the instance to configure. + * @param key the parameter name, not null. + * @param value the value to be set, normally not null. + * @param field the field method, not null. + */ + private static void applyParam(Object instance, String key, String value, Field field) { + if(Modifier.isFinal(field.getModifiers())){ + LOG.finest("Ignoring final field: " + instance.getClass().getSimpleName() + '#' + field.getName()); + return; + } + if(!Modifier.isPublic(field.getModifiers())){ + LOG.finest("Setting field as accessible: " + instance.getClass().getSimpleName() + '#' + field.getName()); + field.setAccessible(true); + } + try { + Class<?> targetType = field.getType(); + field.set(instance, convert(value, targetType)); + } catch (Exception e) { + LOG.log(Level.WARNING, "Could not apply parameter (FIELD) '" + key + "' to " + instance, e); + } + } + + private static Object convert(String value, Class<?> targetType) { + try { + switch (targetType.getSimpleName()) { + case "String": + case "Object": + return value; + case "boolean": + case "Boolean": + return Boolean.valueOf(value); + case "byte": + case "Byte": + return Byte.valueOf(value); + case "char": + case "Character": + if (value.isEmpty()) { + return null; + } + return Character.valueOf(value.charAt(0)); + case "short": + case "Short": + return Short.valueOf(value); + case "int": + case "Integer": + return Integer.valueOf(value); + case "long": + case "Long": + return Long.valueOf(value); + case "float": + case "Float": + return Float.valueOf(value); + case "double": + case "Double": + case "Number": + return Float.valueOf(value); + default: + Constructor c = targetType.getConstructor(String.class); + if (!Modifier.isPublic(c.getModifiers())) { + LOG.fine("Setting constructor as accessible: " + targetType.getSimpleName() + "#<constructor>(String)"); + c.setAccessible(true); + } + return c.newInstance(value); + } + }catch(Exception e){ + LOG.log(Level.WARNING, + "Failed to convert value '"+value+"' to required target type: " + targetType.getName(), e); + return null; + } } public static Map<String, String> extractParameters(Node node) { @@ -92,8 +202,8 @@ public final class ComponentConfigurator<T> { NodeList entryNodes = node.getChildNodes(); for(int c=0;c<entryNodes.getLength();c++) { Node filterNode = entryNodes.item(c); - if ("param".equals(filterNode.getNodeName())) { - String key = filterNode.getAttributes().getNamedItem("name").getNodeValue(); + if(filterNode.getNodeType()==Node.ELEMENT_NODE) { + String key = filterNode.getNodeName(); String value = filterNode.getTextContent(); params.put(key, value); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java index a465146..0fdac29 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/PropertySourceReader.java @@ -80,6 +80,7 @@ public class PropertySourceReader implements MetaConfigurationReader{ ps = decoratePropertySource(ps, node, params); LOG.finer("Adding configured property source: " + ps.getName()); contextBuilder.addPropertySources(ps); + continue; } } } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java index ae4bf24..c5af56c 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactory.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.tamaya.metamodel.internal.factories; import org.apache.tamaya.metamodel.spi.ItemFactory; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java ---------------------------------------------------------------------- diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java index 6ad83e1..22d8618 100644 --- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java +++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolver.java @@ -21,6 +21,7 @@ package org.apache.tamaya.metamodel.internal.resolver; import org.apache.tamaya.metamodel.MetaContext; import org.apache.tamaya.metamodel.spi.SimpleResolver; +import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Objects; @@ -59,16 +60,31 @@ public final class JavaResolver implements SimpleResolver{ return null; } - private String evaluate(String className, String methodName) throws Exception{ + private String evaluate(String className, String memberName) throws Exception{ Objects.requireNonNull(className); - Objects.requireNonNull(methodName); + Objects.requireNonNull(memberName); Class clazz = Class.forName(className); - Method method = clazz.getMethod(methodName); - if(Modifier.isStatic(method.getModifiers())){ - if(!method.isAccessible()){ - method.setAccessible(true); + try { + Method method = clazz.getDeclaredMethod(memberName); + if (Modifier.isStatic(method.getModifiers())) { + if (!method.isAccessible()) { + method.setAccessible(true); + } + return (String) method.invoke(null); } - return (String)method.invoke(null); + }catch(Exception e){ + // ignore + } + try { + Field field = clazz.getDeclaredField(memberName); + if (Modifier.isStatic(field.getModifiers())) { + if (!field.isAccessible()) { + field.setAccessible(true); + } + return (String) field.get(null); + } + }catch(Exception e){ + // ignore } return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java index b461603..fe46d81 100644 --- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/IntegrationTest.java @@ -26,6 +26,8 @@ import org.apache.tamaya.metamodel.MapFilter; import org.apache.tamaya.metamodel.MetaConfiguration; import org.apache.tamaya.metamodel.MetaContext; import org.apache.tamaya.spi.PropertyConverter; +import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertySource; import org.junit.Test; import java.net.URL; @@ -155,6 +157,64 @@ public class IntegrationTest { assertTrue(config.getContext().getPropertySources().get(0) instanceof MyPropertySource); } + @Test + public void testPropertyFilterConfig(){ + Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyfilter-config-test.xml")); + assertNotNull(config); + assertTrue(config.getProperties().isEmpty()); + assertTrue(config.getContext().getPropertySources().isEmpty()); + assertTrue(config.getContext().getPropertyConverters().isEmpty()); + assertFalse(config.getContext().getPropertyFilters().isEmpty()); + assertEquals(1, config.getContext().getPropertyFilters().size()); + PropertyFilter filter = config.getContext().getPropertyFilters().get(0); + assertNotNull(filter); + assertTrue(filter instanceof MyFilter); + MyFilter myFilter = (MyFilter)filter; + assertEquals("my-filter-name", myFilter.getName()); + assertEquals("attrValue1", myFilter.getAttrValue()); + assertEquals("elemValue1", myFilter.getElemValue()); + assertEquals("overrideValue2", myFilter.getOverrideValue()); + } + + @Test + public void testPropertySourceConfig(){ + Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertysource-config-test.xml")); + assertNotNull(config); + assertTrue(config.getProperties().isEmpty()); + assertFalse(config.getContext().getPropertySources().isEmpty()); + assertTrue(config.getContext().getPropertyConverters().isEmpty()); + assertTrue(config.getContext().getPropertyFilters().isEmpty()); + assertEquals(1, config.getContext().getPropertySources().size()); + PropertySource ps = config.getContext().getPropertySources().get(0); + assertNotNull(ps); + assertTrue(ps instanceof MyPropertySource); + MyPropertySource mySource = (MyPropertySource)ps; + assertEquals("my-source-name", mySource.getName2()); + assertEquals("attrValue1", mySource.getAttrValue()); + assertEquals("elemValue1", mySource.getElemValue()); + assertEquals("overrideValue2", mySource.getOverrideValue()); + } + + @Test + public void testPropertyConverterConfig(){ + Configuration config = MetaConfiguration.createConfiguration(getConfig("IntegrationTests/propertyconverter-config-test.xml")); + assertNotNull(config); + assertTrue(config.getProperties().isEmpty()); + assertTrue(config.getContext().getPropertySources().isEmpty()); + assertFalse(config.getContext().getPropertyConverters().isEmpty()); + assertTrue(config.getContext().getPropertyFilters().isEmpty()); + assertEquals(1, config.getContext().getPropertyConverters().size()); + PropertyConverter converter = config.getContext().getPropertyConverters().values().iterator() + .next().get(0); + assertNotNull(converter); + assertTrue(converter instanceof MyConverter); + MyConverter myConverter = (MyConverter)converter; + assertEquals("my-converter-name", myConverter.getName()); + assertEquals("attrValue1", myConverter.getAttrValue()); + assertEquals("elemValue1", myConverter.getElemValue()); + assertEquals("overrideValue2", myConverter.getOverrideValue()); + } + private URL getConfig(String resource) { return getClass().getClassLoader().getResource(resource); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java index e9ca5a5..22f642c 100644 --- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyConverter.java @@ -26,8 +26,44 @@ import org.apache.tamaya.spi.PropertyConverter; */ public class MyConverter implements PropertyConverter<String> { + private String name; + private String attrValue; + private String elemValue; + private String overrideValue; + @Override public String convert(String value, ConversionContext context) { return value; } + + public String getAttrValue() { + return attrValue; + } + + public MyConverter setAttrValue(String attrValue) { + this.attrValue = attrValue; + return this; + } + + public String getElemValue() { + return elemValue; + } + + public MyConverter setElemValue(String elemValue) { + this.elemValue = elemValue; + return this; + } + + public String getOverrideValue() { + return overrideValue; + } + + public MyConverter setOverrideValue(String overrideValue) { + this.overrideValue = overrideValue; + return this; + } + + public String getName() { + return name; + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java index e819e2f..e6ab7e6 100644 --- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyFilter.java @@ -26,8 +26,45 @@ import org.apache.tamaya.spi.PropertyValue; * Created by atsticks on 17.04.17. */ public class MyFilter implements PropertyFilter{ + + private String name; + private String attrValue; + private String elemValue; + private String overrideValue; + @Override public PropertyValue filterProperty(PropertyValue value, FilterContext context) { return value; } + + public String getAttrValue() { + return attrValue; + } + + public MyFilter setAttrValue(String attrValue) { + this.attrValue = attrValue; + return this; + } + + public String getElemValue() { + return elemValue; + } + + public MyFilter setElemValue(String elemValue) { + this.elemValue = elemValue; + return this; + } + + public String getOverrideValue() { + return overrideValue; + } + + public MyFilter setOverrideValue(String overrideValue) { + this.overrideValue = overrideValue; + return this; + } + + public String getName() { + return name; + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java index cdb4ae8..55455f9 100644 --- a/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/ext/MyPropertySource.java @@ -28,8 +28,45 @@ import java.util.Map; * Created by atsticks on 17.04.17. */ public class MyPropertySource extends org.apache.tamaya.spisupport.BasePropertySource{ + + private String name2; + private String attrValue; + private String elemValue; + private String overrideValue; + @Override public Map<String, PropertyValue> getProperties() { return Collections.emptyMap(); } + + public String getAttrValue() { + return attrValue; + } + + public MyPropertySource setAttrValue(String attrValue) { + this.attrValue = attrValue; + return this; + } + + public String getElemValue() { + return elemValue; + } + + public MyPropertySource setElemValue(String elemValue) { + this.elemValue = elemValue; + return this; + } + + public String getOverrideValue() { + return overrideValue; + } + + public MyPropertySource setOverrideValue(String overrideValue) { + this.overrideValue = overrideValue; + return this; + } + + public String getName2() { + return name2; + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java new file mode 100644 index 0000000..bf78f0e --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/CLIArgumentsFactoryTest.java @@ -0,0 +1,54 @@ +/* + * 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.metamodel.internal.factories; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spisupport.CLIPropertySource; +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class CLIArgumentsFactoryTest { + + private static CLIArgumentsFactory f = new CLIArgumentsFactory(); + + @Test + public void getName() throws Exception { + assertEquals("CLI", f.getName()); + } + + @Test + public void create() throws Exception { + PropertySource ps = f.create(Collections.EMPTY_MAP); + assertNotNull(ps); + assertTrue(ps instanceof CLIPropertySource); + } + + @Test + public void getType() throws Exception { + assertEquals(PropertySource.class, f.getType()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java new file mode 100644 index 0000000..bfbcf82 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/EnvPropertiesFactoryTest.java @@ -0,0 +1,54 @@ +/* + * 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.metamodel.internal.factories; + +import org.apache.tamaya.spisupport.EnvironmentPropertySource; +import org.apache.tamaya.spi.PropertySource; +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class EnvPropertiesFactoryTest { + + private static EnvPropertiesFactory f = new EnvPropertiesFactory(); + + @Test + public void getName() throws Exception { + assertEquals("env-properties", f.getName()); + } + + @Test + public void create() throws Exception { + PropertySource ps = f.create(Collections.EMPTY_MAP); + assertNotNull(ps); + assertTrue(ps instanceof EnvironmentPropertySource); + } + + @Test + public void getType() throws Exception { + assertEquals(PropertySource.class, f.getType()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.java new file mode 100644 index 0000000..d91d279 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/FilePropertySourceFactoryTest.java @@ -0,0 +1,63 @@ +/* + * 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.metamodel.internal.factories; + +import org.apache.tamaya.spi.PropertySource; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class FilePropertySourceFactoryTest { + + private static FilePropertySourceFactory f = new FilePropertySourceFactory(); + + @Test + public void getName() throws Exception { + assertEquals("file", f.getName()); + } + + @Test + public void create() throws Exception { + Map<String,String> params = new HashMap<>(); + params.put("location", "src/test/resources/GLOBAL.properties"); + PropertySource ps = f.create(params); + assertNotNull(ps); + } + + @Test + public void create_Error() throws Exception { + Map<String,String> params = new HashMap<>(); + PropertySource ps = f.create(Collections.<String, String>emptyMap()); + assertNull("Should throw error for missing location.", ps); + } + + @Test + public void getType() throws Exception { + assertEquals(PropertySource.class, f.getType()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.java new file mode 100644 index 0000000..bd6ee93 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceFactoryTest.java @@ -0,0 +1,63 @@ +/* + * 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.metamodel.internal.factories; + +import org.apache.tamaya.spi.PropertySource; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class ResourcePropertySourceFactoryTest { + + private static ResourcePropertySourceFactory f = new ResourcePropertySourceFactory(); + + @Test + public void getName() throws Exception { + assertEquals("resource", f.getName()); + } + + @Test + public void create() throws Exception { + Map<String,String> params = new HashMap<>(); + params.put("location", "GLOBAL.properties"); + PropertySource ps = f.create(params); + assertNotNull(ps); + } + + @Test + public void create_Error() throws Exception { + Map<String,String> params = new HashMap<>(); + PropertySource ps = f.create(Collections.<String, String>emptyMap()); + assertNull("Should return null for missing location.", ps); + } + + @Test + public void getType() throws Exception { + assertEquals(PropertySource.class, f.getType()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java new file mode 100644 index 0000000..edc0d95 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/ResourcePropertySourceProviderFactoryTest.java @@ -0,0 +1,64 @@ +/* + * 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.metamodel.internal.factories; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertySourceProvider; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class ResourcePropertySourceProviderFactoryTest { + + private static ResourcePropertySourceProviderFactory f = new ResourcePropertySourceProviderFactory(); + + @Test + public void getName() throws Exception { + assertEquals("resources", f.getName()); + } + + @Test + public void create() throws Exception { + Map<String,String> params = new HashMap<>(); + params.put("location", "GLOBAL.properties"); + PropertySourceProvider prov = f.create(params); + assertNotNull(prov); + } + + @Test + public void create_Error() throws Exception { + Map<String,String> params = new HashMap<>(); + PropertySourceProvider prov = f.create(Collections.<String, String>emptyMap()); + assertNull("Should return null for missing location.", prov); + } + + @Test + public void getType() throws Exception { + assertEquals(PropertySourceProvider.class, f.getType()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java new file mode 100644 index 0000000..3fa1d22 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/SysPropertiesFactoryTest.java @@ -0,0 +1,54 @@ +/* + * 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.metamodel.internal.factories; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spisupport.SystemPropertySource; +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class SysPropertiesFactoryTest { + + private static SysPropertiesFactory f = new SysPropertiesFactory(); + + @Test + public void getName() throws Exception { + assertEquals("sys-properties", f.getName()); + } + + @Test + public void create() throws Exception { + PropertySource ps = f.create(Collections.EMPTY_MAP); + assertNotNull(ps); + assertTrue(ps instanceof SystemPropertySource); + } + + @Test + public void getType() throws Exception { + assertEquals(PropertySource.class, f.getType()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.java new file mode 100644 index 0000000..f316417 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/factories/URLPropertySourceFactoryTest.java @@ -0,0 +1,63 @@ +/* + * 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.metamodel.internal.factories; + +import org.apache.tamaya.spi.PropertySource; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class URLPropertySourceFactoryTest { + + private static URLPropertySourceFactory f = new URLPropertySourceFactory(); + + @Test + public void getName() throws Exception { + assertEquals("url", f.getName()); + } + + @Test + public void create() throws Exception { + Map<String,String> params = new HashMap<>(); + params.put("location", "http://apache.org"); + PropertySource ps = f.create(params); + assertNotNull(ps); + } + + @Test + public void create_Error() throws Exception { + Map<String,String> params = new HashMap<>(); + PropertySource ps = f.create(Collections.<String, String>emptyMap()); + assertNull("Should return null for missing location.", ps); + } + + @Test + public void getType() throws Exception { + assertEquals(PropertySource.class, f.getType()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java new file mode 100644 index 0000000..55ca290 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/JavaResolverTest.java @@ -0,0 +1,71 @@ +/* + * 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.metamodel.internal.resolver; + +import org.junit.Test; + +import static org.junit.Assert.*; + + +/** + * Created by atsticks on 18.04.17. + */ +public class JavaResolverTest { + + private static final String TEST = "ResTest"; + private JavaResolver r = new JavaResolver(); + + @Test + public void getResolverId() throws Exception { + assertEquals(r.getResolverId(), "java"); + } + + @Test + public void evaluate() throws Exception { + assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#TEST")); + assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#getTest4")); + assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#getTest6")); + assertEquals(TEST, r.evaluate("org.apache.tamaya.metamodel.internal.resolver.JavaResolverTest#getTest7")); + } + + private String getTest5(){ + return TEST; + } + + String getTest2(){ + return TEST; + } + + public String getTest3(){ + return TEST; + } + + static String getTest4(){ + return TEST; + } + + private static String getTest6(){ + return TEST; + } + + public static String getTest7(){ + return TEST; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java ---------------------------------------------------------------------- diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java new file mode 100644 index 0000000..988c224 --- /dev/null +++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/internal/resolver/PropertiesResolverTest.java @@ -0,0 +1,52 @@ +/* + * 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.metamodel.internal.resolver; + +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.assertEquals; + + +/** + * Created by atsticks on 18.04.17. + */ +public class PropertiesResolverTest { + + private PropertiesResolver r = new PropertiesResolver(); + + @Test + public void getResolverId() throws Exception { + assertEquals(r.getResolverId(), "properties"); + } + + @Test + public void evaluate() throws Exception { + for(Map.Entry<String,String> en: System.getenv().entrySet()){ + assertEquals(en.getValue(), r.evaluate("env:"+en.getKey())); + } + assertEquals("foo", r.evaluate("env:fsdifoisfo?default=foo")); + for(Map.Entry en: System.getProperties().entrySet()){ + assertEquals(en.getValue(), r.evaluate("system:"+en.getKey())); + } + assertEquals("foo", r.evaluate("system:fsdifoisfo?default=foo")); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml ---------------------------------------------------------------------- diff --git a/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml new file mode 100644 index 0000000..485ac8b --- /dev/null +++ b/metamodel/src/test/resources/IntegrationTests/propertyconverter-config-test.xml @@ -0,0 +1,32 @@ +<!-- +// 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 current 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. +// --> +<configuration> + + <property-converters> + <org.apache.tamaya.metamodel.ext.MyConverter targetType="java.lang.String" + attrValue="attrValue1" + overrideValue="overrideValue1"> + <name>my-converter-name</name> + <elemValue>elemValue1</elemValue> + <overrideValue>overrideValue2</overrideValue> + </org.apache.tamaya.metamodel.ext.MyConverter> + </property-converters> + +</configuration> + http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml ---------------------------------------------------------------------- diff --git a/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml new file mode 100644 index 0000000..71c1b3a --- /dev/null +++ b/metamodel/src/test/resources/IntegrationTests/propertyfilter-config-test.xml @@ -0,0 +1,30 @@ +<!-- +// 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 current 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. +// --> +<configuration> + + <property-filters> + <org.apache.tamaya.metamodel.ext.MyFilter attrValue="attrValue1" overrideValue="overrideValue1"> + <name>my-filter-name</name> + <elemValue>elemValue1</elemValue> + <overrideValue>overrideValue2</overrideValue> + </org.apache.tamaya.metamodel.ext.MyFilter> + </property-filters> + +</configuration> + http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml ---------------------------------------------------------------------- diff --git a/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml b/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml new file mode 100644 index 0000000..28710d4 --- /dev/null +++ b/metamodel/src/test/resources/IntegrationTests/propertysource-config-test.xml @@ -0,0 +1,31 @@ +<!-- +// 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 current 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. +// --> +<configuration> + + <property-sources> + <org.apache.tamaya.metamodel.ext.MyPropertySource + attrValue="attrValue1" overrideValue="overrideValue1"> + <name2>my-source-name</name2> + <elemValue>elemValue1</elemValue> + <overrideValue>overrideValue2</overrideValue> + </org.apache.tamaya.metamodel.ext.MyPropertySource> + </property-sources> + +</configuration> + http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/d344e732/server/src/main/resources/META-INF/web.xml ---------------------------------------------------------------------- diff --git a/server/src/main/resources/META-INF/web.xml b/server/src/main/resources/META-INF/web.xml new file mode 100644 index 0000000..e69de29