You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ce...@apache.org on 2012/10/31 15:23:46 UTC

svn commit: r1404165 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/util/ test/java/org/apache/activemq/transport/tcp/ test/java/org/apache/activemq/util/

Author: ceposta
Date: Wed Oct 31 14:23:45 2012
New Revision: 1404165

URL: http://svn.apache.org/viewvc?rev=1404165&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-4145 IntrospectionSupport does not convert from primitive to Wrapper classes appropriately

Added two tests to show the conversion was not happening properly, and added an identity converter to the TypeConversionSupport to do a pass-through conversion on types that are the same after a primitive to wrapper class conversion

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TcpTransportServerTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/IntrospectionSupportTest.java
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java?rev=1404165&r1=1404164&r2=1404165&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java Wed Oct 31 14:23:45 2012
@@ -29,6 +29,13 @@ import org.apache.activemq.command.Activ
  */
 public final class TypeConversionSupport {
 
+    private static final Converter IDENTITY_CONVERTER = new Converter() {
+        @Override
+        public Object convert(Object value) {
+            return value;
+        }
+    };
+
     private static class ConversionKey {
         final Class from;
         final Class to;
@@ -191,6 +198,10 @@ public final class TypeConversionSupport
             to = convertPrimitiveTypeToWrapperType(to);
         }
 
+        if (from.equals(to)) {
+            return IDENTITY_CONVERTER;
+        }
+
         return CONVERSION_MAP.get(new ConversionKey(from, to));
     }
 

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TcpTransportServerTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TcpTransportServerTest.java?rev=1404165&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TcpTransportServerTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/TcpTransportServerTest.java Wed Oct 31 14:23:45 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.activemq.transport.tcp;
+
+import junit.framework.TestCase;
+import org.apache.activemq.transport.*;
+
+import javax.net.ServerSocketFactory;
+import java.net.Socket;
+import java.net.URI;
+import java.util.HashMap;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class TcpTransportServerTest extends TestCase{
+
+    public void testDefaultPropertiesSetOnTransport() throws Exception {
+        TcpTransportServer server = (TcpTransportServer) TransportFactory.bind(new URI("tcp://localhost:61616?trace=true"));
+        server.setTransportOption(new HashMap<String, Object>());
+
+        server.setAcceptListener(new TransportAcceptListener() {
+            @Override
+            public void onAccept(Transport transport) {
+                assertTrue("This transport does not have a TransportLogger!!", hasTransportLogger(transport));
+            }
+
+            @Override
+            public void onAcceptError(Exception error) {
+                fail("Should not have received an error!");
+            }
+        });
+
+        server.start();
+
+
+        Socket socket = new Socket("localhost", 61616);
+        server.handleSocket(socket);
+        server.stop();
+
+
+    }
+
+    private boolean hasTransportLogger(Transport transport) {
+        boolean end = false;
+
+        Transport current = transport;
+        while(!end) {
+
+            if (current instanceof TransportFilter) {
+                TransportFilter filter = (TransportFilter) current;
+
+                if(filter instanceof TransportLogger){
+                    return true;
+                }
+
+                current = filter.getNext();
+            }
+            else {
+                end = true;
+            }
+        }
+
+        return false;
+    }
+}

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/IntrospectionSupportTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/IntrospectionSupportTest.java?rev=1404165&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/IntrospectionSupportTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/IntrospectionSupportTest.java Wed Oct 31 14:23:45 2012
@@ -0,0 +1,53 @@
+/**
+ * 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.activemq.util;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
+ */
+public class IntrospectionSupportTest extends TestCase {
+
+    class DummyClass {
+        private boolean trace;
+
+        DummyClass(boolean trace) {
+            this.trace = trace;
+        }
+
+        public boolean isTrace() {
+            return trace;
+        }
+
+        public void setTrace(boolean trace) {
+            this.trace = trace;
+        }
+    }
+
+    public void testSetPropertyPrimitiveWithWrapperValue() {
+        // Wrapper value
+        Boolean value = Boolean.valueOf(true);
+
+        DummyClass dummyClass = new DummyClass(false);
+
+        // dummy field expects a primitive
+        IntrospectionSupport.setProperty(dummyClass, "trace", value);
+
+        assertTrue(dummyClass.isTrace());
+    }
+}