Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 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 | package org.onosproject.net.host.impl; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | |
Charles Chan | 60c4528 | 2017-07-11 15:07:59 -0700 | [diff] [blame] | 20 | import com.google.common.collect.Sets; |
Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.VlanId; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 26 | import org.onosproject.net.config.ConfigApplyDelegate; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 27 | import org.onosproject.net.config.basics.BasicHostConfig; |
Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 28 | import org.onosproject.net.AnnotationKeys; |
| 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.HostId; |
| 31 | import org.onosproject.net.HostLocation; |
| 32 | import org.onosproject.net.PortNumber; |
| 33 | import org.onosproject.net.host.DefaultHostDescription; |
| 34 | import org.onosproject.net.host.HostDescription; |
| 35 | |
| 36 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 37 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 38 | |
| 39 | public class BasicHostOperatorTest { |
| 40 | private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01"); |
| 41 | private static final VlanId VLAN = VlanId.vlanId((short) 10); |
| 42 | private static final IpAddress IP = IpAddress.valueOf("10.0.0.1"); |
| 43 | |
| 44 | private static final HostId ID = HostId.hostId(MAC); |
| 45 | private static final HostLocation LOC = new HostLocation( |
| 46 | DeviceId.deviceId("of:foo"), |
| 47 | PortNumber.portNumber(100), |
| 48 | 123L |
| 49 | ); |
| 50 | private static final HostDescription HOST = new DefaultHostDescription(MAC, VLAN, LOC, IP); |
| 51 | |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 52 | private final ConfigApplyDelegate delegate = config -> { }; |
Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 53 | private final ObjectMapper mapper = new ObjectMapper(); |
| 54 | |
| 55 | private static final BasicHostConfig BHC = new BasicHostConfig(); |
| 56 | private static final String NAME = "testhost"; |
| 57 | private static final double LAT = 40.96; |
Simon Hunt | f4fd2a2 | 2016-08-10 15:41:09 -0700 | [diff] [blame] | 58 | private static final double LON = 0.0; |
Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 59 | |
| 60 | @Before |
| 61 | public void setUp() { |
| 62 | BHC.init(ID, "test", JsonNodeFactory.instance.objectNode(), mapper, delegate); |
Charles Chan | 60c4528 | 2017-07-11 15:07:59 -0700 | [diff] [blame] | 63 | BHC.setLocations(Sets.newHashSet(LOC)).name(NAME).latitude(40.96); |
Simon Hunt | f4fd2a2 | 2016-08-10 15:41:09 -0700 | [diff] [blame] | 64 | // if you set lat or long, the other becomes valid as 0.0 (not null) |
Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testDescOps() { |
| 69 | HostDescription desc = BasicHostOperator.combine(BHC, HOST); |
| 70 | assertEquals(NAME, desc.annotations().value(AnnotationKeys.NAME)); |
Simon Hunt | f4fd2a2 | 2016-08-10 15:41:09 -0700 | [diff] [blame] | 71 | assertEquals(String.valueOf(LON), desc.annotations().value(AnnotationKeys.LONGITUDE)); |
Ayaka Koshibe | f1cedf4 | 2015-08-05 18:03:56 -0700 | [diff] [blame] | 72 | assertEquals(String.valueOf(LAT), desc.annotations().value(AnnotationKeys.LATITUDE)); |
| 73 | } |
| 74 | } |