tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject incubator-tamaya git commit: TAMAYA-39 Added default property source provider for JSON based property sources. TAMAYA-65 Started to use Arquillian for integration tests.
Date Wed, 11 Feb 2015 18:02:42 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master d3ff6e5bc -> c7f85a53a


TAMAYA-39 Added default property source provider for JSON based property sources.
TAMAYA-65 Started to use Arquillian for integration tests.


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

Branch: refs/heads/master
Commit: c7f85a53a9ca38855dcd59fd15788c8809c7201c
Parents: d3ff6e5
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Wed Feb 11 19:01:49 2015 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Wed Feb 11 19:01:49 2015 +0100

----------------------------------------------------------------------
 modules/json/pom.xml                            | 62 +++++++++++++-
 .../json/JSONPropertySourceProvider.java        | 64 ++++++++++++++
 ...org.apache.tamaya.spi.PropertySourceProvider | 18 ++++
 .../JSONPropertySourceConfigurationTest.java    | 52 ------------
 ...pertySourceProviderExistingConfigFileIT.java | 87 ++++++++++++++++++++
 ...opertySourceProviderMissingConfigFileIT.java | 69 ++++++++++++++++
 modules/json/src/test/resources/arquillian.xml  | 30 +++++++
 pom.xml                                         | 51 ++++++++++++
 8 files changed, 379 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/modules/json/pom.xml
----------------------------------------------------------------------
diff --git a/modules/json/pom.xml b/modules/json/pom.xml
index 5ac7c52..78ee8d7 100644
--- a/modules/json/pom.xml
+++ b/modules/json/pom.xml
@@ -61,6 +61,35 @@ under the License.
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.jboss.arquillian.daemon</groupId>
+            <artifactId>arquillian-daemon-container-managed</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.daemon</groupId>
+            <artifactId>arquillian-daemon-container-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.daemon</groupId>
+            <artifactId>arquillian-daemon-main</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.daemon</groupId>
+            <artifactId>arquillian-daemon-protocol-arquillian</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.daemon</groupId>
+            <artifactId>arquillian-daemon-protocol-wire</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.daemon</groupId>
+            <artifactId>arquillian-daemon-server</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.junit</groupId>
+            <artifactId>arquillian-junit-container</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.hamcrest</groupId>
             <artifactId>hamcrest-library</artifactId>
@@ -69,8 +98,37 @@ under the License.
             <groupId>org.hamcrest</groupId>
             <artifactId>hamcrest-core</artifactId>
         </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copyMain</id>
+                        <phase>process-test-resources</phase>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}</outputDirectory>
+                            <overWriteReleases>false</overWriteReleases>
+                            <overWriteSnapshots>false</overWriteSnapshots>
+                            <overWriteIfNewer>true</overWriteIfNewer>
+                            <stripVersion>true</stripVersion>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.jboss.arquillian.daemon</groupId>
+                                    <artifactId>arquillian-daemon-main</artifactId>
+                                </artifactItem>
+                            </artifactItems>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 
 
