HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 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.DefaultDevice; |
| 27 | import org.onosproject.net.DefaultPort; |
| 28 | import org.onosproject.net.Device; |
| 29 | import org.onosproject.net.Port; |
| 30 | import org.onosproject.net.device.DeviceService; |
| 31 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 32 | |
| 33 | /** |
| 34 | * Unit test for PortCodec. |
| 35 | */ |
| 36 | public 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 | } |