blob: 2d4877a2d9d2c785fb518f20fe281448a6f77474 [file] [log] [blame]
Ayaka Koshibef1cedf42015-08-05 18:03:56 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Ayaka Koshibef1cedf42015-08-05 18:03:56 -07003 *
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 */
16package org.onosproject.net.host.impl;
17
18import static org.junit.Assert.assertEquals;
19
Charles Chan60c45282017-07-11 15:07:59 -070020import com.google.common.collect.Sets;
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070021import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.IpAddress;
24import org.onlab.packet.MacAddress;
25import org.onlab.packet.VlanId;
Ray Milkeya4122362015-08-18 15:19:08 -070026import org.onosproject.net.config.ConfigApplyDelegate;
Thomas Vachuska4998caa2015-08-26 13:28:38 -070027import org.onosproject.net.config.basics.BasicHostConfig;
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070028import org.onosproject.net.AnnotationKeys;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.HostId;
31import org.onosproject.net.HostLocation;
32import org.onosproject.net.PortNumber;
33import org.onosproject.net.host.DefaultHostDescription;
34import org.onosproject.net.host.HostDescription;
35
36import com.fasterxml.jackson.databind.ObjectMapper;
37import com.fasterxml.jackson.databind.node.JsonNodeFactory;
38
39public 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 SHIMIZU74626412015-09-11 11:46:27 -070052 private final ConfigApplyDelegate delegate = config -> { };
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070053 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 Huntf4fd2a22016-08-10 15:41:09 -070058 private static final double LON = 0.0;
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070059
60 @Before
61 public void setUp() {
62 BHC.init(ID, "test", JsonNodeFactory.instance.objectNode(), mapper, delegate);
Charles Chan60c45282017-07-11 15:07:59 -070063 BHC.setLocations(Sets.newHashSet(LOC)).name(NAME).latitude(40.96);
Simon Huntf4fd2a22016-08-10 15:41:09 -070064 // if you set lat or long, the other becomes valid as 0.0 (not null)
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070065 }
66
67 @Test
68 public void testDescOps() {
69 HostDescription desc = BasicHostOperator.combine(BHC, HOST);
70 assertEquals(NAME, desc.annotations().value(AnnotationKeys.NAME));
Simon Huntf4fd2a22016-08-10 15:41:09 -070071 assertEquals(String.valueOf(LON), desc.annotations().value(AnnotationKeys.LONGITUDE));
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070072 assertEquals(String.valueOf(LAT), desc.annotations().value(AnnotationKeys.LATITUDE));
73 }
74}