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