blob: 8f59106826cdaba5bf5d9f11fdc44885489d92b8 [file] [log] [blame]
Ray Milkeyd03eda02015-01-09 14:58:48 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeyd03eda02015-01-09 14:58:48 -08003 *
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 */
16package org.onosproject.codec.impl;
17
18import org.junit.Test;
19import org.onlab.packet.Ethernet;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22
23import com.fasterxml.jackson.databind.node.ObjectNode;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.notNullValue;
27import static org.onosproject.codec.impl.EthernetJsonMatcher.matchesEthernet;
28
29/**
30 * Unit test for Ethernet class codec.
31 */
32public 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}