tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [incubator-tamaya] branch master updated: Added tests and reset method.
Date Sun, 16 Dec 2018 00:35:32 GMT
This is an automated email from the ASF dual-hosted git repository.

anatole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya.git


The following commit(s) were added to refs/heads/master by this push:
     new 87716bc  Added tests and reset method.
87716bc is described below

commit 87716bc3faaca1ca29d2732b939dc9722698ed5f
Author: Anatole Tresch <atsticks@gmail.com>
AuthorDate: Sun Dec 16 01:35:24 2018 +0100

    Added tests and reset method.
---
 .../main/java/org/apache/tamaya/Configuration.java |   5 -
 .../java/org/apache/tamaya/spi/ServiceContext.java |   6 +
 .../java/org/apache/tamaya/ConfigurationTest.java  | 121 +++++++++++++++++++++
 .../tamaya/spi/ServiceContextManagerTest.java      |   5 +
 .../org/apache/tamaya/spi/ServiceContextTest.java  |   5 +
 .../tamaya/spi/TestLowerOrdinalServiceContext.java |   5 +
 .../org/apache/tamaya/spi/TestServiceContext.java  |   5 +
 .../tamaya/core/internal/OSGIServiceContext.java   |   5 +
 .../tamaya/spisupport/DefaultServiceContext.java   |   7 ++
 .../spisupport/services/DefaultServiceContext.java |   5 +
 10 files changed, 164 insertions(+), 5 deletions(-)

diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index 5f91027..61c8c01 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -517,11 +517,6 @@ public interface Configuration {
         }
 
         @Override
-        public ConfigurationSnapshot getSnapshot(String... keys) {
-            return ConfigurationSnapshot.EMPTY;
-        }
-
-        @Override
         public String toString(){
             return "Configuration<EMPTY>";
         }
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
index 1f346b7..61cba9c 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
@@ -189,4 +189,10 @@ public interface ServiceContext extends ClassloaderAware{
      * @return the instances registered or already present.
      */
     <T> List<T> register(Class<T> type, List<T> instances, boolean
force);
+
+    /**
+     * Resets the current service context, removing all loaded services. This implicitly
triggers a new load
+     * of the service context.
+     */
+    void reset();
 }
diff --git a/code/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/code/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
index d950c01..65c85ba 100644
--- a/code/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -20,12 +20,16 @@ package org.apache.tamaya;
 
 import org.apache.tamaya.spi.ConfigurationBuilder;
 import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
 import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.function.UnaryOperator;
 
 import static org.assertj.core.api.Assertions.*;
