Merge "Bug 8153: Enforce check-style rules for netconf - netconf-util"
authorTomas Cere <tcere@cisco.com>
Thu, 27 Apr 2017 12:51:03 +0000 (12:51 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 27 Apr 2017 12:51:03 +0000 (12:51 +0000)
26 files changed:
netconf/netconf-util/pom.xml
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/CloseableUtil.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperation.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/FramingMechanism.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SendErrorExceptionUtil.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtil.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfiguration.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/CloseableUtilTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/NetconfUtilTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperationTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperationTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageUtilTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterNotificationTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterRpcTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtilTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/NetconfXmlUnitRecursiveQualifier.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlUnitUtil.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java

index 6e8c024d15d44133d8700f77d62b915af650da29..9e30e953200fdcf6872aee20f659fb4ec9ec889a 100644 (file)
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <configuration>
+          <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
index cff8b2a890c5f6d8e547da3f817bb9936f759792..1067da9d91a619dfad978dd8b3b44945e551b57e 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.util;
 
 public class CloseableUtil {
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public static void closeAll(Iterable<? extends AutoCloseable> autoCloseables) throws Exception {
         Exception lastException = null;
         for (AutoCloseable autoCloseable : autoCloseables) {
index 0e8b9aeec4592b0f98dc5a4d719db0e44933c7c4..d81e5c9be72c37df19bcb7c69b3c240c41308991 100644 (file)
@@ -52,18 +52,22 @@ public final class NetconfUtil {
                 + XmlUtil.toString(response));
     }
 
-    public static void writeNormalizedNode(final NormalizedNode<?, ?> normalized, final DOMResult result, final SchemaPath schemaPath, final SchemaContext context)
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public static void writeNormalizedNode(final NormalizedNode<?, ?> normalized, final DOMResult result,
+                                           final SchemaPath schemaPath, final SchemaContext context)
             throws IOException, XMLStreamException {
         final XMLStreamWriter writer = XML_FACTORY.createXMLStreamWriter(result);
         try (
-             final NormalizedNodeStreamWriter normalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(writer, context, schemaPath);
-             final NormalizedNodeWriter normalizedNodeWriter =  NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter)
+             NormalizedNodeStreamWriter normalizedNodeStreamWriter =
+                     XMLStreamNormalizedNodeStreamWriter.create(writer, context, schemaPath);
+             NormalizedNodeWriter normalizedNodeWriter =
+                     NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter)
         ) {
             normalizedNodeWriter.write(normalized);
             normalizedNodeWriter.flush();
         } finally {
             try {
-                if(writer != null) {
+                if (writer != null) {
                     writer.close();
                 }
             } catch (final Exception e) {
index 32d6d79cc2cf65b330e72c7deb6f52c100df3a90..e66e59f3e7ebddacf65820a8d4daf088f2eb3a95 100644 (file)
@@ -23,8 +23,9 @@ public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperat
     @Override
     protected Element handle(final Document document, final XmlElement operationElement,
                              final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
-        if (!subsequentOperation.isExecutionTermination()){
-            throw new DocumentedException(String.format("No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation),
+        if (!subsequentOperation.isExecutionTermination()) {
+            throw new DocumentedException(String.format(
+                    "No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.MALFORMED_MESSAGE,
                     DocumentedException.ErrorSeverity.ERROR);
@@ -38,5 +39,6 @@ public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperat
         return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
     }
 
-    protected abstract Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws DocumentedException;
+    protected abstract Element handleWithNoSubsequentOperations(Document document,
+                                                                XmlElement operationElement) throws DocumentedException;
 }
index 6a4d2ae50422d45c373aae858409b63021dca6e9..4d988112eae8ad078b426e781015cc46eb6ae7fe 100644 (file)
@@ -41,8 +41,16 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
         return canHandle(operationNameAndNamespace.getOperationName(), operationNameAndNamespace.getNamespace());
     }
 
+    protected HandlingPriority canHandle(final String operationName, final String operationNamespace) {
+        return operationName.equals(getOperationName()) && operationNamespace.equals(getOperationNamespace())
+                ? getHandlingPriority()
+                : HandlingPriority.CANNOT_HANDLE;
+    }
+
     public static final class OperationNameAndNamespace {
-        private final String operationName, namespace;
+        private final String operationName;
+        private final String namespace;
+
         private final XmlElement operationElement;
 
         public OperationNameAndNamespace(final Document message) throws DocumentedException {
@@ -64,6 +72,7 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
         public XmlElement getOperationElement() {
             return operationElement;
         }
+
     }
 
     protected static XmlElement getRequestElementWithCheck(final Document message) throws DocumentedException {
@@ -71,12 +80,6 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
     }
 
-    protected HandlingPriority canHandle(final String operationName, final String operationNamespace) {
-        return operationName.equals(getOperationName()) && operationNamespace.equals(getOperationNamespace())
-                ? getHandlingPriority()
-                : HandlingPriority.CANNOT_HANDLE;
-    }
-
     protected HandlingPriority getHandlingPriority() {
         return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
     }
@@ -99,14 +102,16 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
         Map<String, Attr> attributes = requestElement.getAttributes();
 
         Element response = handle(document, operationElement, subsequentOperation);
-        Element rpcReply = XmlUtil.createElement(document, XmlMappingConstants.RPC_REPLY_KEY, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+        Element rpcReply = XmlUtil.createElement(document, XmlMappingConstants.RPC_REPLY_KEY,
+                Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
 
-        if(XmlElement.fromDomElement(response).hasNamespace()) {
+        if (XmlElement.fromDomElement(response).hasNamespace()) {
             rpcReply.appendChild(response);
         } else {
-            Element responseNS = XmlUtil.createElement(document, response.getNodeName(), Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+            Element responseNS = XmlUtil.createElement(document, response.getNodeName(),
+                    Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
             NodeList list = response.getChildNodes();
-            while(list.getLength()!=0) {
+            while (list.getLength() != 0) {
                 responseNS.appendChild(list.item(0));
             }
             rpcReply.appendChild(responseNS);
@@ -119,7 +124,8 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
         return document;
     }
 
-    protected abstract Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation)
+    protected abstract Element handle(Document document, XmlElement message,
+                                      NetconfOperationChainedExecution subsequentOperation)
             throws DocumentedException;
 
     @Override
@@ -127,7 +133,7 @@ public abstract class AbstractNetconfOperation implements NetconfOperation {
         final StringBuffer sb = new StringBuffer(getClass().getName());
         try {
             sb.append("{name=").append(getOperationName());
-        } catch(UnsupportedOperationException e) {
+        } catch (UnsupportedOperationException e) {
             // no problem
         }
         sb.append(", namespace=").append(getOperationNamespace());
index b85a0ad3a869b119d5aa6e28420d2eb51edd2b7b..ae7d7472e94217191d0b8303ed4f5707a96c32ae 100644 (file)
@@ -13,11 +13,15 @@ package org.opendaylight.netconf.util.messages;
  */
 public enum FramingMechanism {
     /**
+     * Chunked framing mechanism.
+     *
      * @see <a href="http://tools.ietf.org/html/rfc6242#section-4.2">Chunked
      *      framing mechanism</a>
      */
     CHUNK,
     /**
+     * End-of-Message framing mechanism.
+     *
      * @see <a
      *      href="http://tools.ietf.org/html/rfc6242#section-4.3">End-of-message
      *      framing mechanism</a>
index 021ba009fac88a9980b7da6a5ede96043d5e29fd..995f6a47d02716492469f8953f0b3844513c6cd2 100644 (file)
@@ -38,7 +38,7 @@ public final class NetconfMessageUtil {
     }
 
     public static boolean isOKMessage(XmlElement xmlElement) throws NetconfDocumentedException {
-        if(xmlElement.getChildElements().size() != 1) {
+        if (xmlElement.getChildElements().size() != 1) {
             return false;
         }
         try {
@@ -57,7 +57,7 @@ public final class NetconfMessageUtil {
     }
 
     public static boolean isErrorMessage(XmlElement xmlElement) throws NetconfDocumentedException {
-        if(xmlElement.getChildElements().size() != 1) {
+        if (xmlElement.getChildElements().size() != 1) {
             return false;
         }
         try {
index 8b72bb836b90d61d78419dd659572c8c7e5bbf38..4768fad00ecea66354528281f700e8ff74f3afe5 100644 (file)
@@ -34,15 +34,15 @@ public final class SendErrorExceptionUtil {
             final DocumentedException sendErrorException) {
         LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException);
         final Document errorDocument = createDocument(sendErrorException);
-        ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument));
-        f.addListener(new SendErrorVerifyingListener(sendErrorException));
+        ChannelFuture channelFuture = session.sendMessage(new NetconfMessage(errorDocument));
+        channelFuture.addListener(new SendErrorVerifyingListener(sendErrorException));
     }
 
     public static void sendErrorMessage(final Channel channel, final DocumentedException sendErrorException) {
         LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException);
         final Document errorDocument = createDocument(sendErrorException);
-        ChannelFuture f = channel.writeAndFlush(new NetconfMessage(errorDocument));
-        f.addListener(new SendErrorVerifyingListener(sendErrorException));
+        ChannelFuture channelFuture = channel.writeAndFlush(new NetconfMessage(errorDocument));
+        channelFuture.addListener(new SendErrorVerifyingListener(sendErrorException));
     }
 
     public static void sendErrorMessage(final NetconfSession session, final DocumentedException sendErrorException,
@@ -53,20 +53,21 @@ public final class SendErrorExceptionUtil {
         }
 
         tryToCopyAttributes(incommingMessage.getDocument(), errorDocument, sendErrorException);
-        ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument));
-        f.addListener(new SendErrorVerifyingListener(sendErrorException));
+        ChannelFuture channelFuture = session.sendMessage(new NetconfMessage(errorDocument));
+        channelFuture.addListener(new SendErrorVerifyingListener(sendErrorException));
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private static void tryToCopyAttributes(final Document incommingDocument, final Document errorDocument,
             final DocumentedException sendErrorException) {
         try {
             final Element incommingRpc = incommingDocument.getDocumentElement();
-            Preconditions.checkState(incommingRpc.getTagName().equals(XmlNetconfConstants.RPC_KEY), "Missing %s element",
-                    XmlNetconfConstants.RPC_KEY);
+            Preconditions.checkState(incommingRpc.getTagName().equals(XmlNetconfConstants.RPC_KEY),
+                    "Missing %s element", XmlNetconfConstants.RPC_KEY);
 
             final Element rpcReply = errorDocument.getDocumentElement();
-            Preconditions.checkState(rpcReply.getTagName().equals(XmlMappingConstants.RPC_REPLY_KEY), "Missing %s element",
-                    XmlMappingConstants.RPC_REPLY_KEY);
+            Preconditions.checkState(rpcReply.getTagName().equals(XmlMappingConstants.RPC_REPLY_KEY),
+                    "Missing %s element", XmlMappingConstants.RPC_REPLY_KEY);
 
             final NamedNodeMap incomingAttributes = incommingRpc.getAttributes();
             for (int i = 0; i < incomingAttributes.getLength(); i++) {
@@ -93,7 +94,7 @@ public final class SendErrorExceptionUtil {
     private static final class SendErrorVerifyingListener implements ChannelFutureListener {
         private final DocumentedException sendErrorException;
 
-        public SendErrorVerifyingListener(final DocumentedException sendErrorException) {
+        SendErrorVerifyingListener(final DocumentedException sendErrorException) {
             this.sendErrorException = sendErrorException;
         }
 
index aa570952d6798bd021a679dbb21506097f88e88a..96e19b9378b73d4693157f3b71e3e52378953af2 100644 (file)
@@ -28,15 +28,17 @@ import org.w3c.dom.Node;
 public class SubtreeFilter {
     private static final Logger LOG = LoggerFactory.getLogger(SubtreeFilter.class);
 
-    public static Document applyRpcSubtreeFilter(Document requestDocument, Document rpcReply) throws DocumentedException {
+    public static Document applyRpcSubtreeFilter(Document requestDocument,
+                                                 Document rpcReply) throws DocumentedException {
         OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(requestDocument);
-        if (XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(operationNameAndNamespace.getNamespace()) &&
-                XmlNetconfConstants.GET.equals(operationNameAndNamespace.getOperationName()) ||
-                XmlNetconfConstants.GET_CONFIG.equals(operationNameAndNamespace.getOperationName())) {
+        if (XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(operationNameAndNamespace.getNamespace())
+                && XmlNetconfConstants.GET.equals(operationNameAndNamespace.getOperationName())
+                || XmlNetconfConstants.GET_CONFIG.equals(operationNameAndNamespace.getOperationName())) {
             // process subtree filtering here, in case registered netconf operations do
             // not implement filtering.
-            Optional<XmlElement> maybeFilter = operationNameAndNamespace.getOperationElement().getOnlyChildElementOptionally(
-                    XmlNetconfConstants.FILTER, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+            Optional<XmlElement> maybeFilter = operationNameAndNamespace.getOperationElement()
+                    .getOnlyChildElementOptionally(XmlNetconfConstants.FILTER,
+                            XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
             if (!maybeFilter.isPresent()) {
                 return rpcReply;
             }
@@ -57,9 +59,10 @@ public class SubtreeFilter {
      * @param filter filter
      * @param notification notification
      * @return document containing filtered notification content
-     * @throws DocumentedException
+     * @throws DocumentedException if operation fails
      */
-    public static Optional<Document> applySubtreeNotificationFilter(XmlElement filter, Document notification) throws DocumentedException {
+    public static Optional<Document> applySubtreeNotificationFilter(XmlElement filter,
+                                                                    Document notification) throws DocumentedException {
         removeEventTimeNode(notification);
         if (isSupported(filter)) {
             return Optional.fromNullable(filteredNotification(filter, notification));
@@ -68,14 +71,15 @@ public class SubtreeFilter {
     }
 
     private static void removeEventTimeNode(Document document) {
-        final Node eventTimeNode = document.getDocumentElement().getElementsByTagNameNS(
-                XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME).item(0);
+        final Node eventTimeNode = document.getDocumentElement().getElementsByTagNameNS(XmlNetconfConstants
+                .URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME).item(0);
         document.getDocumentElement().removeChild(eventTimeNode);
     }
 
     private static boolean isSupported(XmlElement filter) {
-        return "subtree".equals(filter.getAttribute("type"))||
-                "subtree".equals(filter.getAttribute("type", XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
+        return "subtree".equals(filter.getAttribute("type"))
+                || "subtree".equals(filter.getAttribute("type",
+                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
     }
 
     private static Document extractNotificationContent(Document notification) throws DocumentedException {
@@ -86,14 +90,15 @@ public class SubtreeFilter {
         return notification;
     }
 
-    private static Document filteredNotification(XmlElement filter, Document originalNotification) throws DocumentedException {
+    private static Document filteredNotification(XmlElement filter,
+                                                 Document originalNotification) throws DocumentedException {
         Document result = XmlUtil.newDocument();
         XmlElement dataSrc = XmlElement.fromDomDocument(originalNotification);
         Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false);
         for (XmlElement filterChild : filter.getChildElements()) {
             addSubtree2(filterChild, dataSrc.getOnlyChildElement(), XmlElement.fromDomElement(dataDst));
         }
-        if(dataDst.getFirstChild() != null) {
+        if (dataDst.getFirstChild() != null) {
             result.appendChild(dataDst.getFirstChild());
             return result;
         } else {
@@ -107,7 +112,8 @@ public class SubtreeFilter {
         Element rpcReply = originalReplyDocument.getDocumentElement();
         Node rpcReplyDst = result.importNode(rpcReply, false);
         result.appendChild(rpcReplyDst);
-        XmlElement dataSrc = XmlElement.fromDomElement(rpcReply).getOnlyChildElement("data", XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
+        XmlElement dataSrc = XmlElement.fromDomElement(rpcReply).getOnlyChildElement("data",
+                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
         Element dataDst = (Element) result.importNode(dataSrc.getDomElement(), false);
         rpcReplyDst.appendChild(dataDst);
         addSubtree(filter, dataSrc, XmlElement.fromDomElement(dataDst));
@@ -123,7 +129,8 @@ public class SubtreeFilter {
         }
     }
 
-    private static MatchingResult addSubtree2(XmlElement filter, XmlElement src, XmlElement dstParent) throws DocumentedException {
+    private static MatchingResult addSubtree2(XmlElement filter, XmlElement src,
+                                              XmlElement dstParent) throws DocumentedException {
         Document document = dstParent.getDomElement().getOwnerDocument();
         MatchingResult matches = matches(src, filter);
         if (matches != MatchingResult.NO_MATCH && matches != MatchingResult.CONTENT_MISMATCH) {
@@ -137,7 +144,8 @@ public class SubtreeFilter {
                 int numberOfTextMatchingChildren = 0;
                 for (XmlElement srcChild : src.getChildElements()) {
                     for (XmlElement filterChild : filter.getChildElements()) {
-                        MatchingResult childMatch = addSubtree2(filterChild, srcChild, XmlElement.fromDomElement(copied));
+                        MatchingResult childMatch =
+                                addSubtree2(filterChild, srcChild, XmlElement.fromDomElement(copied));
                         if (childMatch == MatchingResult.CONTENT_MISMATCH) {
                             return MatchingResult.NO_MATCH;
                         }
@@ -166,8 +174,8 @@ public class SubtreeFilter {
      * If filter node has no children and has text content, it also must match.
      */
     private static MatchingResult matches(XmlElement src, XmlElement filter) throws DocumentedException {
-        boolean tagMatch = src.getName().equals(filter.getName()) &&
-                src.getNamespaceOptionally().equals(filter.getNamespaceOptionally());
+        boolean tagMatch = src.getName().equals(filter.getName())
+                && src.getNamespaceOptionally().equals(filter.getNamespaceOptionally());
         MatchingResult result = null;
         if (tagMatch) {
             // match text content
@@ -183,7 +191,7 @@ public class SubtreeFilter {
             if (result == null) {
                 for (Attr attr : filter.getAttributes().values()) {
                     // ignore namespace declarations
-                    if (XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI()) == false ) {
+                    if (XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI()) == false) {
                         // find attr with matching localName(),  namespaceURI(),  == value() in src
                         String found = src.getAttribute(attr.getLocalName(), attr.getNamespaceURI());
                         if (attr.getValue().equals(found) && result != MatchingResult.NO_MATCH) {
@@ -205,7 +213,8 @@ public class SubtreeFilter {
         return result;
     }
 
-    private static boolean prefixedContentMatches(final XmlElement filter, final XmlElement src) throws DocumentedException {
+    private static boolean prefixedContentMatches(final XmlElement filter,
+                                                  final XmlElement src) throws DocumentedException {
         final Map.Entry<String, String> prefixToNamespaceOfFilter;
         final Map.Entry<String, String> prefixToNamespaceOfSrc;
         try {
@@ -226,8 +235,10 @@ public class SubtreeFilter {
             return false;
         }
 
-        final String unprefixedFilterContent = filter.getTextContent().substring(prefixToNamespaceOfFilter.getKey().length() + 1);
-        final String unprefixedSrcContnet = src.getTextContent().substring(prefixToNamespaceOfSrc.getKey().length() + 1);
+        final String unprefixedFilterContent =
+                filter.getTextContent().substring(prefixToNamespaceOfFilter.getKey().length() + 1);
+        final String unprefixedSrcContnet =
+                src.getTextContent().substring(prefixToNamespaceOfSrc.getKey().length() + 1);
         // Finally compare unprefixed content
         return unprefixedFilterContent.equals(unprefixedSrcContnet);
     }
index cd74911138a86e5e09b508588d334458632a0a3c..64537f336fc96ce49408a02633c0d761cf813cec 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.netconf.util.osgi;
 
 import java.util.Collection;
-import java.util.Optional;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -30,11 +29,11 @@ public final class NetconfConfigUtil {
         final Collection<ServiceReference<ManagedService>> serviceReferences
                 = bundleContext.getServiceReferences(ManagedService.class, null);
         for (final ServiceReference<ManagedService> serviceReference : serviceReferences) {
-                ManagedService service = bundleContext.getService(serviceReference);
-                if (service instanceof NetconfConfiguration){
-                    LOG.debug("Netconf configuration service found");
-                    return (NetconfConfiguration) service;
-                }
+            ManagedService service = bundleContext.getService(serviceReference);
+            if (service instanceof NetconfConfiguration) {
+                LOG.debug("Netconf configuration service found");
+                return (NetconfConfiguration) service;
+            }
         }
 
         throw new IllegalStateException("Netconf configuration service not found");
index f84d5a195426cf9a82b42391c2d5f5022f518b2d..c67675a91062780df065aedbf9f898abbf7df199 100644 (file)
@@ -55,9 +55,11 @@ public class NetconfConfiguration implements ManagedService {
             LOG.debug("CSS netconf server configuration cannot be updated as passed dictionary is null");
             return;
         }
-        final InetSocketAddress sshServerAddress = new InetSocketAddress((String) dictionaryConfig.get(SSH_ADDRESS_PROP),
-                Integer.parseInt((String) dictionaryConfig.get(SSH_PORT_PROP)));
-        final InetSocketAddress tcpServerAddress = new InetSocketAddress((String) dictionaryConfig.get(TCP_ADDRESS_PROP),
+        final InetSocketAddress sshServerAddress =
+                new InetSocketAddress((String) dictionaryConfig.get(SSH_ADDRESS_PROP),
+                        Integer.parseInt((String) dictionaryConfig.get(SSH_PORT_PROP)));
+        final InetSocketAddress tcpServerAddress =
+                new InetSocketAddress((String) dictionaryConfig.get(TCP_ADDRESS_PROP),
                 Integer.parseInt((String) dictionaryConfig.get(TCP_PORT_PROP)));
 
         netconfConfiguration = new NetconfConfigurationHolder(tcpServerAddress,
@@ -67,11 +69,11 @@ public class NetconfConfiguration implements ManagedService {
         LOG.debug("CSS netconf server configuration was updated: {}", dictionaryConfig.toString());
     }
 
-    public InetSocketAddress getSshServerAddress(){
+    public InetSocketAddress getSshServerAddress() {
         return netconfConfiguration.getSshServerAddress();
     }
 
-    public InetSocketAddress getTcpServerAddress(){
+    public InetSocketAddress getTcpServerAddress() {
         return netconfConfiguration.getTcpServerAddress();
     }
 
index 9c95ed58ac8a14fbb850aaeb9376069330ed4ed8..a705ea647a1074f4a49f976b75bfa04b03d96eb8 100644 (file)
@@ -27,11 +27,11 @@ public class HardcodedNamespaceResolver implements NamespaceContext {
     }
 
     /**
-     * This method returns the uri for all prefixes needed. Wherever possible it
-     * uses XMLConstants.
+     * Returns the URI for all prefixes needed. Wherever possible it
+     * uses {@code XMLConstants}.
      *
-     * @param prefix
-     * @return uri
+     * @param prefix    prefix
+     * @return uri      uniform resource identifier
      */
     @Override
     public String getNamespaceURI(String prefix) {
index ebe7bd023bec82a2593af64be23fc6ef71eb57c2..b3c3da5c2630ac6b75d313797ce5d9ab3319cadd 100644 (file)
@@ -24,13 +24,13 @@ public final class XMLNetconfUtil {
         throw new UnsupportedOperationException("Utility class");
     }
 
-    public static XPathExpression compileXPath(final String xPath) {
-        final XPath xpath = FACTORY.newXPath();
-        xpath.setNamespaceContext(NS_CONTEXT);
+    public static XPathExpression compileXPath(final String xpath) {
+        final XPath newXPath = FACTORY.newXPath();
+        newXPath.setNamespaceContext(NS_CONTEXT);
         try {
-            return xpath.compile(xPath);
+            return newXPath.compile(xpath);
         } catch (final XPathExpressionException e) {
-            throw new IllegalStateException("Error while compiling xpath expression " + xPath, e);
+            throw new IllegalStateException("Error while compiling xpath expression " + xpath, e);
         }
     }
 
index 786395d9b1798e6be2d69bd325a5fb7c01149045..907b2b45058c8dd0352e22d5251ee265dda7e3e7 100644 (file)
@@ -18,6 +18,7 @@ import org.junit.Test;
 
 public class CloseableUtilTest {
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Test
     public void testCloseAllFail() throws Exception {
         final AutoCloseable failingCloseable = new AutoCloseable() {
index 5a7941ad7af0f33fd9b9751fd41fdf8ab05f8e84..38f5bd039f516d99bd59e825426ee081e6d90ced 100644 (file)
@@ -44,8 +44,9 @@ public class NetconfUtilTest {
 
     @Test
     public void testConflictingVersionDetection() throws Exception {
-        final Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/netconfMessages/conflictingversion/conflictingVersionResponse.xml"));
-        try{
+        final Document document = XmlUtil.readXmlToDocument(getClass()
+                .getResourceAsStream("/netconfMessages/conflictingversion/conflictingVersionResponse.xml"));
+        try {
             NetconfUtil.checkIsMessageOk(document);
             fail();
         } catch (final IllegalStateException e) {
@@ -63,7 +64,8 @@ public class NetconfUtilTest {
                 .withValue("admin")
                 .build();
         final MapEntryNode session1 = Builders.mapEntryBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Session.QNAME, QName.create(Session.QNAME, "session-id"), 1L))
+                .withNodeIdentifier(new YangInstanceIdentifier
+                        .NodeIdentifierWithPredicates(Session.QNAME, QName.create(Session.QNAME, "session-id"), 1L))
                 .withChild(username)
                 .build();
         final MapNode sessionList = Builders.mapBuilder()
index 1426505c5d06533f7c7b010241192d37116e8d3a..f9de09342a4c71b0315ca1dc8d779892914be4af 100644 (file)
@@ -33,7 +33,8 @@ public class AbstractLastNetconfOperationTest {
         }
 
         @Override
-        protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws DocumentedException{
+        protected Element handleWithNoSubsequentOperations(Document document,
+                                                           XmlElement operationElement) throws DocumentedException {
             handleWithNoSubsequentOperationsRun = true;
             return null;
         }
index 81ccae28f48b22632d7d9817788687dd324d5827..75b870f7f66313b8a5fbd10543062c2402471555 100644 (file)
@@ -43,7 +43,8 @@ public class AbstractNetconfOperationTest {
         }
 
         @Override
-        protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws DocumentedException{
+        protected Element handle(Document document, XmlElement message,
+                                 NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
             this.handleRun = true;
             try {
                 return XmlUtil.readXmlToElement("<element/>");
index dc48b8b62464b1070a56ebfc9061df190c961a3b..9ba35770e4ee67e1ec002ce509c9f262dbf1739b 100644 (file)
@@ -25,7 +25,8 @@ public class AbstractSingletonNetconfOperationTest {
         }
 
         @Override
-        protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws DocumentedException{
+        protected Element handleWithNoSubsequentOperations(Document document,
+                                                           XmlElement operationElement) throws DocumentedException {
             return null;
         }
 
index ad307fe360cedd2ac71544a3557d232436ddbbc2..53d2c585ef6f26a06a8b269917cb24b3f3c47789 100644 (file)
@@ -24,12 +24,14 @@ public class NetconfMessageUtilTest {
         assertTrue(NetconfMessageUtil.isOKMessage(new NetconfMessage(okMessage)));
         assertFalse(NetconfMessageUtil.isErrorMessage(new NetconfMessage(okMessage)));
 
-        Document errorMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/communicationError/testClientSendsRpcReply_expectedResponse.xml");
+        Document errorMessage = XmlFileLoader
+                .xmlFileToDocument("netconfMessages/communicationError/testClientSendsRpcReply_expectedResponse.xml");
         assertTrue(NetconfMessageUtil.isErrorMessage(new NetconfMessage(errorMessage)));
         assertFalse(NetconfMessageUtil.isOKMessage(new NetconfMessage(errorMessage)));
 
         Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/client_hello.xml");
-        Collection<String> caps = NetconfMessageUtil.extractCapabilitiesFromHello(new NetconfMessage(helloMessage).getDocument());
+        Collection<String> caps =
+                NetconfMessageUtil.extractCapabilitiesFromHello(new NetconfMessage(helloMessage).getDocument());
         assertTrue(caps.contains("urn:ietf:params:netconf:base:1.0"));
         assertTrue(caps.contains("urn:ietf:params:netconf:base:1.1"));
     }
index ac7d83ce374938dd0ebde0bfbb1d1703c52f589c..96f179a112290f4ae74fcbab97c76abc2bc3931e 100644 (file)
@@ -50,7 +50,7 @@ public class SubtreeFilterNotificationTest {
     }
 
     @Before
-    public void setUp(){
+    public void setUp() {
         XMLUnit.setIgnoreWhitespace(true);
     }
 
@@ -59,8 +59,9 @@ public class SubtreeFilterNotificationTest {
         XmlElement filter = XmlElement.fromDomDocument(getDocument("filter.xml"));
         Document preFilterDocument = getDocument("pre-filter.xml");
         Document postFilterDocument = getDocument("post-filter.xml");
-        Optional<Document> actualPostFilterDocumentOpt = SubtreeFilter.applySubtreeNotificationFilter(filter, preFilterDocument);
-        if(actualPostFilterDocumentOpt.isPresent()) {
+        Optional<Document> actualPostFilterDocumentOpt =
+                SubtreeFilter.applySubtreeNotificationFilter(filter, preFilterDocument);
+        if (actualPostFilterDocumentOpt.isPresent()) {
             Document actualPostFilterDocument = actualPostFilterDocumentOpt.get();
             LOG.info("Actual document: {}", XmlUtil.toString(actualPostFilterDocument));
             Diff diff = XMLUnit.compareXML(postFilterDocument, actualPostFilterDocument);
@@ -71,7 +72,7 @@ public class SubtreeFilterNotificationTest {
     }
 
     public Document getDocument(String fileName) throws SAXException, IOException {
-        return XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/subtree/notification/" + directoryIndex + "/" +
-                fileName));
+        return XmlUtil.readXmlToDocument(getClass().getResourceAsStream(
+                "/subtree/notification/" + directoryIndex + "/" + fileName));
     }
 }
index e486c75f2e0d8d6abc8f3e29ec4f420c212de433..d5b4a24a842f87d3342eaf6dfefacab67663cd50 100644 (file)
@@ -47,7 +47,7 @@ public class SubtreeFilterRpcTest {
     }
 
     @Before
-    public void setUp(){
+    public void setUp() {
         XMLUnit.setIgnoreWhitespace(true);
     }
 
@@ -64,7 +64,7 @@ public class SubtreeFilterRpcTest {
     }
 
     public Document getDocument(String fileName) throws SAXException, IOException {
-        return XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/subtree/rpc/" + directoryIndex + "/" +
-                fileName));
+        return XmlUtil.readXmlToDocument(
+                getClass().getResourceAsStream("/subtree/rpc/" + directoryIndex + "/" + fileName));
     }
 }
index e777bb05f6f97cee52ac72f64c92149340cbecf5..64bf74fec5387cb2f2a7a1cb1e6413765a09c21f 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.netconf.util.osgi;
 
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -66,7 +67,7 @@ public class NetconfConfigUtilTest {
             NetconfConfigUtil.getNetconfConfigurationService(context);
             Assert.fail(IllegalStateException.class + "exception expected");
         } catch (IllegalStateException e) {
-
+            assertTrue(e.getMessage().startsWith("Netconf configuration service not found"));
         }
     }
 
index 494b96ec4351318e11c8ff9e0d3a6f39320516cf..4e55591271fbede48ceae2ad8aa97711a6ce8787 100644 (file)
@@ -16,7 +16,7 @@ import org.w3c.dom.NodeList;
 
 /**
  * Custom xmlunit qualifier that doesn't care about order when deeper in the recursion
- * defaults to comparing element name and text content
+ * defaults to comparing element name and text content.
  */
 public class NetconfXmlUnitRecursiveQualifier implements ElementQualifier {
 
@@ -36,6 +36,7 @@ public class NetconfXmlUnitRecursiveQualifier implements ElementQualifier {
         return compareNodes(currentControl, currentTest);
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private boolean compareNodes(Node currentControl, Node currentTest) {
         try {
 
@@ -54,8 +55,8 @@ public class NetconfXmlUnitRecursiveQualifier implements ElementQualifier {
                 return !(currentControl.hasChildNodes() || currentTest.hasChildNodes());
             }
 
-            return (countNodesWithoutConsecutiveTextNodes(controlNodes) == countNodesWithoutConsecutiveTextNodes(testNodes))
-                    && checkChildren(controlNodes, testNodes);
+            return (countNodesWithoutConsecutiveTextNodes(controlNodes)
+                    == countNodesWithoutConsecutiveTextNodes(testNodes)) && checkChildren(controlNodes, testNodes);
 
         } catch (Exception e) {
             return false;
@@ -106,16 +107,16 @@ public class NetconfXmlUnitRecursiveQualifier implements ElementQualifier {
         return builder.toString();
     }
 
-    private static int countNodesWithoutConsecutiveTextNodes(NodeList l) {
+    private static int countNodesWithoutConsecutiveTextNodes(NodeList nodeList) {
         int count = 0;
         boolean lastNodeWasText = false;
-        final int length = l.getLength();
+        final int length = nodeList.getLength();
         for (int i = 0; i < length; i++) {
-            Node n = l.item(i);
-            if (!lastNodeWasText || n.getNodeType() != Node.TEXT_NODE) {
+            Node node = nodeList.item(i);
+            if (!lastNodeWasText || node.getNodeType() != Node.TEXT_NODE) {
                 count++;
             }
-            lastNodeWasText = n.getNodeType() == Node.TEXT_NODE;
+            lastNodeWasText = node.getNodeType() == Node.TEXT_NODE;
         }
         return count;
     }
index e8941445ed1743e48b3970b4451ffa3540da355e..9ce2be2013e3c5e7ad11d7ceb0d8a5717ae5fa12 100644 (file)
@@ -26,7 +26,8 @@ public class XmlUnitUtil {
 
     private XmlUnitUtil() {}
 
-    public static void assertContainsElementWithText(final Document doc, final String textToFind) throws NodeTestException {
+    public static void assertContainsElementWithText(final Document doc,
+                                                     final String textToFind) throws NodeTestException {
         NodeTest nt = new NodeTest(doc);
         NodeTester tester = new AbstractNodeTester() {
 
@@ -34,7 +35,7 @@ public class XmlUnitUtil {
 
             @Override
             public void testText(Text text) throws NodeTestException {
-                if(!textFound) {
+                if (!textFound) {
                     if (text.getData().equalsIgnoreCase(textToFind)) {
                         textFound = true;
                     }
@@ -58,7 +59,7 @@ public class XmlUnitUtil {
             @Override
             public void testElement(Element element) throws NodeTestException {
                 if (!elementFound) {
-                    if(element.isEqualNode(testElement)) {
+                    if (element.isEqualNode(testElement)) {
                         elementFound = true;
                     }
                 }
@@ -72,7 +73,8 @@ public class XmlUnitUtil {
         assertNodeTestPasses(nt, tester, new short[]{Node.ELEMENT_NODE}, true);
     }
 
-    public static void assertContainsElementWithName(final Document doc, final String elementName) throws NodeTestException {
+    public static void assertContainsElementWithName(final Document doc,
+                                                     final String elementName) throws NodeTestException {
         NodeTest nt = new NodeTest(doc);
         NodeTester tester = new AbstractNodeTester() {
 
index dd646df7141764f9bfc8d85d8ed23b79cd02a01a..c728862068048bfd09b3854132ad3d9874217764 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.util.xml;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import org.junit.Test;
@@ -18,13 +19,16 @@ public class HardcodedNamespaceResolverTest {
 
     @Test
     public void testResolver() throws Exception {
-        final HardcodedNamespaceResolver hardcodedNamespaceResolver = new HardcodedNamespaceResolver("prefix", "namespace");
+        final HardcodedNamespaceResolver hardcodedNamespaceResolver =
+                new HardcodedNamespaceResolver("prefix", "namespace");
 
         assertEquals("namespace", hardcodedNamespaceResolver.getNamespaceURI("prefix"));
-        try{
+        try {
             hardcodedNamespaceResolver.getNamespaceURI("unknown");
             fail("Unknown namespace lookup should fail");
-        } catch(IllegalStateException e) {}
+        } catch (IllegalStateException e) {
+            assertTrue(e.getMessage().startsWith("Prefix mapping not found for "));
+        }
 
         assertNull(hardcodedNamespaceResolver.getPrefix("any"));
         assertNull(hardcodedNamespaceResolver.getPrefixes("any"));
index f70406bb2cc357e927606043e5562974762e1755..3ca07d4dd438e21e73db8a11837bae2146ae6839 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.netconf.util.xml;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import javax.xml.xpath.XPathConstants;
@@ -25,8 +26,11 @@ public class XMLNetconfUtilTest {
         try {
             XMLNetconfUtil.compileXPath("!@(*&$!");
             fail("Incorrect xpath should fail");
-        } catch (IllegalStateException e) {}
-        final Object value = XmlUtil.evaluateXPath(correctXPath, XmlUtil.readXmlToDocument("<top><innerText>value</innerText></top>"), XPathConstants.NODE);
+        } catch (IllegalStateException e) {
+            assertTrue(e.getMessage().startsWith("Error while compiling xpath expression "));
+        }
+        final Object value = XmlUtil.evaluateXPath(correctXPath,
+                XmlUtil.readXmlToDocument("<top><innerText>value</innerText></top>"), XPathConstants.NODE);
         assertEquals("value", ((Element) value).getTextContent());
     }