blob: 57b26afb69169f7ef1155183e5348cb9193c2ef6 [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 */
16package org.opencord.kafka.integrations;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import org.junit.jupiter.api.AfterEach;
20import org.junit.jupiter.api.BeforeEach;
21import org.junit.jupiter.api.Test;
Ilayda Ozdemir8b96b322020-06-18 08:52:17 +000022import org.opencord.igmpproxy.IgmpStatisticType;
kishoreefa3db52020-03-23 16:09:26 +053023import org.opencord.igmpproxy.IgmpStatisticsEventListener;
24import org.opencord.igmpproxy.IgmpStatisticsService;
25import org.opencord.kafka.EventBusService;
26
27import static org.junit.Assert.assertEquals;
28
29/**
30 * set of unit test cases for IgmpKafkaIntegration.
31 */
32public class IgmpKafkaIntegrationTest extends KafkaIntegrationTestBase {
33 private IgmpKafkaIntegration igmpKafkaIntegration;
34 private IgmpStatisticsEventListener igmpStatisticsEventListener;
35
36 @BeforeEach
37 void setup() {
38 igmpKafkaIntegration = new IgmpKafkaIntegration();
39 igmpKafkaIntegration.eventBusService = new MockEventBusService();
40 igmpKafkaIntegration.ignore = new MockIgmpStatisticsService();
41 igmpKafkaIntegration.bindIgmpStatService(igmpKafkaIntegration.ignore);
42 igmpKafkaIntegration.activate();
43 }
44
45 @AfterEach
46 void tearDown() {
47 igmpKafkaIntegration.unbindIgmpStatService(igmpKafkaIntegration.ignore);
48 igmpKafkaIntegration.deactivate();
49 }
50
51 /**
52 * test to verify IgmpStatisticsEvent event.
53 */
54 @Test
55 void testIgmpStatisticsEvent() {
56 igmpStatisticsEventListener.event(getIgmpStatisticsEvent());
57 assertEquals(MockEventBusService.igmpstats, 1);
58 assertEquals(MockEventBusService.otherCounter, 0);
59 }
60
61 private static class MockEventBusService implements EventBusService {
62 static int igmpstats;
63 static int otherCounter;
64
65 MockEventBusService() {
66 igmpstats = 0;
67 otherCounter = 0;
68 }
69
70 @Override
71 public void send(String topic, JsonNode data) {
72 if (topic.equals(IgmpKafkaIntegration.IGMP_STATISTICS_TOPIC)) {
73 igmpstats++;
74 } else {
75 otherCounter++;
76 }
77 }
78 }
79
80 private class MockIgmpStatisticsService implements IgmpStatisticsService {
kishoreefa3db52020-03-23 16:09:26 +053081
82 @Override
83 public void addListener(IgmpStatisticsEventListener listener) {
84 igmpStatisticsEventListener = listener;
85 }
86
87 @Override
88 public void removeListener(IgmpStatisticsEventListener listener) {
89 igmpStatisticsEventListener = null;
90 }
Ilayda Ozdemir8b96b322020-06-18 08:52:17 +000091
92 @Override
93 public void increaseStat(IgmpStatisticType igmpStatisticType) {
94
95 }
96
97 @Override
98 public void resetAllStats() {
99
100 }
101
102 @Override
103 public Long getStat(IgmpStatisticType igmpStatisticType) {
104 return 0L;
105 }
kishoreefa3db52020-03-23 16:09:26 +0530106 }
107}