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  package org.apache.mina.coap.codec;
    20
    21  import static org.apache.mina.coap.codec.TestMessages.*;
    22
    23  import java.nio.ByteBuffer;
    24
    25  import org.apache.mina.coap.CoapMessage;
    26  import org.apache.mina.util.ByteBufferDumper;
    27  import org.junit.Assert;
    28  import org.junit.Test;
    29
    30  /**
    31   * Unit tests for {@link CoapEncoder}
    32   */
    33  public class CoapEncoderTest {
    34
    35      private CoapEncoder encoder = new CoapEncoder();
    36
    37      @Test
    38      public void no_content_no_option() {
    39          CoapMessage message = NO_CONTENT_NO_OPTION;
    40          ByteBuffer encoded = encoder.encode(message, null);
    41          Assert.assertEquals(NO_CONTENT_NO_OPTION_HEX, ByteBufferDumper.toHex(encoded));
    42
    43      }
    44
    45      @Test
    46      public void some_content_no_option() {
    47          CoapMessage message = SOME_CONTENT_NO_OPTION;
    48          ByteBuffer encoded = encoder.encode(message, null);
    49
    50          Assert.assertEquals(SOME_CONTENT_NO_OPTION_HEX, ByteBufferDumper.toHex(encoded));
    51
    52      }
    53
    54      @Test
    55      public void payload_and_one_option() {
    56          CoapMessage message = PAYLOAD_AND_ONE_OPTION;
    57          ByteBuffer encoded = encoder.encode(message, null);
    58          Assert.assertEquals(PAYLOAD_AND_ONE_OPTION_HEX, ByteBufferDumper.toHex(encoded));
    59
    60      }
    61
    62      @Test
    63      public void payload_and_multiple_option() {
    64          CoapMessage message = PAYLOAD_AND_MULTIPLE_OPTION;
    65          ByteBuffer encoded = encoder.encode(message, null);
    66          Assert.assertEquals(PAYLOAD_AND_MULTIPLE_OPTION_HEX, ByteBufferDumper.toHex(encoded));
    67      }
    68
    69      @Test
    70      public void observe() {
    71          CoapMessage message = OBSERVE;
    72          ByteBuffer encoded = encoder.encode(message, null);
    73          Assert.assertEquals(OBSERVE_HEX, ByteBufferDumper.toHex(encoded));
    74      }
    75  }