TAMAYA-259: Added tests.
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/2c1f5dfd Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/2c1f5dfd Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/2c1f5dfd Branch: refs/heads/master Commit: 2c1f5dfdd550ade9327e01d7a6850ea30d8d64bf Parents: b90a4bb Author: anatole <anat...@apache.org> Authored: Sun Mar 19 21:46:02 2017 +0100 Committer: anatole <anat...@apache.org> Committed: Sun Mar 19 21:46:02 2017 +0100 ---------------------------------------------------------------------- modules/features/pom.xml | 84 ++++++++++++ .../org/apache/tamaya/features/Features.java | 12 +- .../apache/tamaya/features/FeaturesTest.java | 115 ++++++++++++++++ .../tamaya/features/FeaturesTestNoOnly.java | 135 +++++++++++++++++++ 4 files changed, 340 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2c1f5dfd/modules/features/pom.xml ---------------------------------------------------------------------- diff --git a/modules/features/pom.xml b/modules/features/pom.xml index 4bc274b..30677d2 100644 --- a/modules/features/pom.xml +++ b/modules/features/pom.xml @@ -57,6 +57,90 @@ under the License. <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-injection</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-optional</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-formats</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-cdi</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-resolver</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-resources</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-mutable-config</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-spring</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-filter</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-spisupport</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-events</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-jndi</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>4.2.4.RELEASE</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.osgi.compendium</artifactId> + <version>1.0.0</version> + <scope>test</scope> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2c1f5dfd/modules/features/src/main/java/org/apache/tamaya/features/Features.java ---------------------------------------------------------------------- diff --git a/modules/features/src/main/java/org/apache/tamaya/features/Features.java b/modules/features/src/main/java/org/apache/tamaya/features/Features.java index 6abb6c5..3b73635 100644 --- a/modules/features/src/main/java/org/apache/tamaya/features/Features.java +++ b/modules/features/src/main/java/org/apache/tamaya/features/Features.java @@ -57,7 +57,7 @@ public final class Features { * Checks if <i>tamaya-injection</i> is on the classpath. * @return true, if <i>tamaya-injection</i> is on the classpath. */ - public static boolean injectionAvailable() { + public static boolean injectionStandaloneAvailable() { return checkClassIsLoadable("org.apache.tamaya.inject.ConfigurationInjector"); } @@ -66,7 +66,7 @@ public final class Features { * @return true, if <i>tamaya-injection-cdi</i> or <i>tamaya-injection-ee</i> is on the classpath. */ public static boolean injectionCDIAvailable() { - return checkClassIsLoadable("org.apache.tamaya.integration.cdi.TamayaCDIIntegration"); + return checkClassIsLoadable("org.apache.tamaya.cdi.DefaultDynamicValue"); } /** @@ -74,7 +74,7 @@ public final class Features { * @return true, if <i>tamaya-mutableconfig</i> is on the classpath. */ public static boolean mutableConfigAvailable() { - return checkClassIsLoadable("org.apache.tamaya.mutableconfig.MutableConfigProvider"); + return checkClassIsLoadable("org.apache.tamaya.mutableconfig.MutableConfigurationProvider"); } /** @@ -90,7 +90,7 @@ public final class Features { * @return true, if <i>tamaya-resolver</i> is on the classpath. */ public static boolean resolverAvailable() { - return checkClassIsLoadable("org.apache.tamaya.resolver.ResourceResolver"); + return checkClassIsLoadable("org.apache.tamaya.resolver.Resolver"); } /** @@ -168,9 +168,9 @@ public final class Features { */ public static boolean checkClassIsLoadable(String classname) { try{ - Class.forName(Objects.requireNonNull(classname)); + Class.forName(Objects.requireNonNull(classname), false, Thread.currentThread().getContextClassLoader()); return true; - }catch(Exception e){ + }catch(Throwable e){ return false; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2c1f5dfd/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java ---------------------------------------------------------------------- diff --git a/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java new file mode 100644 index 0000000..db6e16c --- /dev/null +++ b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java @@ -0,0 +1,115 @@ +/* + * 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.features; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests if feature are seen. Created by atsticks on 19.03.17. + */ +public class FeaturesTest { + @Test + public void eventsAvailable() throws Exception { + assertTrue(Features.eventsAvailable()); + } + + @Test + public void formatsAvailable() throws Exception { + assertTrue(Features.formatsAvailable()); + } + + @Test + public void tamayaCoreAvailable() throws Exception { + assertTrue(Features.tamayaCoreAvailable()); + } + + @Test + public void injectionCDIAvailable() throws Exception { + assertTrue(Features.injectionCDIAvailable()); + } + + @Test + public void injectionStandaloneAvailable() throws Exception { + assertTrue(Features.injectionStandaloneAvailable()); + } + + @Test + public void mutableConfigAvailable() throws Exception { + assertTrue(Features.mutableConfigAvailable()); + } + + @Test + public void optionalAvailable() throws Exception { + assertTrue(Features.optionalAvailable()); + } + + @Test + public void resolverAvailable() throws Exception { + assertTrue(Features.resolverAvailable()); + } + + @Test + public void resourcesAvailable() throws Exception { + assertTrue(Features.resourcesAvailable()); + } + + @Test + public void spiSupportAvailable() throws Exception { + assertTrue(Features.spiSupportAvailable()); + } + + @Test + public void filterSupportAvailable() throws Exception { + assertTrue(Features.filterSupportAvailable()); + } + + @Test + public void springAvailable() throws Exception { + assertTrue(Features.springAvailable()); + } + + @Test + public void jndiAvailable() throws Exception { + assertTrue(Features.jndiAvailable()); + } + + @Test + public void extSpringCoreAvailable() throws Exception { + assertTrue(Features.extSpringCoreAvailable()); + } + + @Test + public void extOSGIAvailable() throws Exception { + assertTrue(Features.extOSGIAvailable()); + } + + @Test + public void extJndiAvailable() throws Exception { + assertTrue(Features.extJndiAvailable()); + } + + @Test + public void checkClassIsLoadable() throws Exception { + assertTrue(Features.checkClassIsLoadable("java.lang.String")); + assertFalse(Features.checkClassIsLoadable("foo.Bar")); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2c1f5dfd/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java ---------------------------------------------------------------------- diff --git a/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java new file mode 100644 index 0000000..1bcb64b --- /dev/null +++ b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java @@ -0,0 +1,135 @@ +/* + * 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.features; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.net.URL; +import java.net.URLClassLoader; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Tests if feature are not seen, using an empty class loader. Created by atsticks on 19.03.17. + */ +public class FeaturesTestNoOnly { + + ClassLoader classloader; + + @Before + public void setup(){ + this.classloader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[]{}, null)); + } + + @After + public void cleanup(){ + Thread.currentThread().setContextClassLoader(this.classloader); + } + + @Test + public void eventsAvailable() throws Exception { + assertFalse(Features.eventsAvailable()); + } + + @Test + public void formatsAvailable() throws Exception { + assertFalse(Features.formatsAvailable()); + } + + @Test + public void tamayaCoreAvailable() throws Exception { + assertFalse(Features.tamayaCoreAvailable()); + } + + @Test + public void injectionCDIAvailable() throws Exception { + assertFalse(Features.injectionCDIAvailable()); + } + + @Test + public void injectionStandaloneAvailable() throws Exception { + assertFalse(Features.injectionStandaloneAvailable()); + } + + @Test + public void mutableConfigAvailable() throws Exception { + assertFalse(Features.mutableConfigAvailable()); + } + + @Test + public void optionalAvailable() throws Exception { + assertFalse(Features.optionalAvailable()); + } + + @Test + public void resolverAvailable() throws Exception { + assertFalse(Features.resolverAvailable()); + } + + @Test + public void resourcesAvailable() throws Exception { + assertFalse(Features.resourcesAvailable()); + } + + @Test + public void spiSupportAvailable() throws Exception { + assertFalse(Features.spiSupportAvailable()); + } + + @Test + public void filterSupportAvailable() throws Exception { + assertFalse(Features.filterSupportAvailable()); + } + + @Test + public void springAvailable() throws Exception { + assertFalse(Features.springAvailable()); + } + + @Test + public void jndiAvailable() throws Exception { + assertFalse(Features.jndiAvailable()); + } + + @Test + public void extSpringCoreAvailable() throws Exception { + assertFalse(Features.extSpringCoreAvailable()); + } + + @Test + public void extOSGIAvailable() throws Exception { + assertFalse(Features.extOSGIAvailable()); + } + + @Test + public void extJndiAvailable() throws Exception { + assertTrue(Features.extJndiAvailable()); + } + + @Test + public void checkClassIsLoadable() throws Exception { + assertTrue(Features.checkClassIsLoadable("java.lang.String")); + assertFalse(Features.checkClassIsLoadable("foo.Bar")); + } + +} \ No newline at end of file