blob: 588e0f8dfd22fa9257c27597667a03bb824200fd [file] [log] [blame]
kishoreefa3db52020-03-23 16:09:26 +05301/*
Joey Armstrong89c55e02023-01-09 18:09:41 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
kishoreefa3db52020-03-23 16:09:26 +05303 *
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
17package org.opencord.kafka.integrations;
18
19import com.fasterxml.jackson.databind.JsonNode;
kishoreefa3db52020-03-23 16:09:26 +053020import org.junit.jupiter.api.AfterEach;
21import org.junit.jupiter.api.BeforeEach;
22import org.junit.jupiter.api.Test;
23import org.onlab.packet.VlanId;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.DeviceId;
26import org.opencord.kafka.EventBusService;
27import org.opencord.olt.AccessDeviceListener;
28import org.opencord.olt.AccessDeviceService;
kishoreefa3db52020-03-23 16:09:26 +053029
30import java.util.List;
kishoreefa3db52020-03-23 16:09:26 +053031
32import static org.junit.Assert.assertEquals;
33
34/**
35 * Set of unit test cases for AccessDeviceKafkaIntegration.
36 */
37class 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 Scandolo777f6152021-10-08 11:17:53 -0700110 public boolean provisionSubscriber(ConnectPoint accessSubscriberId,
111 VlanId optional, VlanId optional1,
112 Integer optional2) {
kishoreefa3db52020-03-23 16:09:26 +0530113 return false;
114 }
115
116 @Override
Matteo Scandolo777f6152021-10-08 11:17:53 -0700117 public boolean removeSubscriber(ConnectPoint accessSubscriberId,
118 VlanId optional, VlanId optional1,
119 Integer optional2) {
kishoreefa3db52020-03-23 16:09:26 +0530120 return false;
121 }
122
123 @Override
Matteo Scandolo777f6152021-10-08 11:17:53 -0700124 public List<DeviceId> getConnectedOlts() {
kishoreefa3db52020-03-23 16:09:26 +0530125 return null;
126 }
127
128 @Override
Matteo Scandolo777f6152021-10-08 11:17:53 -0700129 public ConnectPoint findSubscriberConnectPoint(String id) {
Matteo Scandolo91d31b32020-08-11 09:23:55 -0700130 return null;
131 }
132
133 @Override
kishoreefa3db52020-03-23 16:09:26 +0530134 public void addListener(AccessDeviceListener listener) {
135 accessDeviceListener = listener;
136 }
137
138 @Override
139 public void removeListener(AccessDeviceListener listener) {
140 accessDeviceListener = null;
141 }
142 }
143}