a7077a813a1db02ffb440ee0d9e47dcdf9493968
[onosfw.git] /
1 /*
2  * Copyright 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  */
16 package org.onosproject.store.host.impl;
17
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;
33
34 import java.util.HashSet;
35 import java.util.Set;
36
37 /**
38  * Tests for the ECHostStore.
39  */
40 public class ECHostStoreTest extends TestCase {
41
42     private ECHostStore ecXHostStore;
43
44     private static final HostId HOSTID = HostId.hostId(MacAddress.valueOf("1a:1a:1a:1a:1a:1a"));
45
46     private static final IpAddress IP1 = IpAddress.valueOf("10.2.0.2");
47     private static final IpAddress IP2 = IpAddress.valueOf("10.2.0.3");
48
49     private static final ProviderId PID = new ProviderId("of", "foo");
50
51     @Before
52     public void setUp() {
53         ecXHostStore = new ECHostStore();
54
55         ecXHostStore.storageService = new TestStorageService();
56         ecXHostStore.clockService = new TestLogicalClockService();
57         ecXHostStore.activate();
58     }
59
60     @After
61     public void tearDown() {
62         ecXHostStore.deactivate();
63     }
64
65     /**
66      * Tests the removeIp method call.
67      */
68     @Test
69     public void testRemoveIp() {
70         Set<IpAddress> ips = new HashSet<>();
71         ips.add(IP1);
72         ips.add(IP2);
73
74         HostDescription description = new DefaultHostDescription(HOSTID.mac(),
75                                                                     HOSTID.vlanId(),
76                                                                     HostLocation.NONE,
77                                                                     ips);
78         ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
79         ecXHostStore.removeIp(HOSTID, IP1);
80         Host host = ecXHostStore.getHost(HOSTID);
81
82         assertFalse(host.ipAddresses().contains(IP1));
83         assertTrue(host.ipAddresses().contains(IP2));
84     }
85
86     /**
87      * Mocks the LogicalClockService class.
88      */
89     class TestLogicalClockService implements LogicalClockService {
90         @Override
91         public Timestamp getTimestamp() {
92             return null;
93         }
94     }
95 }