blob: 539d22c48c9fff04912b6fb980835929d9aeb634 [file] [log] [blame]
Ray Milkey39616f32015-05-14 15:43:00 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkey39616f32015-05-14 15:43:00 -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 */
16package org.onosproject.codec.impl;
17
18
Andrea Campanella80520b82016-01-05 17:55:29 -080019import java.util.ArrayList;
Ray Milkey39616f32015-05-14 15:43:00 -070020import java.util.Map;
21
Sho SHIMIZU50a6dbe2016-06-06 15:49:38 -070022import com.google.common.collect.ImmutableList;
Ray Milkey39616f32015-05-14 15:43:00 -070023import org.junit.Test;
24import org.onosproject.net.driver.Behaviour;
25import org.onosproject.net.driver.DefaultDriver;
26import org.onosproject.net.driver.Driver;
27import org.onosproject.net.driver.TestBehaviour;
28import org.onosproject.net.driver.TestBehaviourImpl;
29import org.onosproject.net.driver.TestBehaviourTwo;
30import org.onosproject.net.driver.TestBehaviourTwoImpl;
31
32import com.fasterxml.jackson.databind.node.ObjectNode;
33import com.google.common.collect.ImmutableMap;
34
35import static org.hamcrest.MatcherAssert.assertThat;
36import static org.onosproject.codec.impl.DriverJsonMatcher.matchesDriver;
37
38/**
39 * Unit tests for the driver codec.
40 */
41public class DriverCodecTest {
42
43 @Test
44 public void codecTest() {
45 Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours =
46 ImmutableMap.of(TestBehaviour.class,
47 TestBehaviourImpl.class,
48 TestBehaviourTwo.class,
49 TestBehaviourTwoImpl.class);
50 Map<String, String> properties =
51 ImmutableMap.of("key1", "value1", "key2", "value2");
52
Andrea Campanella80520b82016-01-05 17:55:29 -080053 DefaultDriver parent = new DefaultDriver("parent", new ArrayList<>(), "Acme",
Ray Milkey39616f32015-05-14 15:43:00 -070054 "HW1.2.3", "SW1.2.3",
55 behaviours,
56 properties);
Sho SHIMIZU50a6dbe2016-06-06 15:49:38 -070057 DefaultDriver child = new DefaultDriver("child", ImmutableList.of(parent), "Acme",
Ray Milkey39616f32015-05-14 15:43:00 -070058 "HW1.2.3.1", "SW1.2.3.1",
59 behaviours,
60 properties);
61
62 MockCodecContext context = new MockCodecContext();
63 ObjectNode driverJson = context.codec(Driver.class).encode(child, context);
64
65 assertThat(driverJson, matchesDriver(child));
66 }
67}