blob: 282867d9e155bb3c5d979f8c3749a0815afe65ed [file] [log] [blame]
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -07003 *
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
17package org.onosproject.codec.impl;
18
19import static org.hamcrest.MatcherAssert.assertThat;
20import static org.hamcrest.Matchers.is;
21import static org.hamcrest.Matchers.notNullValue;
22import static org.onosproject.codec.impl.JsonCodecUtils.assertJsonEncodable;
23
24import org.junit.Test;
25import org.onosproject.codec.JsonCodec;
26import org.onosproject.net.DefaultDevice;
27import org.onosproject.net.DefaultPort;
28import org.onosproject.net.Device;
29import org.onosproject.net.Port;
30import org.onosproject.net.device.DeviceService;
31import org.onosproject.net.device.DeviceServiceAdapter;
32
33/**
34 * Unit test for PortCodec.
35 */
36public class PortCodecTest {
37
38
39
40 private final Device device = new DefaultDevice(JsonCodecUtils.PID,
41 JsonCodecUtils.DID1,
42 Device.Type.SWITCH,
43 JsonCodecUtils.MFR,
44 JsonCodecUtils.HW,
45 JsonCodecUtils.SW1,
46 JsonCodecUtils.SN,
47 JsonCodecUtils.CID,
48 JsonCodecUtils.A1);
49
50 private final Port port = new DefaultPort(device,
51 JsonCodecUtils.P1,
52 true,
53 JsonCodecUtils.A1);
54
55 @Test
56 public void portCodecTest() {
57 final MockCodecContext context = new MockCodecContext();
58 context.registerService(DeviceService.class, new DeviceServiceAdapter());
59 final JsonCodec<Port> codec = context.codec(Port.class);
60 assertThat(codec, is(notNullValue()));
61 final Port pojoIn = port;
62
63 assertJsonEncodable(context, codec, pojoIn);
64 }
65
66}