You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/09/27 12:23:33 UTC

[isis] branch v2 updated: ISIS-2086: adds and fixes smoketest for loading IsisConfiguration

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/v2 by this push:
     new ac0c58f  ISIS-2086: adds and fixes smoketest for loading IsisConfiguration
ac0c58f is described below

commit ac0c58f264f5047a8266af26f526a4b6ffa8e6da
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Sep 27 14:23:24 2019 +0200

    ISIS-2086: adds and fixes smoketest for loading IsisConfiguration
    
    - includes simplifications on how we might want to use lombok here
---
 .../org/apache/isis/config/IsisConfiguration.java  | 25 ++++++----
 .../src/main/resources/application.properties      |  0
 .../isis/testdomain/config/FooProperties.java      | 13 +++++
 .../org/apache/isis/testdomain/config/FooTest.java | 58 ++++++++++++++++++++++
 .../isis/testdomain/config/IsisConfigBeanTest.java | 54 ++++++++++++++++++++
 .../resources/application-config-test.properties   |  7 +++
 6 files changed, 146 insertions(+), 11 deletions(-)

diff --git a/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java b/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java
index 85f5fcd..d05595f 100644
--- a/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java
+++ b/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java
@@ -18,12 +18,12 @@
  */
 package org.apache.isis.config;
 
-import lombok.Getter;
-import lombok.Setter;
-
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
+import lombok.Data;
+
 /**
  * 
  * Configuration 'beans' with meta-data (IDE-support).
@@ -36,32 +36,36 @@ import org.springframework.context.annotation.Configuration;
  */
 @Configuration
 @ConfigurationProperties(ConfigurationConstants.ROOT_PREFIX)
+@EnableConfigurationProperties(IsisConfiguration.class)
+@Data
 public class IsisConfiguration {
 
-    @Getter
     private final Reflector reflector = new Reflector();
+    
+    @Data
     public static class Reflector {
 
-        @Getter
         private final ExplicitAnnotations explicitAnnotations = new ExplicitAnnotations();
+        
+        @Data
         public static class ExplicitAnnotations {
 
             /**
              * Whether or not a public method needs to be annotated with
              * @{@link org.apache.isis.applib.annotation.Action} in order to be picked up as an action in the metamodel.
              */
-            @Getter @Setter
             private boolean action = false;
         }
     }
 
-    @Getter
-    private final Services services = new Services();
+    private Services services;
+    
+    @Data
     public static class Services {
 
-        @Getter
-        private final Services.Container container = new Services.Container();
+        private final Services.Container container = new Container();
 
+        @Data
         public static class Container {
 
             /**
@@ -80,7 +84,6 @@ public class IsisConfiguration {
              *     seems the most prudent way forward.
              * </p>
              */
-            @Getter @Setter
             private boolean disableAutoFlush = false;
 
         }
diff --git a/examples/smoketests/src/main/resources/application.properties b/examples/smoketests/src/main/resources/application.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/FooProperties.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/FooProperties.java
new file mode 100644
index 0000000..3581054
--- /dev/null
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/FooProperties.java
@@ -0,0 +1,13 @@
+package org.apache.isis.testdomain.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import lombok.Data;
+
+@ConfigurationProperties("foo")
+@Data
+class FooProperties {
+
+    private boolean flag = false;
+    
+}
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/FooTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/FooTest.java
new file mode 100644
index 0000000..0d151c2
--- /dev/null
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/FooTest.java
@@ -0,0 +1,58 @@
+/*
+ *  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.isis.testdomain.config;
+
+import javax.inject.Inject;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Configuration;
+
+import org.apache.isis.testdomain.Smoketest;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@Smoketest
+@SpringBootTest(
+        classes = { 
+                FooTest.Setup.class
+        }, 
+        properties = {
+                "logging.config=log4j2-test.xml",
+                "foo.flag=true"
+        })
+@EnableConfigurationProperties(FooProperties.class)
+public class FooTest {
+    
+    @Configuration
+    static class Setup {
+        
+    }
+
+    @Inject private FooProperties foo;
+
+    @Test
+    void foo() {
+        assertNotNull(foo);
+        assertTrue(foo.isFlag());
+    }
+
+}
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/IsisConfigBeanTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/IsisConfigBeanTest.java
new file mode 100644
index 0000000..41300b5
--- /dev/null
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/config/IsisConfigBeanTest.java
@@ -0,0 +1,54 @@
+/*
+ *  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.isis.testdomain.config;
+
+import javax.inject.Inject;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+
+import org.apache.isis.config.IsisConfiguration;
+import org.apache.isis.testdomain.Smoketest;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@Smoketest
+@SpringBootTest(
+        classes = { 
+                IsisConfiguration.class
+        }, 
+        properties = {
+                "logging.config=log4j2-test.xml",
+        })
+@TestPropertySource({
+    "classpath:/application-config-test.properties"
+})
+public class IsisConfigBeanTest {
+
+    @Inject private IsisConfiguration isisConfiguration;
+
+    @Test
+    void configurationBean_shouldBePickedUpBySpring() {
+        assertNotNull(isisConfiguration);
+        assertTrue(isisConfiguration.getReflector().getExplicitAnnotations().isAction());
+    }
+
+}
diff --git a/examples/smoketests/src/test/resources/application-config-test.properties b/examples/smoketests/src/test/resources/application-config-test.properties
new file mode 100644
index 0000000..8096a03
--- /dev/null
+++ b/examples/smoketests/src/test/resources/application-config-test.properties
@@ -0,0 +1,7 @@
+#
+# renamed to kebab-case, but the old camelCase is also recognised and supported.
+#
+#
+
+isis.reflector.explicit-annotations.action=true
+