blob: ce1ee9c169689b5529ccfb34b416ff13cd6a98fc [file] [log] [blame]
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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.notNullValue;
21import static org.hamcrest.Matchers.is;
22import static org.onosproject.codec.impl.JsonCodecUtils.assertJsonEncodable;
kalagesa42019542017-03-14 18:00:47 +053023import com.google.common.collect.ImmutableMap;
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070024import org.junit.Test;
25import org.onosproject.codec.JsonCodec;
26import org.onosproject.net.DefaultDevice;
27import org.onosproject.net.Device;
kalagesa42019542017-03-14 18:00:47 +053028import static org.easymock.EasyMock.replay;
29import static org.easymock.EasyMock.expect;
30import static org.easymock.EasyMock.createMock;
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070031import org.onosproject.net.device.DeviceService;
kalagesa42019542017-03-14 18:00:47 +053032import org.onosproject.net.driver.DriverService;
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070033import org.onosproject.net.device.DeviceServiceAdapter;
kalagesa42019542017-03-14 18:00:47 +053034import org.onosproject.net.driver.DefaultDriver;
35import org.onosproject.net.driver.TestBehaviourImpl;
36import org.onosproject.net.driver.TestBehaviour;
37import org.onosproject.net.driver.TestBehaviourTwo;
38import org.onosproject.net.driver.TestBehaviourTwoImpl;
39
40import java.util.ArrayList;
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070041
42/**
43 * Unit test for DeviceCodec.
44 */
45public class DeviceCodecTest {
kalagesa42019542017-03-14 18:00:47 +053046 DriverService mockDriverService = createMock(DriverService.class);
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070047
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);
kalagesa42019542017-03-14 18:00:47 +053057 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 Yuta5bb99a42015-03-19 16:52:15 -070063
64 @Test
65 public void deviceCodecTest() {
66 final MockCodecContext context = new MockCodecContext();
kalagesa42019542017-03-14 18:00:47 +053067
68 expect(mockDriverService.getDriver(JsonCodecUtils.DID1))
69 .andReturn(driver)
70 .anyTimes();
71
72 replay(mockDriverService);
73
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070074 context.registerService(DeviceService.class, new DeviceServiceAdapter());
kalagesa42019542017-03-14 18:00:47 +053075 context.registerService(DriverService.class, mockDriverService);
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070076 final JsonCodec<Device> codec = context.codec(Device.class);
77 assertThat(codec, is(notNullValue()));
kalagesa42019542017-03-14 18:00:47 +053078
HIGUCHI Yuta5bb99a42015-03-19 16:52:15 -070079 final Device pojoIn = device;
80
81 assertJsonEncodable(context, codec, pojoIn);
82 }
83
84}