tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject incubator-tamaya-extensions git commit: [TAMAYA-206] Re-added the example for the configuration injection module to the examples of the extensions.
Date Wed, 04 Jan 2017 21:20:08 GMT
Repository: incubator-tamaya-extensions
Updated Branches:
  refs/heads/master 519532923 -> cc911b72e


[TAMAYA-206] Re-added the example for the configuration injection module to the examples of
the extensions.


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/cc911b72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/cc911b72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/cc911b72

Branch: refs/heads/master
Commit: cc911b72e71a182cbe77f1cefdb7f1f3450d7007
Parents: 5195329
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Wed Jan 4 22:19:58 2017 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Wed Jan 4 22:19:58 2017 +0100

----------------------------------------------------------------------
 examples/03-injection-example/pom.xml           | 76 ++++++++++++++++
 .../tamaya/ext/examples/injection/Example.java  | 48 ++++++++++
 .../ext/examples/injection/ExampleTemplate.java | 42 +++++++++
 .../tamaya/ext/examples/injection/Main.java     | 67 ++++++++++++++
 .../ext/examples/injection/package-info.java    | 24 +++++
 .../META-INF/javaconfiguration.properties       | 27 ++++++
 .../ext/examples/injection/MinimalTest.java     | 95 ++++++++++++++++++++
 .../tamaya/ext/examples/injection/TestEnum.java | 23 +++++
 .../META-INF/javaconfiguration.properties       | 25 ++++++
 examples/pom.xml                                |  1 +
 10 files changed, 428 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/pom.xml b/examples/03-injection-example/pom.xml
