blob: 3d1331a24b37c96cf7e29b73ebe0d0d388e0e067 [file] [log] [blame]
Ayaka Koshibef1cedf42015-08-05 18:03:56 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.IpAddress;
23import org.onlab.packet.MacAddress;
24import org.onlab.packet.VlanId;
Ray Milkeya4122362015-08-18 15:19:08 -070025import org.onosproject.net.config.ConfigApplyDelegate;
Thomas Vachuska4998caa2015-08-26 13:28:38 -070026import org.onosproject.net.config.basics.BasicHostConfig;
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070027import org.onosproject.net.AnnotationKeys;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.HostId;
30import org.onosproject.net.HostLocation;
31import org.onosproject.net.PortNumber;
32import org.onosproject.net.host.DefaultHostDescription;
33import org.onosproject.net.host.HostDescription;
34
35import com.fasterxml.jackson.databind.ObjectMapper;
36import com.fasterxml.jackson.databind.node.JsonNodeFactory;
37
38public class BasicHostOperatorTest {
39 private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01");
40 private static final VlanId VLAN = VlanId.vlanId((short) 10);
41 private static final IpAddress IP = IpAddress.valueOf("10.0.0.1");
42
43 private static final HostId ID = HostId.hostId(MAC);
44 private static final HostLocation LOC = new HostLocation(
45 DeviceId.deviceId("of:foo"),
46 PortNumber.portNumber(100),
47 123L
48 );
49 private static final HostDescription HOST = new DefaultHostDescription(MAC, VLAN, LOC, IP);
50
Sho SHIMIZU74626412015-09-11 11:46:27 -070051 private final ConfigApplyDelegate delegate = config -> { };
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070052 private final ObjectMapper mapper = new ObjectMapper();
53
54 private static final BasicHostConfig BHC = new BasicHostConfig();
55 private static final String NAME = "testhost";
56 private static final double LAT = 40.96;
Simon Huntf4fd2a22016-08-10 15:41:09 -070057 private static final double LON = 0.0;
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070058
59 @Before
60 public void setUp() {
61 BHC.init(ID, "test", JsonNodeFactory.instance.objectNode(), mapper, delegate);
62 BHC.name(NAME).latitude(40.96);
Simon Huntf4fd2a22016-08-10 15:41:09 -070063 // if you set lat or long, the other becomes valid as 0.0 (not null)
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070064 }
65
66 @Test
67 public void testDescOps() {
68 HostDescription desc = BasicHostOperator.combine(BHC, HOST);
69 assertEquals(NAME, desc.annotations().value(AnnotationKeys.NAME));
Simon Huntf4fd2a22016-08-10 15:41:09 -070070 assertEquals(String.valueOf(LON), desc.annotations().value(AnnotationKeys.LONGITUDE));
Ayaka Koshibef1cedf42015-08-05 18:03:56 -070071 assertEquals(String.valueOf(LAT), desc.annotations().value(AnnotationKeys.LATITUDE));
72 }
73}