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 org.apache.mina.util.ByteBufferDumper;
24  import org.junit.Assert;
25  import org.junit.Test;
26  
27  /**
28   * Unit test for {@link CoapDecoder}
29   */
30  public class CoapDecoderTest {
31  
32      private CoapDecoder decoder = new CoapDecoder();
33  
34      @Test
35      public void some_content_no_option() {
36          Assert.assertEquals(SOME_CONTENT_NO_OPTION,
37                  decoder.decode(ByteBufferDumper.fromHexString(SOME_CONTENT_NO_OPTION_HEX), null));
38      }
39  
40      @Test
41      public void no_content_no_option() {
42          Assert.assertEquals(NO_CONTENT_NO_OPTION,
43                  decoder.decode(ByteBufferDumper.fromHexString(NO_CONTENT_NO_OPTION_HEX), null));
44      }
45  
46      @Test
47      public void payload_and_one_option() {
48          Assert.assertEquals(PAYLOAD_AND_ONE_OPTION,
49                  decoder.decode(ByteBufferDumper.fromHexString(PAYLOAD_AND_ONE_OPTION_HEX), null));
50      }
51  
52      @Test
53      public void payload_and_multiple_option() {
54          Assert.assertEquals(PAYLOAD_AND_MULTIPLE_OPTION,
55                  decoder.decode(ByteBufferDumper.fromHexString(PAYLOAD_AND_MULTIPLE_OPTION_HEX), null));
56      }
57  
58      @Test
59      public void observe_message() {
60          Assert.assertEquals(OBSERVE, decoder.decode(ByteBufferDumper.fromHexString(OBSERVE_HEX), null));
61      }
62  }