You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2014/12/12 14:16:09 UTC

[2/2] incubator-tamaya git commit: TAMAYA-20: Fixed test source path.

TAMAYA-20: Fixed test source path.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/8b4ecc98
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/8b4ecc98
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/8b4ecc98

Branch: refs/heads/master
Commit: 8b4ecc988b93275a03d066961277a25f82850f50
Parents: 5ee59ae
Author: anatole <an...@apache.org>
Authored: Fri Dec 12 14:16:02 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Fri Dec 12 14:16:02 2014 +0100

----------------------------------------------------------------------
 .../tamaya/TestConfigServiceSingletonSpi.java   | 88 ++++++++++++++++++
 .../tamaya/TestEnvironmentManagerSingleton.java | 56 +++++++++++
 .../TestPropertyAdaptersSingletonSpi.java       | 97 ++++++++++++++++++++
 3 files changed, 241 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b4ecc98/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
new file mode 100644
index 0000000..e20707e
--- /dev/null
+++ b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
@@ -0,0 +1,88 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
+
+import java.beans.PropertyChangeListener;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by Anatole on 09.09.2014.
+ */
+public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingletonSpi{
+
+
+    private Map<String, Configuration> configs = new ConcurrentHashMap<>();
+
+    public TestConfigServiceSingletonSpi(){
+        Map<String,String> config = new HashMap<>();
+        config.put("a.b.c.key1", "value current a.b.c.key1");
+        config.put("a.b.c.key2", "value current a.b.c.key2");
+        config.put("a.b.key3", "value current a.b.key3");
+        config.put("a.b.key4", "value current a.b.key4");
+        config.put("a.key5", "value current a.key5");
+        config.put("a.key6", "value current a.key6");
+        config.put("int1", "123456");
+        config.put("int2", "111222");
+        config.put("booleanT", "true");
+        config.put("double1", "1234.5678");
+        config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
+        config.put("testProperty", "value current testProperty");
+        config.put("runtimeVersion", "${java.version}");
+        // configs.put("test", new MapConfiguration(MetaInfoBuilder.current().setName("test").build(), config));
+    }
+
+    @Override
+    public boolean isConfigurationDefined(String name){
+        return configs.containsKey(name);
+    }
+
+    @Override
+    public <T> T getConfiguration(String name, Class<T> type){
+        if(type.equals(Configuration.class)) {
+            Configuration config = configs.get(name);
+            return (T)Optional.ofNullable(config).orElseThrow(() -> new ConfigException("No such config: " + name));
+        }
+        throw new ConfigException("Not such config name="+name+", type="+ type.getName());
+    }
+
+    @Override
+    public <T> T getConfiguration(Class<T> type) {
+        // TODO
+        throw new UnsupportedOperationException("Not yet implemented");
+    }
+
+    @Override
+    public void configure(Object instance) {
+        // TODO
+        throw new UnsupportedOperationException("Not yet implemented");
+    }
+
+    @Override
+    public String evaluateValue(Configuration config, String expression){
+        // TODO improve this ugly implementation...
+        for(Map.Entry<String, String> en: config.toMap().entrySet()){
+            expression = expression.replaceAll("\\$\\{"+en.getKey()+"\\}", en.getValue());
+        }
+        return expression;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b4ecc98/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java b/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
new file mode 100644
index 0000000..6f4ee6d
--- /dev/null
+++ b/api/src/test/java/org/apache/tamaya/TestEnvironmentManagerSingleton.java
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.EnvironmentManagerSingletonSpi;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Created by Anatole on 12.09.2014.
+ */
+public class TestEnvironmentManagerSingleton implements EnvironmentManagerSingletonSpi{
+    @Override
+    public Environment getEnvironment(){
+        return null;
+    }
+
+    @Override
+    public Environment getRootEnvironment(){
+        return null;
+    }
+
+    @Override
+    public Optional<Environment> getEnvironment(String environmentType, String contextId) {
+        return null;
+    }
+
+    @Override
+    public Set<String> getEnvironmentContexts(String environmentType) {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public List<String> getEnvironmentTypeOrder() {
+        return Collections.emptyList();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b4ecc98/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
new file mode 100644
index 0000000..2d3cfbc
--- /dev/null
+++ b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import org.apache.tamaya.annotation.WithPropertyAdapter;
+import org.apache.tamaya.spi.PropertyAdaptersSingletonSpi;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.Currency;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Test implementation current {@link PropertyAdaptersSingletonSpi}, which provides adapters
+ * for some basic types.
+ */
+public final class TestPropertyAdaptersSingletonSpi implements PropertyAdaptersSingletonSpi{
+
+    private Map<Class, PropertyAdapter<?>> adapters = new ConcurrentHashMap<>();
+
+    private TestPropertyAdaptersSingletonSpi(){
+        register(char.class, (s) -> s.charAt(0));
+        register(int.class, Integer::parseInt);
+        register(byte.class, Byte::parseByte);
+        register(short.class, Short::parseShort);
+        register(boolean.class, Boolean::parseBoolean);
+        register(float.class, Float::parseFloat);
+        register(double.class, Double::parseDouble);
+
+        register(Character.class, (s) -> s.charAt(0));
+        register(Integer.class, Integer::parseInt);
+        register(Byte.class, Byte::parseByte);
+        register(Short.class, Short::parseShort);
+        register(Boolean.class, Boolean::parseBoolean);
+        register(Float.class, Float::parseFloat);
+        register(Double.class, Double::parseDouble);
+        register(BigDecimal.class, BigDecimal::new);
+        register(BigInteger.class, BigInteger::new);
+
+        register(Currency.class, Currency::getInstance);
+
+        register(LocalDate.class, LocalDate::parse);
+        register(LocalTime.class, LocalTime::parse);
+        register(LocalDateTime.class, LocalDateTime::parse);
+        register(ZoneId.class, ZoneId::of);
+    }
+
+
+    @Override
+    public <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter){
+        Objects.requireNonNull(targetType);
+        Objects.requireNonNull(adapter);
+        return (PropertyAdapter<T>)adapters.put(targetType, adapter);
+    }
+
+    @Override
+    public <T> PropertyAdapter<T> getAdapter(Class<T> targetType, WithPropertyAdapter annotation){
+        if(annotation!=null){
+            Class<?> adapterType = annotation.value();
+            if(!adapterType.equals(PropertyAdapter.class)){
+                try{
+                    return (PropertyAdapter<T>)adapterType.newInstance();
+                }
+                catch(Exception e){
+                    throw new ConfigException("Failed to load PropertyAdapter: " + adapterType, e);
+                }
+            }
+        }
+        return (PropertyAdapter<T>) adapters.get(targetType);
+    }
+
+    @Override
+    public boolean isTargetTypeSupported(Class<?> targetType){
+        return adapters.containsKey(targetType);
+    }
+}