Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 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 | |
Sho SHIMIZU | 50a6dbe | 2016-06-06 15:49:38 -0700 | [diff] [blame] | 22 | import com.google.common.collect.ImmutableList; |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 23 | import org.junit.Test; |
| 24 | import org.onosproject.net.driver.Behaviour; |
| 25 | import org.onosproject.net.driver.DefaultDriver; |
| 26 | import org.onosproject.net.driver.Driver; |
| 27 | import org.onosproject.net.driver.TestBehaviour; |
| 28 | import org.onosproject.net.driver.TestBehaviourImpl; |
| 29 | import org.onosproject.net.driver.TestBehaviourTwo; |
| 30 | import org.onosproject.net.driver.TestBehaviourTwoImpl; |
| 31 | |
| 32 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 33 | import com.google.common.collect.ImmutableMap; |
| 34 | |
| 35 | import static org.hamcrest.MatcherAssert.assertThat; |
| 36 | import static org.onosproject.codec.impl.DriverJsonMatcher.matchesDriver; |
| 37 | |
| 38 | /** |
| 39 | * Unit tests for the driver codec. |
| 40 | */ |
| 41 | public 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 Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 53 | DefaultDriver parent = new DefaultDriver("parent", new ArrayList<>(), "Acme", |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 54 | "HW1.2.3", "SW1.2.3", |
| 55 | behaviours, |
| 56 | properties); |
Sho SHIMIZU | 50a6dbe | 2016-06-06 15:49:38 -0700 | [diff] [blame] | 57 | DefaultDriver child = new DefaultDriver("child", ImmutableList.of(parent), "Acme", |
Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame] | 58 | "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 | } |