new file mode 100644
index 0000000..519e3ec
--- /dev/null
+++ b/examples/03-injection-example/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.tamaya.ext.examples</groupId>
+        <artifactId>examples</artifactId>
+        <version>0.3-incubating-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.tamaya.ext.examples</groupId>
+    <artifactId>03-injection-example</artifactId>
+    <version>0.3-incubating-SNAPSHOT</version>
+    <name>Apache Tamaya Configuration Injection Example</name>
+
+    <description>This project contains a simple illustrating how configuration values
can be injected.</description>
+
+    <properties>
+        <geronimo-jcdi-1.1-spec.version>1.0</geronimo-jcdi-1.1-spec.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tamaya</groupId>
+            <artifactId>tamaya-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya.ext</groupId>
+            <artifactId>tamaya-injection</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>java-hamcrest</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+            <version>${geronimo-jcdi-1.1-spec.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-atinject_1.0_spec</artifactId>
+            <version>1.0</version>
+        </dependency>
+
+    </dependencies>
+
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java
b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java
new file mode 100644
index 0000000..6f78e58
--- /dev/null
+++ b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java
@@ -0,0 +1,48 @@
+/*
+ * 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.ext.examples.injection;
+
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
+
+/**
+ * Simple example bean, mapped by default names mostly.
+ */
+@ConfigDefaultSections("example")
+@SuppressWarnings("all")
+public class Example {
+
+    private String type;
+    private String name;
+    @Config(defaultValue = "No description available.")
+    private String description;
+    private int version;
+    @Config("author")
+    private String exampleAuthor;
+
+    @Override
+    public String toString() {
+        return "Example Metadata:" +
+                "type='" + type + '\'' +
+                ", name='" + name + '\'' +
+                ", description='" + description + '\'' +
+                ", version=" + version +
+                ", exampleAuthor='" + exampleAuthor + '\'';
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java
b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java
new file mode 100644
index 0000000..8eb6839
--- /dev/null
+++ b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java
@@ -0,0 +1,42 @@
+/*
+ * 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.ext.examples.injection;
+
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
+
+/**
+ * Simple example bean, mapped by default names mostly.
+ */
+@ConfigDefaultSections("example")
+public interface ExampleTemplate {
+
+    String getType();
+
+    String getName();
+
+    @Config(defaultValue = "No description available.")
+    String getDescription();
+
+    int getVersion();
+
+    @Config("author")
+    String getExampleAuthor();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Main.java
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Main.java
b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Main.java
new file mode 100644
index 0000000..4872fde
--- /dev/null
+++ b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Main.java
@@ -0,0 +1,67 @@
+/*
+ * 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.ext.examples.injection;
+
+import org.apache.tamaya.inject.ConfigurationInjection;
+import org.apache.tamaya.inject.ConfigurationInjector;
+
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
+
+/**
+ * Example illustrating the functionality of injecting configuration and
+ * defining configuration templates.
+ */
+public class Main {
+
+    /*
+     * Turns off all logging.
+     */
+    static {
+        LogManager.getLogManager().reset();
+        Logger globalLogger = Logger.getLogger(java.util.logging.Logger.GLOBAL_LOGGER_NAME);
+        globalLogger.setLevel(java.util.logging.Level.OFF);
+    }
+
+    private Main() {
+    }
+
+    public static void main(String[] args) {
+        ConfigurationInjector injector = ConfigurationInjection.getConfigurationInjector();
+        ExampleTemplate template = injector.createTemplate(ExampleTemplate.class);
+
+        System.out.println("****************************************************");
+        System.out.println("Injection and TemplatesExample");
+        System.out.println("****************************************************");
+        System.out.println();
+
+        Example example = new Example();
+        injector.configure(example);
+
+        System.out.println("Injected:");
+        System.out.println("---------");
+        System.out.println(example);
+        System.out.println("Template:");
+        System.out.println("---------");
+        System.out.println(template);
+        System.out.println();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/package-info.java
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/package-info.java
b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/package-info.java
new file mode 100644
index 0000000..e583914
--- /dev/null
+++ b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+/**
+ * Example illustrating the functionality of injecting configuration and
+ * defining configuration templates.
+ */
+package org.apache.tamaya.ext.examples.injection;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/main/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/main/resources/META-INF/javaconfiguration.properties
b/examples/03-injection-example/src/main/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..b986ea8
--- /dev/null
+++ b/examples/03-injection-example/src/main/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,27 @@
+#
+# 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 current 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.
+#
+example.type=standalone
+example.name=Minimal
+example.description=This example illustrates basic configuration injection mechanisms.
+example.version=1
+example.author=anatole@apache.org
+
+
+example.number=350322222222222222222266666666666666666666622222222222222222
+example.testEnum=V2

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
b/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
new file mode 100644
index 0000000..022b5b8
--- /dev/null
+++ b/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.ext.examples.injection;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.math.BigInteger;
+
+public class MinimalTest {
+
+    private static Configuration config;
+
+    @BeforeClass
+    public static void before() throws InterruptedException {
+        config = ConfigurationProvider.getConfiguration();
+        Thread.sleep(100L);
+    }
+
+    @Test
+    public void printMetaInfo() {
+        System.out.println("****************************************************");
+        System.out.println("Minimal Example");
+        System.out.println("****************************************************");
+        System.out.println();
+        System.out.println("Example Metadata:");
+        System.out.println("\tType        :  " + config.get("example.type"));
+        System.out.println("\tName        :  " + config.get("example.name"));
+        System.out.println("\tDescription :  " + config.get("example.description"));
+        System.out.println("\tVersion     :  " + config.get("example.version"));
+        System.out.println("\tAuthor      :  " + config.get("example.author"));
+        System.out.println();
+    }
+
+    @Test(expected = ConfigException.class)
+    public void getNumberValueTooLong() {
+        String value = config.get("example.number");
+        System.err.println("**** example.number(String)=" + value);
+        int number = config.get("example.number",int.class);
+        System.out.println("----\n   example.number(int)=" + number);
+    }
+
+    @Test
+    public void getNumberValueAsInt_BadCase() {
+        String value = config.get("example.numberAsHex");
+        int number = config.get("example.numberAsHex",int.class);
+        print("example.numberAsHex", number);
+    }
+
+    @Test
+    public void getNumberValueAsBigInteger() {
+        String value = config.get("example.number");
+        BigInteger number = config.get("example.number", BigInteger.class);
+        print("example.number", number);
+    }
+
+    @Test(expected = ConfigException.class)
+    public void getNumberValueAsLongHex() {
+        String value = config.get("example.numberAsLongHex");
+        long number = config.get("example.numberAsLongHex",int.class);
+        print("example.numberAsLongHex", number);
+    }
+
+    @Test
+    public void getEnum() {
+        String value = config.get("example.testEnum");
+        TestEnum en = config.get("example.testEnum", TestEnum.class);
+        print("example.testEnum", en);
+    }
+
+    protected void print(String key, Object value) {
+        System.out.println("----\n" +
+                "  " + key + "(String)=" + config.get(key)
+                + "\n  " + key + "(" + value.getClass().getSimpleName() + ")=" + value);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/TestEnum.java
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/TestEnum.java
b/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/TestEnum.java
new file mode 100644
index 0000000..2606b4b
--- /dev/null
+++ b/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/TestEnum.java
@@ -0,0 +1,23 @@
+/*
+ * 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.ext.examples.injection;
+
+public enum TestEnum {
+    V1, V2, V3
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties
b/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..acb9caf
--- /dev/null
+++ b/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,25 @@
+#
+# 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 current 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.
+#
+tamaya.ordinal=-1
+example.description=A minimal example only using API and RI, now partially overridden!
+
+example.number=35333333333333333333333333333333333333333333333333333333333330
+example.numberAsHex=0xFA
+example.numberAsLongHex=0xFFFSFSFF
+example.testEnum=V1

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cc911b72/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 5e74986..6fe281a 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -39,6 +39,7 @@ under the License.
     <modules>
         <module>01-resources-example</module>
         <module>02-resolver-example</module>
+        <module>03-injection-example</module>
     </modules>
 
     


Mime
View raw message