HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [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 | |
| 17 | package org.onosproject.codec.impl; |
| 18 | |
| 19 | import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | import static org.hamcrest.Matchers.is; |
| 21 | import static org.hamcrest.Matchers.notNullValue; |
| 22 | import static org.onosproject.codec.impl.JsonCodecUtils.assertJsonEncodable; |
| 23 | |
| 24 | import org.junit.Test; |
| 25 | import org.onosproject.codec.JsonCodec; |
| 26 | import org.onosproject.net.DefaultLink; |
| 27 | import org.onosproject.net.Link; |
| 28 | import org.onosproject.net.device.DeviceService; |
| 29 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 30 | |
| 31 | /** |
| 32 | * Unit test for LinkCodec. |
| 33 | */ |
| 34 | public class LinkCodecTest { |
| 35 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 36 | 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 Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 45 | |
| 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 | } |