tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [2/2] incubator-tamaya git commit: Fixed bugs.
Date Sat, 28 Feb 2015 22:23:04 GMT
Fixed bugs.


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

Branch: refs/heads/master
Commit: b35b5171844bf9c1aeec108c9365546c8a7d8778
Parents: be94160
Author: anatole <anatole@apache.org>
Authored: Sat Feb 28 23:22:50 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Sat Feb 28 23:22:50 2015 +0100

----------------------------------------------------------------------
 docs/API.adoc                                   | 20 +++---
 docs/Core.adoc                                  |  4 +-
 .../java/org/apache/tamaya/TypeLiteral.java     |  3 +-
 .../internal/PropertyConverterManagerTest.java  |  3 +-
 .../org/apache/tamaya/ConfigExceptionTest.java  | 46 ++++++++++++++
 .../tamaya/ConfigurationProviderTest.java       | 66 ++++++++++++++++++++
 .../tamaya/TestConfigurationProvider.java       |  6 ++
 .../tamaya/spi/ServiceContextManagerTest.java   | 26 +++++++-
 .../internal/DefaultConfigurationProvider.java  |  1 -
 9 files changed, 158 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/docs/API.adoc
----------------------------------------------------------------------
diff --git a/docs/API.adoc b/docs/API.adoc
index 6977d54..0f0d32a 100644
--- a/docs/API.adoc
+++ b/docs/API.adoc
@@ -585,16 +585,16 @@ The +ServiceContext+ hereby defines access methods to obtain components,
whereas
 +ServiceContextManager+ singleton:
 
 [source,java]
-.Accessing the +ServiceContext+
---------------------------------------------
-ServiceContext serviceContext = ServiceContextManager.getServiceContext();
-
-public interface ServiceContext{
-    int ordinal();
-    <T> T getService(Class<T> serviceType);
-    <T> List<T> getServices(Class<T> serviceType);
-}
---------------------------------------------
+                                            .Accessing the +ServiceContext+
+                                            --------------------------------------------
+                                            ServiceContext serviceContext = ServiceContextManager.getServiceContext();
+
+                                            public interface ServiceContext{
+                                                int ordinal();
+                                                <T> T getService(Class<T> serviceType);
+                                                <T> List<T> getServices(Class<T>
serviceType);
+                                            }
+                                            --------------------------------------------
 
 With the +ServiceContext+ a component can be accessed in two different ways:
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/docs/Core.adoc
----------------------------------------------------------------------
diff --git a/docs/Core.adoc b/docs/Core.adoc
index 1134f73..6671ae6 100644
--- a/docs/Core.adoc
+++ b/docs/Core.adoc
@@ -64,7 +64,7 @@ For details about the extension modules available and  their functionality
refer
 
 As said the _Core_ module delivers several default +PropertyConverter+ instances out of the
box:
 
-[width="100%",frame="1",options="header"]
+[width="100%",frame="1",options="header",grid="all"]
 |=======
 |_Target Type_             |_Class Name_              |_Supported Formats_
 |java.math.BigDecimal    |BigDecimalConverter     |1.2345, 0xFF
@@ -142,7 +142,7 @@ NOTE: TODO Discuss the defaults provided by core!
 The Tamaya Core implementation provides a couple of default +PropertySource+ implementations,
which are automatically
 registered. They are all in the package +org.apache.tamaya.core.propertysource+:
 
