blob: feb5b228a47cc07aecb685f09675495ab56588c9 [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
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;
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 Leenheerec551d32017-03-10 15:48:18 -080057 .isDurable(FALSE)
58 .metric(METRIC)
59 .type(Link.Type.DIRECT)
60 .latency(LATENCY)
61 .isBidirectional(FALSE);
Ray Milkeydbf59f02016-08-19 12:54:16 -070062
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 Leenheerec551d32017-03-10 15:48:18 -080068 assertThat(config.isBidirectional(), is(FALSE));
Ray Milkeydbf59f02016-08-19 12:54:16 -070069 assertThat(config.isValid(), is(true));
70 }
71}