You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2017/09/29 10:40:48 UTC
incubator-tamaya-extensions git commit: [TAMAYA-290] Added tests and
improved the implementation of ConfiguredVetoExtension.
Repository: incubator-tamaya-extensions
Updated Branches:
refs/heads/master 8fc2efbdb -> 2a70bd635
[TAMAYA-290] Added tests and improved the implementation of ConfiguredVetoExtension.
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/2a70bd63
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/2a70bd63
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/2a70bd63
Branch: refs/heads/master
Commit: 2a70bd6356e473590f8e4a89230b11fd6e6cfb01
Parents: 8fc2efb
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Fri Sep 29 12:40:15 2017 +0200
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Fri Sep 29 12:40:15 2017 +0200
----------------------------------------------------------------------
modules/injection/cdi/pom.xml | 4 +
.../cdi/extra/ConfiguredVetoExtension.java | 7 +-
.../tamaya/cdi/CDIAwareServiceContextTest.java | 23 ++++
.../tamaya/cdi/CDIConfiguredMethodTest.java | 74 +++++++++++
.../tamaya/cdi/CDIConfiguredTypeTest.java | 25 ++++
.../cdi/extra/ConfiguredVetoExtensionTest.java | 124 +++++++++++++++++++
.../org/apache/tamaya/cdi/extra/TestKlazz.java | 22 ++++
.../org/apache/tamaya/cdi/extra/TestKlazz2.java | 22 ++++
8 files changed, 298 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/pom.xml b/modules/injection/cdi/pom.xml
index ad11948..8f970e3 100644
--- a/modules/injection/cdi/pom.xml
+++ b/modules/injection/cdi/pom.xml
@@ -128,6 +128,10 @@ under the License.
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
</dependencies>
<profiles>
<profile>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtension.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtension.java b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtension.java
index a4c1489..e86ee89 100644
--- a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtension.java
+++ b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtension.java
@@ -30,11 +30,12 @@ import javax.enterprise.inject.spi.ProcessAnnotatedType;
*/
public class ConfiguredVetoExtension implements Extension {
- public void observesBean(@Observes ProcessAnnotatedType<?> type){
+ public void observesBean(@Observes ProcessAnnotatedType<?> type) {
String vetoedTypesVal = ConfigurationProvider.getConfiguration().get("javax.enterprise.inject.vetoed");
String[] vetoedTypes = vetoedTypesVal.split(",");
- for(String typeExpr:vetoedTypes){
- if(type.getAnnotatedType().getJavaClass().getName().matches(typeExpr)){
+ for (String typeExpr : vetoedTypes) {
+ String typeExprTrimmed = typeExpr.trim();
+ if (type.getAnnotatedType().getJavaClass().getName().matches(typeExprTrimmed)) {
type.veto();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIAwareServiceContextTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIAwareServiceContextTest.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIAwareServiceContextTest.java
new file mode 100644
index 0000000..5616b00
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIAwareServiceContextTest.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.cdi;
+
+public class CDIAwareServiceContextTest {
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
new file mode 100644
index 0000000..1818c5b
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredMethodTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.cdi;
+
+import org.hamcrest.Matchers;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.mockito.Mockito.when;
+
+public class CDIConfiguredMethodTest {
+
+ @Test
+ public void returnsTheConfiguredKeys() {
+ List<String> keys = asList("rate", "weight");
+ InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+ CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+ assertThat(ccm.getConfiguredKeys(), Matchers.containsInAnyOrder("rate", "weight"));
+ }
+
+ @Test
+ public void returnsTheNameOfTheGivenMethod() throws NoSuchMethodException {
+ Method method = Klazz.class.getMethod("getValue");
+ List<String> keys = asList("rate", "weight");
+ InjectionPoint ip = Mockito.mock(InjectionPoint.class);
+
+ when(ip.getMember()).thenReturn(method);
+
+ CDIConfiguredMethod ccm = new CDIConfiguredMethod(ip, keys);
+
+ assertThat(ccm.getName(), equalTo("getValue"));
+ }
+
+ public static class Klazz {
+ private OtherKlazz<String> value;
+
+ public OtherKlazz<String> getValue() {
+ return value;
+ }
+
+ public void setValue(OtherKlazz<String> value) {
+ this.value = value;
+ }
+ }
+
+ public static class OtherKlazz<T> {
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredTypeTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredTypeTest.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredTypeTest.java
new file mode 100644
index 0000000..0d6e422
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/CDIConfiguredTypeTest.java
@@ -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 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.cdi;
+
+import static org.junit.Assert.*;
+
+public class CDIConfiguredTypeTest {
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java
new file mode 100644
index 0000000..11f7dfd
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.cdi.extra;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.junit.Test;
+
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+import static org.mockito.Mockito.*;
+
+public class ConfiguredVetoExtensionTest {
+ ConfiguredVetoExtension extension = new ConfiguredVetoExtension();
+
+ @Test
+ public void willBeVetoedIfTypeHasBeenConfiguredAsConcreteClassName() {
+ ConfigurationContext context = mock(ConfigurationContext.class);
+ Configuration configuration = mock(Configuration.class);
+
+ when(configuration.getContext()).thenReturn(context);
+ when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn("org.apache.tamaya.cdi.extra.TestKlazz");
+
+ ConfigurationProvider.setConfiguration(configuration);
+
+ AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class);
+ when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class);
+
+ ProcessAnnotatedType<TestKlazz> processAnnotatedType = mock(ProcessAnnotatedType.class);
+ when(processAnnotatedType.getAnnotatedType()).thenReturn(annotatedType);
+
+ extension.observesBean(processAnnotatedType);
+
+ (processAnnotatedType).veto();
+ }
+
+ @Test
+ public void willNotBeVetoedIfTypeHasNotBeenConfigured() {
+ ConfigurationContext context = mock(ConfigurationContext.class);
+ Configuration configuration = mock(Configuration.class);
+
+ when(configuration.getContext()).thenReturn(context);
+ when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn("org.apache.tamaya.cdi.extra.O");
+
+ ConfigurationProvider.setConfiguration(configuration);
+
+ AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class);
+ when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class);
+
+ ProcessAnnotatedType<TestKlazz> processAnnotatedType = mock(ProcessAnnotatedType.class);
+ when(processAnnotatedType.getAnnotatedType()).thenReturn(annotatedType);
+
+ extension.observesBean(processAnnotatedType);
+
+ verify(processAnnotatedType, never()).veto();
+ }
+
+ @Test
+ public void handlesPropertyWithWhitespacesCorrectly() {
+ String configuredValue = " " + TestKlazz.class.getName() +
+ ",\t" + TestKlazz2.class.getName();
+
+ ConfigurationContext context = mock(ConfigurationContext.class);
+ Configuration configuration = mock(Configuration.class);
+
+ when(configuration.getContext()).thenReturn(context);
+ when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn(configuredValue);
+
+ ConfigurationProvider.setConfiguration(configuration);
+
+ AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class);
+ when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class);
+
+ ProcessAnnotatedType<TestKlazz> processAnnotatedType = mock(ProcessAnnotatedType.class);
+ when(processAnnotatedType.getAnnotatedType()).thenReturn(annotatedType);
+
+ extension.observesBean(processAnnotatedType);
+
+ verify(processAnnotatedType).veto();
+ }
+
+ @Test
+ public void useOfRegexPattersWorks() {
+ String configuredValue = " " + TestKlazz.class.getPackage().getName() +
+ "\\..+";
+
+ ConfigurationContext context = mock(ConfigurationContext.class);
+ Configuration configuration = mock(Configuration.class);
+
+ when(configuration.getContext()).thenReturn(context);
+ when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn(configuredValue);
+
+ ConfigurationProvider.setConfiguration(configuration);
+
+ AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class);
+ when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class);
+
+ ProcessAnnotatedType<TestKlazz> processAnnotatedType = mock(ProcessAnnotatedType.class);
+ when(processAnnotatedType.getAnnotatedType()).thenReturn(annotatedType);
+
+ extension.observesBean(processAnnotatedType);
+
+ verify(processAnnotatedType).veto();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz.java
new file mode 100644
index 0000000..345ff12
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz.java
@@ -0,0 +1,22 @@
+/*
+ * 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.cdi.extra;
+
+public class TestKlazz {
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2a70bd63/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz2.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz2.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz2.java
new file mode 100644
index 0000000..3cd67e8
--- /dev/null
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/TestKlazz2.java
@@ -0,0 +1,22 @@
+/*
+ * 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.cdi.extra;
+
+public class TestKlazz2 {
+}