servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r778756 [2/2] - in /servicemix/components/engines/servicemix-bean/trunk: ./ src/main/java/org/apache/servicemix/bean/ src/main/java/org/apache/servicemix/bean/pojos/ src/main/java/org/apache/servicemix/bean/support/ src/test/java/org/apache...
Date Tue, 26 May 2009 15:38:26 GMT
Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/HolderTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/HolderTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/HolderTest.java
(added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/HolderTest.java
Tue May 26 15:38:25 2009
@@ -0,0 +1,100 @@
+/*
+ * 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.servicemix.bean.support;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.jbi.exception.FaultException;
+import org.apache.servicemix.tck.mock.MockExchangeFactory;
+
+/**
+ * Test cases for {@link Holder}
+ */
+public class HolderTest extends TestCase {
+    
+    private final MessageExchangeFactory factory = new MockExchangeFactory(); 
+    
+    private Holder holder;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        holder = new Holder();
+    }
+    
+    public void testBasicFunctionality() throws Exception {
+        Executors.newSingleThreadExecutor().execute(new Runnable() {
+            public void run() {
+                try {
+                    assertNotNull(holder.get(1, TimeUnit.SECONDS));
+                    assertTrue(holder.isDone());
+                } catch (InterruptedException e) {
+                    fail(e.getMessage());
+                } catch (ExecutionException e) {
+                    fail(e.getMessage());
+                }
+            }
+        });
+        
+        MessageExchange exchange = factory.createInOutExchange();
+        exchange.setStatus(ExchangeStatus.DONE);
+        NormalizedMessage out = exchange.createMessage();
+        exchange.setMessage(out, "out");
+
+        //this should kick off the tests in the background thread
+        holder.set(exchange);
+    }
+    
+    public void testCancel() throws Exception {
+        holder.cancel(true);
+        assertTrue(holder.isCancelled());
+    }
+    
+    public void testWrapFaults() throws Exception {
+        MessageExchange exchange = factory.createInOutExchange();
+        exchange.setStatus(ExchangeStatus.ACTIVE);
+        exchange.setFault(exchange.createFault());
+        assertExecutionExceptionOnGet(exchange, FaultException.class);
+    }
+    
+    public void testWrapErrors() throws Exception {
+        MessageExchange exchange = factory.createInOutExchange();
+        exchange.setStatus(ExchangeStatus.ERROR);
+        exchange.setError(new RuntimeException("This thing completely went wrong..."));
+        assertExecutionExceptionOnGet(exchange, RuntimeException.class);
+    }
+
+    private void assertExecutionExceptionOnGet(MessageExchange exchange, Class<?> type)
throws InterruptedException {
+        try {
+            holder.set(exchange);
+            holder.get();
+            fail("Should have thrown an ExecutionException");
+        } catch (ExecutionException e) {
+            assertEquals(type, e.getCause().getClass());
+        }
+    }
+
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/HolderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ReflectionUtilsTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ReflectionUtilsTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ReflectionUtilsTest.java
(added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ReflectionUtilsTest.java
Tue May 26 15:38:25 2009
@@ -0,0 +1,44 @@
+/*
+ * 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.servicemix.bean.support;
+
+import javax.annotation.PostConstruct;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link ReflectionUtils}
+ */
+public class ReflectionUtilsTest extends TestCase {
+    
+    public void testInvoke() throws Exception {
+        Pojo pojo = new Pojo();
+        assertFalse(pojo.constructed);
+        ReflectionUtils.callLifecycleMethod(pojo, PostConstruct.class);
+        assertTrue(pojo.constructed);
+    }
+    
+    private static final class Pojo {
+        
+        private boolean constructed;
+
+        @PostConstruct
+        public void doSomething() {
+            constructed = true;
+        }
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ReflectionUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/RequestTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/RequestTest.java?rev=778756&r1=778755&r2=778756&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/RequestTest.java
(original)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/RequestTest.java
Tue May 26 15:38:25 2009
@@ -16,6 +16,9 @@
  */
 package org.apache.servicemix.bean.support;
 
+import java.lang.reflect.Method;
+import java.util.Map;
+
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
 
@@ -67,6 +70,14 @@
         assertEquals("We shouldn't have duplicate MessageExchange instances", 1, request.getExchanges().size());
     }
     
+    public void testLazyCreateCallbacks() throws Exception {
+        MessageExchange exchange = createMockExchange("my-exchange-id");
+        Request request = new Request("my-correlation-id", new Object(), exchange);
+        Map<Method, Boolean> callbacks = request.getCallbacks();
+        assertNotNull(callbacks);
+        assertSame(callbacks, request.getCallbacks());
+    }
+    
     private MessageExchange createMockExchange(String id) {
         MockMessageExchange exchange = new MockMessageExchange();
         exchange.setExchangeId(id);

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ResolverUtilTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ResolverUtilTest.java?rev=778756&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ResolverUtilTest.java
(added)
+++ servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ResolverUtilTest.java
Tue May 26 15:38:25 2009
@@ -0,0 +1,73 @@
+/*
+ * 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.servicemix.bean.support;
+
+import org.apache.camel.util.ResolverUtil.IsA;
+import org.apache.servicemix.bean.Endpoint;
+import org.apache.servicemix.bean.beans.AutoDeployedBean;
+import org.apache.servicemix.bean.beans.ListenerBean;
+import org.apache.servicemix.bean.beans.PlainBean;
+import org.apache.servicemix.bean.support.ResolverUtil.AnnotatedWith;
+import org.apache.servicemix.jbi.listener.MessageExchangeListener;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link ResolverUtil}
+ */
+public class ResolverUtilTest extends TestCase {
+    
+    public void testIsA() throws Exception {
+        IsA test = new IsA(MessageExchangeListener.class);
+        assertFalse(test.matches(PlainBean.class));
+        assertTrue(test.matches(ListenerBean.class));
+    }
+    
+    public void testAnnotatedWith() throws Exception {
+        AnnotatedWith test = new AnnotatedWith(Endpoint.class);
+        assertFalse(test.matches(PlainBean.class));
+        assertTrue(test.matches(AutoDeployedBean.class));
+    }
+    
+    public void testFindImplementations() throws Exception {
+        ResolverUtil util = new ResolverUtil();
+        util.findImplementations(MessageExchangeListener.class, "org.apache.servicemix.bean.beans");
+        // should have found 3 implementations
+        assertEquals(3, util.getClasses().size());
+        // and make sure we don't break by omitting the package to search
+        util.findImplementations(MessageExchangeListener.class, null);
+        assertEquals(3, util.getClasses().size());
+    }
+    
+    public void testFindImplementationsInJar() throws Exception {
+        ResolverUtil util = new ResolverUtil();
+        util.findImplementations(MessageExchangeListener.class, "org.apache.servicemix.common");
+        // should have found 3 implementations
+        assertNotNull(util.getClasses());
+        assertFalse(util.getClasses().isEmpty());
+    }
+    
+    public void testFindAnnotated() throws Exception {
+        ResolverUtil util = new ResolverUtil();
+        util.findAnnotated(Endpoint.class, "org.apache.servicemix.bean.beans");
+        // should have found 1 implementation
+        assertEquals(1, util.getClasses().size());
+        // and make sure we don't break by omitting the package to search
+        util.findAnnotated(Endpoint.class, null);
+        assertEquals(1, util.getClasses().size());
+    }
+}

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/java/org/apache/servicemix/bean/support/ResolverUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: servicemix/components/engines/servicemix-bean/trunk/src/test/resources/attachment.png
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-bean/trunk/src/test/resources/attachment.png?rev=778756&view=auto
==============================================================================
Binary file - no diff available.

Propchange: servicemix/components/engines/servicemix-bean/trunk/src/test/resources/attachment.png
------------------------------------------------------------------------------
    svn:mime-type = image/png



Mime
View raw message