Bug 8153: Enforce check-style rules for netconf - netconf-notification-impl 64/55964/3
authormatus.kubica <matus.kubica@pantheon.tech>
Tue, 25 Apr 2017 09:27:34 +0000 (11:27 +0200)
committerTomas Cere <tcere@cisco.com>
Thu, 27 Apr 2017 12:58:29 +0000 (12:58 +0000)
    Organize Imports for Checkstyle compliance.
    Checkstyle compliance: line length.
    Checkstyle compliance: various types of small changes.
    Checkstyle compliant Exception handling.
    Checkstyle final clean up & enforcement.
    Add the fail on violation flag into the pom.xml .

Change-Id: I0f0f2a503bfc41becf6709503c02808af4324964
Signed-off-by: matus.kubica <matus.kubica@pantheon.tech>
netconf/netconf-notifications-impl/pom.xml
netconf/netconf-notifications-impl/src/main/java/org/opendaylight/netconf/notifications/impl/NetconfNotificationManager.java
netconf/netconf-notifications-impl/src/main/java/org/opendaylight/netconf/notifications/impl/ops/CreateSubscription.java
netconf/netconf-notifications-impl/src/main/java/org/opendaylight/netconf/notifications/impl/ops/Get.java
netconf/netconf-notifications-impl/src/main/java/org/opendaylight/netconf/notifications/impl/ops/NotificationsTransformUtil.java
netconf/netconf-notifications-impl/src/main/java/org/opendaylight/netconf/notifications/impl/osgi/Activator.java
netconf/netconf-notifications-impl/src/test/java/org/opendaylight/netconf/notifications/impl/NetconfNotificationManagerTest.java
netconf/netconf-notifications-impl/src/test/java/org/opendaylight/netconf/notifications/impl/ops/CreateSubscriptionTest.java
netconf/netconf-notifications-impl/src/test/java/org/opendaylight/netconf/notifications/impl/ops/GetTest.java
netconf/netconf-notifications-impl/src/test/java/org/opendaylight/netconf/notifications/impl/ops/NotificationsTransformUtilTest.java
netconf/netconf-notifications-impl/src/test/java/org/opendaylight/netconf/notifications/impl/osgi/ActivatorTest.java

index 79eb3a92dabea0a713ccd744360681fb2c19c544..5d4a84d64354c580dde284a925fe623372097824 100644 (file)
                     </instructions>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 </project>
index 00552066a2ce9f73c66ab74621e0d1d8accc45e2..c8989e59496ae304ccbf721f75c4e3d3c3023c29 100644 (file)
@@ -44,7 +44,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @ThreadSafe
-public class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry, NetconfNotificationListener, AutoCloseable {
+public class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry,
+        NetconfNotificationListener, AutoCloseable {
 
     public static final StreamNameType BASE_STREAM_NAME = new StreamNameType("NETCONF");
     public static final Stream BASE_NETCONF_STREAM;
@@ -60,11 +61,14 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfNotificationManager.class);
 
-    // TODO excessive synchronization provides thread safety but is most likely not optimal (combination of concurrent collections might improve performance)
-    // And also calling callbacks from a synchronized block is dangerous since the listeners/publishers can block the whole notification processing
+    // TODO excessive synchronization provides thread safety but is most likely not optimal
+    // (combination of concurrent collections might improve performance)
+    // And also calling callbacks from a synchronized block is dangerous
+    // since the listeners/publishers can block the whole notification processing
 
     @GuardedBy("this")
-    private final Multimap<StreamNameType, GenericNotificationListenerReg> notificationListeners = HashMultimap.create();
+    private final Multimap<StreamNameType, GenericNotificationListenerReg> notificationListeners =
+            HashMultimap.create();
 
     @GuardedBy("this")
     private final Set<NetconfNotificationStreamListener> streamListeners = Sets.newHashSet();
@@ -91,13 +95,16 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
     }
 
     @Override
