blob: d0bf59dc4348451fb409b9a547ee340570df188f [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 org.junit.jupiter.api.AfterEach;
21import org.junit.jupiter.api.BeforeEach;
22import org.junit.jupiter.api.Test;
23import org.opencord.bng.PppoeBngControlHandler;
24import org.opencord.bng.PppoeEventListener;
25import org.opencord.kafka.EventBusService;
26
27import static org.junit.Assert.assertEquals;
28
29/**
30 * set of unit test cases for BngPppoeKafkaIntegration.
31 */
32class BngPppoeKafkaIntegrationTest extends KafkaIntegrationTestBase {
33
34 private BngPppoeKafkaIntegration bngPppoeKafka;
35 private PppoeEventListener pppoeEventListener;
36
37 @BeforeEach
38 void setUp() {
39 bngPppoeKafka = new BngPppoeKafkaIntegration();
40 bngPppoeKafka.eventBusService = new MockEventBusService();
41 bngPppoeKafka.ignore = new MockPppoeBngControlHandler();
42 bngPppoeKafka.bindPppoeBngControl(bngPppoeKafka.ignore);
43 bngPppoeKafka.activate();
44 }
45
46 @AfterEach
47 void tearDown() {
48 bngPppoeKafka.deactivate();
49 }
50
51 /**
52 * testcase to perform PppoeEvent.
53 */
54 @Test
55 void testbngPpoeEvent() {
56 pppoeEventListener.event(getPppoeEvent());
57 assertEquals(MockEventBusService.kafkaEvents, 1);
58 assertEquals(MockEventBusService.otherCounter, 0);
59 }
60
61 private static class MockEventBusService implements EventBusService {
62 static int kafkaEvents;
63 static int otherCounter;
64
65 MockEventBusService() {
66 kafkaEvents = 0;
67 otherCounter = 0;
68 }
69
70 @Override
71 public void send(String topic, JsonNode data) {
72 if (topic.equals(BngPppoeKafkaIntegration.TOPIC_PPPOE)) {
73 kafkaEvents++;
74 } else {
75 otherCounter++;
76 }
77 }
78 }
79
80 private class MockPppoeBngControlHandler implements PppoeBngControlHandler {
81 @Override
82 public void addListener(PppoeEventListener listener) {
83 pppoeEventListener = listener;
84 }
85
86 @Override
87 public void removeListener(PppoeEventListener listener) {
88 pppoeEventListener = null;
89 }
90 }
91}