blob: 94f0fa3f6e1259670089d39fa8537d37f2a577e2 [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey85267002016-11-16 11:06:35 -08003 *
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 Milkeydbf59f02016-08-19 12:54:16 -070016package org.onosproject.net.config.basics;
17
Marc De Leenheerec551d32017-03-10 15:48:18 -080018import com.fasterxml.jackson.databind.ObjectMapper;
19import com.fasterxml.jackson.databind.node.JsonNodeFactory;
Ray Milkeydbf59f02016-08-19 12:54:16 -070020import org.junit.Test;
21import org.onosproject.net.Link;
22import org.onosproject.net.LinkKey;
23import org.onosproject.net.NetTestTools;
24import org.onosproject.net.config.ConfigApplyDelegate;
25
Marc De Leenheerec551d32017-03-10 15:48:18 -080026import java.time.Duration;
Ray Milkeydbf59f02016-08-19 12:54:16 -070027
28import static java.lang.Boolean.FALSE;
29import static org.hamcrest.MatcherAssert.assertThat;
30import static org.hamcrest.Matchers.is;
31
32/**
33 * Unit tests for the BasicLinkConfig class.
34 */
35
36public class BasicLinkConfigTest {
37 private static final long BANDWIDTH = 11;
38 private static final double METRIC = 3.0;
Aaron Dunlap239ea5c2020-02-26 12:10:31 -060039 private static final double JITTER = 3.0;
40 private static final double DELAY = 3.0;
41 private static final double LOSS = 3.0;
42 private static final double AVAILABILITY = 3.0;
43 private static final double FLAPPING = 3.0;
Ray Milkeydbf59f02016-08-19 12:54:16 -070044 private static final Duration LATENCY = Duration.ofNanos(5555);
45
46 /**
47 * Tests construction, setters and getters of a BasicLinkConfig object.
48 */
49 @Test
50 public void testConstruction() {
51 BasicLinkConfig config = new BasicLinkConfig();
52 ConfigApplyDelegate delegate = configApply -> { };
53 ObjectMapper mapper = new ObjectMapper();
54 LinkKey linkKey = LinkKey.linkKey(
55 NetTestTools.connectPoint("device1", 1),
56 NetTestTools.connectPoint("device2", 2));
57
58 config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
59
60
61 config.bandwidth(BANDWIDTH)
Aaron Dunlap239ea5c2020-02-26 12:10:31 -060062 .jitter(JITTER)
63 .delay(DELAY)
64 .loss(LOSS)
65 .availability(AVAILABILITY)
66 .flapping(FLAPPING)
Marc De Leenheerec551d32017-03-10 15:48:18 -080067 .isDurable(FALSE)
68 .metric(METRIC)
69 .type(Link.Type.DIRECT)
70 .latency(LATENCY)
71 .isBidirectional(FALSE);
Ray Milkeydbf59f02016-08-19 12:54:16 -070072
73 assertThat(config.bandwidth(), is(BANDWIDTH));
Aaron Dunlap239ea5c2020-02-26 12:10:31 -060074 assertThat(config.jitter(), is(JITTER));
75 assertThat(config.delay(), is(DELAY));
76 assertThat(config.loss(), is(LOSS));
77 assertThat(config.availability(), is(AVAILABILITY));
78 assertThat(config.flapping(), is(FLAPPING));
Ray Milkeydbf59f02016-08-19 12:54:16 -070079 assertThat(config.isDurable(), is(FALSE));
80 assertThat(config.metric(), is(METRIC));
81 assertThat(config.type(), is(Link.Type.DIRECT));
82 assertThat(config.latency(), is(LATENCY));
Marc De Leenheerec551d32017-03-10 15:48:18 -080083 assertThat(config.isBidirectional(), is(FALSE));
Ray Milkeydbf59f02016-08-19 12:54:16 -070084 assertThat(config.isValid(), is(true));
85 }
86}