blob: 4f9dacb2159ca1d8ef5f40b8c4f3d536a2e3d110 [file] [log] [blame]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +00001/*
2 * Copyright 2017-present Open Networking Foundation
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.opencord.sadis.impl;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertTrue;
20import static org.junit.Assert.assertNull;
21
22import java.util.List;
23
24import org.junit.After;
25import org.junit.Before;
26import org.junit.Test;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000027
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000028import org.opencord.sadis.BaseConfig;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000029import org.opencord.sadis.BaseInformation;
Gamze Abaka3795c0b2019-08-21 07:21:41 +000030import org.opencord.sadis.BaseInformationService;
31import org.opencord.sadis.SubscriberAndDeviceInformation;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000032
33/**
34 * Set of tests of the SADIS ONOS application component.
35 */
36public class SubscriberAndDeviceManagerTest extends BaseSadis {
37
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000038 @Before
39 public void setUp() throws Exception {
40 config = new SubscriberAndDeviceInformationConfig();
41 super.setUp("/LocalSubConfig.json", SubscriberAndDeviceInformationConfig.class);
42 }
43
44 @After
45 public void tearDown() {
46 super.tearDown();
47 }
48
49 @Test
50 public void testConfiguration() {
51 SubscriberAndDeviceInformationConfig config = sadis.cfgService.getConfig(null,
52 SubscriberAndDeviceInformationConfig.class);
53 checkConfigInfo(50, "PT1m", config);
54 checkEntriesForSubscriberAndAccessDevice(config);
55 }
56
57 private void checkEntriesForSubscriberAndAccessDevice(BaseConfig config) {
58 List<SubscriberAndDeviceInformation> entries = config.getEntries();
59 assertEquals(3, entries.size());
Gamze Abaka3795c0b2019-08-21 07:21:41 +000060 assertTrue(checkEquality(entry1, entries.get(0)));
61 assertTrue(checkEquality(entry2, entries.get(1)));
62 assertTrue(checkEquality(entry5, entries.get(2)));
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000063 }
64
65 @Test
66 public void testLocalMode() throws Exception {
67
68 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
69
Gamze Abaka3795c0b2019-08-21 07:21:41 +000070 checkGetForExisting(ID1, entry1, subscriberService);
71 checkGetForExisting(ID2, entry2, subscriberService);
72 checkGetForExisting(ID5, entry5, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000073
Gamze Abaka3795c0b2019-08-21 07:21:41 +000074 invalidateId(ID1, subscriberService);
75 checkFromBoth(ID1, entry1, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000076
77 invalidateAll(subscriberService);
Gamze Abaka3795c0b2019-08-21 07:21:41 +000078 checkFromBoth(ID2, entry2, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000079 }
80
81
82 private void checkGetForNonExist(String id, BaseInformationService service) {
83 BaseInformation entry = service.get(id);
84 assertNull(entry);
85 }
86
87 @Test
88 public void testRemoteMode() throws Exception {
89 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
90 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
91 configListener.event(event);
92
Gamze Abaka3795c0b2019-08-21 07:21:41 +000093 checkGetForExisting(ID3, entry3, subscriberService);
94 checkGetForExisting(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000095
Gamze Abaka3795c0b2019-08-21 07:21:41 +000096 invalidateId(ID3, subscriberService);
97 checkFromBoth(ID3, entry3, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000098
99 invalidateAll(subscriberService);
Gamze Abaka3795c0b2019-08-21 07:21:41 +0000100 checkFromBoth(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000101 }
102
103 @Test
104 public void testModeSwitch() throws Exception {
105 BaseInformationService<SubscriberAndDeviceInformation> service = sadis.getSubscriberInfoService();
106 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
107 configListener.event(event);
108
Gamze Abaka3795c0b2019-08-21 07:21:41 +0000109 checkGetForExisting(ID3, null, service);
110 checkGetForNonExist(ID1, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000111
112 config.init(subject, "sadis-local-mode-test", node("/LocalSubConfig.json"), mapper, delegate);
113 configListener.event(event);
114
Gamze Abaka3795c0b2019-08-21 07:21:41 +0000115 checkGetForExisting(ID1, null, service);
116 checkGetForNonExist(ID3, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000117 }
118
119
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000120
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000121 public boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
122 SubscriberAndDeviceInformation sub = (SubscriberAndDeviceInformation) localEntry;
123 SubscriberAndDeviceInformation other = (SubscriberAndDeviceInformation) localEntry;
124
125 if (other == null) {
126 return false;
127 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000128 if (sub.hardwareIdentifier() == null) {
129 if (other.hardwareIdentifier() != null) {
130 return false;
131 }
132 } else if (!sub.hardwareIdentifier().equals(other.hardwareIdentifier())) {
133 return false;
134 }
135 if (sub.id() == null) {
136 if (other.id() != null) {
137 return false;
138 }
139 } else if (!sub.id().equals(other.id())) {
140 return false;
141 }
142 if (sub.nasPortId() == null) {
143 if (other.nasPortId() != null) {
144 return false;
145 }
146 } else if (!sub.nasPortId().equals(other.nasPortId())) {
147 return false;
148 }
149 if (sub.nasId() == null) {
150 if (other.nasId() != null) {
151 return false;
152 }
153 } else if (!sub.nasId().equals(other.nasId())) {
154 return false;
155 }
156 if (sub.ipAddress() == null) {
157 if (other.ipAddress() != null) {
158 return false;
159 }
160 } else if (!sub.ipAddress().equals(other.ipAddress())) {
161 return false;
162 }
163 if (sub.uplinkPort() != other.uplinkPort()) {
164 return false;
165 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000166 if (sub.slot() != other.slot()) {
167 return false;
168 }
169 if (sub.circuitId() == null) {
170 if (other.circuitId() != null) {
171 return false;
172 }
173 } else if (!sub.circuitId().equals(other.circuitId())) {
174 return false;
175 }
176 if (sub.remoteId() == null) {
177 if (other.remoteId() != null) {
178 return false;
179 }
180 } else if (!sub.remoteId().equals(other.remoteId())) {
181 return false;
182 }
Gamze Abaka3795c0b2019-08-21 07:21:41 +0000183 if (sub.uniTagList() == null) {
184 if (other.uniTagList() != null) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000185 return false;
186 }
Gamze Abaka3795c0b2019-08-21 07:21:41 +0000187 } else if (!sub.uniTagList().equals(other.uniTagList())) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000188 return false;
189 }
190 return true;
191 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000192}