http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/384b09eb/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java b/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java new file mode 100644 index 0000000..759d429 --- /dev/null +++ b/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-extensions/blob/384b09eb/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java b/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java index 45c15d2..b56407c 100644 --- a/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java +++ b/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-extensions/blob/384b09eb/src/test/java/org/apache/tamaya/events/SimpleEvent.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/events/SimpleEvent.java b/src/test/java/org/apache/tamaya/events/SimpleEvent.java new file mode 100644 index 0000000..2245ec0 --- /dev/null +++ b/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-extensions/blob/384b09eb/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java b/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java index 0a639ab..95269e2 100644 --- a/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java +++ b/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-extensions/blob/384b09eb/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java b/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java index 5640b81..ee631ce 100644 --- a/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java +++ b/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-extensions/blob/384b09eb/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java b/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java index b3be028..0dcdfba 100644 --- a/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java +++ b/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-extensions/blob/384b09eb/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java b/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java index 7bac25a..55b49dc 100644 --- a/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java +++ b/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; } };