From dc30e36dcdd472c68ad77853b615740a133521ce Mon Sep 17 00:00:00 2001 From: "matus.kubica" Date: Tue, 25 Apr 2017 15:49:16 +0200 Subject: [PATCH] Bug 8153: Enforce check-style rules for netconf - netconf-util 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: I4895535d9481489b96ba22671a3f61cc89398d4a Signed-off-by: matus.kubica --- netconf/netconf-util/pom.xml | 7 +++ .../netconf/util/CloseableUtil.java | 1 + .../netconf/util/NetconfUtil.java | 12 ++-- .../mapping/AbstractLastNetconfOperation.java | 8 ++- .../mapping/AbstractNetconfOperation.java | 32 ++++++----- .../util/messages/FramingMechanism.java | 4 ++ .../util/messages/NetconfMessageUtil.java | 4 +- .../util/messages/SendErrorExceptionUtil.java | 23 ++++---- .../netconf/util/messages/SubtreeFilter.java | 57 +++++++++++-------- .../netconf/util/osgi/NetconfConfigUtil.java | 11 ++-- .../util/osgi/NetconfConfiguration.java | 12 ++-- .../util/xml/HardcodedNamespaceResolver.java | 8 +-- .../netconf/util/xml/XMLNetconfUtil.java | 10 ++-- .../netconf/util/CloseableUtilTest.java | 1 + .../netconf/util/NetconfUtilTest.java | 8 ++- .../AbstractLastNetconfOperationTest.java | 3 +- .../mapping/AbstractNetconfOperationTest.java | 3 +- ...AbstractSingletonNetconfOperationTest.java | 3 +- .../util/messages/NetconfMessageUtilTest.java | 6 +- .../SubtreeFilterNotificationTest.java | 11 ++-- .../util/messages/SubtreeFilterRpcTest.java | 6 +- .../util/osgi/NetconfConfigUtilTest.java | 3 +- .../NetconfXmlUnitRecursiveQualifier.java | 17 +++--- .../netconf/util/test/XmlUnitUtil.java | 10 ++-- .../xml/HardcodedNamespaceResolverTest.java | 10 +++- .../netconf/util/xml/XMLNetconfUtilTest.java | 8 ++- 26 files changed, 168 insertions(+), 110 deletions(-) diff --git a/netconf/netconf-util/pom.xml b/netconf/netconf-util/pom.xml index 6e8c024d15..9e30e95320 100644 --- a/netconf/netconf-util/pom.xml +++ b/netconf/netconf-util/pom.xml @@ -139,6 +139,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/CloseableUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/CloseableUtil.java index cff8b2a890..1067da9d91 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/CloseableUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/CloseableUtil.java @@ -10,6 +10,7 @@ package org.opendaylight.netconf.util; public class CloseableUtil { + @SuppressWarnings("checkstyle:IllegalCatch") public static void closeAll(Iterable autoCloseables) throws Exception { Exception lastException = null; for (AutoCloseable autoCloseable : autoCloseables) { diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java index 0e8b9aeec4..d81e5c9be7 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NetconfUtil.java @@ -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) { diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java index 32d6d79cc2..e66e59f3e7 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java @@ -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; } diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperation.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperation.java index 6a4d2ae504..4d988112ea 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperation.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperation.java @@ -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 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()); diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/FramingMechanism.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/FramingMechanism.java index b85a0ad3a8..ae7d7472e9 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/FramingMechanism.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/FramingMechanism.java @@ -13,11 +13,15 @@ package org.opendaylight.netconf.util.messages; */ public enum FramingMechanism { /** + * Chunked framing mechanism. + * * @see Chunked * framing mechanism */ CHUNK, /** + * End-of-Message framing mechanism. + * * @see End-of-message * framing mechanism diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java index 021ba009fa..995f6a47d0 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/NetconfMessageUtil.java @@ -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 { diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SendErrorExceptionUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SendErrorExceptionUtil.java index 8b72bb836b..4768fad00e 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SendErrorExceptionUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SendErrorExceptionUtil.java @@ -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; } diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java index aa570952d6..96e19b9378 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java @@ -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 maybeFilter = operationNameAndNamespace.getOperationElement().getOnlyChildElementOptionally( - XmlNetconfConstants.FILTER, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); + Optional 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 applySubtreeNotificationFilter(XmlElement filter, Document notification) throws DocumentedException { + public static Optional 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 prefixToNamespaceOfFilter; final Map.Entry 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); } diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtil.java index cd74911138..64537f336f 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtil.java @@ -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> serviceReferences = bundleContext.getServiceReferences(ManagedService.class, null); for (final ServiceReference 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"); diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfiguration.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfiguration.java index f84d5a1954..c67675a910 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfiguration.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfiguration.java @@ -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(); } diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java index 9c95ed58ac..a705ea647a 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java @@ -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) { diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java index ebe7bd023b..b3c3da5c26 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java @@ -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); } } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/CloseableUtilTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/CloseableUtilTest.java index 786395d9b1..907b2b4505 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/CloseableUtilTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/CloseableUtilTest.java @@ -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() { diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/NetconfUtilTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/NetconfUtilTest.java index 5a7941ad7a..38f5bd039f 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/NetconfUtilTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/NetconfUtilTest.java @@ -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() diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperationTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperationTest.java index 1426505c5d..f9de09342a 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperationTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperationTest.java @@ -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; } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperationTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperationTest.java index 81ccae28f4..75b870f7f6 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperationTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractNetconfOperationTest.java @@ -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(""); diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java index dc48b8b624..9ba35770e4 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java @@ -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; } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageUtilTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageUtilTest.java index ad307fe360..53d2c585ef 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageUtilTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/NetconfMessageUtilTest.java @@ -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 caps = NetconfMessageUtil.extractCapabilitiesFromHello(new NetconfMessage(helloMessage).getDocument()); + Collection 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")); } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterNotificationTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterNotificationTest.java index ac7d83ce37..96f179a112 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterNotificationTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterNotificationTest.java @@ -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 actualPostFilterDocumentOpt = SubtreeFilter.applySubtreeNotificationFilter(filter, preFilterDocument); - if(actualPostFilterDocumentOpt.isPresent()) { + Optional 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)); } } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterRpcTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterRpcTest.java index e486c75f2e..d5b4a24a84 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterRpcTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SubtreeFilterRpcTest.java @@ -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)); } } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtilTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtilTest.java index e777bb05f6..64bf74fec5 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtilTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigUtilTest.java @@ -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")); } } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/NetconfXmlUnitRecursiveQualifier.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/NetconfXmlUnitRecursiveQualifier.java index 494b96ec43..4e55591271 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/NetconfXmlUnitRecursiveQualifier.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/NetconfXmlUnitRecursiveQualifier.java @@ -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; } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlUnitUtil.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlUnitUtil.java index e8941445ed..9ce2be2013 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlUnitUtil.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlUnitUtil.java @@ -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() { diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java index dd646df714..c728862068 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java @@ -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")); diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java index f70406bb2c..3ca07d4dd4 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java @@ -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("value"), XPathConstants.NODE); + } catch (IllegalStateException e) { + assertTrue(e.getMessage().startsWith("Error while compiling xpath expression ")); + } + final Object value = XmlUtil.evaluateXPath(correctXPath, + XmlUtil.readXmlToDocument("value"), XPathConstants.NODE); assertEquals("value", ((Element) value).getTextContent()); } -- 2.36.6