Ray Milkey | d29bc1c | 2018-03-13 11:57:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.net.config.basics; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onosproject.net.HostId; |
| 25 | import org.onosproject.net.HostLocation; |
| 26 | import org.onosproject.net.NetTestTools; |
| 27 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 28 | |
| 29 | import java.util.Set; |
| 30 | |
| 31 | import static org.hamcrest.MatcherAssert.assertThat; |
| 32 | import static org.hamcrest.Matchers.hasItems; |
| 33 | import static org.hamcrest.Matchers.hasSize; |
| 34 | import static org.hamcrest.Matchers.is; |
| 35 | |
| 36 | public 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 | } |