camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r1241110 - in /camel/trunk/components/camel-cdi/src: main/java/org/apache/camel/component/cdi/util/AnyLiteral.java main/java/org/apache/camel/component/cdi/util/BeanProvider.java test/java/org/apache/camel/cdi/CdiContainerBeanManagerTest.java
Date Mon, 06 Feb 2012 18:55:07 GMT
Author: hadrian
Date: Mon Feb  6 18:55:07 2012
New Revision: 1241110

URL: http://svn.apache.org/viewvc?rev=1241110&view=rev
Log:
Remove warnings and System.out calls

Modified:
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/AnyLiteral.java
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/BeanProvider.java
    camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContainerBeanManagerTest.java

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/AnyLiteral.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/AnyLiteral.java?rev=1241110&r1=1241109&r2=1241110&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/AnyLiteral.java
(original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/AnyLiteral.java
Mon Feb  6 18:55:07 2012
@@ -19,5 +19,6 @@ package org.apache.camel.component.cdi.u
 import javax.enterprise.inject.Any;
 import javax.enterprise.util.AnnotationLiteral;
 
-public class AnyLiteral extends AnnotationLiteral<Any> implements Any {
+public class AnyLiteral extends AnnotationLiteral<Any> {
+    private static final long serialVersionUID = 1L;
 }

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/BeanProvider.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/BeanProvider.java?rev=1241110&r1=1241109&r2=1241110&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/BeanProvider.java
(original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/util/BeanProvider.java
Mon Feb  6 18:55:07 2012
@@ -19,7 +19,6 @@ package org.apache.camel.component.cdi.u
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -80,10 +79,9 @@ public final class BeanProvider {
                 return null;
             }
 
-            throw new IllegalStateException("Could not find beans for Type=" + type
-                    + " and qualifiers:" + Arrays.toString(qualifiers));
+            throw new IllegalStateException("Could not find beans for Type='" + type
+                    + "' and qualifiers: " + Arrays.toString(qualifiers));
         }
-
         return getContextualReference(type, beanManager, beans);
     }
 
@@ -126,11 +124,9 @@ public final class BeanProvider {
             if (optional) {
                 return null;
             }
-
             throw new IllegalStateException("Could not find beans for Type=" + type
                     + " and name:" + name);
         }
-
         return getContextualReference(type, beanManager, beans);
     }
 