-[width="100%",frame="1",options="header"]
+[width="100%",frame="1",options="header",grid="all"]
 |=======
 |_Type_                                   |_Class Name_                   |_Ordinal Used_
 |Environment Properties                   |EnvironmentPropertySource      |300

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
index 174bf36..edd69eb 100644
--- a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
+++ b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -52,10 +52,9 @@ public class TypeLiteral<T> implements Serializable {
     /**
      * Creates a new TypeLiteral based on a given type.
      * @param type the type , not null.
-     * @param <R> the literal generic type.
      * @return the corresponding TypeLiteral, never null.
      */
-    public static <R> TypeLiteral<R> of(Type type){
+    public static TypeLiteral<?> of(Type type){
         return new TypeLiteral<>(type);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/java7/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
b/java7/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
index 39327c4..1a34d4b 100644
--- a/java7/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
@@ -43,7 +43,8 @@ public class PropertyConverterManagerTest {
     public void factoryMethodOfIsUsedAsConverter() {
         PropertyConverterManager manager = new PropertyConverterManager();
 
-        List<PropertyConverter<MyType>> converters = manager.getPropertyConverters((TypeLiteral)TypeLiteral.of(MyType.class));
+        List<PropertyConverter<MyType>> converters = manager.getPropertyConverters(
+                (TypeLiteral)TypeLiteral.of(MyType.class));
 
         assertThat(converters, hasSize(1));
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/java8/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java b/java8/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java
new file mode 100644
index 0000000..2a7da00
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests instantiating {@link org.apache.tamaya.ConfigException}.
+ */
+public class ConfigExceptionTest {
+
+    @Test
+    public void testCreationMessage(){
+        ConfigException ex = new ConfigException("test");
+        assertNull(ex.getCause());
+        assertEquals(ex.getMessage(), "test");
+    }
+
+    @Test
+    public void testCreationMessageThrowable(){
+        Exception e = new IllegalStateException("blabla");
+        ConfigException ex = new ConfigException("test", e);
+        assertTrue(ex.getCause() == e);
+        assertEquals("test", ex.getMessage());
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/java8/api/src/test/java/org/apache/tamaya/ConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/ConfigurationProviderTest.java b/java8/api/src/test/java/org/apache/tamaya/ConfigurationProviderTest.java
new file mode 100644
index 0000000..2247f2f
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/ConfigurationProviderTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Simple tests for the }@link ConfigurationProvider} singleton class.
+ */
+public class ConfigurationProviderTest {
+
+    @Test
+    public void testGetConfiguration() throws Exception {
+        Configuration cfg = ConfigurationProvider.getConfiguration();
+        assertNotNull(cfg);
+    }
+
+//    @Test
+//    public void testSetConfigurationContext() throws Exception {
+//        ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
+//        ConfigurationContext ctx = builder.build();
+//        ConfigurationContext prevCtx = ConfigurationProvider.getConfigurationContext();
+//        assertNotNull(prevCtx);
+//        ConfigurationProvider.setConfigurationContext(ctx);
+//        assertTrue(ConfigurationProvider.getConfigurationContext() == ctx);
+//        ConfigurationProvider.setConfigurationContext(prevCtx);
+//        assertTrue(ConfigurationProvider.getConfigurationContext() == prevCtx);
+//
+//    }
+//
+//    @Test
+//    public void testIsConfigurationContextSettable() throws Exception {
+//        assertTrue(ConfigurationProvider.isConfigurationContextSettable());
+//    }
+//
+//    @Test
+//    public void testGetConfigurationContextBuilder() throws Exception {
+//        ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
+//        assertNotNull(builder);
+//        assertTrue(builder.build().getPropertyConverters().isEmpty());
+//        assertTrue(builder.build().getPropertyFilters().isEmpty());
+//        assertTrue(builder.build().getPropertySources().isEmpty());
+//
+//    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
index f2dac28..c84af21 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
@@ -19,6 +19,7 @@
 package org.apache.tamaya;
 
 import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
 import org.apache.tamaya.spi.ConfigurationProviderSpi;
 
 import java.util.HashMap;
@@ -41,4 +42,9 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi
{
     public ConfigurationContext getConfigurationContext() {
         return null;
     }
+
+    @Override
+    public ConfigurationContextBuilder getConfigurationContextBuilder() {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
b/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
index 0309c6c..c16de86 100644
--- a/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
+++ b/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
@@ -27,10 +27,14 @@ import java.io.IOException;
 import java.lang.reflect.Field;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Optional;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 public class ServiceContextManagerTest {
 
     private static URLClassLoader classLoader;
@@ -65,8 +69,28 @@ public class ServiceContextManagerTest {
     public void testGetServiceContext() {
 
         ServiceContext context = ServiceContextManager.getServiceContext();
-        Assert.assertEquals(100, context.ordinal());
+        Assert.assertEquals(1, context.ordinal());
+
+    }
+
+    @Test
+    public void testSetServiceContext(){
+        ServiceContext ctx = new ServiceContext() {
+            @Override
+            public <T> Optional<T> getService(Class<T> serviceType) {
+                return null;
+            }
 
+            @Override
+            public <T> List<T> getServices(Class<T> serviceType) {
+                return Collections.emptyList();
+            }
+        };
+        ServiceContext prevContext = ServiceContextManager.set(ctx);
+        if(prevContext!=null) {
+            ServiceContextManager.set(prevContext);
+            assertTrue(ServiceContextManager.getServiceContext() == prevContext);
+        }
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b35b5171/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
index 859a4c2..faf95b7 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -52,7 +52,6 @@ public class DefaultConfigurationProvider implements ConfigurationProviderSpi
{
     public void setConfigurationContext(ConfigurationContext context){
         Configuration oldConfig = this.config;
         Configuration newConfig = new DefaultConfiguration(context);
-        // TODO think on a SPI or move event part into API...
         this.config = newConfig;
         this.context = context;
     }


Mime
View raw message