Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [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 | */ |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config.basics; |
| 17 | |
Marc De Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.Link; |
| 22 | import org.onosproject.net.LinkKey; |
| 23 | import org.onosproject.net.NetTestTools; |
| 24 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 25 | |
Marc De Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 26 | import java.time.Duration; |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 27 | |
| 28 | import static java.lang.Boolean.FALSE; |
| 29 | import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | import static org.hamcrest.Matchers.is; |
| 31 | |
| 32 | /** |
| 33 | * Unit tests for the BasicLinkConfig class. |
| 34 | */ |
| 35 | |
| 36 | public class BasicLinkConfigTest { |
| 37 | private static final long BANDWIDTH = 11; |
| 38 | private static final double METRIC = 3.0; |
| 39 | private static final Duration LATENCY = Duration.ofNanos(5555); |
| 40 | |
| 41 | /** |
| 42 | * Tests construction, setters and getters of a BasicLinkConfig object. |
| 43 | */ |
| 44 | @Test |
| 45 | public void testConstruction() { |
| 46 | BasicLinkConfig config = new BasicLinkConfig(); |
| 47 | ConfigApplyDelegate delegate = configApply -> { }; |
| 48 | ObjectMapper mapper = new ObjectMapper(); |
| 49 | LinkKey linkKey = LinkKey.linkKey( |
| 50 | NetTestTools.connectPoint("device1", 1), |
| 51 | NetTestTools.connectPoint("device2", 2)); |
| 52 | |
| 53 | config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 54 | |
| 55 | |
| 56 | config.bandwidth(BANDWIDTH) |
Marc De Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 57 | .isDurable(FALSE) |
| 58 | .metric(METRIC) |
| 59 | .type(Link.Type.DIRECT) |
| 60 | .latency(LATENCY) |
| 61 | .isBidirectional(FALSE); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 62 | |
| 63 | assertThat(config.bandwidth(), is(BANDWIDTH)); |
| 64 | assertThat(config.isDurable(), is(FALSE)); |
| 65 | assertThat(config.metric(), is(METRIC)); |
| 66 | assertThat(config.type(), is(Link.Type.DIRECT)); |
| 67 | assertThat(config.latency(), is(LATENCY)); |
Marc De Leenheer | ec551d3 | 2017-03-10 15:48:18 -0800 | [diff] [blame] | 68 | assertThat(config.isBidirectional(), is(FALSE)); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 69 | assertThat(config.isValid(), is(true)); |
| 70 | } |
| 71 | } |