Clean up mdsal-netconf-notification 44/104344/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Feb 2023 15:11:57 +0000 (16:11 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 13 Feb 2023 11:47:00 +0000 (11:47 +0000)
Remove impl.ops package and modernize classes a bit.

Change-Id: I4a5f549c2d05cefac544ce1a426815cbc2bc17d8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/CreateSubscription.java [moved from netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java with 97% similarity]
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationOperationService.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NotificationsTransformUtil.java [moved from netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtil.java with 98% similarity]
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/OperationalDatastoreListener.java
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/CreateSubscriptionTest.java [moved from netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscriptionTest.java with 97% similarity]
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/NotificationsTransformUtilTest.java [moved from netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtilTest.java with 98% similarity]
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/OperationalDatastoreListenerTest.java

@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.netconf.mdsal.notification.impl.ops;
+package org.opendaylight.netconf.mdsal.notification.impl;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
@@ -19,7 +19,6 @@ import org.opendaylight.netconf.api.NetconfSession;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mapping.api.SessionAwareNetconfOperation;
-import org.opendaylight.netconf.mdsal.notification.impl.NetconfNotificationManager;
 import org.opendaylight.netconf.notifications.NetconfNotification;
 import org.opendaylight.netconf.notifications.NetconfNotificationListener;
 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
index 0a1bac8a2ada4ff47e883c313137845121189e6e..0960aaa37212e3bffdbbe7ae0a356349b2bf0e9c 100644 (file)
@@ -27,7 +27,6 @@ import javax.inject.Singleton;
 import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeGenerator;
-import org.opendaylight.netconf.mdsal.notification.impl.ops.NotificationsTransformUtil;
 import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
 import org.opendaylight.netconf.notifications.NetconfNotification;
 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
index 3bfa7baaf7312db261e72250b118ca6430a40a17..b36cc8029bfecf5cadaa06a7ad6ffd67c6cdef3c 100644 (file)
@@ -5,42 +5,29 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.notification.impl;
 
-import java.util.Collections;
 import java.util.Set;
 import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
-import org.opendaylight.netconf.mdsal.notification.impl.ops.CreateSubscription;
 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
 
-public class NetconfNotificationOperationService implements NetconfOperationService {
-    private final Set<NetconfOperation> netconfOperations;
+public final class NetconfNotificationOperationService implements NetconfOperationService {
+    private final CreateSubscription createSubscription;
 
-    public NetconfNotificationOperationService(String netconfSessionIdForReporting, NetconfNotificationRegistry
-            netconfNotificationRegistry) {
-        this.netconfOperations = Collections.singleton(new CreateSubscription(netconfSessionIdForReporting,
-                netconfNotificationRegistry));
+    public NetconfNotificationOperationService(final String netconfSessionIdForReporting,
+            final NetconfNotificationRegistry netconfNotificationRegistry) {
+        createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationRegistry);
     }
 
-
     @Override
     public Set<NetconfOperation> getNetconfOperations() {
-        return netconfOperations;
+        return Set.of(createSubscription);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public void close() {
-        for (NetconfOperation netconfOperation : netconfOperations) {
-            if (netconfOperation instanceof AutoCloseable) {
-                try {
-                    ((AutoCloseable) netconfOperation).close();
-                } catch (Exception e) {
-                    throw new IllegalStateException("Exception while closing " + netconfOperation, e);
-                }
-            }
-        }
+        createSubscription.close();
     }
 }
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.netconf.mdsal.notification.impl.ops;
+package org.opendaylight.netconf.mdsal.notification.impl;
 
 import static com.google.common.base.Verify.verify;
 
index 5154b838746d7b33295ad7a125c66b45330aadc9..406e564025899aa3e89d5ca5270ae398c9eae647 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.mdsal.notification.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
@@ -21,7 +23,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * @param <T> data object class
  */
 abstract class OperationalDatastoreListener<T extends DataObject> implements DataTreeChangeListener<T> {
-
     private final InstanceIdentifier<T> instanceIdentifier;
 
     /**
@@ -30,7 +31,7 @@ abstract class OperationalDatastoreListener<T extends DataObject> implements Dat
      * @param instanceIdentifier instance identifier of subtree, on which this instance should listen on changes.
      */
     OperationalDatastoreListener(final InstanceIdentifier<T> instanceIdentifier) {
-        this.instanceIdentifier = instanceIdentifier;
+        this.instanceIdentifier = requireNonNull(instanceIdentifier);
     }
 
     /**
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.netconf.mdsal.notification.impl.ops;
+package org.opendaylight.netconf.mdsal.notification.impl;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.MatcherAssert.assertThat;
index c8b9faceae5c1e633d2377e668992ee19ae891ca..254489d4bb7932892b00a22c2ced18aad6721b1c 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collection;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.binding.api.DataBroker;
@@ -30,12 +31,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 public class OperationalDatastoreListenerTest {
     @Mock
     private DataBroker dataBroker;
+    @Captor
+    private ArgumentCaptor<DataTreeIdentifier<?>> argumentId;
 
     @Test
     public void testDataStoreListener() {
         final InstanceIdentifier<TestInterface> instanceIdentifier = InstanceIdentifier.create(TestInterface.class);
-        final DataTreeIdentifier<TestInterface> testId =
-                DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
 
         final var op = new OperationalDatastoreListener<>(instanceIdentifier) {
             @Override
@@ -45,12 +46,11 @@ public class OperationalDatastoreListenerTest {
         };
         doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
 
-        ArgumentCaptor<DataTreeIdentifier> argumentId = ArgumentCaptor.forClass(DataTreeIdentifier.class);
         op.registerOnChanges(dataBroker);
         verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
 
-        assertEquals(testId, argumentId.getValue());
-
+        assertEquals(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier),
+            argumentId.getValue());
     }
 
     interface TestInterface extends ChildOf<DataRoot> {