blob: 940ed919294f6bfb4e311a56959793eaa114ff90 [file] [log] [blame]
Ayaka Koshibef1cedf42015-08-05 18:03:56 -07001/*
2 * Copyright 2014-2015 Open Networking Laboratory
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 */
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;
57
58 @Before
59 public void setUp() {
60 BHC.init(ID, "test", JsonNodeFactory.instance.objectNode(), mapper, delegate);
61 BHC.name(NAME).latitude(40.96);
62 }
63
64 @Test
65 public void testDescOps() {
66 HostDescription desc = BasicHostOperator.combine(BHC, HOST);
67 assertEquals(NAME, desc.annotations().value(AnnotationKeys.NAME));
68 assertEquals(null, desc.annotations().value(AnnotationKeys.LONGITUDE));
69 assertEquals(String.valueOf(LAT), desc.annotations().value(AnnotationKeys.LATITUDE));
70 }
71}