blob: 7d9835f77889ee8b2ac654d0f493221862f4a932 [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.DefaultLink;
27import org.onosproject.net.Link;
28import org.onosproject.net.device.DeviceService;
29import org.onosproject.net.device.DeviceServiceAdapter;
30
31/**
32 * Unit test for LinkCodec.
33 */
34public class LinkCodecTest {
35
Ray Milkey2693bda2016-01-22 16:08:14 -080036 private final Link link = DefaultLink.builder()
37 .providerId(JsonCodecUtils.PID)
38 .src(JsonCodecUtils.CP1)
39 .dst(JsonCodecUtils.CP2)
40 .type(Link.Type.DIRECT)
41 .state(Link.State.ACTIVE)
42 .isExpected(false)
43 .annotations(JsonCodecUtils.A1)
44 .build();
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070045
46 @Test
47 public void linkCodecTest() {
48 final MockCodecContext context = new MockCodecContext();
49 context.registerService(DeviceService.class, new DeviceServiceAdapter());
50 final JsonCodec<Link> codec = context.codec(Link.class);
51 assertThat(codec, is(notNullValue()));
52 final Link pojoIn = link;
53
54 assertJsonEncodable(context, codec, pojoIn);
55 }
56}