View Javadoc

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
    10   *    http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   *  Unless required by applicable law or agreed to in writing,
    13   *  software distributed under the License is distributed on an
    14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   *  KIND, either express or implied.  See the License for the
    16   *  specific language governing permissions and limitations
    17   *  under the License.
    18   *
    19   */
    20  package org.apache.mina.codec.delimited.serialization;
    21
    22  import java.io.Serializable;
    23  import java.util.LinkedList;
    24  import java.util.List;
    25
    26  import org.apache.mina.codec.delimited.IoBufferDecoder;
    27  import org.apache.mina.codec.delimited.ByteBufferEncoder;
    28
    29  /**
    30   * A {@link JavaNativeMessageEncoder} and {@link JavaNativeMessageDecoder} test.
    31   *
    32   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
    33   */
    34  public class JavaNativeTest extends GenericSerializerTest<JavaNativeTest.TestBean> {
    35      static public class TestBean implements Serializable {
    36          private static final long serialVersionUID = 1L;
    37
    38          @Override
    39          public int hashCode() {
    40              final int prime = 31;
    41              int result = 1;
    42              result = prime * result + ((a == null) ? 0 : a.hashCode());
    43              result = prime * result + b;
    44              long temp;
    45              temp = Double.doubleToLongBits(c);
    46              result = prime * result + (int) (temp ^ (temp >>> 32));
    47              return result;
    48          }
    49
    50          @Override
    51          public boolean equals(Object obj) {
    52              if (this == obj) {
    53                  return true;
    54              }
    55              if (obj == null) {
    56                  return false;
    57              }
    58              if (getClass() != obj.getClass()) {
    59                  return false;
    60              }
    61              TestBean other = (TestBean) obj;
    62              if (a == null) {
    63                  if (other.a != null) {
    64                      return false;
    65                  }
    66              } else if (!a.equals(other.a)) {
    67                  return false;
    68              }
    69              if (b != other.b) {
    70                  return false;
    71              }
    72              if (Double.doubleToLongBits(c) != Double.doubleToLongBits(other.c)) {
    73                  return false;
    74              }
    75              return true;
    76          }
    77
    78          public TestBean(String a, int b, double c) {
    79              super();
    80              this.a = a;
    81              this.b = b;
    82              this.c = c;
    83          }
    84
    85          private final String a;
    86
    87          private final int b;
    88
    89          private final double c;
    90      }
    91
    92      @Override
    93      public List<TestBean> getObjects() {
    94          List<TestBean> list = new LinkedList<TestBean>();
    95          list.add(new TestBean("Hello", 86, 12.34));
    96          list.add(new TestBean("MINA", 94, 67.89));
    97          return list;
    98      }
    99
    100     @Override
    101     public IoBufferDecoder<TestBean> getDecoder() throws Exception {
    102         return new JavaNativeMessageDecoder<TestBean>();
    103     }
    104
    105     @Override
    106     public ByteBufferEncoder<TestBean> getEncoder() throws Exception {
    107         return new JavaNativeMessageEncoder<TestBean>();
    108     }
    109
    110 }