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-extensions git commit: Added tests for mutable config.
Date Sun, 18 Dec 2016 22:54:36 GMT
Added tests for mutable config.


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

Branch: refs/heads/master
Commit: ad8dfd8aaa9e502dc4d8efd2fd5229bf4f7b9562
Parents: 8b94067
Author: anatole <anatole@apache.org>
Authored: Sun Dec 18 14:12:05 2016 +0100
Committer: anatole <anatole@apache.org>
Committed: Sun Dec 18 23:54:31 2016 +0100

----------------------------------------------------------------------
 .../LazyRefreshablePropertySourceTest.java      | 162 +++++++++++++++++++
 .../src/test/resources/test.properties          |  21 +++
 .../src/test/resources/test2.properties         |  21 +++
 3 files changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ad8dfd8a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySourceTest.java
b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySourceTest.java
new file mode 100644
index 0000000..e67ca59
--- /dev/null
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySourceTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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.mutableconfig.propertysources;
+
+import org.apache.tamaya.functions.Supplier;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spisupport.SimplePropertySource;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link LazyRefreshablePropertySource}. Created by atsticks on 11.11.16.
+ */
+public class LazyRefreshablePropertySourceTest {
+
+    private SimplePropertySource simplePropertySource = new SimplePropertySource(
+        getClass().getClassLoader().getResource("test.properties")
+    );
+    private SimplePropertySource simplePropertySource2 = new SimplePropertySource(
+            getClass().getClassLoader().getResource("test2.properties")
+    );
+    private volatile boolean selectFirst;
+
+    @Test
+    public void of() throws Exception {
+        assertNotNull(LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        return simplePropertySource;
+                    }
+                }
+        ));
+    }
+
+    @Test
+    public void of_WithDefaultOrdinal() throws Exception {
+        assertNotNull(LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        return simplePropertySource;
+                    }
+                }, 100
+        ));
+    }
+
+    @Test
+    public void get() throws Exception {
+        LazyRefreshablePropertySource ps = LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        return simplePropertySource;
+                    }
+                }
+        );
+        assertEquals(ps.get("test1").getValue(), "test1");
+        assertEquals(ps.get("test2").getValue(), "test2");
+        assertNull(ps.get("test3"));
+    }
+
+    @Test
+    public void getName() throws Exception {
+        LazyRefreshablePropertySource ps = LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        return simplePropertySource;
+                    }
+                }
+        );
+        assertEquals(ps.getName(), simplePropertySource.getName());
+    }
+
+    @Test
+    public void getProperties() throws Exception {
+        LazyRefreshablePropertySource ps = LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        return simplePropertySource;
+                    }
+                }
+        );
+        assertEquals(ps.getProperties(), simplePropertySource.getProperties());
+    }
+
+    @Test
+    public void refresh() throws Exception {
+        LazyRefreshablePropertySource ps1 = LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        try {
+                            if (selectFirst) {
+                                return simplePropertySource;
+                            } else {
+                                return simplePropertySource2;
+                            }
+                        }finally{
+                            selectFirst = !selectFirst;
+                        }
+                    }
+                }
+        );
+        // Simulate a refresh with the switching provider created above...
+        ps1.setUpdateInterval(1L);
+        if(ps1.get("test3")!=null){
+            Thread.sleep(5L); //  NOSONAR
+            assertEquals("test4", ps1.get("test4").getValue());
+        }else{
+            Thread.sleep(5L); //  NOSONAR
+            assertNull("test3", ps1.get("test3"));
+        }
+    }
+
+    @Test
+    public void testEqualsAndHashCode() throws Exception {
+        LazyRefreshablePropertySource ps1 = LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        return simplePropertySource;
+                    }
+                }
+        );
+        LazyRefreshablePropertySource ps2 = LazyRefreshablePropertySource.of(
+                new Supplier<PropertySource>() {
+                    @Override
+                    public PropertySource get() {
+                        return simplePropertySource;
+                    }
+                }
+        );
+        assertEquals(ps1, ps2);
+        assertEquals(ps1.hashCode(), ps2.hashCode());
+    }
+
+    @Test
+    public void testToString() throws Exception {
+
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ad8dfd8a/modules/mutable-config/src/test/resources/test.properties
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/resources/test.properties b/modules/mutable-config/src/test/resources/test.properties
new file mode 100644
index 0000000..da1cb4a
--- /dev/null
+++ b/modules/mutable-config/src/test/resources/test.properties
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+test1=test1
+test2=test2
+test4=test4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ad8dfd8a/modules/mutable-config/src/test/resources/test2.properties
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/resources/test2.properties b/modules/mutable-config/src/test/resources/test2.properties
new file mode 100644
index 0000000..d08e4e2
--- /dev/null
+++ b/modules/mutable-config/src/test/resources/test2.properties
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+test1=test1
+test2=test2
+test5=test3
\ No newline at end of file


Mime
View raw message