From e0460d542f7088c543e51fd01917b3d360a1c1e2 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 20 May 2017 12:19:08 +0200 Subject: [PATCH] Fix various warnings The code is full of eclipse warnings around static methods, raw types and similar. Fix that up. Change-Id: I8aa84b8c0fbde5c32ab855dfc215205501ce2777 Signed-off-by: Robert Varga --- .../mdsal/connector/CurrentSchemaContext.java | 2 +- .../MdsalNetconfOperationServiceFactory.java | 13 ++-- .../ops/EditOperationStrategyProvider.java | 64 +++++++++---------- .../mdsal/connector/ops/RuntimeRpc.java | 14 ++-- .../mdsal/connector/ops/get/AbstractGet.java | 4 +- .../ops/get/FilterContentValidator.java | 8 ++- .../get/UniversalNamespaceContextImpl.java | 5 +- .../ops/NetconfMDSalMappingTest.java | 33 ++++------ .../mdsal/connector/ops/RuntimeRpcTest.java | 11 ++-- .../ops/get/FilterContentValidatorTest.java | 4 +- .../osgi/NetconfConfigurationActivator.java | 6 +- .../util/xml/HardcodedNamespaceResolver.java | 14 ++-- .../netconf/util/NetconfUtilTest.java | 2 +- .../NetconfConfigurationActivatorTest.java | 2 +- .../impl/DepthAwareNormalizedNodeWriter.java | 34 ++++------ .../impl/JsonNormalizedNodeBodyReader.java | 8 +-- .../sal/rest/impl/JsonToPatchBodyReader.java | 30 ++++----- .../impl/NormalizedNodeJsonBodyWriter.java | 16 ++--- .../impl/NormalizedNodeXmlBodyWriter.java | 4 +- .../RestconfDocumentedExceptionMapper.java | 2 +- .../sal/restconf/impl/BrokerFacade.java | 10 +-- .../netconf/sal/restconf/impl/RestCodec.java | 8 +-- .../NotificationListenerAdapter.java | 4 +- .../JsonNormalizedNodeBodyReader.java | 4 +- .../providers/JsonToPatchBodyReader.java | 42 ++++++------ .../NormalizedNodeJsonBodyWriter.java | 9 ++- .../ParameterAwareNormalizedNodeWriter.java | 46 ++++++------- .../providers/XmlToPatchBodyReader.java | 47 +++++++------- .../restful/utils/CreateStreamUtil.java | 6 +- .../to/json/test/NnToJsonWithAugmentTest.java | 1 + .../restconf/impl/test/BrokerFacadeTest.java | 2 +- ...nSnToXmlAndJsonInstanceIdentifierTest.java | 6 +- .../impl/test/CutDataToCorrectDepthTest.java | 6 +- .../impl/test/InvokeRpcMethodTest.java | 4 +- .../impl/test/RestDeleteOperationTest.java | 4 +- ...stconfImplNotificationSubscribingTest.java | 49 ++++---------- .../listeners/NotificationListenerTest.java | 18 +++--- .../base/services/impl/RestconfImplTest.java | 8 +-- .../impl/RestconfOperationsServiceTest.java | 7 +- .../handlers/SchemaContextHandlerTest.java | 6 +- ...angInstanceIdentifierDeserializerTest.java | 4 +- .../YangInstanceIdentifierSerializerTest.java | 4 +- .../impl/RestconfDataServiceImplTest.java | 6 +- ...stconfInvokeOperationsServiceImplTest.java | 8 +-- ...onfStreamsSubscriptionServiceImplTest.java | 12 ++-- .../utils/PatchDataTransactionUtilTest.java | 2 +- .../utils/PostDataTransactionUtilTest.java | 6 +- .../mapping/RestconfMappingNodeUtilTest.java | 20 +++--- 48 files changed, 289 insertions(+), 336 deletions(-) diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/CurrentSchemaContext.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/CurrentSchemaContext.java index 8ec0d42d1c..d83cfb56f4 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/CurrentSchemaContext.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/CurrentSchemaContext.java @@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; public class CurrentSchemaContext implements SchemaContextListener, AutoCloseable { - private final AtomicReference currentContext = new AtomicReference(); + private final AtomicReference currentContext = new AtomicReference<>(); private final ListenerRegistration schemaContextListenerListenerRegistration; private final Set listeners1 = Collections.synchronizedSet(Sets.newHashSet()); private final SchemaSourceProvider rootSchemaSourceProvider; diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java index 2e84d3d216..273709db1c 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java @@ -28,6 +28,7 @@ import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListen import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; @@ -116,9 +117,9 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ private static Optional moduleToCapability( final Module module, final SchemaSourceProvider rootSchemaSourceProviderDependency) { - final SourceIdentifier moduleSourceIdentifier = SourceIdentifier.create(module.getName(), - (SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.absent() : - Optional.of(module.getQNameModule().getFormattedRevision()))); + final SourceIdentifier moduleSourceIdentifier = RevisionSourceIdentifier.create(module.getName(), + SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.absent() : + Optional.of(module.getQNameModule().getFormattedRevision())); InputStream sourceStream = null; String source; @@ -141,10 +142,10 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ if (source != null) { return Optional.of(new YangModuleCapability(module, source)); - } else { - LOG.warn("Missing source for module {}. This module will not be available from netconf server", - moduleSourceIdentifier); } + + LOG.warn("Missing source for module {}. This module will not be available from netconf server", + moduleSourceIdentifier); return Optional.absent(); } diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditOperationStrategyProvider.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditOperationStrategyProvider.java index 505e38739b..a29e37d47f 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditOperationStrategyProvider.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditOperationStrategyProvider.java @@ -151,17 +151,17 @@ class EditOperationStrategyProvider extends DomToNormalizedNodeParserFactory.Bui if (dataTreeChangeTracker.getDeleteOperationTracker() > 0 || dataTreeChangeTracker .getRemoveOperationTracker() > 0) { return node; - } else { - if (!action.equals(dataTreeChangeTracker.peekAction())) { - dataTreeChangeTracker.pushPath(node.getIdentifier()); - dataTreeChangeTracker.addDataTreeChange(new DataTreeChangeTracker.DataTreeChange(node, action, - new ArrayList<>(dataTreeChangeTracker.getCurrentPath()))); - dataTreeChangeTracker.popPath(); - return null; - } else { - return node; - } } + + if (action.equals(dataTreeChangeTracker.peekAction())) { + return node; + } + + dataTreeChangeTracker.pushPath(node.getIdentifier()); + dataTreeChangeTracker.addDataTreeChange(new DataTreeChangeTracker.DataTreeChange(node, action, + new ArrayList<>(dataTreeChangeTracker.getCurrentPath()))); + dataTreeChangeTracker.popPath(); + return null; } @Override @@ -200,17 +200,17 @@ class EditOperationStrategyProvider extends DomToNormalizedNodeParserFactory.Bui if (dataTreeChangeTracker.getDeleteOperationTracker() > 0 || dataTreeChangeTracker.getRemoveOperationTracker() > 0) { return node; - } else { - if (!action.equals(dataTreeChangeTracker.peekAction())) { - dataTreeChangeTracker.pushPath(node.getIdentifier()); - dataTreeChangeTracker.addDataTreeChange(new DataTreeChangeTracker.DataTreeChange(node, action, - new ArrayList<>(dataTreeChangeTracker.getCurrentPath()))); - dataTreeChangeTracker.popPath(); - return null; - } else { - return node; - } } + + if (action.equals(dataTreeChangeTracker.peekAction())) { + return node; + } + + dataTreeChangeTracker.pushPath(node.getIdentifier()); + dataTreeChangeTracker.addDataTreeChange(new DataTreeChangeTracker.DataTreeChange(node, action, + new ArrayList<>(dataTreeChangeTracker.getCurrentPath()))); + dataTreeChangeTracker.popPath(); + return null; } @Override @@ -244,19 +244,19 @@ class EditOperationStrategyProvider extends DomToNormalizedNodeParserFactory.Bui || dataTreeChangeTracker.getRemoveOperationTracker() > 0) { dataTreeChangeTracker.popPath(); return node; - } else { - //if parent and current actions dont match create a DataTreeChange and add it to the change list - //dont add a new child to the parent node - if (!currentAction.equals(dataTreeChangeTracker.peekAction())) { - dataTreeChangeTracker.addDataTreeChange(new DataTreeChangeTracker.DataTreeChange(node, - currentAction, new ArrayList<>(dataTreeChangeTracker.getCurrentPath()))); - dataTreeChangeTracker.popPath(); - return null; - } else { - dataTreeChangeTracker.popPath(); - return node; - } } + + if (currentAction.equals(dataTreeChangeTracker.peekAction())) { + dataTreeChangeTracker.popPath(); + return node; + } + + //if parent and current actions dont match create a DataTreeChange and add it to the change list + //dont add a new child to the parent node + dataTreeChangeTracker.addDataTreeChange(new DataTreeChangeTracker.DataTreeChange(node, + currentAction, new ArrayList<>(dataTreeChangeTracker.getCurrentPath()))); + dataTreeChangeTracker.popPath(); + return null; } @Override diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java index bd47a3d9bd..30cd1dae8b 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java @@ -98,7 +98,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation { throw new UnsupportedOperationException("Runtime rpc does not have a stable name"); } - private URI createNsUri(final String namespace) { + private static URI createNsUri(final String namespace) { final URI namespaceURI; try { namespaceURI = new URI(namespace); @@ -115,8 +115,8 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation { schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(namespaceURI, null)); } - private Optional getRpcDefinitionFromModule(final Module module, final URI namespaceURI, - final String name) { + private static Optional getRpcDefinitionFromModule(final Module module, final URI namespaceURI, + final String name) { for (final RpcDefinition rpcDef : module.getRpcs()) { if (rpcDef.getQName().getNamespace().equals(namespaceURI) && rpcDef.getQName().getLocalName().equals(name)) { @@ -234,7 +234,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation { return result.getNode(); } - private XMLStreamWriter getXmlStreamWriter(final DOMResult result) { + private static XMLStreamWriter getXmlStreamWriter(final DOMResult result) { try { return XML_OUTPUT_FACTORY.createXMLStreamWriter(result); } catch (final XMLStreamException e) { @@ -242,10 +242,10 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation { } } - private void writeRootElement(final XMLStreamWriter xmlWriter, final SchemaOrderedNormalizedNodeWriter nnWriter, - final ContainerNode data) { + private static void writeRootElement(final XMLStreamWriter xmlWriter, + final SchemaOrderedNormalizedNodeWriter nnWriter, final ContainerNode data) { try { - final Collection> value = (Collection) data.getValue(); + final Collection> value = data.getValue(); nnWriter.write(value); nnWriter.flush(); xmlWriter.flush(); diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java index 5bbcd340ff..5acceb359b 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java @@ -132,9 +132,9 @@ public abstract class AbstractGet extends AbstractSingletonNetconfOperation { return Optional.absent(); } return Optional.of(getInstanceIdentifierFromFilter(filterElement.get())); - } else { - return Optional.of(ROOT); } + + return Optional.of(ROOT); } @VisibleForTesting diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java index f313274016..c6f5714e1f 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java @@ -7,7 +7,6 @@ */ package org.opendaylight.netconf.mdsal.connector.ops.get; -import static org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder; import static org.opendaylight.yangtools.yang.data.util.ParserStreamUtils.findSchemaNodeByNameAndNamespace; import com.google.common.base.Optional; @@ -22,12 +21,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamWriter; import org.opendaylight.controller.config.util.xml.DocumentedException; import org.opendaylight.controller.config.util.xml.MissingNameSpaceException; import org.opendaylight.controller.config.util.xml.XmlElement; import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder; import org.opendaylight.yangtools.yang.data.codec.xml.XmlCodecFactory; import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec; import org.opendaylight.yangtools.yang.data.util.codec.TypeAwareCodec; @@ -210,7 +211,8 @@ public class FilterContentValidator { final NamespaceContext nsContext = new UniversalNamespaceContextImpl(document, false); final XmlCodecFactory xmlCodecFactory = XmlCodecFactory.create(schemaContext.getCurrentContext()); - final TypeAwareCodec identityrefTypeCodec = xmlCodecFactory.codecFor(listKey); + final TypeAwareCodec identityrefTypeCodec = + xmlCodecFactory.codecFor(listKey); final QName deserializedKey = (QName) identityrefTypeCodec.parseValue(nsContext, keyValue.get()); keys.put(qualifiedName, deserializedKey); @@ -282,6 +284,8 @@ public class FilterContentValidator { } private static class ValidationException extends Exception { + private static final long serialVersionUID = 1L; + ValidationException(final XmlElement parent, final XmlElement child) { super("Element " + child + " can't be child of " + parent); } diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/UniversalNamespaceContextImpl.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/UniversalNamespaceContextImpl.java index f1deb93382..3fa27d94b6 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/UniversalNamespaceContextImpl.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/UniversalNamespaceContextImpl.java @@ -39,7 +39,7 @@ public class UniversalNamespaceContextImpl implements NamespaceContext { * A single node is read, the namespace attributes are extracted and stored. * * @param node to examine - * @param attributesOnly, if true no recursion happens + * @param attributesOnly if true no recursion happens */ private void readNode(final Node node, final boolean attributesOnly) { final NamedNodeMap attributes = node.getAttributes(); @@ -93,6 +93,7 @@ public class UniversalNamespaceContextImpl implements NamespaceContext { * @param prefix to search for * @return uri */ + @Override public String getNamespaceURI(final String prefix) { if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { return prefix2Uri.get(DEFAULT_NS); @@ -105,10 +106,12 @@ public class UniversalNamespaceContextImpl implements NamespaceContext { * This method is not needed in this context, but can be implemented in a * similar way. */ + @Override public String getPrefix(final String namespaceURI) { return uri2Prefix.get(namespaceURI); } + @Override public Iterator getPrefixes(final String namespaceURI) { // Not implemented return null; diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java index ab87564bef..320c27b09f 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java @@ -36,8 +36,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker; import org.opendaylight.controller.config.util.xml.DocumentedException; import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity; @@ -148,15 +146,12 @@ public class NetconfMDSalMappingTest { final ConcurrentDOMDataBroker cdb = new ConcurrentDOMDataBroker(datastores, listenableFutureExecutor); this.transactionProvider = new TransactionProvider(cdb, SESSION_ID_FOR_REPORTING); - doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { - final SourceIdentifier sId = (SourceIdentifier) invocationOnMock.getArguments()[0]; - final YangTextSchemaSource yangTextSchemaSource = - YangTextSchemaSource.delegateForByteSource(sId, ByteSource.wrap("module test".getBytes())); - return Futures.immediateCheckedFuture(yangTextSchemaSource); + doAnswer(invocationOnMock -> { + final SourceIdentifier sId = (SourceIdentifier) invocationOnMock.getArguments()[0]; + final YangTextSchemaSource yangTextSchemaSource = + YangTextSchemaSource.delegateForByteSource(sId, ByteSource.wrap("module test".getBytes())); + return Futures.immediateCheckedFuture(yangTextSchemaSource); - } }).when(sourceProvider).getSource(any(SourceIdentifier.class)); this.currentSchemaContext = new CurrentSchemaContext(schemaService, sourceProvider); @@ -613,7 +608,7 @@ public class NetconfMDSalMappingTest { assertEmptyDatastore(getConfigRunning()); } - private void verifyResponse(final Document response, final Document template) throws Exception { + private static void verifyResponse(final Document response, final Document template) throws Exception { final DetailedDiff dd = new DetailedDiff(new Diff(response, template)); dd.overrideElementQualifier(new NetconfXmlUnitRecursiveQualifier()); @@ -623,7 +618,7 @@ public class NetconfMDSalMappingTest { assertTrue(dd.toString(), dd.similar()); } - private void assertEmptyDatastore(final Document response) { + private static void assertEmptyDatastore(final Document response) { final NodeList nodes = response.getChildNodes(); assertTrue(nodes.getLength() == 1); @@ -678,37 +673,37 @@ public class NetconfMDSalMappingTest { return executeOperation(getConfig, resource); } - private Document lock() throws Exception { + private static Document lock() throws Exception { final Lock lock = new Lock(SESSION_ID_FOR_REPORTING); return executeOperation(lock, "messages/mapping/lock.xml"); } - private Document unlock() throws Exception { + private static Document unlock() throws Exception { final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING); return executeOperation(unlock, "messages/mapping/unlock.xml"); } - private Document lockWithoutTarget() throws Exception { + private static Document lockWithoutTarget() throws Exception { final Lock lock = new Lock(SESSION_ID_FOR_REPORTING); return executeOperation(lock, "messages/mapping/lock_notarget.xml"); } - private Document unlockWithoutTarget() throws Exception { + private static Document unlockWithoutTarget() throws Exception { final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING); return executeOperation(unlock, "messages/mapping/unlock_notarget.xml"); } - private Document lockCandidate() throws Exception { + private static Document lockCandidate() throws Exception { final Lock lock = new Lock(SESSION_ID_FOR_REPORTING); return executeOperation(lock, "messages/mapping/lock_candidate.xml"); } - private Document unlockCandidate() throws Exception { + private static Document unlockCandidate() throws Exception { final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING); return executeOperation(unlock, "messages/mapping/unlock_candidate.xml"); } - private Document executeOperation(final NetconfOperation op, final String filename) throws Exception { + private static Document executeOperation(final NetconfOperation op, final String filename) throws Exception { final Document request = XmlFileLoader.xmlFileToDocument(filename); final Document response = op.handle(request, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT); diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java index ca6c47eb98..7df0ff59e0 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java @@ -110,6 +110,7 @@ public class RuntimeRpcTest { public CheckedFuture invokeRpc( @Nonnull final SchemaPath type, @Nullable final NormalizedNode input) { return Futures.immediateFailedCheckedFuture(new DOMRpcException("rpc invocation not implemented yet") { + private static final long serialVersionUID = 1L; }); } @@ -126,7 +127,8 @@ public class RuntimeRpcTest { @Override public CheckedFuture invokeRpc( @Nonnull final SchemaPath type, @Nullable final NormalizedNode input) { - final Collection> children = (Collection) input.getValue(); + final Collection> children = + (Collection>) input.getValue(); final Module module = schemaContext.findModuleByNamespaceAndRevision( type.getLastComponent().getNamespace(), null); final RpcDefinition rpcDefinition = getRpcDefinitionFromModule( @@ -155,7 +157,7 @@ public class RuntimeRpcTest { @Mock private SchemaContextListener listener; @Mock - private ListenerRegistration registration; + private ListenerRegistration registration; @Mock private SchemaSourceProvider sourceProvider; @@ -274,14 +276,15 @@ public class RuntimeRpcTest { } } - private void verifyResponse(final Document response, final Document template) throws Exception { + private static void verifyResponse(final Document response, final Document template) { final DetailedDiff dd = new DetailedDiff(new Diff(response, template)); dd.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); //we care about order so response has to be identical assertTrue(dd.identical()); } - private RpcDefinition getRpcDefinitionFromModule(final Module module, final URI namespaceURI, final String name) { + private static RpcDefinition getRpcDefinitionFromModule(final Module module, final URI namespaceURI, + final String name) { for (final RpcDefinition rpcDef : module.getRpcs()) { if (rpcDef.getQName().getNamespace().equals(namespaceURI) && rpcDef.getQName().getLocalName().equals(name)) { diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java index 2156270b80..8ee3e38a33 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java @@ -145,8 +145,8 @@ public class FilterContentValidatorTest { final QName qName = QName.create(input); if (qName.getModule().getNamespace() != null) { return qName; - } else { - return QName.create(Preconditions.checkNotNull(prev), input); } + + return QName.create(Preconditions.checkNotNull(prev), input); } } diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivator.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivator.java index 28d820aa89..3c1a9c5cb0 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivator.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivator.java @@ -28,17 +28,17 @@ public class NetconfConfigurationActivator implements BundleActivator { PROPS.put(Constants.SERVICE_PID, CONFIG_PID); } - private ServiceRegistration configService; + private ServiceRegistration configService; @Override - public void start(BundleContext bundleContext) { + public void start(final BundleContext bundleContext) { LOG.debug("Starting netconf configuration service"); configService = bundleContext.registerService(ManagedService.class, new NetconfConfiguration(), PROPS); } @Override - public void stop(BundleContext bundleContext) { + public void stop(final BundleContext bundleContext) { if (configService != null) { LOG.debug("Unregistering netconf configuration service"); configService.unregister(); 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 a705ea647a..942fe86a4c 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 @@ -18,11 +18,11 @@ import javax.xml.namespace.NamespaceContext; public class HardcodedNamespaceResolver implements NamespaceContext { private final Map prefixesToNamespaces; - public HardcodedNamespaceResolver(String prefix, String namespace) { + public HardcodedNamespaceResolver(final String prefix, final String namespace) { this(ImmutableMap.of(prefix, namespace)); } - public HardcodedNamespaceResolver(Map prefixesToNamespaces) { + public HardcodedNamespaceResolver(final Map prefixesToNamespaces) { this.prefixesToNamespaces = Collections.unmodifiableMap(prefixesToNamespaces); } @@ -34,22 +34,22 @@ public class HardcodedNamespaceResolver implements NamespaceContext { * @return uri uniform resource identifier */ @Override - public String getNamespaceURI(String prefix) { + public String getNamespaceURI(final String prefix) { if (prefixesToNamespaces.containsKey(prefix)) { return prefixesToNamespaces.get(prefix); - } else { - throw new IllegalStateException("Prefix mapping not found for " + prefix); } + + throw new IllegalStateException("Prefix mapping not found for " + prefix); } @Override - public String getPrefix(String namespaceURI) { + public String getPrefix(final String namespaceURI) { // Not needed in this context. return null; } @Override - public Iterator getPrefixes(String namespaceURI) { + public Iterator getPrefixes(final String namespaceURI) { // Not needed in this context. return null; } 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 38f5bd039f..c263a07692 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 @@ -59,7 +59,7 @@ public class NetconfUtilTest { final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); moduleInfoBackedContext.addModuleInfos(Collections.singletonList($YangModuleInfoImpl.getInstance())); final SchemaContext context = moduleInfoBackedContext.getSchemaContext(); - final LeafNode username = Builders.leafBuilder() + final LeafNode username = Builders.leafBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(Session.QNAME, "username"))) .withValue("admin") .build(); diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivatorTest.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivatorTest.java index cd21d8ce29..70fadc2314 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivatorTest.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/osgi/NetconfConfigurationActivatorTest.java @@ -30,7 +30,7 @@ public class NetconfConfigurationActivatorTest { @Mock private BundleContext context; @Mock - private ServiceRegistration registration; + private ServiceRegistration registration; @Before public void setUp() throws Exception { diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/DepthAwareNormalizedNodeWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/DepthAwareNormalizedNodeWriter.java index e3135b4a67..37f6cea601 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/DepthAwareNormalizedNodeWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/DepthAwareNormalizedNodeWriter.java @@ -11,7 +11,6 @@ import static org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedN import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import java.io.IOException; import java.util.Collection; @@ -91,11 +90,8 @@ public class DepthAwareNormalizedNodeWriter implements RestconfNormalizedNodeWri */ public static DepthAwareNormalizedNodeWriter forStreamWriter(final NormalizedNodeStreamWriter writer, final boolean orderKeyLeaves, final int maxDepth) { - if (orderKeyLeaves) { - return new OrderedDepthAwareNormalizedNodeWriter(writer, maxDepth); - } else { - return new DepthAwareNormalizedNodeWriter(writer, maxDepth); - } + return orderKeyLeaves ? new OrderedDepthAwareNormalizedNodeWriter(writer, maxDepth) + : new DepthAwareNormalizedNodeWriter(writer, maxDepth); } /** @@ -106,6 +102,7 @@ public class DepthAwareNormalizedNodeWriter implements RestconfNormalizedNodeWri * @return DepthAwareNormalizedNodeWriter * @throws IOException when thrown from the backing writer. */ + @Override public final DepthAwareNormalizedNodeWriter write(final NormalizedNode node) throws IOException { if (wasProcessedAsCompositeNode(node)) { return this; @@ -138,7 +135,7 @@ public class DepthAwareNormalizedNodeWriter implements RestconfNormalizedNodeWri * @return Best estimate of the collection size required to hold all the children. */ static final int childSizeHint(final Iterable children) { - return (children instanceof Collection) ? ((Collection) children).size() : UNKNOWN_SIZE; + return children instanceof Collection ? ((Collection) children).size() : UNKNOWN_SIZE; } private boolean wasProcessAsSimpleNode(final NormalizedNode node) throws IOException { @@ -197,7 +194,7 @@ public class DepthAwareNormalizedNodeWriter implements RestconfNormalizedNodeWri return true; } - private void writeOnlyKeys(Map keyValues) throws IllegalArgumentException, IOException { + private void writeOnlyKeys(final Map keyValues) throws IllegalArgumentException, IOException { for (Map.Entry entry : keyValues.entrySet()) { writer.leafNode(new NodeIdentifier(entry.getKey()), entry.getValue()); } @@ -304,19 +301,16 @@ public class DepthAwareNormalizedNodeWriter implements RestconfNormalizedNodeWri // Write all the rest currentDepth++; - boolean result = writeChildren(Iterables.filter(node.getValue(), new Predicate>() { - @Override - public boolean apply(final NormalizedNode input) { - if (input instanceof AugmentationNode) { - return true; - } - if (!qnames.contains(input.getNodeType())) { - return true; - } - - LOG.debug("Skipping key child {}", input); - return false; + boolean result = writeChildren(Iterables.filter(node.getValue(), input -> { + if (input instanceof AugmentationNode) { + return true; + } + if (!qnames.contains(input.getNodeType())) { + return true; } + + LOG.debug("Skipping key child {}", input); + return false; })); currentDepth--; return result; diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java index 3b7d07e716..0f558fa229 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java @@ -77,9 +77,9 @@ public class JsonNormalizedNodeBodyReader new org.opendaylight.restconf.jersey.providers.JsonNormalizedNodeBodyReader(); jsonReaderNewRest.injectParams(getUriInfo(), getRequest()); return jsonReaderNewRest.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream); - } else { - return readFrom(getInstanceIdentifierContext(), entityStream, isPost()); } + + return readFrom(getInstanceIdentifierContext(), entityStream, isPost()); } catch (final Exception e) { propagateExceptionAs(e); return null; // no-op @@ -130,8 +130,8 @@ public class JsonNormalizedNodeBodyReader final List iiToDataList = new ArrayList<>(); InstanceIdentifierContext newIIContext; - while ((result instanceof AugmentationNode) || (result instanceof ChoiceNode)) { - final Object childNode = ((DataContainerNode) result).getValue().iterator().next(); + while (result instanceof AugmentationNode || result instanceof ChoiceNode) { + final Object childNode = ((DataContainerNode) result).getValue().iterator().next(); if (isPost) { iiToDataList.add(result.getIdentifier()); } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java index aa7c32a1cf..d922a5aa94 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java @@ -122,7 +122,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider ErrorTag.MALFORMED_MESSAGE, exception); } - private List read(final JsonReader in, final InstanceIdentifierContext path) throws IOException { + private List read(final JsonReader in, final InstanceIdentifierContext path) throws IOException { final List resultCollection = new ArrayList<>(); final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec( path.getSchemaContext()); @@ -178,7 +178,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * @throws IOException if operation fails */ private void parseByName(@Nonnull final String name, @Nonnull final PatchEdit edit, - @Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext path, + @Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext path, @Nonnull final StringModuleInstanceIdentifierCodec codec, @Nonnull final List resultCollection) throws IOException { switch (name) { @@ -217,7 +217,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * @throws IOException if operation fails */ private void readEditDefinition(@Nonnull final PatchEdit edit, @Nonnull final JsonReader in, - @Nonnull final InstanceIdentifierContext path, + @Nonnull final InstanceIdentifierContext path, @Nonnull final StringModuleInstanceIdentifierCodec codec) throws IOException { final StringBuffer value = new StringBuffer(); in.beginObject(); @@ -358,8 +358,8 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * @param in reader JsonReader reader * @return NormalizedNode representing data */ - private static NormalizedNode readEditData(@Nonnull final JsonReader in, @Nonnull final SchemaNode targetSchemaNode, - @Nonnull final InstanceIdentifierContext path) { + private static NormalizedNode readEditData(@Nonnull final JsonReader in, + @Nonnull final SchemaNode targetSchemaNode, @Nonnull final InstanceIdentifierContext path) { final NormalizedNodeResult resultHolder = new NormalizedNodeResult(); final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder); JsonParserStream.create(writer, path.getSchemaContext(), targetSchemaNode).parse(in); @@ -373,8 +373,8 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * @return PatchEntity Patch entity */ private static PatchEntity prepareEditOperation(@Nonnull final PatchEdit edit) { - if ((edit.getOperation() != null) && (edit.getTargetSchemaNode() != null) - && checkDataPresence(edit.getOperation(), (edit.getData() != null))) { + if (edit.getOperation() != null && edit.getTargetSchemaNode() != null + && checkDataPresence(edit.getOperation(), edit.getData() != null)) { if (isPatchOperationWithValue(edit.getOperation())) { // for lists allow to manipulate with list items through their parent final YangInstanceIdentifier targetNode; @@ -385,9 +385,9 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider } return new PatchEntity(edit.getId(), edit.getOperation(), targetNode, edit.getData()); - } else { - return new PatchEntity(edit.getId(), edit.getOperation(), edit.getTarget()); } + + return new PatchEntity(edit.getId(), edit.getOperation(), edit.getTarget()); } throw new RestconfDocumentedException("Error parsing input", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE); @@ -401,11 +401,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * allow it, false otherwise */ private static boolean checkDataPresence(@Nonnull final String operation, final boolean hasData) { - if (isPatchOperationWithValue(operation)) { - return hasData; - } else { - return !hasData; - } + return isPatchOperationWithValue(operation) == hasData; } /** @@ -416,7 +412,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider private String operation; private YangInstanceIdentifier target; private SchemaNode targetSchemaNode; - private NormalizedNode data; + private NormalizedNode data; public String getId() { return this.id; @@ -450,11 +446,11 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider this.targetSchemaNode = targetSchemaNode; } - public NormalizedNode getData() { + public NormalizedNode getData() { return this.data; } - public void setData(final NormalizedNode data) { + public void setData(final NormalizedNode data) { this.data = data; } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java index 202f08897d..7891d40372 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java @@ -121,7 +121,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter context) { // TODO: Performance: Cache JSON Codec factory and schema context - return JSONCodecFactory.create(context.getSchemaContext()); + return JSONCodecFactory.getShared(context.getSchemaContext()); } - } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeXmlBodyWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeXmlBodyWriter.java index cfe6b2116b..40123d0e98 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeXmlBodyWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeXmlBodyWriter.java @@ -135,9 +135,9 @@ public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter> leafBuilder = Builders.leafBuilder((LeafSchemaNode) childSchema); if (keys.contains(child.getNodeType())) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(((LeafNode) child).getValue()); builder.withChild(leafBuilder.build()); } else { if (trim) { if (defaultVal == null || !defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(((LeafNode) child).getValue()); builder.withChild(leafBuilder.build()); } } else { if (defaultVal != null && defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(((LeafNode) child).getValue()); builder.withChild(leafBuilder.build()); } } @@ -672,12 +672,12 @@ public class BrokerFacade { Builders.leafBuilder((LeafSchemaNode) childSchema); if (trim) { if (defaultVal == null || !defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(((LeafNode) child).getValue()); builder.withChild(leafBuilder.build()); } } else { if (defaultVal != null && defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(((LeafNode) child).getValue()); builder.withChild(leafBuilder.build()); } } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java index 0518de3f8f..0202b722cc 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java @@ -212,11 +212,11 @@ public class RestCodec { final IdentityValuesDTO identityValuesDTO = new IdentityValuesDTO(); for (final PathArgument pathArgument : data.getPathArguments()) { final IdentityValue identityValue = qNameToIdentityValue(pathArgument.getNodeType()); - if ((pathArgument instanceof NodeIdentifierWithPredicates) && (identityValue != null)) { + if (pathArgument instanceof NodeIdentifierWithPredicates && identityValue != null) { final List predicates = keyValuesToPredicateList(((NodeIdentifierWithPredicates) pathArgument).getKeyValues()); identityValue.setPredicates(predicates); - } else if ((pathArgument instanceof NodeWithValue) && (identityValue != null)) { + } else if (pathArgument instanceof NodeWithValue && identityValue != null) { final List predicates = new ArrayList<>(); final String value = String.valueOf(((NodeWithValue) pathArgument).getValue()); predicates.add(new Predicate(null, value)); @@ -266,7 +266,7 @@ public class RestCodec { String.valueOf(identityValue.getValue())); return null; } - pathArgument = new NodeWithValue(qName, leafListPredicate.getValue()); + pathArgument = new NodeWithValue<>(qName, leafListPredicate.getValue()); } else if (node instanceof ListSchemaNode) { // predicates are keys of list final DataNodeContainer listNode = (DataNodeContainer) node; final Map predicatesMap = new HashMap<>(); @@ -286,7 +286,7 @@ public class RestCodec { } } result.add(pathArgument); - if (i < (identities.size() - 1)) { // last element in instance-identifier can be other than + if (i < identities.size() - 1) { // last element in instance-identifier can be other than // DataNodeContainer if (node instanceof DataNodeContainer) { parentContainer = (DataNodeContainer) node; diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java index 084457aea3..cdf1ff2645 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java @@ -71,7 +71,7 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem this.outputType = Preconditions.checkNotNull(outputType); this.path = Preconditions.checkNotNull(path); - Preconditions.checkArgument((streamName != null) && !streamName.isEmpty()); + Preconditions.checkArgument(streamName != null && !streamName.isEmpty()); this.streamName = streamName; } @@ -156,7 +156,7 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem private String writeBodyToString() { final Writer writer = new StringWriter(); final NormalizedNodeStreamWriter jsonStream = - JSONNormalizedNodeStreamWriter.createExclusiveWriter(JSONCodecFactory.create(this.schemaContext), + JSONNormalizedNodeStreamWriter.createExclusiveWriter(JSONCodecFactory.getShared(this.schemaContext), this.notification.getType(), null, JsonWriterFactory.createJsonWriter(writer)); final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream); try { diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonNormalizedNodeBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonNormalizedNodeBodyReader.java index e76ad6b989..9dbf3f0e9c 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonNormalizedNodeBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonNormalizedNodeBodyReader.java @@ -108,8 +108,8 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr final List iiToDataList = new ArrayList<>(); InstanceIdentifierContext newIIContext; - while ((result instanceof AugmentationNode) || (result instanceof ChoiceNode)) { - final Object childNode = ((DataContainerNode) result).getValue().iterator().next(); + while (result instanceof AugmentationNode || result instanceof ChoiceNode) { + final Object childNode = ((DataContainerNode) result).getValue().iterator().next(); if (isPost) { iiToDataList.add(result.getIdentifier()); } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPatchBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPatchBodyReader.java index 4a217599a6..2665e58e2a 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPatchBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/JsonToPatchBodyReader.java @@ -115,7 +115,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider ErrorTag.MALFORMED_MESSAGE, exception); } - private List read(final JsonReader in, final InstanceIdentifierContext path) throws IOException { + private List read(final JsonReader in, final InstanceIdentifierContext path) throws IOException { final List resultCollection = new ArrayList<>(); final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec( path.getSchemaContext()); @@ -171,7 +171,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * @throws IOException if operation fails */ private void parseByName(@Nonnull final String name, @Nonnull final PatchEdit edit, - @Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext path, + @Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext path, @Nonnull final StringModuleInstanceIdentifierCodec codec, @Nonnull final List resultCollection) throws IOException { switch (name) { @@ -211,7 +211,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * @throws IOException if operation fails */ private void readEditDefinition(@Nonnull final PatchEdit edit, @Nonnull final JsonReader in, - @Nonnull final InstanceIdentifierContext path, + @Nonnull final InstanceIdentifierContext path, @Nonnull final StringModuleInstanceIdentifierCodec codec) throws IOException { final StringBuffer value = new StringBuffer(); in.beginObject(); @@ -352,8 +352,8 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * @param in reader JsonReader reader * @return NormalizedNode representing data */ - private static NormalizedNode readEditData(@Nonnull final JsonReader in, @Nonnull final SchemaNode targetSchemaNode, - @Nonnull final InstanceIdentifierContext path) { + private static NormalizedNode readEditData(@Nonnull final JsonReader in, + @Nonnull final SchemaNode targetSchemaNode, @Nonnull final InstanceIdentifierContext path) { final NormalizedNodeResult resultHolder = new NormalizedNodeResult(); final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder); JsonParserStream.create(writer, path.getSchemaContext(), targetSchemaNode).parse(in); @@ -369,19 +369,19 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider private static PatchEntity prepareEditOperation(@Nonnull final PatchEdit edit) { if (edit.getOperation() != null && edit.getTargetSchemaNode() != null && checkDataPresence(edit.getOperation(), edit.getData() != null)) { - if (isPatchOperationWithValue(edit.getOperation())) { - // for lists allow to manipulate with list items through their parent - final YangInstanceIdentifier targetNode; - if (edit.getTarget().getLastPathArgument() instanceof NodeIdentifierWithPredicates) { - targetNode = edit.getTarget().getParent(); - } else { - targetNode = edit.getTarget(); - } + if (!isPatchOperationWithValue(edit.getOperation())) { + return new PatchEntity(edit.getId(), edit.getOperation(), edit.getTarget()); + } - return new PatchEntity(edit.getId(), edit.getOperation(), targetNode, edit.getData()); + // for lists allow to manipulate with list items through their parent + final YangInstanceIdentifier targetNode; + if (edit.getTarget().getLastPathArgument() instanceof NodeIdentifierWithPredicates) { + targetNode = edit.getTarget().getParent(); } else { - return new PatchEntity(edit.getId(), edit.getOperation(), edit.getTarget()); + targetNode = edit.getTarget(); } + + return new PatchEntity(edit.getId(), edit.getOperation(), targetNode, edit.getData()); } throw new RestconfDocumentedException("Error parsing input", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE); @@ -395,11 +395,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider * allow it, false otherwise */ private static boolean checkDataPresence(@Nonnull final String operation, final boolean hasData) { - if (isPatchOperationWithValue(operation)) { - return hasData; - } else { - return !hasData; - } + return isPatchOperationWithValue(operation) == hasData; } /** @@ -410,7 +406,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider private String operation; private YangInstanceIdentifier target; private SchemaNode targetSchemaNode; - private NormalizedNode data; + private NormalizedNode data; public String getId() { return id; @@ -444,11 +440,11 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider this.targetSchemaNode = targetSchemaNode; } - public NormalizedNode getData() { + public NormalizedNode getData() { return data; } - public void setData(final NormalizedNode data) { + public void setData(final NormalizedNode data) { this.data = data; } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/NormalizedNodeJsonBodyWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/NormalizedNodeJsonBodyWriter.java index 563b566623..b89b30c12f 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/NormalizedNodeJsonBodyWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/NormalizedNodeJsonBodyWriter.java @@ -127,7 +127,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter context) { // TODO: Performance: Cache JSON Codec factory and schema context - return JSONCodecFactory.create(context.getSchemaContext()); + return JSONCodecFactory.getShared(context.getSchemaContext()); } } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/ParameterAwareNormalizedNodeWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/ParameterAwareNormalizedNodeWriter.java index ce108409bc..c86bd6fcb3 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/ParameterAwareNormalizedNodeWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/ParameterAwareNormalizedNodeWriter.java @@ -13,7 +13,6 @@ import static org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedN import com.google.common.annotations.Beta; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import java.io.IOException; import java.util.Collection; @@ -102,11 +101,8 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod final boolean orderKeyLeaves, final Integer maxDepth, final List> fields) { - if (orderKeyLeaves) { - return new OrderedParameterAwareNormalizedNodeWriter(writer, maxDepth, fields); - } else { - return new ParameterAwareNormalizedNodeWriter(writer, maxDepth, fields); - } + return orderKeyLeaves ? new OrderedParameterAwareNormalizedNodeWriter(writer, maxDepth, fields) + : new ParameterAwareNormalizedNodeWriter(writer, maxDepth, fields); } /** @@ -117,6 +113,7 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod * @return {@code ParameterAwareNormalizedNodeWriter} * @throws IOException when thrown from the backing writer. */ + @Override public final ParameterAwareNormalizedNodeWriter write(final NormalizedNode node) throws IOException { if (wasProcessedAsCompositeNode(node)) { return this; @@ -149,7 +146,7 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod * @return Best estimate of the collection size required to hold all the children. */ static final int childSizeHint(final Iterable children) { - return (children instanceof Collection) ? ((Collection) children).size() : UNKNOWN_SIZE; + return children instanceof Collection ? ((Collection) children).size() : UNKNOWN_SIZE; } private boolean wasProcessAsSimpleNode(final NormalizedNode node) throws IOException { @@ -192,7 +189,7 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod protected boolean selectedByParameters(final NormalizedNode node, final boolean mixinParent) { // nodes to be written are not limited by fields, only by depth if (fields == null) { - return (maxDepth == null || currentDepth < maxDepth); + return maxDepth == null || currentDepth < maxDepth; } // children of mixin nodes are never selected in fields but must be written if they are first in selected target @@ -207,15 +204,11 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod // write only selected nodes if (currentDepth > 0 && currentDepth <= fields.size()) { - if (fields.get(currentDepth - 1).contains(node.getNodeType())) { - return true; - } else { - return false; - } + return fields.get(currentDepth - 1).contains(node.getNodeType()); } // after this depth only depth parameter is used to determine when to write node - return (maxDepth == null || currentDepth < maxDepth); + return maxDepth == null || currentDepth < maxDepth; } /** @@ -370,20 +363,17 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod currentDepth++; // Write all the rest final boolean result = - writeChildren(Iterables.filter(node.getValue(), new Predicate>() { - @Override - public boolean apply(final NormalizedNode input) { - if (input instanceof AugmentationNode) { - return true; - } - if (!qnames.contains(input.getNodeType())) { - return true; - } - - LOG.debug("Skipping key child {}", input); - return false; - } - }), false); + writeChildren(Iterables.filter(node.getValue(), input -> { + if (input instanceof AugmentationNode) { + return true; + } + if (!qnames.contains(input.getNodeType())) { + return true; + } + + LOG.debug("Skipping key child {}", input); + return false; + }), false); currentDepth--; return result; } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/XmlToPatchBodyReader.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/XmlToPatchBodyReader.java index 1972ea970a..eed386645d 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/XmlToPatchBodyReader.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/jersey/providers/XmlToPatchBodyReader.java @@ -61,6 +61,7 @@ public class XmlToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider i MessageBodyReader { private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class); + private static final Splitter SLASH_SPLITTER = Splitter.on('/'); @Override public boolean isReadable(final Class type, final Type genericType, @@ -113,7 +114,7 @@ public class XmlToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider i final Element firstValueElement = values != null ? values.get(0) : null; // get namespace according to schema node from path context or value - final String namespace = (firstValueElement == null) + final String namespace = firstValueElement == null ? schemaNode.getQName().getNamespace().toString() : firstValueElement.getNamespaceURI(); // find module according to namespace @@ -148,24 +149,24 @@ public class XmlToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider i LOG.debug("Target node {} not found in path {} ", target, pathContext.getSchemaNode()); throw new RestconfDocumentedException("Error parsing input", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE); - } else { - if (PatchEditOperation.isPatchOperationWithValue(operation)) { - NormalizedNode parsed = null; - if (schemaNode instanceof ContainerSchemaNode) { - parsed = parserFactory.getContainerNodeParser().parse(values, (ContainerSchemaNode) schemaNode); - } else if (schemaNode instanceof ListSchemaNode) { - parsed = parserFactory.getMapNodeParser().parse(values, (ListSchemaNode) schemaNode); - } - - // for lists allow to manipulate with list items through their parent - if (targetII.getLastPathArgument() instanceof NodeIdentifierWithPredicates) { - targetII = targetII.getParent(); - } - - resultCollection.add(new PatchEntity(editId, operation, targetII, parsed)); - } else { - resultCollection.add(new PatchEntity(editId, operation, targetII)); + } + + if (PatchEditOperation.isPatchOperationWithValue(operation)) { + NormalizedNode parsed = null; + if (schemaNode instanceof ContainerSchemaNode) { + parsed = parserFactory.getContainerNodeParser().parse(values, (ContainerSchemaNode) schemaNode); + } else if (schemaNode instanceof ListSchemaNode) { + parsed = parserFactory.getMapNodeParser().parse(values, (ListSchemaNode) schemaNode); } + + // for lists allow to manipulate with list items through their parent + if (targetII.getLastPathArgument() instanceof NodeIdentifierWithPredicates) { + targetII = targetII.getParent(); + } + + resultCollection.add(new PatchEntity(editId, operation, targetII, parsed)); + } else { + resultCollection.add(new PatchEntity(editId, operation, targetII)); } } @@ -219,7 +220,7 @@ public class XmlToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider i */ private static String prepareNonCondXpath(@Nonnull final DataSchemaNode schemaNode, @Nonnull final String target, @Nonnull final Element value, @Nonnull final String namespace, @Nonnull final String revision) { - final Iterator args = Splitter.on("/").split(target.substring(target.indexOf(':') + 1)).iterator(); + final Iterator args = SLASH_SPLITTER.split(target.substring(target.indexOf(':') + 1)).iterator(); final StringBuilder nonCondXpath = new StringBuilder(); SchemaNode childNode = schemaNode; @@ -271,13 +272,11 @@ public class XmlToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider i private static void appendKeys(@Nonnull final StringBuilder nonCondXpath, @Nonnull final Iterator keyNames, @Nonnull final Iterator keyValues) { while (keyNames.hasNext()) { - nonCondXpath.append("["); + nonCondXpath.append('['); nonCondXpath.append(keyNames.next().getLocalName()); - nonCondXpath.append("="); - nonCondXpath.append("'"); + nonCondXpath.append("='"); nonCondXpath.append(keyValues.next()); - nonCondXpath.append("'"); - nonCondXpath.append("]"); + nonCondXpath.append("']"); } } } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/utils/CreateStreamUtil.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/utils/CreateStreamUtil.java index 10955e7929..c358b42bda 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/utils/CreateStreamUtil.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/utils/CreateStreamUtil.java @@ -221,12 +221,12 @@ public final class CreateStreamUtil { streamName = streamName + "/JSON"; } - if (!Notificator.existNotificationListenerFor(streamName)) { - return Notificator.createNotificationListener(paths, streamName, outputType); - } else { + if (Notificator.existNotificationListenerFor(streamName)) { final List notificationListenerFor = Notificator.getNotificationListenerFor(streamName); return SubscribeToStreamUtil.pickSpecificListenerByOutput(notificationListenerFor, outputType); } + + return Notificator.createNotificationListener(paths, streamName, outputType); } } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java index 632cfc199b..a108094751 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java @@ -23,6 +23,7 @@ import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter; import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +@Deprecated public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest { private static SchemaContext schemaContext; diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java index 33fa3c4dcb..a2485dfc81 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java @@ -381,7 +381,7 @@ public class BrokerFacadeTest { final DOMTransactionChain transactionChain = mock(DOMTransactionChain.class); final DOMDataWriteTransaction wTx = mock(DOMDataWriteTransaction.class); - final CheckedFuture checked = Futures.immediateCheckedFuture(""); + final CheckedFuture checked = Futures.immediateCheckedFuture(null); when(wTx.submit()).thenReturn(checked); when(transactionChain.newWriteOnlyTransaction()).thenReturn(wTx); final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(transactionChain); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java index a6154e8460..dd0ea449a1 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java @@ -57,7 +57,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch final Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:augment:module"); - while (prefixes.hasNext() && (augmentAugmentModulePrefix == null)) { + while (prefixes.hasNext() && augmentAugmentModulePrefix == null) { final String prefix = (String) prefixes.next(); if (!prefix.isEmpty()) { augmentAugmentModulePrefix = prefix; @@ -100,7 +100,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch final Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:module:leaf:list"); - while (prefixes.hasNext() && (augmentModuleLfLstPrefix == null)) { + while (prefixes.hasNext() && augmentModuleLfLstPrefix == null) { final String prefix = (String) prefixes.next(); if (!prefix.isEmpty()) { augmentModuleLfLstPrefix = prefix; @@ -144,7 +144,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch final List pathArguments = new ArrayList<>(); pathArguments.add(new NodeIdentifier(new QName(new URI("instance:identifier:module"), "cont"))); pathArguments.add(new NodeIdentifier(new QName(new URI("instance:identifier:module"), "cont1"))); - pathArguments.add(new NodeWithValue(new QName(new URI("augment:module:leaf:list"), "lflst11"), "lflst11_1")); + pathArguments.add(new NodeWithValue<>(new QName(new URI("augment:module:leaf:list"), "lflst11"), "lflst11_1")); return YangInstanceIdentifier.create(pathArguments); } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CutDataToCorrectDepthTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CutDataToCorrectDepthTest.java index c0b616a63d..72e9351ade 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CutDataToCorrectDepthTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CutDataToCorrectDepthTest.java @@ -82,7 +82,7 @@ public class CutDataToCorrectDepthTest extends JerseyTest { public NormalizedNodeContext getData(@Encoded @PathParam("identifier") final String identifier, @Context final UriInfo uriInfo) { - final InstanceIdentifierContext iiWithData = ControllerContext.getInstance().toInstanceIdentifier( + final InstanceIdentifierContext iiWithData = ControllerContext.getInstance().toInstanceIdentifier( identifier); NormalizedNode data = null; @@ -311,8 +311,8 @@ public class CutDataToCorrectDepthTest extends JerseyTest { keys); } - private static NodeWithValue toIdentifier(final String localName, final Object value) { - return new NodeWithValue(QName.create("urn:nested:module", "2014-06-3", localName), value); + private static NodeWithValue toIdentifier(final String localName, final Object value) { + return new NodeWithValue<>(QName.create("urn:nested:module", "2014-06-3", localName), value); } private static UnkeyedListEntryNode nodeDataDepth3Operational() { diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java index ec0a666fb4..6276457b26 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java @@ -155,7 +155,7 @@ public class InvokeRpcMethodTest { final DataSchemaNode lfSchemaNode = ((ContainerSchemaNode) contSchemaNode).getDataChildByName(lfQName); assertTrue(lfSchemaNode instanceof LeafSchemaNode); final LeafNode lfNode = - (Builders.leafBuilder((LeafSchemaNode) lfSchemaNode).withValue("any value")).build(); + Builders.leafBuilder((LeafSchemaNode) lfSchemaNode).withValue("any value").build(); contNode.withChild(lfNode); container.withChild(contNode.build()); @@ -309,7 +309,6 @@ public class InvokeRpcMethodTest { assertNotNull(rpcDef); assertNotNull(rpcInputSchemaNode); - assertTrue(rpcInputSchemaNode instanceof ContainerSchemaNode); final DataContainerNodeAttrBuilder containerBuilder = Builders.containerBuilder(rpcInputSchemaNode); @@ -359,7 +358,6 @@ public class InvokeRpcMethodTest { } assertNotNull(rpcDef); assertNotNull(rpcOutputSchemaNode); - assertTrue(rpcOutputSchemaNode instanceof ContainerSchemaNode); final DataContainerNodeAttrBuilder containerBuilder = Builders.containerBuilder(rpcOutputSchemaNode); final DataSchemaNode leafSchema = rpcOutputSchemaNode diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java index 831fd5541c..b98176433d 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java @@ -92,8 +92,8 @@ public class RestDeleteOperationTest extends JerseyTest { @Test public void deleteFailTest() throws Exception { final String uri = "/config/test-interface:interfaces"; - final Exception exception = new TransactionCommitFailedException("failed test"); - final CheckedFuture future = Futures.immediateFailedCheckedFuture(exception); + final CheckedFuture future = + Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("failed test")); when(brokerFacade.commitConfigurationDataDelete(any(YangInstanceIdentifier.class))).thenReturn(future); final Response response = target(uri).request(MediaType.APPLICATION_XML).delete(); assertEquals(500, response.getStatus()); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java index 8623708067..e993fb4907 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.sal.restconf.impl.test; import java.time.Instant; +import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -70,11 +71,9 @@ public class RestconfImplNotificationSubscribingTest { @Test public void startTimeTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00Z"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); @@ -84,11 +83,9 @@ public class RestconfImplNotificationSubscribingTest { @Test public void milisecsTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00.12345Z"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); @@ -98,11 +95,9 @@ public class RestconfImplNotificationSubscribingTest { @Test public void zonesPlusTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00+01:00"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); @@ -112,11 +107,9 @@ public class RestconfImplNotificationSubscribingTest { @Test public void zonesMinusTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00-01:00"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); @@ -126,17 +119,13 @@ public class RestconfImplNotificationSubscribingTest { @Test public void startAndStopTimeTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00Z"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); - final Entry> entry2 = Mockito.mock(Entry.class); - Mockito.when(entry2.getKey()).thenReturn("stop-time"); final List time2 = new ArrayList<>(); time2.add("2014-10-25T12:31:00Z"); - Mockito.when(entry2.getValue()).thenReturn(time2); + final Entry> entry2 = new SimpleImmutableEntry<>("stop-time", time2); list.add(entry); list.add(entry2); @@ -148,11 +137,9 @@ public class RestconfImplNotificationSubscribingTest { @Test(expected = RestconfDocumentedException.class) public void stopTimeTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("stop-time"); final List time = new ArrayList<>(); time.add("2014-10-25T12:31:00Z"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("stop-time", time); list.add(entry); subscribe(list); @@ -162,11 +149,9 @@ public class RestconfImplNotificationSubscribingTest { @Test(expected = RestconfDocumentedException.class) public void badParamTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("time"); final List time = new ArrayList<>(); time.add("2014-10-25T12:31:00Z"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("time", time); list.add(entry); subscribe(list); @@ -176,11 +161,9 @@ public class RestconfImplNotificationSubscribingTest { @Test(expected = IllegalArgumentException.class) public void badValueTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("badvalue"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); @@ -190,11 +173,9 @@ public class RestconfImplNotificationSubscribingTest { @Test(expected = IllegalArgumentException.class) public void badZonesTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00Z+1:00"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); @@ -204,11 +185,9 @@ public class RestconfImplNotificationSubscribingTest { @Test(expected = IllegalArgumentException.class) public void badMilisecsTest() { final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00:0026Z"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); @@ -223,11 +202,9 @@ public class RestconfImplNotificationSubscribingTest { final ListenerAdapter listener = Notificator.createListener(path, this.identifier, NotificationOutputType.XML); final List>> list = new ArrayList<>(); - final Entry> entry = Mockito.mock(Entry.class); - Mockito.when(entry.getKey()).thenReturn("start-time"); final List time = new ArrayList<>(); time.add("2014-10-25T10:02:00Z"); - Mockito.when(entry.getValue()).thenReturn(time); + final Entry> entry = new SimpleImmutableEntry<>("start-time", time); list.add(entry); subscribe(list); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerTest.java index 7d610d00da..fc0a66ad39 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerTest.java @@ -73,7 +73,7 @@ public class NotificationListenerTest { final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), leaf); when(notificationData.getType()).thenReturn(schemaPathNotifi); @@ -93,7 +93,7 @@ public class NotificationListenerTest { final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), leaf); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), cont); @@ -115,7 +115,7 @@ public class NotificationListenerTest { final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); final MapEntryNode entry = mockMapEntry(QName.create(MODULE, "lst"), leaf); final MapNode list = mockList(QName.create(MODULE, "lst"), entry); final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), list); @@ -139,7 +139,7 @@ public class NotificationListenerTest { final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), leaf); when(notificationData.getType()).thenReturn(schemaPathNotifi); @@ -158,7 +158,7 @@ public class NotificationListenerTest { final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf-augm")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf-augm")); final AugmentationNode augm = mockAugm(leaf); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), augm); @@ -172,7 +172,7 @@ public class NotificationListenerTest { assertTrue(result.contains("lf-augm" + '"' + ":" + '"' + "value")); } - private static AugmentationNode mockAugm(final LeafNode leaf) { + private static AugmentationNode mockAugm(final LeafNode leaf) { final AugmentationNode augm = mock(AugmentationNode.class); final AugmentationIdentifier augmId = new AugmentationIdentifier(SingletonSet.of(leaf.getNodeType())); when(augm.getIdentifier()).thenReturn(augmId); @@ -184,7 +184,7 @@ public class NotificationListenerTest { return augm; } - private static MapEntryNode mockMapEntry(final QName entryQName, final LeafNode leaf) { + private static MapEntryNode mockMapEntry(final QName entryQName, final LeafNode leaf) { final MapEntryNode entry = mock(MapEntryNode.class); final Map keyValues = new HashMap<>(); keyValues.put(leaf.getNodeType(), "value"); @@ -219,8 +219,8 @@ public class NotificationListenerTest { return cont; } - private static LeafNode mockLeaf(final QName leafQName) { - final LeafNode child = mock(LeafNode.class); + private static LeafNode mockLeaf(final QName leafQName) { + final LeafNode child = mock(LeafNode.class); when(child.getNodeType()).thenReturn(leafQName); when(child.getIdentifier()).thenReturn(NodeIdentifier.create(leafQName)); when(child.getValue()).thenReturn("value"); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java index 879e2fe489..f32182e072 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfImplTest.java @@ -11,6 +11,7 @@ import com.google.common.util.concurrent.CheckedFuture; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; @@ -34,16 +35,15 @@ public class RestconfImplTest { Mockito.when(txHandler.get()).thenReturn(domTx); final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); - final CheckedFuture checked = Mockito.mock(CheckedFuture.class); + final CheckedFuture checked = Mockito.mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); - final Object valueObj = null; - Mockito.when(checked.checkedGet()).thenReturn(valueObj); + Mockito.when(checked.checkedGet()).thenReturn(null); final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler); schemaContextHandler.onGlobalContextUpdated(schemaContext); final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler); final NormalizedNodeContext libraryVersion = restconfImpl.getLibraryVersion(); - final LeafNode value = (LeafNode) libraryVersion.getData(); + final LeafNode value = (LeafNode) libraryVersion.getData(); Assert.assertEquals(IetfYangLibrary.REVISION, value.getValue()); } } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java index ded94ef834..71e68a221c 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/base/services/impl/RestconfOperationsServiceTest.java @@ -12,7 +12,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.Futures; import java.net.URI; import java.util.Set; import javax.ws.rs.core.UriInfo; @@ -61,10 +61,7 @@ public class RestconfOperationsServiceTest { Mockito.when(txHandler.get()).thenReturn(domTx); final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); - final CheckedFuture checked = Mockito.mock(CheckedFuture.class); - Mockito.when(wTx.submit()).thenReturn(checked); - final Object valueObj = null; - Mockito.when(checked.checkedGet()).thenReturn(valueObj); + Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null)); this.schemaContextHandler = new SchemaContextHandler(txHandler); this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java index ba3c43ea95..5eceb84945 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/handlers/SchemaContextHandlerTest.java @@ -16,6 +16,7 @@ import com.google.common.util.concurrent.CheckedFuture; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils; @@ -40,10 +41,9 @@ public class SchemaContextHandlerTest { Mockito.when(txHandler.get()).thenReturn(domTx); final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); - final CheckedFuture checked = Mockito.mock(CheckedFuture.class); + final CheckedFuture checked = Mockito.mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); - final Object value = null; - Mockito.when(checked.checkedGet()).thenReturn(value); + Mockito.when(checked.checkedGet()).thenReturn(null); this.schemaContextHandler = new SchemaContextHandler(txHandler); this.schemaContext = diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java index bcb40603a5..e13a4cd478 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierDeserializerTest.java @@ -116,7 +116,7 @@ public class YangInstanceIdentifierDeserializerTest { YangInstanceIdentifier.NodeIdentifier.create(leafList), iterator.next()); assertEquals("Not expected path argument", - new YangInstanceIdentifier.NodeWithValue(leafList, "instance"), + new YangInstanceIdentifier.NodeWithValue<>(leafList, "instance"), iterator.next()); } @@ -209,7 +209,7 @@ public class YangInstanceIdentifierDeserializerTest { new YangInstanceIdentifier.NodeIdentifier(leafList), iterator.next()); assertEquals("Not expected path argument", - new YangInstanceIdentifier.NodeWithValue(leafList, true).toString(), + new YangInstanceIdentifier.NodeWithValue<>(leafList, true).toString(), iterator.next().toString()); } diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java index 7d5455ffa8..22f2586067 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/parser/builder/YangInstanceIdentifierSerializerTest.java @@ -89,7 +89,7 @@ public class YangInstanceIdentifierSerializerTest { .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates( list, QName.create(list, "list-key"), 100)) .node(leafList) - .node(new NodeWithValue(leafList, "instance")) + .node(new NodeWithValue<>(leafList, "instance")) .build(); final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); @@ -175,7 +175,7 @@ public class YangInstanceIdentifierSerializerTest { public void serializeLeafListTest() { final YangInstanceIdentifier data = YangInstanceIdentifier.builder() .node(QName.create("serializer:test", "2016-06-06", "leaf-list-0")) - .node(new NodeWithValue(QName.create("serializer:test", "2016-06-06", "leaf-list-0"), "instance")) + .node(new NodeWithValue<>(QName.create("serializer:test", "2016-06-06", "leaf-list-0"), "instance")) .build(); final String result = YangInstanceIdentifierSerializer.create(this.schemaContext, data); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java index e33ea5cbd0..e8f525bb81 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImplTest.java @@ -37,6 +37,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; @@ -178,10 +179,9 @@ public class RestconfDataServiceImplTest { Mockito.when(txHandler.get()).thenReturn(domTx); final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); - final CheckedFuture checked = Mockito.mock(CheckedFuture.class); + final CheckedFuture checked = Mockito.mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); - final Object valueObj = null; - Mockito.when(checked.checkedGet()).thenReturn(valueObj); + Mockito.when(checked.checkedGet()).thenReturn(null); final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler); schemaContextHandler.onGlobalContextUpdated(this.contextRef.get()); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java index 378e53ae84..10547da8db 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfInvokeOperationsServiceImplTest.java @@ -17,6 +17,7 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; @@ -57,10 +58,9 @@ public class RestconfInvokeOperationsServiceImplTest { Mockito.when(txHandler.get()).thenReturn(domTx); final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); - final CheckedFuture checked = Mockito.mock(CheckedFuture.class); + final CheckedFuture checked = Mockito.mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); - final Object valueObj = null; - Mockito.when(checked.checkedGet()).thenReturn(valueObj); + Mockito.when(checked.checkedGet()).thenReturn(null); final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler); schemaContextHandler.onGlobalContextUpdated(contextRef.get()); this.invokeOperationsService = @@ -71,7 +71,7 @@ public class RestconfInvokeOperationsServiceImplTest { @Test public void testInvokeRpc() throws Exception { final String identifier = "invoke-rpc-module:rpcTest"; - final NormalizedNode result = Mockito.mock(NormalizedNode.class); + final NormalizedNode result = Mockito.mock(NormalizedNode.class); final NormalizedNodeContext payload = prepNNC(result); final UriInfo uriInfo = Mockito.mock(UriInfo.class); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java index e3ecf2c0af..330d5a24c4 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/services/impl/RestconfStreamsSubscriptionServiceImplTest.java @@ -33,6 +33,8 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; @@ -80,15 +82,15 @@ public class RestconfStreamsSubscriptionServiceImplTest { final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); final DOMDataReadWriteTransaction rwTx = Mockito.mock(DOMDataReadWriteTransaction.class); - final CheckedFuture checkedFuture = Futures.immediateCheckedFuture(true); + final CheckedFuture checkedFuture = Futures.immediateCheckedFuture(Boolean.TRUE); Mockito.when(rwTx.exists(Mockito.any(), Mockito.any())).thenReturn(checkedFuture); - final CheckedFuture checkedFutureEmpty = Futures.immediateCheckedFuture(""); + final CheckedFuture checkedFutureEmpty = + Futures.immediateCheckedFuture(null); Mockito.when(rwTx.submit()).thenReturn(checkedFutureEmpty); Mockito.when(domTx.newReadWriteTransaction()).thenReturn(rwTx); - final CheckedFuture checked = Mockito.mock(CheckedFuture.class); + final CheckedFuture checked = Mockito.mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); - final Object valueObj = null; - Mockito.when(checked.checkedGet()).thenReturn(valueObj); + Mockito.when(checked.checkedGet()).thenReturn(null); this.schemaHandler = new SchemaContextHandler(txHandler); final DOMDataBroker dataBroker = mock(DOMDataBroker.class); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java index 5ead74cb6b..5d7845961f 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PatchDataTransactionUtilTest.java @@ -101,7 +101,7 @@ public class PatchDataTransactionUtilTest { .build(); /* values that are used for creating leaf for testPatchDataCreateAndDelete test */ - final LeafNode buildGapLeaf = Builders.leafBuilder() + final LeafNode buildGapLeaf = Builders.leafBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(leafGapQName)) .withValue(0.2) .build(); diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java index 4dfbe347ec..e796e03e1f 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/PostDataTransactionUtilTest.java @@ -85,7 +85,7 @@ public class PostDataTransactionUtilTest { .node(baseQName) .build(); - final LeafNode buildLeaf = Builders.leafBuilder() + final LeafNode buildLeaf = Builders.leafBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(leafQname)) .withValue(0.2) .build(); @@ -130,7 +130,7 @@ public class PostDataTransactionUtilTest { doReturn(Futures.immediateCheckedFuture(false)) .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2); final YangInstanceIdentifier.NodeIdentifier identifier = - ((ContainerNode) ((SingletonSet) payload.getData().getValue()).iterator().next()).getIdentifier(); + ((ContainerNode) ((SingletonSet) payload.getData().getValue()).iterator().next()).getIdentifier(); final YangInstanceIdentifier node = payload.getInstanceIdentifierContext().getInstanceIdentifier().node(identifier); doReturn(Futures.immediateCheckedFuture(false)) @@ -180,7 +180,7 @@ public class PostDataTransactionUtilTest { doReturn(Futures.immediateCheckedFuture(false)) .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2); final YangInstanceIdentifier.NodeIdentifier identifier = - ((ContainerNode) ((SingletonSet) payload.getData().getValue()).iterator().next()).getIdentifier(); + ((ContainerNode) ((SingletonSet) payload.getData().getValue()).iterator().next()).getIdentifier(); final YangInstanceIdentifier node = payload.getInstanceIdentifierContext().getInstanceIdentifier().node(identifier); doReturn(Futures.immediateCheckedFuture(false)) diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java index c6073ae6d1..8abf3581c8 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/mapping/RestconfMappingNodeUtilTest.java @@ -132,8 +132,8 @@ public class RestconfMappingNodeUtilTest { if (child.getNodeType().equals(MonitoringModule.CONT_CAPABILITES_QNAME)) { for (final DataContainerChild dataContainerChild : ((ContainerNode) child) .getValue()) { - for (final Object entry : ((LeafSetNode) dataContainerChild).getValue()) { - listOfValues.add(((LeafSetEntryNode) entry).getValue()); + for (final Object entry : ((LeafSetNode) dataContainerChild).getValue()) { + listOfValues.add(((LeafSetEntryNode) entry).getValue()); } } } @@ -159,7 +159,7 @@ public class RestconfMappingNodeUtilTest { final Map map = prepareMap(path.getLastPathArgument().getNodeType().getLocalName(), uri, start, outputType); - final NormalizedNode mappedData = + final NormalizedNode mappedData = RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring( path, start, outputType, uri, monitoringModule, exist, schemaContextMonitoring); assertNotNull(mappedData); @@ -179,7 +179,7 @@ public class RestconfMappingNodeUtilTest { map.put(MonitoringModule.LEAF_DESCR_STREAM_QNAME, "Notifi"); final QName notifiQName = QName.create("urn:nested:module", "2014-06-3", "notifi"); - final NormalizedNode mappedData = + final NormalizedNode mappedData = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(notifiQName, schemaContextMonitoring.getNotifications(), start, outputType, uri, monitoringModule, exist); assertNotNull(mappedData); @@ -191,17 +191,17 @@ public class RestconfMappingNodeUtilTest { final Map map = new HashMap<>(); map.put(MonitoringModule.LEAF_NAME_STREAM_QNAME, name); map.put(MonitoringModule.LEAF_LOCATION_ACCESS_QNAME, uri.toString()); - map.put(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME, true); + map.put(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME, Boolean.TRUE); map.put(MonitoringModule.LEAF_START_TIME_STREAM_QNAME, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format( OffsetDateTime.ofInstant(start, ZoneId.systemDefault()))); map.put(MonitoringModule.LEAF_ENCODING_ACCESS_QNAME, outputType); return map; } - private static void testData(final Map map, final NormalizedNode mappedData) { + private static void testData(final Map map, final NormalizedNode mappedData) { for (final DataContainerChild child : ((MapEntryNode) mappedData).getValue()) { if (child instanceof LeafNode) { - final LeafNode leaf = ((LeafNode) child); + final LeafNode leaf = (LeafNode) child; Assert.assertTrue(map.containsKey(leaf.getNodeType())); Assert.assertEquals(map.get(leaf.getNodeType()), leaf.getValue()); } @@ -220,7 +220,7 @@ public class RestconfMappingNodeUtilTest { for (final DataContainerChild child : containerNode.getValue()) { if (child instanceof LeafNode) { - assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, ((LeafNode) child).getNodeType()); + assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, ((LeafNode) child).getNodeType()); } if (child instanceof MapNode) { assertEquals(IetfYangLibrary.MODULE_QNAME_LIST, ((MapNode) child).getNodeType()); @@ -231,10 +231,10 @@ public class RestconfMappingNodeUtilTest { .getValue()) { switch (dataContainerChild.getNodeType().getLocalName()) { case IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF: - name = String.valueOf(((LeafNode) dataContainerChild).getValue()); + name = String.valueOf(((LeafNode) dataContainerChild).getValue()); break; case IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF: - revision = String.valueOf(((LeafNode) dataContainerChild).getValue()); + revision = String.valueOf(((LeafNode) dataContainerChild).getValue()); break; default : LOG.info("Unknown local name '{}' of node.", -- 2.36.6