Ray Milkey | d03eda0 | 2015-01-09 14:58:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onlab.packet.Ethernet; |
| 20 | import org.onosproject.codec.CodecContext; |
| 21 | import org.onosproject.codec.JsonCodec; |
| 22 | |
| 23 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 24 | |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.notNullValue; |
| 27 | import static org.onosproject.codec.impl.EthernetJsonMatcher.matchesEthernet; |
| 28 | |
| 29 | /** |
| 30 | * Unit test for Ethernet class codec. |
| 31 | */ |
| 32 | public class EthernetCodecTest { |
| 33 | |
| 34 | /** |
| 35 | * Unit test for the ethernet object codec. |
| 36 | */ |
| 37 | @Test |
| 38 | public void ethernetCodecTest() { |
| 39 | final CodecContext context = new MockCodecContext(); |
| 40 | final JsonCodec<Ethernet> ethernetCodec = context.codec(Ethernet.class); |
| 41 | assertThat(ethernetCodec, notNullValue()); |
| 42 | |
| 43 | final Ethernet eth1 = new Ethernet(); |
| 44 | eth1.setSourceMACAddress("11:22:33:44:55:01"); |
| 45 | eth1.setDestinationMACAddress("11:22:33:44:55:02"); |
| 46 | eth1.setPad(true); |
| 47 | eth1.setEtherType(Ethernet.TYPE_ARP); |
| 48 | eth1.setPriorityCode((byte) 7); |
| 49 | eth1.setVlanID((short) 33); |
| 50 | |
| 51 | final ObjectNode eth1Json = ethernetCodec.encode(eth1, context); |
| 52 | assertThat(eth1Json, notNullValue()); |
| 53 | assertThat(eth1Json, matchesEthernet(eth1)); |
| 54 | } |
| 55 | } |