Implement registerNotificationListeners()
[netconf.git] / plugins / netconf-client-mdsal / src / test / java / org / opendaylight / netconf / client / mdsal / spi / NC1224Test.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.client.mdsal.spi;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11
12 import java.util.Map;
13 import org.junit.jupiter.api.AfterEach;
14 import org.junit.jupiter.api.Test;
15 import org.junit.jupiter.api.extension.ExtendWith;
16 import org.mockito.Mock;
17 import org.mockito.junit.jupiter.MockitoExtension;
18 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
21
22 @ExtendWith(MockitoExtension.class)
23 class NC1224Test {
24     private static final Absolute ONE = Absolute.of(QName.create("test", "one"));
25     private static final Absolute TWO = Absolute.of(QName.create("test", "two"));
26
27     private final NetconfDeviceNotificationService svc = new NetconfDeviceNotificationService();
28
29     @Mock
30     private DOMNotificationListener listener;
31
32     @AfterEach
33     void afterEach() {
34         assertEquals(0, svc.size());
35     }
36
37     @Test
38     void registerEmpty() {
39         try (var reg = svc.registerNotificationListener(listener)) {
40             assertEquals(0, svc.size());
41         }
42     }
43
44     @Test
45     void registerEmptyMap() {
46         try (var reg = svc.registerNotificationListeners(Map.of())) {
47             assertEquals(0, svc.size());
48         }
49     }
50
51     @Test
52     void registerOne() {
53         try (var reg = svc.registerNotificationListener(listener, ONE)) {
54             assertEquals(1, svc.size());
55         }
56     }
57
58     @Test
59     void registerOneMap() {
60         try (var reg = svc.registerNotificationListeners(Map.of(ONE, listener))) {
61             assertEquals(1, svc.size());
62         }
63     }
64
65     @Test
66     void registerOneTwo() {
67         try (var reg = svc.registerNotificationListener(listener, ONE, TWO)) {
68             assertEquals(2, svc.size());
69         }
70     }
71
72     @Test
73     void registerOneTwoMap() {
74         try (var reg = svc.registerNotificationListeners(Map.of(ONE, listener, TWO, listener))) {
75             assertEquals(2, svc.size());
76         }
77     }
78 }