blob: 9ace8655fe22932157887447c695f3415c8efcd2 [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
2 * Copyright 2016-present 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 */
Ray Milkeydbf59f02016-08-19 12:54:16 -070016package org.onosproject.net.config.basics;
17
18import java.time.Duration;
19
20import 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
26import com.fasterxml.jackson.databind.ObjectMapper;
27import com.fasterxml.jackson.databind.node.JsonNodeFactory;
28
29import static java.lang.Boolean.FALSE;
30import static org.hamcrest.MatcherAssert.assertThat;
31import static org.hamcrest.Matchers.is;
32
33/**
34 * Unit tests for the BasicLinkConfig class.
35 */
36
37public class BasicLinkConfigTest {
38 private static final long BANDWIDTH = 11;
39 private static final double METRIC = 3.0;
40 private static final Duration LATENCY = Duration.ofNanos(5555);
41
42 /**
43 * Tests construction, setters and getters of a BasicLinkConfig object.
44 */
45 @Test
46 public void testConstruction() {
47 BasicLinkConfig config = new BasicLinkConfig();
48 ConfigApplyDelegate delegate = configApply -> { };
49 ObjectMapper mapper = new ObjectMapper();
50 LinkKey linkKey = LinkKey.linkKey(
51 NetTestTools.connectPoint("device1", 1),
52 NetTestTools.connectPoint("device2", 2));
53
54 config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
55
56
57 config.bandwidth(BANDWIDTH)
58 .isDurable(FALSE)
59 .metric(METRIC)
60 .type(Link.Type.DIRECT)
61 .latency(LATENCY);
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));
68 assertThat(config.isValid(), is(true));
69 }
70}