*/
package org.opendaylight.aaa.odl;
-import java.util.Map;
import org.opendaylight.aaa.api.AuthenticationException;
import org.opendaylight.aaa.api.Claim;
import org.opendaylight.aaa.api.CredentialAuth;
public final class CredentialServiceAuthProvider implements AuthProvider, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
- /**
- * Singleton instance with delayed instantiation.
- */
- public static volatile Map.Entry<BundleContext, CredentialServiceAuthProvider> INSTANCE;
-
// FIXME CredentialAuth is generic and it causes warnings during compilation
// Maybe there should be a PasswordCredentialAuth implements CredentialAuth<PasswordCredentials>
private volatile CredentialAuth<PasswordCredentials> nullableCredService;
return "Invalid IP:" + deviceIp + " or Port:" + devicePort + "Please enter a valid entry to proceed.";
}
- final boolean isTcpOnly = (connectionType.equals("true")) ? true : false;
- final boolean isSchemaless = (schemaless.equals("true")) ? true : false;
+ final boolean isTcpOnly = connectionType.equals("true");
+ final boolean isSchemaless = schemaless.equals("true");
final Credentials credentials = new LoginPasswordBuilder().setPassword(password).setUsername(username).build();
final NetconfNode netconfNode = new NetconfNodeBuilder()
: updated.get(NetconfConsoleConstants.NETCONF_IP);
final String devicePort = Strings.isNullOrEmpty(updated.get(NetconfConsoleConstants.NETCONF_PORT))
? netconfNode.getPort().getValue().toString() : updated.get(NetconfConsoleConstants.NETCONF_PORT);
- final Boolean tcpOnly = (updated.get(NetconfConsoleConstants.TCP_ONLY).equals("true")) ? true : false;
+ final Boolean tcpOnly = updated.get(NetconfConsoleConstants.TCP_ONLY).equals("true");
final Boolean isSchemaless =
- (updated.get(NetconfConsoleConstants.SCHEMALESS).equals("true")) ? true : false;
+ updated.get(NetconfConsoleConstants.SCHEMALESS).equals("true");
final String newUsername = Strings.isNullOrEmpty(updated.get(NetconfConsoleConstants.USERNAME))
? updated.get(NetconfConsoleConstants.USERNAME) : username;
final String newPassword = Strings.isNullOrEmpty(updated.get(NetconfConsoleConstants.PASSWORD))
* @return :<code>true</code> if not empty, else, <code>false</code>
*/
private static boolean isNetconfNodesPresent(final Topology topology) {
- if (topology == null || topology.getNode() == null || topology.getNode().isEmpty()) {
- return false;
- }
- return true;
+ return topology != null && topology.getNode() != null && !topology.getNode().isEmpty();
}
/**
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import java.util.Objects;
public final class HandlingPriority implements Comparable<HandlingPriority> {
HandlingPriority that = (HandlingPriority) obj;
- if (priority != null ? !priority.equals(that.priority) : that.priority != null) {
- return false;
- }
-
- return true;
+ return Objects.equals(priority, that.priority);
}
@Override
// Do not fail negotiation if promise is done or canceled
// It would result in setting result of the promise second time and that throws exception
- if (isPromiseFinished() == false) {
+ if (!isPromiseFinished()) {
LOG.warn("Netconf session was not established after {}", connectionTimeoutMillis);
changeState(State.FAILED);
final NetconfMessage message = getNetconfMessage(additionalHeader, doc);
if (message instanceof NetconfHelloMessage) {
- Preconditions.checkState(helloReceived == false,
+ Preconditions.checkState(!helloReceived,
"Multiple hello messages received, unexpected hello: %s", message);
out.add(message);
helloReceived = true;
createFidelityElement(doc, fidelityElements, exiOptions.getPreservePIs(), PIS_KEY);
createFidelityElement(doc, fidelityElements, exiOptions.getPreserveNS(), PREFIXES_KEY);
- if (fidelityElements.isEmpty() == false) {
+ if (!fidelityElements.isEmpty()) {
final Element fidelityElement = doc.createElementNS(
XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0, FIDELITY_KEY);
for (final Element element : fidelityElements) {
session.close(false).addListener(new SshFutureListener<CloseFuture>() {
@Override
public void operationComplete(final CloseFuture future) {
- if (future.isClosed() == false) {
+ if (!future.isClosed()) {
session.close(true);
}
session = null;
promise.setFailure(new IllegalStateException("Channel closed"));
} else {
final ByteBuf byteBufMsg = (ByteBuf) msg;
- if (pending.isEmpty() == false) {
+ if (!pending.isEmpty()) {
queueRequest(ctx, byteBufMsg, promise);
return;
}
} catch (final WritePendingException e) {
- if (wasPending == false) {
+ if (!wasPending) {
queueRequest(ctx, byteBufMsg, promise);
}
}
// Replay not supported
final Optional<XmlElement> startTime =
operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
- Preconditions.checkArgument(startTime.isPresent() == false, "StartTime element not yet supported");
+ Preconditions.checkArgument(!startTime.isPresent(), "StartTime element not yet supported");
// Stop time not supported
final Optional<XmlElement> stopTime =
operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
- Preconditions.checkArgument(stopTime.isPresent() == false, "StopTime element not yet supported");
+ Preconditions.checkArgument(!stopTime.isPresent(), "StopTime element not yet supported");
final StreamNameType streamNameType = parseStreamIfPresent(operationElement);
Preconditions.checkNotNull(netconfSession);
// Premature streams are allowed (meaning listener can register even if no provider is available yet)
- if (notifications.isStreamAvailable(streamNameType) == false) {
+ if (!notifications.isStreamAvailable(streamNameType)) {
LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType,
getNetconfSessionIdForReporting());
}
throws DocumentedException {
final Document partialResponse = subsequentOperation.execute(requestMessage);
final Streams availableStreams = notificationRegistry.getNotificationPublishers();
- if (availableStreams.getStream().isEmpty() == false) {
+ if (!availableStreams.getStream().isEmpty()) {
serializeStreamsSubtree(partialResponse, availableStreams);
}
return partialResponse;
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
- if (future.isSuccess() == false) {
+ if (!future.isSuccess()) {
LOG.warn("Unable to release internal connection to netconf server on channel: {}",
clientChannel);
}
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-data-impl</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-codec-xml</artifactId>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
-import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.codec.xml.XMLStreamNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
private NetconfUtil() {}
- public static Document checkIsMessageOk(Document response) throws DocumentedException {
+ public static Document checkIsMessageOk(final Document response) throws DocumentedException {
XmlElement element = XmlElement.fromDomDocument(response);
Preconditions.checkState(element.getName().equals(XmlMappingConstants.RPC_REPLY_KEY));
element = element.getOnlyChildElement();
MatchingResult matches = matches(src, filter);
if (matches != MatchingResult.NO_MATCH && matches != MatchingResult.CONTENT_MISMATCH) {
// copy srcChild to dst
- boolean filterHasChildren = filter.getChildElements().isEmpty() == false;
+ boolean filterHasChildren = !filter.getChildElements().isEmpty();
// copy to depth if this is leaf of filter tree
- Element copied = (Element) document.importNode(src.getDomElement(), filterHasChildren == false);
- boolean shouldAppend = filterHasChildren == false;
+ Element copied = (Element) document.importNode(src.getDomElement(), !filterHasChildren);
+ boolean shouldAppend = !filterHasChildren;
if (filterHasChildren) { // this implies TAG_MATCH
// do the same recursively
int numberOfTextMatchingChildren = 0;
if (result == null) {
for (Attr attr : filter.getAttributes().values()) {
// ignore namespace declarations
- if (XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI()) == false) {
+ if (!XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI())) {
// find attr with matching localName(), namespaceURI(), == value() in src
String found = src.getAttribute(attr.getLocalName(), attr.getNamespaceURI());
if (attr.getValue().equals(found) && result != MatchingResult.NO_MATCH) {
*/
static NetconfStateSchemas create(final DOMRpcService deviceRpc,
final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id) {
- if (remoteSessionCapabilities.isMonitoringSupported() == false) {
+ if (!remoteSessionCapabilities.isMonitoringSupported()) {
// TODO - need to search for get-schema support, not just ietf-netconf-monitoring support
// issue might be a deviation to ietf-netconf-monitoring where get-schema is unsupported...
LOG.warn("{}: Netconf monitoring not supported on device, cannot detect provided schemas", id);
return EMPTY;
}
- if (schemasNodeResult.getErrors().isEmpty() == false) {
+ if (!schemasNodeResult.getErrors().isEmpty()) {
LOG.warn("{}: Unable to detect available schemas, get to {} failed, {}",
id, STATE_SCHEMAS_IDENTIFIER, schemasNodeResult.getErrors());
return EMPTY;
}
final Optional<DataContainerChild<?, ?>> dataNode =
((DataContainerNode<?>) result).getChild(toId(NETCONF_DATA_QNAME));
- if (dataNode.isPresent() == false) {
+ if (!dataNode.isPresent()) {
return Optional.absent();
}
final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> nStateNode =
((DataContainerNode<?>) dataNode.get()).getChild(toId(NetconfState.QNAME));
- if (nStateNode.isPresent() == false) {
+ if (!nStateNode.isPresent()) {
return Optional.absent();
}
final String formatAsString = getSingleChildNodeValue(schemaNode, childNode).get();
- if (formatAsString.equals(Yang.QNAME.toString()) == false) {
+ if (!formatAsString.equals(Yang.QNAME.toString())) {
LOG.debug("{}: Ignoring schema due to unsupported format: {}", id, formatAsString);
return Optional.absent();
}
childNode = NetconfMessageTransformUtil.IETF_NETCONF_MONITORING_SCHEMA_LOCATION;
final Set<String> locationsAsString = getAllChildNodeValues(schemaNode, childNode);
- if (locationsAsString.contains(Schema.Location.Enumeration.NETCONF.toString()) == false) {
+ if (!locationsAsString.contains(Schema.Location.Enumeration.NETCONF.toString())) {
LOG.debug("{}: Ignoring schema due to unsupported location: {}", id, locationsAsString);
return Optional.absent();
}
final RemoteYangSchema that = (RemoteYangSchema) obj;
- if (!qname.equals(that.qname)) {
- return false;
- }
-
- return true;
+ return qname.equals(that.qname);
}
@Override
}
private void queueNotification(final NetconfMessage notification) {
- Preconditions.checkState(passNotifications == false);
+ Preconditions.checkState(!passNotifications);
LOG.debug("{}: Caching notification {}, remote schema not yet fully built", id, notification);
if (LOG.isTraceEnabled()) {
@Override
public synchronized boolean cancel(final boolean mayInterruptIfRunning) {
- return uncancellable ? false : super.cancel(mayInterruptIfRunning);
+ return !uncancellable && super.cancel(mayInterruptIfRunning);
}
@Override
final String inputMsgId = input.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
final String outputMsgId = output.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
- if (inputMsgId.equals(outputMsgId) == false) {
+ if (!inputMsgId.equals(outputMsgId)) {
final Map<String, String> errorInfo = ImmutableMap.<String, String>builder()
.put("actual-message-id", outputMsgId)
.put("expected-message-id", inputMsgId)
private static final String MESSAGE_ID_BLUEPRINT = "%s-%s";
public String getNewMessageId(final String prefix) {
- Preconditions.checkArgument(Strings.isNullOrEmpty(prefix) == false, "Null or empty prefix");
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(prefix), "Null or empty prefix");
return String.format(MESSAGE_ID_BLUEPRINT, prefix, getNewMessageId());
}
if (!name.equals(that.name)) {
return false;
}
- if (!bindingPath.equals(that.bindingPath)) {
- return false;
- }
-
- return true;
+ return bindingPath.equals(that.bindingPath);
}
@Override
final String commandName = consoleIO.read();
final Optional<Command> commandOpt = commandRegistry.getCommand(commandName);
- if (commandOpt.isPresent() == false) {
+ if (!commandOpt.isPresent()) {
continue;
}
final NetconfClientConfigurationBuilder configBuilder) {
this.connect(name, address, configBuilder);
synchronized (handler) {
- while (handler.isUp() == false) {
+ while (!handler.isUp()) {
try {
// TODO implement Timeout for unsuccessful connection
handler.wait();
public synchronized Optional<Command> getCommand(final String nameWithModule) {
final QName commandQName = mergeCommandIds().get(nameWithModule);
final Map<QName, Command> qNameCommandMap = mergeCommands();
- if (commandQName == null || qNameCommandMap.containsKey(commandQName) == false) {
+ if (commandQName == null || !qNameCommandMap.containsKey(commandQName)) {
return Optional.absent();
}
}
public Map<DataSchemaNode, List<NormalizedNode<?, ?>>> unwrap(final OutputDefinition outputDefinition) {
- Preconditions.checkArgument(outputDefinition.isEmpty() == false);
+ Preconditions.checkArgument(!outputDefinition.isEmpty());
final Map<QName, DataSchemaNode> mappedSchemaNodes = mapOutput(outputDefinition);
final Map<DataSchemaNode, List<NormalizedNode<?, ?>>> mappedNodesToSchema = Maps.newHashMap();
}
private boolean isReadingWanted(final DataSchemaNode node) {
- if (readConfigNode && !node.isConfiguration()) {
- return false;
- }
- return true;
+ return !readConfigNode || node.isConfiguration();
}
// TODO javadoc
private Optional<DataSchemaNode> getCurrentNode(DataSchemaNode parent, final String buffer) {
for (final String part : buffer.split(SEPARATOR)) {
- if (IOUtil.isQName(part) == false) {
+ if (!IOUtil.isQName(part)) {
return Optional.of(parent);
}
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils;
+import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
for (final Object childNodeObject : ((DataContainerNode) dataNode).getValue()) {
final NormalizedNode<?, ?> childNode = (NormalizedNode<?, ?>) childNodeObject;
- final Optional<DataSchemaNode> schemaNode = XmlDocumentUtils.findFirstSchema(childNode.getNodeType(),
+ final Optional<DataSchemaNode> schemaNode = SchemaUtils.findFirstSchema(childNode.getNodeType(),
remoteSchemaContext.getDataDefinitions());
Preconditions.checkState(schemaNode.isPresent(), "Unknown data node %s, not defined in schema",
childNode.getNodeType());
public List<File> generate(final boolean useSsh, final int batchSize,
final int generateConfigsTimeout, final String address,
final int devicesPerPort) {
- if (configDir.exists() == false) {
+ if (!configDir.exists()) {
Preconditions.checkState(configDir.mkdirs(), "Unable to create directory " + configDir);
}
Preconditions.checkArgument(timeout > 0, "Timeout =< 0");
Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
- Preconditions.checkArgument(editContent.isDirectory() == false, "Edit content file is a dir");
+ Preconditions.checkArgument(!editContent.isDirectory(), "Edit content file is a dir");
Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
Preconditions.checkArgument(destination.startsWith("/"), "Destination should start with a '/'");
}
Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
- Preconditions.checkArgument(editContent.isDirectory() == false, "Edit content file is a dir");
+ Preconditions.checkArgument(!editContent.isDirectory(), "Edit content file is a dir");
Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
Preconditions.checkArgument(threadAmount > 0, "Parameter thread-amount must be greater than 0");
Preconditions.checkArgument(msgTimeout >= 0, "Parameter msg-timeout must be greater than 0");
}
public boolean isLeafList() {
- return name == null ? true : false;
+ return name == null;
}
}
package org.opendaylight.netconf.sal.restconf.impl;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CharMatcher;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
try {
result.getFutureOfPutData().checkedGet();
return Response.status(result.getStatus()).build();
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
if (e instanceof OptimisticLockFailedException) {
if (--tries <= 0) {
LOG.debug("Got OptimisticLockFailedException on last try - failing " + identifier);
}
}
- private static void isEqualUriAndPayloadKeyValues(final Map<QName, Object> uriKeyValues, final MapEntryNode payload,
+ @VisibleForTesting
+ public static void isEqualUriAndPayloadKeyValues(final Map<QName, Object> uriKeyValues, final MapEntryNode payload,
final List<QName> keyDefinitions) {
final Map<QName, Object> mutableCopyUriKeyValues = Maps.newHashMap(uriKeyValues);
final Object dataKeyValue = payload.getIdentifier().getKeyValues().get(keyDefinition);
- if (!uriKeyValue.equals(dataKeyValue)) {
+ if (!Objects.deepEquals(uriKeyValue, dataKeyValue)) {
final String errMsg = "The value '" + uriKeyValue + "' for key '" + keyDefinition.getLocalName()
+ "' specified in the URI doesn't match the value '" + dataKeyValue
+ "' specified in the message body. ";
future.checkedGet();
} catch (final RestconfDocumentedException e) {
throw e;
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
LOG.info("Error creating data " + (uriInfo != null ? uriInfo.getPath() : ""), e);
throw new RestconfDocumentedException(e.getMessage(), e, e.getErrorList());
}
try {
future.checkedGet();
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
final Optional<Throwable> searchedException = Iterables.tryFind(Throwables.getCausalChain(e),
Predicates.instanceOf(ModifiedNodeDoesNotExistException.class));
if (searchedException.isPresent()) {
final TemporalAccessor p;
try {
p = FORMATTER.parse(value);
- } catch (DateTimeParseException e) {
+ } catch (final DateTimeParseException e) {
throw new RestconfDocumentedException("Cannot parse of value in date: " + value, e);
}
return Instant.from(p);
return false;
}
- if (!java.util.Objects.equals(put, that.put)) {
- return false;
- }
-
- return true;
+ return java.util.Objects.equals(put, that.put);
}
}
return false;
}
- if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
- return false;
- }
-
- return true;
+ return java.util.Objects.equals(failedResponses, that.failedResponses);
}
}
return false;
}
- if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
- return false;
- }
-
- return true;
+ return java.util.Objects.equals(failedResponses, that.failedResponses);
}
}
return false;
}
final Operational that = (Operational) obj;
- if (!java.util.Objects.equals(get, that.get)) {
- return false;
- }
-
- return true;
+ return java.util.Objects.equals(get, that.get);
}
}
return false;
}
- if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
- return false;
- }
-
- return true;
+ return java.util.Objects.equals(failedResponses, that.failedResponses);
}
}
return false;
}
- if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
- return false;
- }
-
- return true;
+ return java.util.Objects.equals(failedResponses, that.failedResponses);
}
}
return false;
}
- if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
- return false;
- }
-
- return true;
+ return java.util.Objects.equals(failedResponses, that.failedResponses);
}
}
* @return True if exist, false otherwise.
*/
public boolean isListening() {
- return this.registration == null ? false : true;
+ return this.registration != null;
}
/**
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.codec.xml.XMLStreamNormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
abstract class AbstractNotificationsData {
private static final Logger LOG = LoggerFactory.getLogger(AbstractNotificationsData.class);
private static final TransformerFactory TF = TransformerFactory.newInstance();
+ private static final XMLOutputFactory OF = XMLOutputFactory.newFactory();
private TransactionChainHandler transactionChainHandler;
private SchemaContextHandler schemaHandler;
*/
protected DOMResult writeNormalizedNode(final NormalizedNode<?, ?> normalized, final SchemaContext context,
final SchemaPath schemaPath) throws IOException, XMLStreamException {
- final XMLOutputFactory xmlFactory = XMLOutputFactory.newFactory();
- final Document doc = XmlDocumentUtils.getDocument();
+ final Document doc = UntrustedXML.newDocumentBuilder().newDocument();
final DOMResult result = new DOMResult(doc);
NormalizedNodeWriter normalizedNodeWriter = null;
NormalizedNodeStreamWriter normalizedNodeStreamWriter = null;
XMLStreamWriter writer = null;
try {
- writer = xmlFactory.createXMLStreamWriter(result);
+ writer = OF.createXMLStreamWriter(result);
normalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(writer, context, schemaPath);
normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter);
import java.io.FileNotFoundException;
import java.net.URI;
import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.ws.rs.core.MultivaluedHashMap;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
this.restconfImpl.setControllerContext(controllerContext);
}
+ @Test
+ public void binaryKeyTest() {
+ final List<Byte> al = new ArrayList<>();
+ al.add(new Byte((byte) 1));
+ binaryKeyTest(al, al);
+ }
+
+ private void binaryKeyTest(final List<Byte> al, final List<Byte> al2) {
+
+ final QName keyDef = QName.create("test:key:binary", "2017-14-08", "b1");
+
+ final Map<QName, Object> uriKeyValues = new HashMap<>();
+ uriKeyValues.put(keyDef, al.toArray());
+
+ final MapEntryNode payload = mock(MapEntryNode.class);
+ final NodeIdentifierWithPredicates nodeIdWithPred =
+ new NodeIdentifierWithPredicates(keyDef, keyDef, al2.toArray());
+ when(payload.getIdentifier()).thenReturn(nodeIdWithPred);
+
+ final List<QName> keyDefinitions = new ArrayList<>();
+ keyDefinitions.add(keyDef);
+ RestconfImpl.isEqualUriAndPayloadKeyValues(uriKeyValues, payload, keyDefinitions);
+ }
+
+ @Test
+ public void binaryKeyFailTest() {
+ final List<Byte> al = new ArrayList<>();
+ al.add(new Byte((byte) 1));
+ final List<Byte> al2 = new ArrayList<>();
+ try {
+ binaryKeyTest(al, al2);
+ } catch (final RestconfDocumentedException e) {
+ final RestconfError err = e.getErrors().iterator().next();
+ assertEquals(ErrorType.PROTOCOL, err.getErrorType());
+ assertEquals(ErrorTag.INVALID_VALUE, err.getErrorTag());
+ }
+ }
+
@SuppressWarnings("unchecked")
@Test
public void testExample() throws FileNotFoundException, ParseException {
private static boolean isEqualNamespaceAndRevision(final QName parentQName, final QName nodeQName) {
if (parentQName == null) {
- if (nodeQName == null) {
- return true;
- }
- return false;
+ return nodeQName == null;
}
return parentQName.getNamespace().equals(nodeQName.getNamespace())
&& parentQName.getRevision().equals(nodeQName.getRevision());