kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 1 | /* |
Joey Armstrong | 89c55e0 | 2023-01-09 18:09:41 -0500 | [diff] [blame^] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 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 | |
| 17 | package org.opencord.kafka.integrations; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 20 | import org.junit.jupiter.api.AfterEach; |
| 21 | import org.junit.jupiter.api.BeforeEach; |
| 22 | import org.junit.jupiter.api.Test; |
| 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.opencord.kafka.EventBusService; |
| 27 | import org.opencord.olt.AccessDeviceListener; |
| 28 | import org.opencord.olt.AccessDeviceService; |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 29 | |
| 30 | import java.util.List; |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 31 | |
| 32 | import static org.junit.Assert.assertEquals; |
| 33 | |
| 34 | /** |
| 35 | * Set of unit test cases for AccessDeviceKafkaIntegration. |
| 36 | */ |
| 37 | class AccessDeviceKafkaIntegrationTest extends KafkaIntegrationTestBase { |
| 38 | |
| 39 | private AccessDeviceKafkaIntegration accessDeviceKakfa; |
| 40 | private AccessDeviceListener accessDeviceListener; |
| 41 | |
| 42 | @BeforeEach |
| 43 | void setUp() { |
| 44 | accessDeviceKakfa = new AccessDeviceKafkaIntegration(); |
| 45 | |
| 46 | accessDeviceKakfa.deviceService = new MockDeviceService(); |
| 47 | accessDeviceKakfa.eventBusService = new MockEventBusService(); |
| 48 | accessDeviceKakfa.accessDeviceService = new MockAccessDeviceService(); |
| 49 | accessDeviceKakfa.bindAccessDeviceService(accessDeviceKakfa.accessDeviceService); |
| 50 | accessDeviceKakfa.activate(); |
| 51 | } |
| 52 | |
| 53 | @AfterEach |
| 54 | void tearDown() { |
| 55 | accessDeviceKakfa.deactivate(); |
| 56 | accessDeviceKakfa = null; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * testcase to perform UNI_ADDED AccessDeviceEvent. |
| 61 | */ |
| 62 | @Test |
| 63 | void testUniAdded() { |
| 64 | accessDeviceListener.event(getUniAdded()); |
| 65 | assertEquals(MockEventBusService.kafkaEvents, 1); |
| 66 | assertEquals(MockEventBusService.otherCounter, 0); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * testcase to perform UNI_REMOVED AccessDeviceEvent. |
| 71 | */ |
| 72 | @Test |
| 73 | void testUniRemoved() { |
| 74 | accessDeviceListener.event(getUniRemoved()); |
| 75 | assertEquals(MockEventBusService.kafkaEvents, 1); |
| 76 | assertEquals(MockEventBusService.otherCounter, 0); |
| 77 | } |
| 78 | |
| 79 | private static class MockEventBusService implements EventBusService { |
| 80 | static int kafkaEvents; |
| 81 | static int otherCounter; |
| 82 | |
| 83 | MockEventBusService() { |
| 84 | kafkaEvents = 0; |
| 85 | otherCounter = 0; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void send(String topic, JsonNode data) { |
| 90 | if (topic.equals(AccessDeviceKafkaIntegration.TOPIC)) { |
| 91 | kafkaEvents++; |
| 92 | } else { |
| 93 | otherCounter++; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | private class MockAccessDeviceService implements AccessDeviceService { |
| 99 | @Override |
| 100 | public boolean provisionSubscriber(ConnectPoint connectPoint) { |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean removeSubscriber(ConnectPoint connectPoint) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | @Override |
Matteo Scandolo | 777f615 | 2021-10-08 11:17:53 -0700 | [diff] [blame] | 110 | public boolean provisionSubscriber(ConnectPoint accessSubscriberId, |
| 111 | VlanId optional, VlanId optional1, |
| 112 | Integer optional2) { |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 113 | return false; |
| 114 | } |
| 115 | |
| 116 | @Override |
Matteo Scandolo | 777f615 | 2021-10-08 11:17:53 -0700 | [diff] [blame] | 117 | public boolean removeSubscriber(ConnectPoint accessSubscriberId, |
| 118 | VlanId optional, VlanId optional1, |
| 119 | Integer optional2) { |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 120 | return false; |
| 121 | } |
| 122 | |
| 123 | @Override |
Matteo Scandolo | 777f615 | 2021-10-08 11:17:53 -0700 | [diff] [blame] | 124 | public List<DeviceId> getConnectedOlts() { |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 125 | return null; |
| 126 | } |
| 127 | |
| 128 | @Override |
Matteo Scandolo | 777f615 | 2021-10-08 11:17:53 -0700 | [diff] [blame] | 129 | public ConnectPoint findSubscriberConnectPoint(String id) { |
Matteo Scandolo | 91d31b3 | 2020-08-11 09:23:55 -0700 | [diff] [blame] | 130 | return null; |
| 131 | } |
| 132 | |
| 133 | @Override |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 134 | public void addListener(AccessDeviceListener listener) { |
| 135 | accessDeviceListener = listener; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void removeListener(AccessDeviceListener listener) { |
| 140 | accessDeviceListener = null; |
| 141 | } |
| 142 | } |
| 143 | } |