tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [03/10] incubator-tamaya git commit: Simplified events module, adapted documentation as well. Removed model dependency from events, since events is the more general module here.
Date Fri, 18 Dec 2015 01:45:31 GMT
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
new file mode 100644
index 0000000..759d429
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
@@ -0,0 +1,57 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * PropertySource implementation that accesses properties that are stored on ThreadLocal
level, e.g. good to use for
+ * testing..
+ */
+public class ChangeableThreadLocalPropertySource extends BasePropertySource{
+
+    private static ThreadLocal<Map<String,String>> STORED_ENTRIES = new ThreadLocal<Map<String,String>>(){
+        protected Map<String,String> initialValue(){
+            return new HashMap<>();
+        }
+    };
+
+    @Override
+    public String getName() {
+        return getClass().getSimpleName();
+    }
+
+    @Override
+    public Map<String, String> getProperties() {
+        return null;
+    }
+
+    public static String put(String key, String value){
+        return STORED_ENTRIES.get().put(key,value);
+    }
+
+    public static void putAll(Map<String,String> properties){
+        STORED_ENTRIES.get().putAll(properties);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
b/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
index 45c15d2..b56407c 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
@@ -20,6 +20,8 @@ package org.apache.tamaya.events;
 
 import org.junit.Test;
 
+import java.util.UUID;
+
 import static org.junit.Assert.*;
 
 /**
@@ -27,37 +29,38 @@ import static org.junit.Assert.*;
  */
 public class ConfigEventManagerTest {
 
-    private String testAddListenerValue;
+    private Object testAddListenerValue;
 
     @Test
     public void testAddRemoveListener() throws Exception {
-        ConfigEventListener<String> testListener = new ConfigEventListener<String>()
{
+        ConfigEventListener testListener = new ConfigEventListener() {
             @Override
-            public void onConfigEvent(String event) {
-                testAddListenerValue = event;
+            public void onConfigEvent(ConfigEvent<?> event) {
+                testAddListenerValue = event.getResource();
             }
         };
         ConfigEventManager.addListener(testListener);
-        ConfigEventManager.fireEvent("Event1", String.class);
+        ConfigEventManager.fireEvent(new SimpleEvent("Event1"));
         assertEquals(testAddListenerValue, "Event1");
         ConfigEventManager.removeListener(testListener);
-        ConfigEventManager.fireEvent("Event2", String.class);
+        ConfigEventManager.fireEvent(new SimpleEvent("Event2"));
         assertEquals(testAddListenerValue, "Event1");
     }
 
     @Test
     public void testFireEvent() throws Exception {
-        ConfigEventListener<String> testListener = new ConfigEventListener<String>()
{
+        ConfigEventListener testListener = new ConfigEventListener() {
             @Override
-            public void onConfigEvent(String event) {
-                testAddListenerValue = event;
+            public void onConfigEvent(ConfigEvent<?> event) {
+                testAddListenerValue = event.getResource();
             }
         };
         ConfigEventManager.addListener(testListener);
-        ConfigEventManager.fireEvent("Event1");
+        ConfigEventManager.fireEvent(new SimpleEvent("Event1"));
         assertEquals(testAddListenerValue, "Event1");
         ConfigEventManager.removeListener(testListener);
-        ConfigEventManager.fireEvent("Event2");
+        ConfigEventManager.fireEvent(new SimpleEvent("Event2"));
         assertEquals(testAddListenerValue, "Event1");
     }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java b/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
new file mode 100644
index 0000000..2245ec0
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
@@ -0,0 +1,13 @@
+package org.apache.tamaya.events;
+
+import org.apache.tamaya.events.spi.BaseConfigEvent;
+
+import java.util.UUID;
+
+public class SimpleEvent extends BaseConfigEvent<String> {
+
+    public SimpleEvent(String paylod) {
+        super(paylod, String.class);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
index 0a639ab..95269e2 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
@@ -20,6 +20,8 @@ package org.apache.tamaya.events.delta;
 
 import org.apache.tamaya.Configuration;
 import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.events.ConfigurationChange;
+import org.apache.tamaya.events.ConfigurationChangeBuilder;
 import org.junit.Test;
 
 import java.util.Map;
@@ -27,7 +29,7 @@ import java.util.Map;
 import static org.junit.Assert.*;
 
 /**
- * Test class for {@link org.apache.tamaya.events.delta.ConfigurationChange}.
+ * Test class for {@link ConfigurationChange}.
  */
 public class ConfigurationChangeTest {
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
index 5640b81..ee631ce 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
@@ -21,19 +21,24 @@ package org.apache.tamaya.events.delta;
 import org.apache.tamaya.Configuration;
 import org.apache.tamaya.ConfigurationProvider;
 import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.events.ChangeType;
+import org.apache.tamaya.events.ConfigurationContextChange;
+import org.apache.tamaya.events.ConfigurationContextChangeBuilder;
+import org.apache.tamaya.events.PropertySourceChangeBuilder;
 import org.apache.tamaya.spi.PropertySource;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
 
 /**
- * Test class for {@link org.apache.tamaya.events.delta.ConfigurationContextChange}.
+ * Test class for {@link ConfigurationContextChange}.
  */
 public class ConfigurationContextChangeTest {
 
     @Test
     public void testEmptyChangeSet() throws Exception {
-        ConfigurationContextChange change = ConfigurationContextChange.emptyChangeSet();
+        ConfigurationContextChange change = ConfigurationContextChange.emptyChangeSet(
+                ConfigurationProvider.getConfigurationContext());
         assertNotNull(change);
         assertTrue(change.isEmpty());
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
index b3be028..0dcdfba 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
@@ -21,6 +21,9 @@ package org.apache.tamaya.events.delta;
 import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
 import org.apache.tamaya.core.propertysource.SimplePropertySource;
 import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.events.ChangeType;
+import org.apache.tamaya.events.PropertySourceChange;
+import org.apache.tamaya.events.PropertySourceChangeBuilder;
 import org.apache.tamaya.spi.PropertySource;
 import org.junit.Test;
 
@@ -30,7 +33,7 @@ import java.util.Map;
 import static org.junit.Assert.*;
 
 /**
- * Tests for {@link org.apache.tamaya.events.delta.PropertySourceChange} and its builder.
+ * Tests for {@link PropertySourceChange} and its builder.
  */
 public class PropertySourceChangeTest {
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
index 7bac25a..55b49dc 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
@@ -18,7 +18,9 @@
  */
 package org.apache.tamaya.events.internal;
 
+import org.apache.tamaya.events.ConfigEvent;
 import org.apache.tamaya.events.ConfigEventListener;
+import org.apache.tamaya.events.SimpleEvent;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -29,32 +31,31 @@ import static org.junit.Assert.assertEquals;
 public class DefaultConfigEventManagerSpiTest {
 
     private DefaultConfigEventManagerSpi spi = new DefaultConfigEventManagerSpi();
-    private String testAddListenerValue;
+    private Object testAddListenerValue;
 
     @Test
     public void testAddListener() throws Exception {
-        ConfigEventListener<String> testListener = new ConfigEventListener<String>()
{
-
+        ConfigEventListener testListener = new ConfigEventListener() {
             @Override
-            public void onConfigEvent(String event) {
-                testAddListenerValue = event;
+            public void onConfigEvent(ConfigEvent<?> event) {
+                testAddListenerValue = event.getResource();
             }
         };
         spi.addListener(testListener);
-        spi.fireEvent("Event1", String.class);
+        spi.fireEvent(new SimpleEvent("Event1"));
         assertEquals(testAddListenerValue, "Event1");
         spi.removeListener(testListener);
-        spi.fireEvent("Event2", String.class);
+        spi.fireEvent(new SimpleEvent("Event2"));
         assertEquals(testAddListenerValue, "Event1");
 
     }
 
     @Test
     public void testRemoveListener() throws Exception {
-        ConfigEventListener<String> testListener = new ConfigEventListener<String>()
{
+        ConfigEventListener testListener = new ConfigEventListener() {
 
             @Override
-            public void onConfigEvent(String event) {
+            public void onConfigEvent(ConfigEvent<?> event) {
                 testAddListenerValue = event;
             }
         };

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
index 18b6b98..c87369a 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
@@ -89,11 +89,11 @@ public final class ConfigModelManager {
      * @param name the name to use, not null.
      * @return the sections defined, never null.
      */
-    public static <T extends ConfigModel> T getModel(String name, Class<T> validationType)
{
+    public static <T extends ConfigModel> T getModel(String name, Class<T> modelType)
{
         for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class))
{
             for(ConfigModel configModel : model.getConfigModels()) {
-                if(configModel.getName().equals(name) && configModel.getClass().equals(validationType))
{
-                    return validationType.cast(configModel);
+                if(configModel.getName().equals(name) && configModel.getClass().equals(modelType))
{
+                    return modelType.cast(configModel);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
index f1c03cc..44960ed 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
@@ -39,33 +39,41 @@ public final class ConfiguredTypeEventsModelPopulator implements ConfigEventList
      */
     private static final Logger LOG = Logger.getLogger(ConfiguredTypeEventsModelPopulator.class.getName());
 
+    /** System property to be set to deactivate auto documentation of configured classes
published thorugh
+     * ConfiguredType events.
+     */
+    private static final String ENABLE_EVENT_DOC = "org.apache.tamaya.model.autoModelEvents";
+
     @Override
     public void onConfigEvent(ConfiguredType confType) {
-        for (ConfiguredField field : confType.getConfiguredFields()) {
-            Collection<String> keys = field.getConfiguredKeys();
-            for (String key : keys) {
-                ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
-                if (val == null) {
-                    ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
-                            .setType(field.getType().getName())
-                            .setDescription("Injected field: " +
-                                    field.getAnnotatedField().getDeclaringClass().getName()
+ '.' + field.toString() +
-                                    ", \nconfigured with keys: " + keys)
-                            .build());
+        String value = System.getProperty(ENABLE_EVENT_DOC);
+        if(value==null?true:Boolean.parseBoolean(value)) {
+            for (ConfiguredField field : confType.getConfiguredFields()) {
+                Collection<String> keys = field.getConfiguredKeys();
+                for (String key : keys) {
+                    ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
+                    if (val == null) {
+                        ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+                                .setType(field.getType().getName())
+                                .setDescription("Injected field: " +
+                                        field.getAnnotatedField().getDeclaringClass().getName()
+ '.' + field.toString() +
+                                        ", \nconfigured with keys: " + keys)
+                                .build());
+                    }
                 }
             }
-        }
-        for (ConfiguredMethod method : confType.getConfiguredMethods()) {
-            Collection<String> keys = method.getConfiguredKeys();
-            for (String key : keys) {
-                ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
-                if (val == null) {
-                    ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
-                            .setType(method.getParameterTypes()[0].getName())
-                            .setDescription("Injected field: " +
-                                    method.getAnnotatedMethod().getDeclaringClass().getName()
+ '.' + method.toString() +
-                                    ", \nconfigured with keys: " + keys)
-                            .build());
+            for (ConfiguredMethod method : confType.getConfiguredMethods()) {
+                Collection<String> keys = method.getConfiguredKeys();
+                for (String key : keys) {
+                    ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
+                    if (val == null) {
+                        ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+                                .setType(method.getParameterTypes()[0].getName())
+                                .setDescription("Injected field: " +
+                                        method.getAnnotatedMethod().getDeclaringClass().getName()
+ '.' + method.toString() +
+                                        ", \nconfigured with keys: " + keys)
+                                .build());
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
index 946d99b..6baa975 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
@@ -30,7 +30,7 @@ import java.util.List;
  * Model provider that adds model definitions for the items published as
  * {@link org.apache.tamaya.inject.spi.ConfiguredType} events.
  */
-public class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
+class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
     /** The collected models. */
     private static Collection<ConfigModel> configModels = new ArrayList<>();
 


Mime
View raw message