You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2008/05/20 04:17:19 UTC

svn commit: r658088 - in /mina/trunk/core/src/test/java/org/apache/mina: common/IoBufferTest.java util/Bar.java util/Foo.java

Author: trustin
Date: Mon May 19 19:17:19 2008
New Revision: 658088

URL: http://svn.apache.org/viewvc?rev=658088&view=rev
Log:
DIRMINA-581 - IoBuffer.putObject() doesn't function right on objects with inheritance
* Added a test method that tests if the serialization and deserialization of an inherited object works or not

Added:
    mina/trunk/core/src/test/java/org/apache/mina/util/Bar.java   (with props)
    mina/trunk/core/src/test/java/org/apache/mina/util/Foo.java   (with props)
Modified:
    mina/trunk/core/src/test/java/org/apache/mina/common/IoBufferTest.java

Modified: mina/trunk/core/src/test/java/org/apache/mina/common/IoBufferTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/common/IoBufferTest.java?rev=658088&r1=658087&r2=658088&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/common/IoBufferTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/common/IoBufferTest.java Mon May 19 19:17:19 2008
@@ -35,6 +35,8 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.mina.util.Bar;
+
 /**
  * Tests {@link IoBuffer}.
  *
@@ -570,6 +572,28 @@
         Assert.assertNotSame(o, o2);
     }
 
+    public void testInheritedObjectSerialization() throws Exception {
+        IoBuffer buf = IoBuffer.allocate(16);
+        buf.setAutoExpand(true);
+
+        Bar expected = new Bar();
+        expected.setFooValue(0x12345678);
+        expected.setBarValue(0x90ABCDEF);
+
+        // Test writing an object.
+        buf.putObject(expected);
+
+        // Test reading an object.
+        buf.clear();
+        Bar actual = (Bar) buf.getObject();
+        Assert.assertSame(Bar.class, actual.getClass());
+        Assert.assertEquals(expected.getFooValue(), actual.getFooValue());
+        Assert.assertEquals(expected.getBarValue(), actual.getBarValue());
+
+        // This assertion is just to make sure that deserialization occurred.
+        Assert.assertNotSame(expected, actual);
+    }
+
     public void testSweepWithZeros() throws Exception {
         IoBuffer buf = IoBuffer.allocate(4);
         buf.putInt(0xdeadbeef);

Added: mina/trunk/core/src/test/java/org/apache/mina/util/Bar.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/util/Bar.java?rev=658088&view=auto
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/util/Bar.java (added)
+++ mina/trunk/core/src/test/java/org/apache/mina/util/Bar.java Mon May 19 19:17:19 2008
@@ -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.mina.util;
+
+import org.apache.mina.common.IoBufferTest;
+
+/**
+ * The subtype of {@link Foo}.  It is used to test the serialization of inherited object
+ * in {@link IoBufferTest}.
+ *
+ * @author The Apache MINA project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class Bar extends Foo {
+
+    private static final long serialVersionUID = -7360624845308368521L;
+
+    private int barValue;
+
+    public int getBarValue() {
+        return barValue;
+    }
+
+    public void setBarValue(int barValue) {
+        this.barValue = barValue;
+    }
+}

Propchange: mina/trunk/core/src/test/java/org/apache/mina/util/Bar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: mina/trunk/core/src/test/java/org/apache/mina/util/Bar.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: mina/trunk/core/src/test/java/org/apache/mina/util/Foo.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/util/Foo.java?rev=658088&view=auto
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/util/Foo.java (added)
+++ mina/trunk/core/src/test/java/org/apache/mina/util/Foo.java Mon May 19 19:17:19 2008
@@ -0,0 +1,46 @@
+/*
+ *  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.mina.util;
+
+import java.io.Serializable;
+
+import org.apache.mina.common.IoBufferTest;
+
+/**
+ * The parent class of {@link Bar}.  It is used to test the serialization of inherited object
+ * in {@link IoBufferTest}.
+ *
+ * @author The Apache MINA project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class Foo implements Serializable {
+
+    private static final long serialVersionUID = 6467037996528575216L;
+
+    private int fooValue;
+
+    public int getFooValue() {
+        return fooValue;
+    }
+
+    public void setFooValue(int fooValue) {
+        this.fooValue = fooValue;
+    }
+}

Propchange: mina/trunk/core/src/test/java/org/apache/mina/util/Foo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: mina/trunk/core/src/test/java/org/apache/mina/util/Foo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date