Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
| 18 | |
Andrea Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 19 | import java.util.ArrayList; |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 20 | import java.util.Map; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.net.driver.Behaviour; |
| 24 | import org.onosproject.net.driver.DefaultDriver; |
| 25 | import org.onosproject.net.driver.Driver; |
| 26 | import org.onosproject.net.driver.TestBehaviour; |
| 27 | import org.onosproject.net.driver.TestBehaviourImpl; |
| 28 | import org.onosproject.net.driver.TestBehaviourTwo; |
| 29 | import org.onosproject.net.driver.TestBehaviourTwoImpl; |
| 30 | |
| 31 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 32 | import com.google.common.collect.ImmutableMap; |
| 33 | |
| 34 | import static org.hamcrest.MatcherAssert.assertThat; |
| 35 | import static org.onosproject.codec.impl.DriverJsonMatcher.matchesDriver; |
| 36 | |
| 37 | /** |
| 38 | * Unit tests for the driver codec. |
| 39 | */ |
| 40 | public 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 Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 52 | DefaultDriver parent = new DefaultDriver("parent", new ArrayList<>(), "Acme", |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 53 | "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 | } |