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 2015/05/21 09:40:29 UTC

[11/15] incubator-tamaya git commit: Adapted to common TypeLiteral changes. TAMAYA-79: Removed file system direct dep.

Adapted to common TypeLiteral changes.
TAMAYA-79: Removed file system direct dep.


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

Branch: refs/heads/master
Commit: 324151d41feb52c7fbbfe57b0e35f28b6b9959f1
Parents: 82b83f2
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:36:26 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:36:26 2015 +0200

----------------------------------------------------------------------
 .../delta/ConfigurationChangeBuilder.java       |  12 ++
 .../events/internal/DefaultEventSupportSpi.java |   4 +-
 .../events/delta/ConfigurationChangeTest.java   | 155 +++++++++++++++++++
 3 files changed, 169 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/324151d4/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
index dc0add8..6274ad9 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
@@ -140,6 +140,17 @@ public final class ConfigurationChangeBuilder {
     }
 
     /**
+     * Applies a single key/value change.
+     * @param key the changed key
+     * @param value the new value.
+     * @return this instance for chining.
+     */
+    public ConfigurationChangeBuilder addChange(String key, String value) {
+        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key), value));
+        return this;
+    }
+
+    /**
      * Get the current values, also considering any changes recorded within this change set.
      *
      * @param key the key current the entry, not null.
@@ -241,4 +252,5 @@ public final class ConfigurationChangeBuilder {
                 ", delta=" + delta + "]";
     }
 
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/324151d4/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
index b92bc49..743de7f 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
@@ -62,7 +62,7 @@ public class DefaultEventSupportSpi implements EventSupportSpi {
 
     @Override
     public <T> void addListener(Listener<T> l) {
-        Type type = TypeLiteral.getTypeParameter(l.getClass(), Listener.class);
+        Type type = TypeLiteral.getGenericInterfaceTypeParameters(l.getClass(), Listener.class)[0];
         List<Listener> listeners = listenerMap.computeIfAbsent(type,
                 (k) -> Collections.synchronizedList(new ArrayList<>()));
         synchronized (listeners) {
@@ -74,7 +74,7 @@ public class DefaultEventSupportSpi implements EventSupportSpi {
 
     @Override
     public <T> void removeListener(Listener<T> l) {
-        Type type = TypeLiteral.getTypeParameter(l.getClass(), Listener.class);
+        Type type = TypeLiteral.getGenericInterfaceTypeParameters(l.getClass(), Listener.class)[0];
         List<Listener> listeners = listenerMap.get(type);
         if (listeners != null) {
             synchronized (listeners) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/324151d4/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
new file mode 100644
index 0000000..58aff64
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.delta;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test class for {@link org.apache.tamaya.events.delta.ConfigurationChange}.
+ */
+public class ConfigurationChangeTest {
+
+    @Test
+    public void testEmptyChangeSet() throws Exception {
+        ConfigurationChange change = ConfigurationChange.emptyChangeSet(ConfigurationProvider.getConfiguration());
+        assertNotNull(change);
+        assertTrue(change.isEmpty());
+    }
+
+    @Test
+    public void testGetConfiguration() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+        assertNotNull(change);
+        assertTrue(change.isEmpty());
+        config.getProperties().entrySet().forEach(
+                en -> {
+                    if (!"[meta]frozenAt".equals(en.getKey())) {
+                        assertEquals("Error for " + en.getKey(), en.getValue(), change.getConfiguration().get(en.getKey()));
+                    }
+                }
+        );
+    }
+
+    @Test
+    public void testGetVersion() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+        assertNotNull(change.getVersion());
+        change = ConfigurationChangeBuilder.of(config).setVersion("version2").build();
+        assertNotNull(change.getVersion());
+        assertEquals("version2", change.getVersion());
+    }
+
+    @Test
+    public void testGetTimestamp() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+        assertTrue((System.currentTimeMillis() - change.getTimestamp()) <= 10L);
+        change = ConfigurationChangeBuilder.of(config).setTimestamp(10L).build();
+        assertEquals(10L, change.getTimestamp());
+    }
+
+    @Test
+    public void testGetEvents() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).remove("key1", "key2").build();
+        assertTrue(change.getEvents().size() == 2);
+        change = ConfigurationChangeBuilder.of(config).addChange("key1Added", "value1Added").build();
+        assertTrue(change.getEvents().size() == 1);
+    }
+
+    @Test
+    public void testGetRemovedSize() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).remove("java.version", "key2").build();
+        assertTrue(change.getRemovedSize() == 2);
+        assertTrue(change.getAddedSize() == 0);
+    }
+
+    @Test
+    public void testGetAddedSize() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+        assertTrue(change.getAddedSize() == 1);
+        assertTrue(change.getRemovedSize() == 0);
+    }
+
+    @Test
+    public void testGetUpdatedSize() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build();
+        assertTrue(change.getUpdatedSize() == 1);
+    }
+
+    @Test
+    public void testIsRemoved() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).remove("java.version").build();
+        assertTrue(change.isRemoved("java.version"));
+    }
+
+    @Test
+    public void testIsAdded() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+        assertTrue(change.isAdded("key1"));
+    }
+
+    @Test
+    public void testIsUpdated() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build();
+        assertTrue(change.isUpdated("java.version"));
+    }
+
+    @Test
+    public void testContainsKey() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+        assertTrue(change.containsKey("key1"));
+        assertFalse(change.containsKey("key2"));
+        change = ConfigurationChangeBuilder.of(config).remove("java.version").build();
+        assertFalse(change.containsKey("java.version"));
+        assertFalse(change.containsKey("key2"));
+    }
+
+    @Test
+    public void testIsEmpty() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
+        assertTrue(change.isEmpty());
+    }
+
+    @Test
+    public void testToString() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
+        change = ConfigurationChangeBuilder.of(config).remove("java.version").build();
+        assertTrue(change.toString().contains("timestamp"));
+        assertTrue(change.toString().contains("version"));
+        assertTrue(change.toString().contains("configuration"));
+        assertFalse(change.toString().contains("key1"));
+        assertFalse(change.toString().contains("key2"));
+    }
+}
\ No newline at end of file