openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1174589 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans: newtests/managed/instance/ newtests/managed/instance/beans/ newtests/managed/multipleinterfaces/ test/component/inject/ test/unittests/inject/
Date Fri, 23 Sep 2011 08:33:55 GMT
Author: struberg
Date: Fri Sep 23 08:33:54 2011
New Revision: 1174589

URL: http://svn.apache.org/viewvc?rev=1174589&view=rev
Log:
OWB-617 provide unit tests for manually resolving an Instance<T>

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
  (contents, props changed)
      - copied, changed from r1163742, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/ProxyFactoryTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/InstanceInjectedComponent.java
  (contents, props changed)
      - copied, changed from r1163742, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/InstanceInjectedComponent.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/UnparameterizedInstanceBean.java
Removed:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/InstanceInjectedComponent.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/InjectedInstanceComponentTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/multipleinterfaces/MyEntityServiceImpl.java

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
(from r1163742, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/ProxyFactoryTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/ProxyFactoryTest.java&r1=1163742&r2=1174589&rev=1174589&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/ProxyFactoryTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
Fri Sep 23 08:33:54 2011
@@ -17,42 +17,78 @@
  * under the License.
  */
 
-package org.apache.webbeans.newtests.managed;
+package org.apache.webbeans.newtests.managed.instance;
 
+import junit.framework.Assert;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.managed.instance.beans.InstanceInjectedComponent;
+import org.apache.webbeans.test.component.CheckWithCheckPayment;
+import org.apache.webbeans.test.component.CheckWithMoneyPayment;
+import org.apache.webbeans.test.component.IPayment;
+import org.apache.webbeans.test.component.PaymentProcessorComponent;
+import org.junit.Test;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.TypeLiteral;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
 
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
+public class InjectedInstanceComponentTest extends AbstractUnitTest {
 
-import junit.framework.Assert;
+        @Test
+    public void testInstanceInjectedComponent()
+    {
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(PaymentProcessorComponent.class);
+        beanClasses.add(InstanceInjectedComponent.class);
+        beanClasses.add(CheckWithCheckPayment.class);
+        beanClasses.add(CheckWithMoneyPayment.class);
+        beanClasses.add(IPayment.class);
 
-import org.apache.webbeans.newtests.AbstractUnitTest;
-import org.apache.webbeans.newtests.managed.multipleinterfaces.MyEntityServiceImpl;
-import org.junit.Test;
+        startContainer(beanClasses, null);
 
-public class ProxyFactoryTest extends AbstractUnitTest {
+        InstanceInjectedComponent instance = getInstance(InstanceInjectedComponent.class);
 
-    @SuppressWarnings("unchecked")
-    @Test
-    public void testProxyFactoryWithMultipleInterfaces() {
-        Collection<String> beanXmls = new ArrayList<String>();
+        org.junit.Assert.assertNotNull(instance);
+        org.junit.Assert.assertNotNull(instance.getInstance());
+        org.junit.Assert.assertNotNull(instance.getPaymentComponent());
+
+        Instance<PaymentProcessorComponent> ins = instance.getInstance();
+
+        boolean ambigious = ins.isAmbiguous();
+
+        Assert.assertFalse(ambigious);
+
+        boolean unsatisfied = ins.isUnsatisfied();
 
+        Assert.assertFalse(unsatisfied);
+
+        shutDownContainer();
+    }
+
+    @Test
+    public void testManualInstanceBeanResolving() {
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(MyEntityServiceImpl.class);
 
-        startContainer(beanClasses, beanXmls);
+        startContainer(beanClasses, null);
 
-        Set<Bean<?>> beans = getBeanManager().getBeans(MyEntityServiceImpl.class);
+        //X TODO doesn't work Set<Bean<?>> beans = getBeanManager().getBeans(Instance.class);
+        Type instanceType = new TypeLiteral<Instance<Object>>(){}.getType();
+        Set<Bean<?>> beans = getBeanManager().getBeans(instanceType);
         Assert.assertNotNull(beans);
+        Assert.assertTrue(beans.size() > 0);
 
-        Bean<MyEntityServiceImpl> bean = (Bean<MyEntityServiceImpl>) beans.iterator().next();
+        Bean<Instance> bean = (Bean<Instance>) getBeanManager().resolve(beans);
         Assert.assertNotNull(bean);
         
-        CreationalContext<MyEntityServiceImpl> ctx = getBeanManager().createCreationalContext(bean);
+        CreationalContext<Instance> ctx = getBeanManager().createCreationalContext(bean);
         
-        Object reference = getBeanManager().getReference(bean, MyEntityServiceImpl.class,
ctx);
+        Object reference = getBeanManager().getReference(bean, instanceType, ctx);
         Assert.assertNotNull(reference);
         
         shutDownContainer();

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/InjectedInstanceComponentTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/InstanceInjectedComponent.java
(from r1163742, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/InstanceInjectedComponent.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/InstanceInjectedComponent.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/InstanceInjectedComponent.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/InstanceInjectedComponent.java&r1=1163742&r2=1174589&rev=1174589&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/InstanceInjectedComponent.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/InstanceInjectedComponent.java
Fri Sep 23 08:33:54 2011
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.test.component.inject;
+package org.apache.webbeans.newtests.managed.instance.beans;
 
 
 import javax.enterprise.context.RequestScoped;

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/InstanceInjectedComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/UnparameterizedInstanceBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/UnparameterizedInstanceBean.java?rev=1174589&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/UnparameterizedInstanceBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/instance/beans/UnparameterizedInstanceBean.java
Fri Sep 23 08:33:54 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.webbeans.newtests.managed.instance.beans;
+
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+/**
+ * Test for injecting a Instance without any generic type.
+ */
+public class UnparameterizedInstanceBean
+{
+    private @Inject Instance instance;
+
+    public Instance getInstanceHook()
+    {
+        return instance;
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/multipleinterfaces/MyEntityServiceImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/multipleinterfaces/MyEntityServiceImpl.java?rev=1174589&r1=1174588&r2=1174589&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/multipleinterfaces/MyEntityServiceImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/multipleinterfaces/MyEntityServiceImpl.java
Fri Sep 23 08:33:54 2011
@@ -24,8 +24,7 @@ import javax.enterprise.context.Applicat
 @ApplicationScoped
 public class MyEntityServiceImpl extends AbstractCrudService<MyEntity> implements MyEntityService
{
 
-    @Override
     public void specialMyEntityFunction(MyEntity e) {
         // do something very special ;)
     }
-}
\ No newline at end of file
+}



Mime
View raw message