blob: 04fd87f414f7977962e0cf49c901695ed134e17c [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
22import org.junit.Test;
23import org.onosproject.net.driver.Behaviour;
24import org.onosproject.net.driver.DefaultDriver;
25import org.onosproject.net.driver.Driver;
26import org.onosproject.net.driver.TestBehaviour;
27import org.onosproject.net.driver.TestBehaviourImpl;
28import org.onosproject.net.driver.TestBehaviourTwo;
29import org.onosproject.net.driver.TestBehaviourTwoImpl;
30
31import com.fasterxml.jackson.databind.node.ObjectNode;
32import com.google.common.collect.ImmutableMap;
33
34import static org.hamcrest.MatcherAssert.assertThat;
35import static org.onosproject.codec.impl.DriverJsonMatcher.matchesDriver;
36
37/**
38 * Unit tests for the driver codec.
39 */
40public class DriverCodecTest {
41
42 @Test
43 public void codecTest() {
44 Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours =
45 ImmutableMap.of(TestBehaviour.class,
46 TestBehaviourImpl.class,
47 TestBehaviourTwo.class,
48 TestBehaviourTwoImpl.class);
49 Map<String, String> properties =
50 ImmutableMap.of("key1", "value1", "key2", "value2");
51
Andrea Campanella80520b82016-01-05 17:55:29 -080052 DefaultDriver parent = new DefaultDriver("parent", new ArrayList<>(), "Acme",
Ray Milkey39616f32015-05-14 15:43:00 -070053 "HW1.2.3", "SW1.2.3",
54 behaviours,
55 properties);
56 DefaultDriver child = new DefaultDriver("child", parent, "Acme",
57 "HW1.2.3.1", "SW1.2.3.1",
58 behaviours,
59 properties);
60
61 MockCodecContext context = new MockCodecContext();
62 ObjectNode driverJson = context.codec(Driver.class).encode(child, context);
63
64 assertThat(driverJson, matchesDriver(child));
65 }
66}