HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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.notNullValue; |
| 21 | import static org.hamcrest.Matchers.is; |
| 22 | import static org.onosproject.codec.impl.JsonCodecUtils.assertJsonEncodable; |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 23 | import com.google.common.collect.ImmutableMap; |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 24 | import org.junit.Test; |
| 25 | import org.onosproject.codec.JsonCodec; |
| 26 | import org.onosproject.net.DefaultDevice; |
| 27 | import org.onosproject.net.Device; |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 28 | import static org.easymock.EasyMock.replay; |
| 29 | import static org.easymock.EasyMock.expect; |
| 30 | import static org.easymock.EasyMock.createMock; |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 31 | import org.onosproject.net.device.DeviceService; |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 32 | import org.onosproject.net.driver.DriverService; |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 33 | import org.onosproject.net.device.DeviceServiceAdapter; |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 34 | import org.onosproject.net.driver.DefaultDriver; |
| 35 | import org.onosproject.net.driver.TestBehaviourImpl; |
| 36 | import org.onosproject.net.driver.TestBehaviour; |
| 37 | import org.onosproject.net.driver.TestBehaviourTwo; |
| 38 | import org.onosproject.net.driver.TestBehaviourTwoImpl; |
| 39 | |
| 40 | import java.util.ArrayList; |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Unit test for DeviceCodec. |
| 44 | */ |
| 45 | public class DeviceCodecTest { |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 46 | DriverService mockDriverService = createMock(DriverService.class); |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 47 | |
| 48 | private Device device = new DefaultDevice(JsonCodecUtils.PID, |
| 49 | JsonCodecUtils.DID1, |
| 50 | Device.Type.SWITCH, |
| 51 | JsonCodecUtils.MFR, |
| 52 | JsonCodecUtils.HW, |
| 53 | JsonCodecUtils.SW1, |
| 54 | JsonCodecUtils.SN, |
| 55 | JsonCodecUtils.CID, |
| 56 | JsonCodecUtils.A1); |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 57 | private DefaultDriver driver = new DefaultDriver("ovs", new ArrayList<>(), "Circus", "lux", "1.2a", |
| 58 | ImmutableMap.of(TestBehaviour.class, |
| 59 | TestBehaviourImpl.class, |
| 60 | TestBehaviourTwo.class, |
| 61 | TestBehaviourTwoImpl.class), |
| 62 | ImmutableMap.of("foo", "bar")); |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 63 | |
| 64 | @Test |
| 65 | public void deviceCodecTest() { |
| 66 | final MockCodecContext context = new MockCodecContext(); |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 67 | |
| 68 | expect(mockDriverService.getDriver(JsonCodecUtils.DID1)) |
| 69 | .andReturn(driver) |
| 70 | .anyTimes(); |
| 71 | |
| 72 | replay(mockDriverService); |
| 73 | |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 74 | context.registerService(DeviceService.class, new DeviceServiceAdapter()); |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 75 | context.registerService(DriverService.class, mockDriverService); |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 76 | final JsonCodec<Device> codec = context.codec(Device.class); |
| 77 | assertThat(codec, is(notNullValue())); |
kalagesa | 4201954 | 2017-03-14 18:00:47 +0530 | [diff] [blame] | 78 | |
HIGUCHI Yuta | 5bb99a4 | 2015-03-19 16:52:15 -0700 | [diff] [blame] | 79 | final Device pojoIn = device; |
| 80 | |
| 81 | assertJsonEncodable(context, codec, pojoIn); |
| 82 | } |
| 83 | |
| 84 | } |