-    </dependencies>
-    
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySourceProvider.java
b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySourceProvider.java
new file mode 100644
index 0000000..426e0ed
--- /dev/null
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySourceProvider.java
@@ -0,0 +1,64 @@
+/*
+ * 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.modules.json;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Provides all <a href="http://json.org">JSON</a>
+ * property sources found in the  classpath
+ * in {@code META-INF/javaconfiguration.json}.
+ *
+ * @see PropertySourceProvider
+ */
+public class JSONPropertySourceProvider implements PropertySourceProvider {
+    public final static String DEFAULT_RESOURCE_NAME = "javaconfiguration.json";
+
+    @Override
+    public Collection<PropertySource> getPropertySources() {
+        List<PropertySource> sources;
+
+        try {
+            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+            Enumeration<URL> urls = classLoader.getResources("META-INF/" + DEFAULT_RESOURCE_NAME);
+
+            sources = Collections.list(urls)
+                                 .stream()
+                                 .map(JSONPropertySource::new)
+                                 .collect(toList());
+
+        } catch (Exception e) {
+            String msg = "Failure while loading JSON property sources.";
+
+            throw new ConfigException(msg, e);
+        }
+
+        return sources;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
b/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..f3199f2
--- /dev/null
+++ b/modules/json/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,18 @@
+#
+# 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.
+#

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
deleted file mode 100644
index 5c354a7..0000000
--- a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.modules.json;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.hamcrest.CoreMatchers;
-import org.junit.Test;
-
-import java.net.URL;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-
-/**
- * Tests for {@link org.apache.tamaya.modules.json.JSONPropertySource}.
- */
-public class JSONPropertySourceConfigurationTest {
-
-
-    @Test
-    public void testFull() throws Exception {
-        URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/simple-flat-string-only-config.json");
-
-        assertThat(configURL, CoreMatchers.notNullValue());
-
-        JSONPropertySource source = new JSONPropertySource(configURL.toString(), 10);
-
-        assertThat(source.getProperties().keySet(), hasSize(3));
-
-        ConfigurationContext context = ConfigurationProvider.getConfigurationContext();
-        context.addPropertySources(source);
-
-        // @todo Finish!
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderExistingConfigFileIT.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderExistingConfigFileIT.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderExistingConfigFileIT.java
new file mode 100644
index 0000000..c5ab552
--- /dev/null
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderExistingConfigFileIT.java
@@ -0,0 +1,87 @@
+/*
+ * 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.modules.json;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyName;
+import org.apache.tamaya.core.internal.DefaultServiceContext;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.ServiceContext;
+import org.hamcrest.Matchers;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+
+@RunWith(Arquillian.class)
+public class JSONPropertySourceProviderExistingConfigFileIT {
+
+    @Deployment
+    public static JavaArchive createDeployment() {
+        JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
+
+        archive.addPackage(ObjectMapper.class.getPackage())
+               .addPackages(true, JsonFactory.class.getPackage())
+               .addPackages(true, PropertyName.class.getPackage())
+               .addPackages(true, JsonAutoDetect.class.getPackage());
+
+        archive.addPackage(org.apache.tamaya.Configuration.class.getPackage())
+               .addPackage(org.apache.tamaya.spi.PropertySource.class.getPackage());
+
+        archive.addPackage(DefaultServiceContext.class.getPackage())
+               .addAsServiceProvider(ServiceContext.class, DefaultServiceContext.class);
+
+        archive.addPackage(JSONPropertySource.class.getPackage())
+               .addAsServiceProvider(PropertySourceProvider.class, JSONPropertySourceProvider.class);
+
+        archive.addAsManifestResource("configs/valid/simple-flat-string-only-config.json",
+                                      JSONPropertySourceProvider.DEFAULT_RESOURCE_NAME);
+
+        return archive;
+    }
+
+    @Test
+    public void providerReturnsListOfProvidersIfThereIsOneDefaultJSONConfig() {
+        List<PropertySourceProvider> services = ServiceContext.getInstance()
+                                                              .getServices(PropertySourceProvider.class);
+
+        PropertySourceProvider provider = services.stream()
+                                                  .filter(s -> s instanceof JSONPropertySourceProvider)
+                                                  .findFirst().get();
+
+        assertThat(provider.getPropertySources(), notNullValue());
+        assertThat(provider.getPropertySources(), hasSize(1));
+
+        PropertySource source = provider.getPropertySources().iterator().next();
+
+        assertThat(source.getProperties().keySet(), Matchers.containsInAnyOrder("a", "b",
"c"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderMissingConfigFileIT.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderMissingConfigFileIT.java
b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderMissingConfigFileIT.java
new file mode 100644
index 0000000..31f91e6
--- /dev/null
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceProviderMissingConfigFileIT.java
@@ -0,0 +1,69 @@
+/*
+ * 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.modules.json;
+
+import org.apache.tamaya.core.internal.DefaultServiceContext;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.ServiceContext;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+
+@RunWith(Arquillian.class)
+public class JSONPropertySourceProviderMissingConfigFileIT {
+
+    @Deployment
+    public static JavaArchive createDeployment() {
+        JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
+
+        archive.addPackage(org.apache.tamaya.Configuration.class.getPackage())
+               .addPackage(org.apache.tamaya.spi.PropertySource.class.getPackage());
+
+        archive.addPackage(DefaultServiceContext.class.getPackage())
+               .addAsServiceProvider(ServiceContext.class, DefaultServiceContext.class);
+
+
+        archive.addPackage(JSONPropertySource.class.getPackage())
+               .addAsServiceProvider(PropertySourceProvider.class, JSONPropertySourceProvider.class);
+
+        return archive;
+    }
+
+    @Test
+    public void providerReturnsEmptyListOfProvidersIfThereIsNoOneDefaultJSONConfig() {
+        List<PropertySourceProvider> services = ServiceContext.getInstance().getServices(PropertySourceProvider.class);
+
+        PropertySourceProvider provider = services.stream()
+                                                  .filter(s -> s instanceof JSONPropertySourceProvider)
+                                                  .findFirst().get();
+
+        assertThat(provider.getPropertySources(), notNullValue());
+        assertThat(provider.getPropertySources(), hasSize(0));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/modules/json/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/modules/json/src/test/resources/arquillian.xml b/modules/json/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..1eeb58b
--- /dev/null
+++ b/modules/json/src/test/resources/arquillian.xml
@@ -0,0 +1,30 @@
+<?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.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+    <container qualifier="daemon" default="true">
+        <configuration>
+            <property name="host">localhost</property>
+            <property name="port">12346</property>
+            <property name="serverJarFile">target/arquillian-daemon-main.jar</property>
+        </configuration>
+    </container>
+</arquillian>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c7f85a53/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f3ce465..677bb54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,7 @@ under the License.
         <junit.version>4.12</junit.version>
 
         <!-- Dependency and plugin relate version properties go here -->
+        <arquillian.deamon.version>1.0.0.Alpha1</arquillian.deamon.version>
         <asciidoctor.version>1.5.0</asciidoctor.version>
         <asciidoctor-diagramm.version>1.2.1</asciidoctor-diagramm.version>
         <asciidoctorj.version>1.5.2</asciidoctorj.version>
@@ -241,6 +242,56 @@ under the License.
             </dependency>
 
             <dependency>
+                <groupId>org.jboss.arquillian.</groupId>
+                <artifactId>arquillian-bom</artifactId>
+                <version>1.1.6.Final</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+
+            <dependency>
+                <groupId>org.jboss.arquillian.daemon</groupId>
+                <artifactId>arquillian-daemon-container-managed</artifactId>
+                <version>${arquillian.deamon.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.jboss.arquillian.daemon</groupId>
+                <artifactId>arquillian-daemon-container-common</artifactId>
+                <version>${arquillian.deamon.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.jboss.arquillian.daemon</groupId>
+                <artifactId>arquillian-daemon-main</artifactId>
+                <version>${arquillian.deamon.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.jboss.arquillian.daemon</groupId>
+                <artifactId>arquillian-daemon-protocol-arquillian</artifactId>
+                <version>${arquillian.deamon.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.jboss.arquillian.daemon</groupId>
+                <artifactId>arquillian-daemon-protocol-wire</artifactId>
+                <version>${arquillian.deamon.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.jboss.arquillian.daemon</groupId>
+                <artifactId>arquillian-daemon-server</artifactId>
+                <version>${arquillian.deamon.version}</version>
+            </dependency>
+
+            <!--<dependency>-->
+                <!--<groupId>org.jboss.arquillian.junit</groupId>-->
+                <!--<artifactId>arquillian-junit-container</artifactId>-->
+            <!--</dependency>-->
+
+            <dependency>
                 <groupId>org.mockito</groupId>
                 <artifactId>mockito-core</artifactId>
                 <version>${mockito.version}</version>


Mime
View raw message