@@ -151,8 +147,7 @@ public final class BeanProvider {
      * @param <T>      target type
      * @return the resolved list of Contextual Reference or an empty-list if optional is
true
      */
-    public static <T> List<T> getContextualReferences(Class<T> type,
-                                                      boolean optional) {
+    public static <T> List<T> getContextualReferences(Class<T> type, boolean
optional) {
         return getContextualReferences(type, optional, true);
     }
 
@@ -168,9 +163,9 @@ public final class BeanProvider {
      * @param <T>                       target type
      * @return the resolved list of Contextual Reference or an empty-list if optional is
true
      */
-    public static <T> List<T> getContextualReferences(Class<T> type,
-                                                      boolean optional,
-                                                      boolean includeDefaultScopedBeans)
{
+    public static <T> List<T> getContextualReferences(
+            Class<T> type, boolean optional, boolean includeDefaultScopedBeans) {
+
         BeanManager beanManager = getBeanManager();
         Set<Bean<?>> beans = beanManager.getBeans(type, new AnyLiteral());
 
@@ -190,7 +185,7 @@ public final class BeanProvider {
 
         for (Bean<?> bean : beans) {
             result.add(getContextualReference(type, beanManager,
-                    new HashSet<Bean<?>>((Collection) Arrays.asList(new Object[]{bean}))));
+                new HashSet<Bean<?>>(Arrays.asList(new Bean<?>[]{bean}))));
         }
         return result;
     }
@@ -217,7 +212,7 @@ public final class BeanProvider {
 
         for (Bean<?> bean : beans) {
             result.put(bean.getName(), getContextualReference(type, beanManager,
-                    new HashSet<Bean<?>>((Collection) Arrays.asList(new Object[]{bean}))));
+                    new HashSet<Bean<?>>(Arrays.asList(new Bean<?>[]{bean}))));
         }
         return result;
     }
@@ -247,14 +242,11 @@ public final class BeanProvider {
      * @param <T>         target type
      * @return the contextual reference
      */
+    @SuppressWarnings("unchecked")
     private static <T> T getContextualReference(Class<T> type, BeanManager beanManager,
Set<Bean<?>> beans) {
         Bean<?> bean = beanManager.resolve(beans);
-
         CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
-
-        @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
-        T result = (T) beanManager.getReference(bean, type, creationalContext);
-        return result;
+        return (T)beanManager.getReference(bean, type, creationalContext);
     }
 
     /**

Modified: camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContainerBeanManagerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContainerBeanManagerTest.java?rev=1241110&r1=1241109&r2=1241110&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContainerBeanManagerTest.java
(original)
+++ camel/trunk/components/camel-cdi/src/test/java/org/apache/camel/cdi/CdiContainerBeanManagerTest.java
Mon Feb  6 18:55:07 2012
@@ -19,13 +19,10 @@ package org.apache.camel.cdi;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.inject.Inject;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.cdi.store.Item;
-import org.apache.camel.cdi.store.ShoppingBean;
 import org.apache.camel.component.cdi.CdiBeanRegistry;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
@@ -35,23 +32,27 @@ import org.apache.webbeans.cditest.CdiTe
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 public class CdiContainerBeanManagerTest extends CamelTestSupport {
+    private static final Logger LOG = LoggerFactory.getLogger(CdiContainerBeanManagerTest.class);
+
     private MockEndpoint resultEndpoint;
     private ProducerTemplate template;
 
     private CdiTestContainer cdiContainer;
 
-    @Inject
-    private ShoppingBean shoppingBean;
+    // @Inject
+    // private ShoppingBean shoppingBean;
 
     @Before
     public void setUp() throws Exception {
         cdiContainer = CdiTestContainerLoader.getCdiContainer();
         cdiContainer.bootContainer();
 
-        System.out.println(">> Container started and bean manager instantiated !");
+        LOG.info(">> Container started and bean manager instantiated !");
 
         // Camel
         context = new DefaultCamelContext(new CdiBeanRegistry());
@@ -61,7 +62,7 @@ public class CdiContainerBeanManagerTest
         resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
         template = context.createProducerTemplate();
 
-        System.out.println(">> Camel started !");
+        LOG.info(">> Camel started !");
     }
 
     @After
@@ -78,13 +79,19 @@ public class CdiContainerBeanManagerTest
         assertMockEndpointsSatisfied();
 
         Exchange exchange = resultEndpoint.getExchanges().get(0);
-        List<Item> results = (List<Item>) exchange.getIn().getBody();
+        List<?> results = exchange.getIn().getBody(List.class);
+        ArrayList<Item> expected = itemsExpected();
+        assertNotNull(results);
+        assertNotNull(expected);
+        assertEquals(expected.size(), results.size());
 
-        Object[] items = (Object[]) results.toArray();
-        Object[] itemsExpected = (Object[]) itemsExpected().toArray();
+        Object[] items = results.toArray();
+        Object[] itemsExpected = itemsExpected().toArray();
         for (int i = 0; i < items.length; ++i) {
-            Item itemExpected = (Item)items[i];
-            Item itemReceived = (Item)itemsExpected[i];
+            assertTrue(itemsExpected[i] != null && (itemsExpected[i] instanceof Item));
+            assertTrue(items[i] != null && (items[i] instanceof Item));
+            Item itemExpected = (Item)itemsExpected[i];
+            Item itemReceived = (Item)items[i];
             assertEquals(itemExpected.getName(), itemReceived.getName());
             assertEquals(itemExpected.getPrice(), itemReceived.getPrice());
         }
@@ -93,15 +100,9 @@ public class CdiContainerBeanManagerTest
 
     private ArrayList<Item> itemsExpected() {
         ArrayList<Item> products = new ArrayList<Item>();
-        Item defaultItem = new Item();
-        defaultItem.setName("Default Item");
-        defaultItem.setPrice(1000L);
-
         for (int i = 1; i < 10; i++) {
-            Item item = new Item("Item-" + i, i * 1500L);
-            products.add(item);
+            products.add(new Item("Item-" + i, 1500L * i));
         }
-
         return products;
     }
 
@@ -112,13 +113,9 @@ public class CdiContainerBeanManagerTest
             public void configure() throws Exception {
 
                 from("direct:inject")
-                        .beanRef("shoppingBean", "listAllProducts")
-                        .to("mock:result");
-
+                    .beanRef("shoppingBean", "listAllProducts")
+                    .to("mock:result");
             }
-
         };
     }
-
-
 }



Mime
View raw message