2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.store.host.impl;
18 import junit.framework.TestCase;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.onlab.packet.IpAddress;
23 import org.onlab.packet.MacAddress;
24 import org.onosproject.net.Host;
25 import org.onosproject.net.HostId;
26 import org.onosproject.net.HostLocation;
27 import org.onosproject.net.host.DefaultHostDescription;
28 import org.onosproject.net.host.HostDescription;
29 import org.onosproject.net.provider.ProviderId;
30 import org.onosproject.store.Timestamp;
31 import org.onosproject.store.service.LogicalClockService;
32 import org.onosproject.store.service.TestStorageService;
34 import java.util.HashSet;
38 * Tests for the ECHostStore.
40 public class ECHostStoreTest extends TestCase {
42 private ECHostStore ecXHostStore;
44 private static final HostId HOSTID = HostId.hostId(MacAddress.valueOf("1a:1a:1a:1a:1a:1a"));
46 private static final IpAddress IP1 = IpAddress.valueOf("10.2.0.2");
47 private static final IpAddress IP2 = IpAddress.valueOf("10.2.0.3");
49 private static final ProviderId PID = new ProviderId("of", "foo");
53 ecXHostStore = new ECHostStore();
55 ecXHostStore.storageService = new TestStorageService();
56 ecXHostStore.clockService = new TestLogicalClockService();
57 ecXHostStore.activate();
61 public void tearDown() {
62 ecXHostStore.deactivate();
66 * Tests the removeIp method call.
69 public void testRemoveIp() {
70 Set<IpAddress> ips = new HashSet<>();
74 HostDescription description = new DefaultHostDescription(HOSTID.mac(),
78 ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
79 ecXHostStore.removeIp(HOSTID, IP1);
80 Host host = ecXHostStore.getHost(HOSTID);
82 assertFalse(host.ipAddresses().contains(IP1));
83 assertTrue(host.ipAddresses().contains(IP2));
87 * Mocks the LogicalClockService class.
89 class TestLogicalClockService implements LogicalClockService {
91 public Timestamp getTimestamp() {