deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lightguar...@apache.org
Subject deltaspike git commit: Fixes DELTASPIKE-400 (null beans in InjectionPoints)
Date Mon, 15 Dec 2014 23:56:23 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 53c8efe71 -> ae145f36a


Fixes DELTASPIKE-400 (null beans in InjectionPoints)

I've added a couple of tests now, we can start building on them for BeanBuilder.

The BaseImmutableBean now checks for the Bean in InjectionPoints and uses the new InjectionPointWrapper
with self as the bean if there is no bean set on the InjectionPoint.

I've not tested to see if everything is wired up correctly, but all the tests are passing.


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

Branch: refs/heads/master
Commit: ae145f36ab2579f6863aed6e31169b7ecf387c73
Parents: 53c8efe
Author: Jason Porter <lightguardjp@apache.org>
Authored: Mon Dec 15 16:46:26 2014 -0700
Committer: Jason Porter <lightguardjp@apache.org>
Committed: Mon Dec 15 16:46:26 2014 -0700

----------------------------------------------------------------------
 .../core/util/bean/BaseImmutableBean.java       |  18 +++-
 .../util/metadata/InjectionPointWrapper.java    |  86 +++++++++++++++
 .../core/api/util/bean/BeanBuilderTest.java     | 104 +++++++++++++++++++
 .../test/core/api/util/bean/SimpleClass.java    |  27 +++++
 .../core/api/util/bean/WithInjectionPoint.java  |  34 ++++++
 5 files changed, 268 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae145f36/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/bean/BaseImmutableBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/bean/BaseImmutableBean.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/bean/BaseImmutableBean.java
index e3e2d1c..6342c25 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/bean/BaseImmutableBean.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/bean/BaseImmutableBean.java
@@ -21,6 +21,7 @@ package org.apache.deltaspike.core.util.bean;
 
 import org.apache.deltaspike.core.api.literal.DefaultLiteral;
 import org.apache.deltaspike.core.util.ArraysUtils;
+import org.apache.deltaspike.core.util.metadata.InjectionPointWrapper;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.spi.Bean;
@@ -149,7 +150,22 @@ public abstract class BaseImmutableBean<T> implements Bean<T>
         }
         else
         {
-            this.injectionPoints = new HashSet<InjectionPoint>(injectionPoints);
+            // Check for null Beans, wrap if there isn't one -- DELTASPIKE-400
+            final HashSet<InjectionPoint> ips = new HashSet<InjectionPoint>(injectionPoints.size());
+
+            for (InjectionPoint ip : injectionPoints)
+            {
+                if (ip.getBean() == null)
+                {
+                    ips.add(new InjectionPointWrapper(ip, this));
+                }
+                else
+                {
+                    ips.add(ip);
+                }
+            }
+
+            this.injectionPoints = ips;
         }
 
         this.alternative = alternative;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae145f36/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/InjectionPointWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/InjectionPointWrapper.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/InjectionPointWrapper.java
new file mode 100644
index 0000000..390e253
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/InjectionPointWrapper.java
@@ -0,0 +1,86 @@
+/*
+ * 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.deltaspike.core.util.metadata;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+/**
+ * Simple wrapper for injection points. Some metadata (as of 2014-12-15 just Bean) can be
overridden, all else
+ * delegates to the wrapped InjectionPoint.
+ */
+public class InjectionPointWrapper implements InjectionPoint
+{
+    final InjectionPoint wrapped;
+    final Bean<?> newBean;
+
+    public InjectionPointWrapper(InjectionPoint wrapped, Bean<?> newBean)
+    {
+        this.wrapped = wrapped;
+        this.newBean = newBean;
+    }
+
+    @Override
+    public Type getType()
+    {
+        return wrapped.getType();
+    }
+
+    @Override
+    public Set<Annotation> getQualifiers()
+    {
+        return wrapped.getQualifiers();
+    }
+
+    @Override
+    public Bean<?> getBean()
+    {
+        return newBean;
+    }
+
+    @Override
+    public Member getMember()
+    {
+        return wrapped.getMember();
+    }
+
+    @Override
+    public Annotated getAnnotated()
+    {
+        return wrapped.getAnnotated();
+    }
+
+    @Override
+    public boolean isDelegate()
+    {
+        return wrapped.isDelegate();
+    }
+
+    @Override
+    public boolean isTransient()
+    {
+        return wrapped.isTransient();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae145f36/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/BeanBuilderTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/BeanBuilderTest.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/BeanBuilderTest.java
new file mode 100644
index 0000000..ebb6070
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/BeanBuilderTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.deltaspike.test.core.api.util.bean;
+
+import org.apache.deltaspike.core.util.bean.BeanBuilder;
+import org.apache.deltaspike.core.util.metadata.builder.ImmutableInjectionPoint;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ */
+@RunWith(Arquillian.class)
+public class BeanBuilderTest
+{
+    @Deployment
+    public static Archive<?> createTestArchive()
+    {
+        return ShrinkWrap
+                .create(WebArchive.class, "beanBuilderTest.war")
+                .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+                .addClasses(SimpleClass.class, WithInjectionPoint.class);
+    }
+
+    @Inject
+    private BeanManager beanManager;
+
+    @Test
+    public void assertNonNullInjectionPointsFromBeanBuilder()
+    {
+        final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
+        final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
+        final Bean<?> newInjectionBean = beanBuilder.readFromType(at).create();
+
+        for (final InjectionPoint ip : newInjectionBean.getInjectionPoints())
+        {
+            Assert.assertNotNull(ip);
+        }
+    }
+
+    @Test
+    public void assertNonNullInjectionPointsWhenOverriding()
+    {
+        final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
+        final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
+        beanBuilder.readFromType(at);
+
+        // It's not easy to actually create these in the state we need, so we have to get
the InjectionPonits,
+        // create new ones with the correct info, null out the bean, set them as the new
injection points
+        // then move on.
+        final Set<InjectionPoint> origInjectionPoints = beanBuilder.getInjectionPoints();
+        beanBuilder.injectionPoints(beanBuilder.getInjectionPoints());
+
+        final Set<InjectionPoint> newInjectionPoints = new HashSet<InjectionPoint>();
+        for (InjectionPoint ip : origInjectionPoints)
+        {
+            newInjectionPoints.add(new ImmutableInjectionPoint((AnnotatedField) ip.getAnnotated(),
+                    ip.getQualifiers(), null, ip.isTransient(), ip.isDelegate()));
+        }
+        beanBuilder.injectionPoints(newInjectionPoints);
+
+        final Bean<?> newInjectionBean = beanBuilder.create();
+
+        for (final InjectionPoint ip : newInjectionBean.getInjectionPoints())
+        {
+            Assert.assertNotNull(ip);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae145f36/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/SimpleClass.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/SimpleClass.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/SimpleClass.java
new file mode 100644
index 0000000..1c6a2aa
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/SimpleClass.java
@@ -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 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.deltaspike.test.core.api.util.bean;
+
+/**
+ *
+ */
+public class SimpleClass
+{
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/ae145f36/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/WithInjectionPoint.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/WithInjectionPoint.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/WithInjectionPoint.java
new file mode 100644
index 0000000..e06f5a1
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/bean/WithInjectionPoint.java
@@ -0,0 +1,34 @@
+/*
+ * 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.deltaspike.test.core.api.util.bean;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ *
+ */
+@Named("ipoint")
+public class WithInjectionPoint
+{
+    @Inject
+    private BeanManager beanManager;
+}


Mime
View raw message