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