blob: 6721cc74be3a5410d7706d3934983e71ed6ed3f6 [file] [log] [blame]
Ray Milkeyd29bc1c2018-03-13 11:57:11 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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
17package org.onosproject.net.config.basics;
18
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.JsonNodeFactory;
21import com.google.common.collect.ImmutableSet;
22import org.junit.Test;
23import org.onlab.packet.IpAddress;
24import org.onosproject.net.HostId;
25import org.onosproject.net.HostLocation;
26import org.onosproject.net.NetTestTools;
27import org.onosproject.net.config.ConfigApplyDelegate;
28
29import java.util.Set;
30
31import static org.hamcrest.MatcherAssert.assertThat;
32import static org.hamcrest.Matchers.hasItems;
33import static org.hamcrest.Matchers.hasSize;
34import static org.hamcrest.Matchers.is;
35
36public class BasicHostConfigTest {
37
38 /**
39 * Tests construction, setters and getters of a BasicLinkConfig object.
40 */
41 @Test
42 public void testConstruction() {
43 BasicHostConfig config = new BasicHostConfig();
44 ConfigApplyDelegate delegate = configApply -> { };
45 ObjectMapper mapper = new ObjectMapper();
46 HostId hostId = NetTestTools.hid("12:34:56:78:90:ab/1");
47 IpAddress ip1 = IpAddress.valueOf("1.1.1.1");
48 IpAddress ip2 = IpAddress.valueOf("1.1.1.2");
49 IpAddress ip3 = IpAddress.valueOf("1.1.1.3");
50 Set<IpAddress> ips = ImmutableSet.of(ip1, ip2, ip3);
51 HostLocation loc1 = new HostLocation(
52 NetTestTools.connectPoint("d1", 1), System.currentTimeMillis());
53 HostLocation loc2 = new HostLocation(
54 NetTestTools.connectPoint("d2", 2), System.currentTimeMillis());
55 Set<HostLocation> locs = ImmutableSet.of(loc1, loc2);
56
57 config.init(hostId, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
58
59 config.setIps(ips)
60 .setLocations(locs);
61
62 assertThat(config.isValid(), is(true));
63 assertThat(config.name(), is("-"));
64 assertThat(config.ipAddresses(), hasSize(3));
65 assertThat(config.ipAddresses(), hasItems(ip1, ip2, ip3));
66 assertThat(config.locations(), hasSize(2));
67 assertThat(config.locations(), hasItems(loc1, loc2));
68 }
69
70}