-    public synchronized NotificationListenerRegistration registerNotificationListener(final StreamNameType stream, final NetconfNotificationListener listener) {
+    public synchronized NotificationListenerRegistration registerNotificationListener(
+            final StreamNameType stream,
+            final NetconfNotificationListener listener) {
         Preconditions.checkNotNull(stream);
         Preconditions.checkNotNull(listener);
 
         LOG.trace("Notification listener registered for stream: {}", stream);
 
-        final GenericNotificationListenerReg genericNotificationListenerReg = new GenericNotificationListenerReg(listener) {
+        final GenericNotificationListenerReg genericNotificationListenerReg =
+                new GenericNotificationListenerReg(listener) {
             @Override
             public void close() {
                 synchronized (NetconfNotificationManager.this) {
@@ -122,7 +129,8 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
     }
 
     @Override
-    public synchronized NotificationRegistration registerStreamListener(final NetconfNotificationStreamListener listener) {
+    public synchronized NotificationRegistration registerStreamListener(
+            final NetconfNotificationStreamListener listener) {
         streamListeners.add(listener);
 
         // Notify about all already available
@@ -169,14 +177,16 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
         }
 
         if (streamMetadata.containsKey(streamName)) {
-            LOG.warn("Notification stream {} already registered as: {}. Will be reused", streamName, streamMetadata.get(streamName));
+            LOG.warn("Notification stream {} already registered as: {}. Will be reused", streamName,
+                    streamMetadata.get(streamName));
         } else {
             streamMetadata.put(streamName, stream);
         }
 
         availableStreams.add(streamName);
 
-        final GenericNotificationPublisherReg genericNotificationPublisherReg = new GenericNotificationPublisherReg(this, streamName) {
+        final GenericNotificationPublisherReg genericNotificationPublisherReg =
+                new GenericNotificationPublisherReg(this, streamName) {
             @Override
             public void close() {
                 synchronized (NetconfNotificationManager.this) {
@@ -191,7 +201,9 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
         return genericNotificationPublisherReg;
     }
 
-    private void unregisterNotificationPublisher(final StreamNameType streamName, final GenericNotificationPublisherReg genericNotificationPublisherReg) {
+    private void unregisterNotificationPublisher(
+            final StreamNameType streamName,
+            final GenericNotificationPublisherReg genericNotificationPublisherReg) {
         availableStreams.remove(streamName);
         notificationPublishers.remove(genericNotificationPublisherReg);
 
@@ -219,7 +231,8 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
     @Override
     public BaseNotificationPublisherRegistration registerBaseNotificationPublisher() {
-        final NotificationPublisherRegistration notificationPublisherRegistration = registerNotificationPublisher(BASE_NETCONF_STREAM);
+        final NotificationPublisherRegistration notificationPublisherRegistration =
+                registerNotificationPublisher(BASE_NETCONF_STREAM);
         return new BaseNotificationPublisherReg(notificationPublisherRegistration);
     }
 
@@ -227,7 +240,8 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
         private NetconfNotificationManager baseListener;
         private final StreamNameType registeredStream;
 
-        public GenericNotificationPublisherReg(final NetconfNotificationManager baseListener, final StreamNameType registeredStream) {
+        GenericNotificationPublisherReg(final NetconfNotificationManager baseListener,
+                                        final StreamNameType registeredStream) {
             this.baseListener = baseListener;
             this.registeredStream = registeredStream;
         }
@@ -254,7 +268,7 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
         private final NotificationPublisherRegistration baseRegistration;
 
-        public BaseNotificationPublisherReg(final NotificationPublisherRegistration baseRegistration) {
+        BaseNotificationPublisherReg(final NotificationPublisherRegistration baseRegistration) {
             this.baseRegistration = baseRegistration;
         }
 
@@ -269,7 +283,8 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
         @Override
         public void onCapabilityChanged(final NetconfCapabilityChange capabilityChange) {
-            baseRegistration.onNotification(BASE_STREAM_NAME, serializeNotification(capabilityChange, CAPABILITY_CHANGE_SCHEMA_PATH));
+            baseRegistration.onNotification(BASE_STREAM_NAME,
+                    serializeNotification(capabilityChange, CAPABILITY_CHANGE_SCHEMA_PATH));
         }
 
         @Override
@@ -286,7 +301,7 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
     private class GenericNotificationListenerReg implements NotificationListenerRegistration {
         private final NetconfNotificationListener listener;
 
-        public GenericNotificationListenerReg(final NetconfNotificationListener listener) {
+        GenericNotificationListenerReg(final NetconfNotificationListener listener) {
             this.listener = listener;
         }
 
index d1a46a67bd7086cdab56c4ac38819932b69e2e5b..812080618cdc51a46dac9d3a2e84751a57eb7be0 100644 (file)
@@ -34,10 +34,12 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 /**
- * Create subscription listens for create subscription requests and registers notification listeners into notification registry.
+ * Create subscription listens for create subscription requests
+ * and registers notification listeners into notification registry.
  * Received notifications are sent to the client right away
  */
-public class CreateSubscription extends AbstractSingletonNetconfOperation implements SessionAwareNetconfOperation, AutoCloseable {
+public class CreateSubscription extends AbstractSingletonNetconfOperation
+        implements SessionAwareNetconfOperation, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(CreateSubscription.class);
 
@@ -47,13 +49,15 @@ public class CreateSubscription extends AbstractSingletonNetconfOperation implem
     private final List<NotificationListenerRegistration> subscriptions = Lists.newArrayList();
     private NetconfSession netconfSession;
 
-    public CreateSubscription(final String netconfSessionIdForReporting, final NetconfNotificationRegistry notifications) {
+    public CreateSubscription(final String netconfSessionIdForReporting,
+                              final NetconfNotificationRegistry notifications) {
         super(netconfSessionIdForReporting);
         this.notifications = notifications;
     }
 
     @Override
-    protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
+    protected Element handleWithNoSubsequentOperations(final Document document,
+                                                       final XmlElement operationElement) throws DocumentedException {
         operationElement.checkName(CREATE_SUBSCRIPTION);
         operationElement.checkNamespace(CreateSubscriptionInput.QNAME.getNamespace().toString());
         // FIXME reimplement using CODEC_REGISTRY and parse everything into generated class instance
@@ -63,23 +67,26 @@ public class CreateSubscription extends AbstractSingletonNetconfOperation implem
         final Optional<XmlElement> filter = operationElement.getOnlyChildElementWithSameNamespaceOptionally("filter");
 
         // Replay not supported
-        final Optional<XmlElement> startTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
+        final Optional<XmlElement> startTime =
+                operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
         Preconditions.checkArgument(startTime.isPresent() == false, "StartTime element not yet supported");
 
         // Stop time not supported
-        final Optional<XmlElement> stopTime = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
+        final Optional<XmlElement> stopTime =
+                operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
         Preconditions.checkArgument(stopTime.isPresent() == false, "StopTime element not yet supported");
 
         final StreamNameType streamNameType = parseStreamIfPresent(operationElement);
 
         Preconditions.checkNotNull(netconfSession);
         // Premature streams are allowed (meaning listener can register even if no provider is available yet)
-        if(notifications.isStreamAvailable(streamNameType) == false) {
-            LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType, getNetconfSessionIdForReporting());
+        if (notifications.isStreamAvailable(streamNameType) == false) {
+            LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType,
+                    getNetconfSessionIdForReporting());
         }
 
-        final NotificationListenerRegistration notificationListenerRegistration =
-                notifications.registerNotificationListener(streamNameType, new NotificationSubscription(netconfSession, filter));
+        final NotificationListenerRegistration notificationListenerRegistration = notifications
+                .registerNotificationListener(streamNameType, new NotificationSubscription(netconfSession, filter));
         subscriptions.add(notificationListenerRegistration);
 
         return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
@@ -87,7 +94,8 @@ public class CreateSubscription extends AbstractSingletonNetconfOperation implem
 
     private static StreamNameType parseStreamIfPresent(final XmlElement operationElement) throws DocumentedException {
         final Optional<XmlElement> stream = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stream");
-        return stream.isPresent() ? new StreamNameType(stream.get().getTextContent()) : NetconfNotificationManager.BASE_STREAM_NAME;
+        return stream.isPresent() ? new StreamNameType(stream.get().getTextContent())
+                : NetconfNotificationManager.BASE_STREAM_NAME;
     }
 
     @Override
@@ -118,7 +126,7 @@ public class CreateSubscription extends AbstractSingletonNetconfOperation implem
         private final NetconfSession currentSession;
         private final Optional<XmlElement> filter;
 
-        public NotificationSubscription(final NetconfSession currentSession, final Optional<XmlElement> filter) {
+        NotificationSubscription(final NetconfSession currentSession, final Optional<XmlElement> filter) {
             this.currentSession = currentSession;
             this.filter = filter;
         }
@@ -127,7 +135,8 @@ public class CreateSubscription extends AbstractSingletonNetconfOperation implem
         public void onNotification(final StreamNameType stream, final NetconfNotification notification) {
             if (filter.isPresent()) {
                 try {
-                    final Optional<Document> filtered = SubtreeFilter.applySubtreeNotificationFilter(this.filter.get(), notification.getDocument());
+                    final Optional<Document> filtered =
+                            SubtreeFilter.applySubtreeNotificationFilter(this.filter.get(), notification.getDocument());
                     if (filtered.isPresent()) {
                         final Date eventTime = notification.getEventTime();
                         currentSession.sendMessage(new NetconfNotification(filtered.get(), eventTime));
index 78db2f6c69c88b1244ffcbcf6347aa55c8542527..3655ae209cf3ffab1e3518eae999757771b34d48 100644 (file)
@@ -37,7 +37,8 @@ import org.w3c.dom.Element;
 public class Get extends AbstractNetconfOperation implements AutoCloseable {
 
     private static final String GET = "get";
-    private static final InstanceIdentifier<Netconf> NETCONF_SUBTREE_INSTANCE_IDENTIFIER = InstanceIdentifier.builder(Netconf.class).build();
+    private static final InstanceIdentifier<Netconf> NETCONF_SUBTREE_INSTANCE_IDENTIFIER =
+            InstanceIdentifier.builder(Netconf.class).build();
 
     private final NetconfNotificationRegistry notificationRegistry;
 
@@ -53,23 +54,33 @@ public class Get extends AbstractNetconfOperation implements AutoCloseable {
     }
 
     @Override
-    public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
+    protected Element handle(final Document document, final XmlElement message,
+                             final NetconfOperationChainedExecution subsequentOperation)
+            throws DocumentedException {
+        throw new UnsupportedOperationException("Never gets called");
+    }
+
+    @Override
+    public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation)
+            throws DocumentedException {
         final Document partialResponse = subsequentOperation.execute(requestMessage);
         final Streams availableStreams = notificationRegistry.getNotificationPublishers();
-        if(availableStreams.getStream().isEmpty() == false) {
+        if (availableStreams.getStream().isEmpty() == false) {
             serializeStreamsSubtree(partialResponse, availableStreams);
         }
         return partialResponse;
     }
 
-    static void serializeStreamsSubtree(final Document partialResponse, final Streams availableStreams) throws DocumentedException {
+    static void serializeStreamsSubtree(final Document partialResponse, final Streams availableStreams)
+            throws DocumentedException {
         final Netconf netconfSubtree = new NetconfBuilder().setStreams(availableStreams).build();
         final NormalizedNode<?, ?> normalized = toNormalized(netconfSubtree);
 
         final DOMResult result = new DOMResult(getPlaceholder(partialResponse));
 
         try {
-            NetconfUtil.writeNormalizedNode(normalized, result, SchemaPath.ROOT, NotificationsTransformUtil.NOTIFICATIONS_SCHEMA_CTX);
+            NetconfUtil.writeNormalizedNode(normalized, result, SchemaPath.ROOT,
+                    NotificationsTransformUtil.NOTIFICATIONS_SCHEMA_CTX);
         } catch (final XMLStreamException | IOException e) {
             throw new IllegalStateException("Unable to serialize " + netconfSubtree, e);
         }
@@ -77,19 +88,14 @@ public class Get extends AbstractNetconfOperation implements AutoCloseable {
 
     private static Element getPlaceholder(final Document innerResult)
             throws DocumentedException {
-        final XmlElement rootElement = XmlElement.fromDomElementWithExpected(
-                innerResult.getDocumentElement(), XmlMappingConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        final XmlElement rootElement = XmlElement.fromDomElementWithExpected(innerResult.getDocumentElement(),
+                XmlMappingConstants.RPC_REPLY_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
         return rootElement.getOnlyChildElement(XmlNetconfConstants.DATA_KEY).getDomElement();
     }
 
     private static NormalizedNode<?, ?> toNormalized(final Netconf netconfSubtree) {
-        return NotificationsTransformUtil.CODEC_REGISTRY.toNormalizedNode(NETCONF_SUBTREE_INSTANCE_IDENTIFIER, netconfSubtree).getValue();
-    }
-
-    @Override
-    protected Element handle(final Document document, final XmlElement message, final NetconfOperationChainedExecution subsequentOperation)
-            throws DocumentedException {
-        throw new UnsupportedOperationException("Never gets called");
+        return NotificationsTransformUtil.CODEC_REGISTRY
+                .toNormalizedNode(NETCONF_SUBTREE_INSTANCE_IDENTIFIER, netconfSubtree).getValue();
     }
 
     @Override
index 8b74054c78e11d943c9b2853a2286c13604c1bdf..d3e7a2eb5da3d161ec23ea2721b227705a102ca2 100644 (file)
@@ -51,7 +51,8 @@ public final class NotificationsTransformUtil {
 
         final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
         moduleInfoBackedContext.addModuleInfos(Collections.singletonList($YangModuleInfoImpl.getInstance()));
-        moduleInfoBackedContext.addModuleInfos(Collections.singletonList(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.$YangModuleInfoImpl.getInstance()));
+        moduleInfoBackedContext.addModuleInfos(Collections.singletonList(org.opendaylight.yang.gen.v1.urn.ietf.params
+                .xml.ns.yang.ietf.netconf.notifications.rev120206.$YangModuleInfoImpl.getInstance()));
         final Optional<SchemaContext> schemaContextOptional = moduleInfoBackedContext.tryToCreateSchemaContext();
         Preconditions.checkState(schemaContextOptional.isPresent());
         NOTIFICATIONS_SCHEMA_CTX = schemaContextOptional.get();
@@ -62,41 +63,43 @@ public final class NotificationsTransformUtil {
 
         final JavassistUtils javassist = JavassistUtils.forClassPool(ClassPool.getDefault());
         CODEC_REGISTRY = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(javassist));
-        CODEC_REGISTRY.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(moduleInfoBackedContext, NOTIFICATIONS_SCHEMA_CTX));
+        CODEC_REGISTRY.onBindingRuntimeContextUpdated(BindingRuntimeContext.create(moduleInfoBackedContext,
+                NOTIFICATIONS_SCHEMA_CTX));
     }
 
     private static RpcDefinition findCreateSubscriptionRpc() {
-        return Iterables.getFirst(Collections2.filter(NOTIFICATIONS_SCHEMA_CTX.getOperations(), new Predicate<RpcDefinition>() {
-            @Override
-            public boolean apply(final RpcDefinition input) {
-                return input.getQName().getLocalName().equals(CreateSubscription.CREATE_SUBSCRIPTION);
-            }
-        }), null);
+        return Iterables.getFirst(Collections2.filter(NOTIFICATIONS_SCHEMA_CTX.getOperations(),
+            new Predicate<RpcDefinition>() {
+                @Override
+                public boolean apply(final RpcDefinition input) {
+                    return input.getQName().getLocalName().equals(CreateSubscription.CREATE_SUBSCRIPTION);
+                }
+            }), null);
     }
 
     /**
-     * Transform base notification for capabilities into NetconfNotification
+     * Transform base notification for capabilities into NetconfNotification.
      */
     public static NetconfNotification transform(final Notification notification, SchemaPath path) {
         return transform(notification, Optional.<Date>absent(), path);
     }
 
-    public static NetconfNotification transform(final Notification notification, final Date eventTime, SchemaPath path) {
+    public static NetconfNotification transform(final Notification notification,
+                                                final Date eventTime, SchemaPath path) {
         return transform(notification, Optional.fromNullable(eventTime), path);
     }
 
-    private static NetconfNotification transform(final Notification notification, final Optional<Date> eventTime, SchemaPath path) {
+    private static NetconfNotification transform(final Notification notification,
+                                                 final Optional<Date> eventTime, SchemaPath path) {
         final ContainerNode containerNode = CODEC_REGISTRY.toNormalizedNodeNotification(notification);
         final DOMResult result = new DOMResult(XmlUtil.newDocument());
         try {
             NetconfUtil.writeNormalizedNode(containerNode, result, path, NOTIFICATIONS_SCHEMA_CTX);
-        } catch (final XMLStreamException| IOException e) {
+        } catch (final XMLStreamException | IOException e) {
             throw new IllegalStateException("Unable to serialize " + notification, e);
         }
         final Document node = (Document) result.getNode();
-        return eventTime.isPresent() ?
-                new NetconfNotification(node, eventTime.get()):
-                new NetconfNotification(node);
+        return eventTime.isPresent() ? new NetconfNotification(node, eventTime.get()) : new NetconfNotification(node);
     }
 
 }
index 1cbd5237389dad5900da775ce0458399ecb20721..146f5e7116aa3f56c2277b687d495696ef658360 100644 (file)
@@ -46,11 +46,13 @@ public class Activator implements BundleActivator {
         // Add properties to autowire with netconf-impl instance for cfg subsystem
         final Dictionary<String, String> props = new Hashtable<>();
         props.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_NOTIFICATION);
-        netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
+        netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class,
+                netconfNotificationManager, new Hashtable<String, Object>());
 
         final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
 
-            private final Set<Capability> capabilities = Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
+            private final Set<Capability> capabilities =
+                    Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
 
             @Override
             public Set<Capability> getCapabilities() {
@@ -72,7 +74,8 @@ public class Activator implements BundleActivator {
             public NetconfOperationService createService(final String netconfSessionIdForReporting) {
                 return new NetconfOperationService() {
 
-                    private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
+                    private final CreateSubscription createSubscription =
+                            new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
 
                     @Override
                     public Set<NetconfOperation> getNetconfOperations() {
@@ -91,12 +94,13 @@ public class Activator implements BundleActivator {
 
         final Dictionary<String, String> properties = new Hashtable<>();
         properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
-        operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
+        operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class,
+                netconfOperationServiceFactory, properties);
     }
 
     @Override
     public void stop(final BundleContext context) throws Exception {
-        if(netconfNotificationCollectorServiceRegistration != null) {
+        if (netconfNotificationCollectorServiceRegistration != null) {
             netconfNotificationCollectorServiceRegistration.unregister();
             netconfNotificationCollectorServiceRegistration = null;
         }
index 98c5e6bc5e77b02533f73b945ea711d397816b04..a40b2c58dc1733bae42263b44cf4abb5b53ca732 100644 (file)
@@ -97,7 +97,8 @@ public class NetconfNotificationManagerTest {
         )) {
             try {
                 final Date apply = NetconfNotification.RFC3339_DATE_PARSER.apply(time);
-                final Date parse = new SimpleDateFormat(RFC3339_DATE_FORMAT_WITH_MILLIS_BLUEPRINT).parse(iterator.next());
+                final Date parse =
+                        new SimpleDateFormat(RFC3339_DATE_FORMAT_WITH_MILLIS_BLUEPRINT).parse(iterator.next());
                 assertEquals(parse.getTime(), apply.getTime());
                 // Testing that we're consistent from formatting to parsing.
                 final String dateString = NetconfNotification.RFC3339_DATE_FORMATTER.apply(apply);
@@ -147,7 +148,8 @@ public class NetconfNotificationManagerTest {
 
         final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
         doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
-        final NotificationListenerRegistration notificationListenerRegistration = netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
+        final NotificationListenerRegistration notificationListenerRegistration = netconfNotificationManager
+                .registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
         final NetconfCapabilityChange notification = capabilityChangedBuilder.build();
         baseNotificationPublisherRegistration.onCapabilityChanged(notification);
 
@@ -163,12 +165,14 @@ public class NetconfNotificationManagerTest {
     public void testClose() throws Exception {
         final NetconfNotificationManager netconfNotificationManager = new NetconfNotificationManager();
 
-        final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher();
+        final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration =
+                netconfNotificationManager.registerBaseNotificationPublisher();
 
         final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
         doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
 
-        netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
+        netconfNotificationManager
+                .registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
 
         final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener =
                 mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class);
@@ -196,7 +200,8 @@ public class NetconfNotificationManagerTest {
     public void testStreamListeners() throws Exception {
         final NetconfNotificationManager netconfNotificationManager = new NetconfNotificationManager();
 
-        final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener = mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class);
+        final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener =
+                mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class);
         doNothing().when(streamListener).onStreamRegistered(any(Stream.class));
         doNothing().when(streamListener).onStreamUnregistered(any(StreamNameType.class));
 
index 4de90fab238649d79d60ab2dd1d8aa5bae1275fb..69bdb1fb843452f305716d4e8bef179ebd87687b 100644 (file)
@@ -29,10 +29,11 @@ import org.w3c.dom.Element;
 
 public class CreateSubscriptionTest {
 
-    private static final String CREATE_SUBSCRIPTION_XML = "<create-subscription\n" +
-            "xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-            "<stream>TESTSTREAM</stream>" +
-            "</create-subscription>";
+    private static final String CREATE_SUBSCRIPTION_XML = "<create-subscription\n"
+            + "xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\" "
+            + "xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+            + "<stream>TESTSTREAM</stream>"
+            + "</create-subscription>";
 
     @Mock
     private NetconfNotificationRegistry notificationRegistry;
@@ -41,7 +42,8 @@ public class CreateSubscriptionTest {
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         doReturn(true).when(notificationRegistry).isStreamAvailable(any(StreamNameType.class));
-        doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry).registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
+        doReturn(mock(NotificationListenerRegistration.class)).when(notificationRegistry)
+                .registerNotificationListener(any(StreamNameType.class), any(NetconfNotificationListener.class));
     }
 
     @Test
@@ -52,7 +54,8 @@ public class CreateSubscriptionTest {
         final Element e = XmlUtil.readXmlToElement(CREATE_SUBSCRIPTION_XML);
 
         final XmlElement operationElement = XmlElement.fromDomElement(e);
-        final Element element = createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
+        final Element element =
+                createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
 
         Assert.assertThat(XmlUtil.toString(element), CoreMatchers.containsString("ok"));
     }
index f3dbc249fbd6f7ef9e92a4c85fad0335d1085035..0abf5cbf9c8a644e9241573d998d7026c5847c3f 100644 (file)
@@ -37,27 +37,27 @@ public class GetTest {
         final Document response = getBlankResponse();
         Get.serializeStreamsSubtree(response, streams);
         NotificationsTransformUtilTest.compareXml(XmlUtil.toString(response),
-                "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                        "<data>\n" +
-                        "<netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n" +
-                        "<streams>\n" +
-                        "<stream>\n" +
-                        "<name>base</name>\n" +
-                        "<description>description</description>\n" +
-                        "<replaySupport>false</replaySupport>\n" +
-                        "</stream>\n" +
-                        "</streams>\n" +
-                        "</netconf>\n" +
-                        "</data>\n" +
-                        "</rpc-reply>\n");
+                "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                        + "<data>\n"
+                        + "<netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n"
+                        + "<streams>\n"
+                        + "<stream>\n"
+                        + "<name>base</name>\n"
+                        + "<description>description</description>\n"
+                        + "<replaySupport>false</replaySupport>\n"
+                        + "</stream>\n"
+                        + "</streams>\n"
+                        + "</netconf>\n"
+                        + "</data>\n"
+                        "</rpc-reply>\n");
     }
 
     private static Document getBlankResponse() throws IOException, SAXException {
 
-        return XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" +
-                "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
-                "<data>\n" +
-                "</data>\n" +
-                "</rpc-reply>");
+        return XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n"
+                + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<data>\n"
+                + "</data>\n"
+                "</rpc-reply>");
     }
 }
\ No newline at end of file
index 84d77ef16381040e6ba933bbfdf1a36cbc092902..4ae9d85316ab86af092c7b65327982fad49d85e4 100644 (file)
@@ -29,19 +29,20 @@ import org.xml.sax.SAXException;
 public class NotificationsTransformUtilTest {
 
     private static final Date DATE = new Date();
-    private static final String innerNotification = "<netconf-capability-change xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-notifications\">" +
-            "<deleted-capability>uri4</deleted-capability>" +
-            "<deleted-capability>uri3</deleted-capability>" +
-            "<added-capability>uri1</added-capability>" +
-            "</netconf-capability-change>";
+    private static final String INNER_NOTIFICATION =
+            "<netconf-capability-change xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-notifications\">"
+                    + "<deleted-capability>uri4</deleted-capability>"
+                    + "<deleted-capability>uri3</deleted-capability>"
+                    + "<added-capability>uri1</added-capability>"
+                    + "</netconf-capability-change>";
 
-    private static final String expectedNotification =
+    private static final String EXPECTED_NOTIFICATION =
             "<notification xmlns=\"urn:ietf:params:netconf:capability:notification:1.0\">"
-                    + innerNotification
+                    + INNER_NOTIFICATION
                     + "<eventTime>"
-                        + NetconfNotification.RFC3339_DATE_FORMATTER.apply(DATE)
-                    + "</eventTime>" +
-            "</notification>";
+                    + NetconfNotification.RFC3339_DATE_FORMATTER.apply(DATE)
+                    + "</eventTime>"
+                    + "</notification>";
 
     @Test
     public void testTransform() throws Exception {
@@ -51,11 +52,12 @@ public class NotificationsTransformUtilTest {
         netconfCapabilityChangeBuilder.setDeletedCapability(Lists.newArrayList(new Uri("uri4"), new Uri("uri3")));
 
         final NetconfCapabilityChange capabilityChange = netconfCapabilityChangeBuilder.build();
-        final NetconfNotification transform = NotificationsTransformUtil.transform(capabilityChange, DATE, SchemaPath.create(true, NetconfCapabilityChange.QNAME));
+        final NetconfNotification transform = NotificationsTransformUtil.transform(capabilityChange, DATE,
+                SchemaPath.create(true, NetconfCapabilityChange.QNAME));
 
         final String serialized = XmlUtil.toString(transform.getDocument());
 
-        compareXml(expectedNotification, serialized);
+        compareXml(EXPECTED_NOTIFICATION, serialized);
     }
 
     static void compareXml(final String expected, final String actual) throws SAXException, IOException {
@@ -68,10 +70,11 @@ public class NotificationsTransformUtilTest {
 
     @Test
     public void testTransformFromDOM() throws Exception {
-        final NetconfNotification netconfNotification = new NetconfNotification(XmlUtil.readXmlToDocument(innerNotification), DATE);
+        final NetconfNotification netconfNotification =
+                new NetconfNotification(XmlUtil.readXmlToDocument(INNER_NOTIFICATION), DATE);
 
         XMLUnit.setIgnoreWhitespace(true);
-        compareXml(expectedNotification, netconfNotification.toString());
+        compareXml(EXPECTED_NOTIFICATION, netconfNotification.toString());
     }
 
 }
index 24e865212786d591cef43c0cceca5af717754bf5..66e9370c6db9a8e2985afe6f46bad82b2d67d489 100644 (file)
@@ -50,10 +50,10 @@ public class ActivatorTest {
         final ServiceRegistration operationaServiceRegistration = mock(ServiceRegistration.class);
 
         // test registering services
-        doReturn(netconfNotificationCollectorServiceRegistration).when(context).
-                registerService(eq(NetconfNotificationCollector.class), any(NetconfNotificationManager.class), any());
-        doReturn(operationaServiceRegistration).when(context).
-                registerService(eq(NetconfOperationServiceFactory.class), any(NetconfOperationServiceFactory.class), any());
+        doReturn(netconfNotificationCollectorServiceRegistration).when(context)
+                .registerService(eq(NetconfNotificationCollector.class), any(NetconfNotificationManager.class), any());
+        doReturn(operationaServiceRegistration).when(context).registerService(eq(NetconfOperationServiceFactory.class),
+                any(NetconfOperationServiceFactory.class), any());
 
         activator.start(context);
 
@@ -72,12 +72,17 @@ public class ActivatorTest {
         // test service factory argument requisites
         final NetconfOperationServiceFactory serviceFactory = serviceFactoryArgumentCaptor.getValue();
 
-        final Set<Capability> capabilities = Collections.singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
+        final Set<Capability> capabilities =
+                Collections.singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
 
-        assertEquals(capabilities.iterator().next().getCapabilityUri(), serviceFactory.getCapabilities().iterator().next().getCapabilityUri());
-        assertEquals(capabilities.iterator().next().getCapabilitySchema(), serviceFactory.getCapabilities().iterator().next().getCapabilitySchema());
-        assertEquals(capabilities.iterator().next().getModuleNamespace(), serviceFactory.getCapabilities().iterator().next().getModuleNamespace());
-        assertEquals(capabilities.iterator().next().getModuleName(), serviceFactory.getCapabilities().iterator().next().getModuleName());
+        assertEquals(capabilities.iterator().next()
+                .getCapabilityUri(), serviceFactory.getCapabilities().iterator().next().getCapabilityUri());
+        assertEquals(capabilities.iterator().next()
+                .getCapabilitySchema(), serviceFactory.getCapabilities().iterator().next().getCapabilitySchema());
+        assertEquals(capabilities.iterator().next()
+                .getModuleNamespace(), serviceFactory.getCapabilities().iterator().next().getModuleNamespace());
+        assertEquals(capabilities.iterator().next()
+                .getModuleName(), serviceFactory.getCapabilities().iterator().next().getModuleName());
 
         final CapabilityListener listener = mock(CapabilityListener.class);
 
@@ -90,17 +95,18 @@ public class ActivatorTest {
         final NetconfOperationService netconfOperationService = serviceFactory.createService("id");
         final Set<NetconfOperation> netconfOperations = netconfOperationService.getNetconfOperations();
 
-        final CreateSubscription createSubscription = new CreateSubscription("id", activator.getNetconfNotificationManager());
+        final CreateSubscription createSubscription =
+                new CreateSubscription("id", activator.getNetconfNotificationManager());
 
         netconfOperations.forEach(
-                operation -> {
-                    if (operation instanceof CreateSubscription) {
-                        assertEquals(createSubscription.toString(), operation.toString());
-                    }
-                    if (operation instanceof Get) {
-                        assertEquals("id", ((Get) operation).getNetconfSessionIdForReporting());
-                    }
+            operation -> {
+                if (operation instanceof CreateSubscription) {
+                    assertEquals(createSubscription.toString(), operation.toString());
                 }
+                if (operation instanceof Get) {
+                    assertEquals("id", ((Get) operation).getNetconfSessionIdForReporting());
+                }
+            }
         );
 
         // test unregister after stop