@@ -38,6 +42,108 @@ import static org.assertj.core.api.Assertions.*;
  */
 public class ConfigurationTest {
 
+    @Before
+    @After
+    public void setup(){
+        ServiceContextManager.getServiceContext().reset();
+    }
+
+    @Test
+    public void test_setCurrent() throws Exception {
+        Configuration saved = Configuration.current();
+        Configuration.setCurrent(Configuration.EMPTY, ServiceContextManager.getDefaultClassLoader());
+        assertThat(Configuration.EMPTY).isEqualTo(Configuration.current());
+        Configuration.setCurrent(saved, ServiceContextManager.getDefaultClassLoader());
+        assertThat(saved).isEqualTo(Configuration.current());
+    }
+
+    @Test
+    public void test_toString() throws Exception {
+        assertThat(Configuration.EMPTY.toString()).isEqualTo("Configuration<EMPTY>");
+    }
+
+    @Test
+    public void test_getProperties() throws Exception {
+        assertThat(Configuration.EMPTY.getProperties()).isEmpty();
+    }
+
+    @Test
+    public void test_get_key() throws Exception {
+        assertThat(Configuration.EMPTY.get("foo")).isNull();
+    }
+
+    @Test
+    public void test_get_key_type() throws Exception {
+        assertThat(Configuration.EMPTY.get("foo", Boolean.class)).isNull();
+    }
+
+    @Test
+    public void test_get_key_typeliteral() throws Exception {
+        assertThat((Predicate<Boolean>)Configuration.EMPTY.get("foo", TypeLiteral.of(Boolean.class))).isNull();
+    }
+
+    @Test
+    public void test_getOptional_key() throws Exception {
+        assertThat(Configuration.EMPTY.getOptional("foo")).isNotNull().isNotPresent();
+    }
+
+    @Test
+    public void test_get_key_class() throws Exception {
+        assertThat(Configuration.EMPTY.get("foo", Boolean.class)).isNull();
+    }
+
+    @Test
+    public void test_get_keys_class() throws Exception {
+        assertThat(Configuration.EMPTY.get(Arrays.asList("foo", "bar"), Boolean.class)).isNull();
+    }
+
+    @Test
+    public void test_get_keys_typeliteral() throws Exception {
+        assertThat((Predicate<Boolean>)Configuration.EMPTY.get(Arrays.asList("foo",
"bar"), TypeLiteral.of(Boolean.class)))
+                .isNull();
+    }
+
+    @Test
+    public void test_get_keys_typeliteral_default() throws Exception {
+        assertThat(Configuration.EMPTY.getOrDefault(Arrays.asList("foo", "bar"), TypeLiteral.of(Boolean.class),
Boolean.TRUE))
+                .isEqualTo(Boolean.TRUE);
+    }
+
+    @Test
+    public void test_getOptional_key_class() throws Exception {
+        assertThat(Configuration.EMPTY.getOptional("foo", Boolean.class)).isNotNull().isNotPresent();
+    }
+
+    @Test
+    public void test_getOptional_key_typeliteral() throws Exception {
+        assertThat(Configuration.EMPTY.getOptional("foo", TypeLiteral.of(Boolean.class))).isNotNull().isNotPresent();
+    }
+
+    @Test
+    public void test_getOptional_keys() throws Exception {
+        assertThat(Configuration.EMPTY.getOptional(Arrays.asList("foo", "bar"))).isNotNull().isNotPresent();
+    }
+
+    @Test
+    public void test_getOptional_keys_class() throws Exception {
+        assertThat(Configuration.EMPTY.getOptional(Arrays.asList("foo", "bar"), Boolean.class)).isNotNull().isNotPresent();
+    }
+
+    @Test
+    public void test_getOptional_keys_typeliteral() throws Exception {
+        assertThat(Configuration.EMPTY.getOptional(Arrays.asList("foo", "bar"), TypeLiteral.of(Boolean.class))).isNotNull().isNotPresent();
+    }
+
+    @Test
+    public void test_getOrDefault_key_default() throws Exception {
+        assertThat(Configuration.EMPTY.getOrDefault("foo", "bar")).isEqualTo("bar");
+    }
+
+    @Test
+    public void test_getOrDefault_key_type_default() throws Exception {
+        assertThat(Configuration.EMPTY.getOrDefault("foo", Boolean.class, Boolean.TRUE)).isEqualTo(Boolean.TRUE);
+    }
+
     @Test
     public void test_current() throws Exception {
         assertThat(Configuration.current()).isNotNull();
@@ -122,6 +228,21 @@ public class ConfigurationTest {
     }
 
     @Test
+    public void testGetSnapshot() throws Exception {
+        assertThat(Configuration.EMPTY.getSnapshot()).isNotNull();
+    }
+
+    @Test
+    public void testGetSnapshot_keys() throws Exception {
+        assertThat(Configuration.EMPTY.getSnapshot("foo", "bar")).isNotNull();
+    }
+
+    @Test
+    public void testGetSnapshot_iterable() throws Exception {
+        assertThat(Configuration.EMPTY.getSnapshot(Arrays.asList("foo", "bar"))).isNotNull();
+    }
+
+    @Test
     public void testToBuilder() throws Exception {
         assertThat(Configuration.current().toBuilder()).isNotNull();
     }
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
index 77f0e85..a478bf4 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
@@ -106,6 +106,11 @@ public class ServiceContextManagerTest {
         public <T> List<T> register(Class<T> type, List<T> instancea,
boolean force) {
             return instancea;
         }
+
+        @Override
+        public void reset() {
+
+        }
     }
 
 }
\ No newline at end of file
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
index afa33bc..079bf9f 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
@@ -79,6 +79,11 @@ public class ServiceContextTest {
             return instances;
         }
 
+        @Override
+        public void reset() {
+
+        }
+
     };
 
     @Test
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/TestLowerOrdinalServiceContext.java
b/code/api/src/test/java/org/apache/tamaya/spi/TestLowerOrdinalServiceContext.java
index b7f2991..6c5beb4 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/TestLowerOrdinalServiceContext.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/TestLowerOrdinalServiceContext.java
@@ -96,4 +96,9 @@ public final class TestLowerOrdinalServiceContext implements ServiceContext
{
         throw ex;
     }
 
+    @Override
+    public void reset() {
+
+    }
+
 }
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/code/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
index 9aae439..b00a7a0 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
@@ -142,4 +142,9 @@ public final class TestServiceContext implements ServiceContext {
         return (List<T>)servicesLoaded.get(type);
     }
 
+    @Override
+    public void reset() {
+
+    }
+
 }
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
index 207dfd8..15c7b54 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
@@ -277,4 +277,9 @@ public class OSGIServiceContext implements ServiceContext{
         }
     }
 
+    @Override
+    public void reset() {
+
+    }
+
 }
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultServiceContext.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultServiceContext.java
index 9c940ae..57b6cba 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultServiceContext.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultServiceContext.java
@@ -209,6 +209,13 @@ public final class DefaultServiceContext implements ServiceContext {
         return (List<T>)servicesLoaded.get(type);
     }
 
+    @Override
+    public void reset() {
+        servicesLoaded.clear();
+        singletons.clear();
+        factoryTypes.clear();
+    }
+
 
     @Override
     public ClassLoader getClassLoader() {
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java
index c0e4a23..c10d41b 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java
@@ -242,4 +242,9 @@ public final class DefaultServiceContext implements ServiceContext {
         return (List<T>)servicesLoaded.get(type);
     }
 
+    @Override
+    public void reset() {
+        this.servicesLoaded.clear();
+    }
+
 }


Mime
View raw message