import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAnyXmlNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAnyXmlNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAnydataNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerLike;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
public final class Builders {
private Builders() {
return ImmutableLeafNodeBuilder.create();
}
- public static <T> NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> leafBuilder(
- final LeafSchemaNode schema) {
- return ImmutableLeafNodeSchemaAwareBuilder.create(schema);
- }
-
// FIXME: 7.0.0: add generic arguments
public static <T> NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> leafSetEntryBuilder() {
return ImmutableLeafSetEntryNodeBuilder.create();
}
- // FIXME: 7.0.0: add generic arguments
- public static <T> NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> leafSetEntryBuilder(
- final LeafListSchemaNode schema) {
- return ImmutableLeafSetEntryNodeSchemaAwareBuilder.create(schema);
- }
-
public static NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> anyXmlBuilder() {
return ImmutableAnyXmlNodeBuilder.create();
}
- public static NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> anyXmlBuilder(
- final AnyxmlSchemaNode schema) {
- return ImmutableAnyXmlNodeSchemaAwareBuilder.create(schema);
- }
-
public static <T> NormalizedNodeBuilder<NodeIdentifier, T, AnydataNode<T>> anydataBuilder(
final Class<T> objectModel) {
return ImmutableAnydataNodeBuilder.create(objectModel);
return ImmutableUserLeafSetNodeBuilder.create();
}
- public static <T> ListNodeBuilder<T, UserLeafSetNode<T>> orderedLeafSetBuilder(final LeafListSchemaNode schema) {
- return ImmutableUserLeafSetNodeSchemaAwareBuilder.create(schema);
- }
-
- public static <T> ListNodeBuilder<T, UserLeafSetNode<T>> orderedLeafSetBuilder(final LeafListSchemaNode schema,
- final UserLeafSetNode<T> node) {
- return ImmutableUserLeafSetNodeSchemaAwareBuilder.create(schema, node);
- }
-
public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder() {
return ImmutableLeafSetNodeBuilder.create();
}
return ImmutableLeafSetNodeBuilder.create(node);
}
- public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder(final LeafListSchemaNode schema) {
- return ImmutableLeafSetNodeSchemaAwareBuilder.create(schema);
- }
-
- public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder(final LeafListSchemaNode schema,
- final SystemLeafSetNode<T> node) {
- return ImmutableLeafSetNodeSchemaAwareBuilder.create(schema, node);
- }
-
public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder() {
return ImmutableContainerNodeBuilder.create();
}
return ImmutableContainerNodeBuilder.create(node);
}
- public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder(final ContainerLike schema) {
- return ImmutableContainerNodeSchemaAwareBuilder.create(schema);
- }
-
- public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder(final ContainerLike schema,
- final ContainerNode node) {
- return ImmutableContainerNodeSchemaAwareBuilder.create(schema, node);
- }
-
public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder() {
return ImmutableMapEntryNodeBuilder.create();
}
return ImmutableMapEntryNodeBuilder.create(mapEntryNode);
}
- public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder(
- final ListSchemaNode schema) {
- return ImmutableMapEntryNodeSchemaAwareBuilder.create(schema);
- }
-
public static CollectionNodeBuilder<MapEntryNode, UserMapNode> orderedMapBuilder() {
return ImmutableUserMapNodeBuilder.create();
}
- public static CollectionNodeBuilder<MapEntryNode, UserMapNode> orderedMapBuilder(final ListSchemaNode schema) {
- return ImmutableUserMapNodeSchemaAwareBuilder.create(schema);
- }
-
public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> unkeyedListBuilder() {
return ImmutableUnkeyedListNodeBuilder.create();
}
return ImmutableMapNodeBuilder.create(node);
}
- public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder(final ListSchemaNode schema) {
- return ImmutableMapNodeSchemaAwareBuilder.create(schema);
- }
-
- public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder(final ListSchemaNode schema,
- final SystemMapNode node) {
- return ImmutableMapNodeSchemaAwareBuilder.create(schema, node);
- }
-
public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentationBuilder() {
return ImmutableAugmentationNodeBuilder.create();
}
- public static DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> augmentationBuilder(
- final AugmentationSchemaNode schema) {
- return ImmutableAugmentationNodeSchemaAwareBuilder.create(schema);
- }
-
public static DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder() {
return ImmutableChoiceNodeBuilder.create();
}
- public static DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder(final ChoiceSchemaNode schema) {
- return ImmutableChoiceNodeSchemaAwareBuilder.create(schema);
- }
-
public static DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> unkeyedListEntryBuilder() {
return ImmutableUnkeyedListEntryNodeBuilder.create();
}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import javax.xml.transform.dom.DOMSource;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
-
-public final class ImmutableAnyXmlNodeSchemaAwareBuilder extends ImmutableAnyXmlNodeBuilder {
- private ImmutableAnyXmlNodeSchemaAwareBuilder(final AnyxmlSchemaNode schema) {
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- public static @NonNull NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> create(
- final AnyxmlSchemaNode schema) {
- return new ImmutableAnyXmlNodeSchemaAwareBuilder(schema);
- }
-
- @Override
- public ImmutableAnyXmlNodeBuilder withValue(final DOMSource withValue) {
- return super.withValue(withValue);
- }
-
- @Override
- public ImmutableAnyXmlNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
-import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-
-public class ImmutableAugmentationNodeSchemaAwareBuilder extends ImmutableAugmentationNodeBuilder {
- private final DataNodeContainerValidator validator;
-
- protected ImmutableAugmentationNodeSchemaAwareBuilder(final AugmentationSchemaNode schema) {
- this.validator = new DataNodeContainerValidator(schema);
- super.withNodeIdentifier(DataSchemaContextNode.augmentationIdentifierFrom(schema));
- }
-
- @Override
- public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withNodeIdentifier(
- final AugmentationIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-
- @Override
- public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
- final DataContainerChild child) {
- return super.withChild(validator.validateChild(child));
- }
-
- public static @NonNull DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> create(
- final AugmentationSchemaNode schema) {
- return new ImmutableAugmentationNodeSchemaAwareBuilder(schema);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.Optional;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
-import org.opendaylight.yangtools.yang.data.util.NormalizedNodeSchemaUtils;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-
-public class ImmutableChoiceNodeSchemaAwareBuilder extends ImmutableChoiceNodeBuilder {
- private final ChoiceSchemaNode schema;
-
- private @Nullable DataNodeContainerValidator validator = null;
-
- protected ImmutableChoiceNodeSchemaAwareBuilder(final ChoiceSchemaNode schema) {
- this.schema = requireNonNull(schema, "Schema was null");
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- @Override
- public DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> withNodeIdentifier(
- final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-
- @Override
- public DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> withChild(final DataContainerChild child) {
- if (validator == null) {
- Optional<CaseSchemaNode> detectedCaseOpt = NormalizedNodeSchemaUtils.detectCase(schema, child);
- DataValidationException.checkLegalChild(detectedCaseOpt.isPresent(), child.getIdentifier(), schema);
- validator = new DataNodeContainerValidator(detectedCaseOpt.get());
- }
-
- return super.withChild(validator.validateChild(child));
- }
-
- @Override
- public ChoiceNode build() {
- // TODO validate when statement
- return super.build();
- }
-
- public static DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final ChoiceSchemaNode schema) {
- return new ImmutableChoiceNodeSchemaAwareBuilder(schema);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-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.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
-import org.opendaylight.yangtools.yang.model.api.ContainerLike;
-
-public final class ImmutableContainerNodeSchemaAwareBuilder extends ImmutableContainerNodeBuilder {
- private final DataNodeContainerValidator validator;
-
- private ImmutableContainerNodeSchemaAwareBuilder(final ContainerLike schema) {
- this.validator = new DataNodeContainerValidator(schema);
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- private ImmutableContainerNodeSchemaAwareBuilder(final ContainerLike schema, final ImmutableContainerNode node) {
- super(node);
- this.validator = new DataNodeContainerValidator(schema);
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerLike schema) {
- return new ImmutableContainerNodeSchemaAwareBuilder(schema);
- }
-
- public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerLike schema,
- final ContainerNode node) {
- if (!(node instanceof ImmutableContainerNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
- }
- return new ImmutableContainerNodeSchemaAwareBuilder(schema, (ImmutableContainerNode)node);
- }
-
- @Override
- public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withNodeIdentifier(
- final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-
- @Override
- public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withChild(final DataContainerChild child) {
- validator.validateChild(child.getIdentifier());
- return super.withChild(child);
- }
-
- @Override
- public ContainerNode build() {
- // TODO check when statements... somewhere
- return super.build();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-
-public final class ImmutableLeafNodeSchemaAwareBuilder<T> extends ImmutableLeafNodeBuilder<T> {
- private ImmutableLeafNodeSchemaAwareBuilder(final LeafSchemaNode schema) {
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- public static <T> @NonNull NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> create(
- final LeafSchemaNode schema) {
- return new ImmutableLeafNodeSchemaAwareBuilder<>(schema);
- }
-
- @Override
- public NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> withValue(final T withValue) {
- // TODO: check value type
- return super.withValue(withValue);
- }
-
- @Override
- public NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> withNodeIdentifier(
- final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-
-public final class ImmutableLeafSetEntryNodeSchemaAwareBuilder<T> extends ImmutableLeafSetEntryNodeBuilder<T> {
- private final LeafListSchemaNode schema;
-
- private ImmutableLeafSetEntryNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
- this.schema = requireNonNull(schema);
- }
-
- public static <T> @NonNull NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> create(
- final LeafListSchemaNode schema) {
- return new ImmutableLeafSetEntryNodeSchemaAwareBuilder<>(schema);
- }
-
- @Override
- public ImmutableLeafSetEntryNodeBuilder<T> withValue(final T withValue) {
- super.withNodeIdentifier(new NodeWithValue<>(schema.getQName(), withValue));
- // TODO check value type using TypeProvider ?
- super.withValue(withValue);
- return this;
- }
-
- @Override
- public ImmutableLeafSetEntryNodeBuilder<T> withNodeIdentifier(final NodeWithValue withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
-
-import java.util.Collections;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-
-public final class ImmutableLeafSetNodeSchemaAwareBuilder<T> extends ImmutableLeafSetNodeBuilder<T> {
- private final LeafListSchemaNode schema;
-
- private ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
- this.schema = requireNonNull(schema);
- super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
- }
-
- public ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema, final ImmutableLeafSetNode<T> node) {
- super(node);
- this.schema = requireNonNull(schema);
- // FIXME: Preconditions.checkArgument(schema.getQName().equals(node.getIdentifier()));
- super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
- }
-
- public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final LeafListSchemaNode schema) {
- return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema);
- }
-
- public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final LeafListSchemaNode schema,
- final SystemLeafSetNode<T> node) {
- if (!(node instanceof ImmutableLeafSetNode<?>)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
- }
-
- return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema, (ImmutableLeafSetNode<T>) node);
- }
-
- @Override
- public ImmutableLeafSetNodeBuilder<T> withChildValue(final T childValue) {
- // TODO check value type
- return super.withChildValue(childValue);
- }
-
- @Override
- public ImmutableLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
- checkArgument(schema.getQName().equals(child.getNodeType()),
- "Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType());
- // TODO check value type using TypeProvider ?
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
- schema, Collections.singleton(schema.getQName()));
- return super.withChild(child);
- }
-
- @Override
- public ImmutableLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Map.Entry;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.util.ImmutableMapTemplate;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataNodeContainerValidator;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException.IllegalListKeyException;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-public final class ImmutableMapEntryNodeSchemaAwareBuilder extends ImmutableMapEntryNodeBuilder {
-
- private final ListSchemaNode schema;
- private final DataNodeContainerValidator validator;
-
- ImmutableMapEntryNodeSchemaAwareBuilder(final ListSchemaNode schema) {
- this.schema = requireNonNull(schema);
- this.validator = new DataNodeContainerValidator(schema);
- }
-
- @Override
- public ImmutableMapEntryNodeBuilder withNodeIdentifier(final NodeIdentifierWithPredicates withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-
- @Override
- public DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(
- final DataContainerChild child) {
- validator.validateChild(child.getIdentifier());
- return super.withChild(child);
- }
-
- @Override
- public MapEntryNode build() {
- super.withNodeIdentifier(constructNodeIdentifier());
- return super.build();
- }
-
- public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> create(
- final ListSchemaNode schema) {
- return new ImmutableMapEntryNodeSchemaAwareBuilder(schema);
- }
-
- /**
- * Build map entry node identifier from schema and provided children.
- */
- private NodeIdentifierWithPredicates constructNodeIdentifier() {
- final Map<QName, Object> predicates;
- final Collection<QName> keys = schema.getKeyDefinition();
- if (!keys.isEmpty()) {
- predicates = keyDefToPredicates(keys);
- } else if (!childrenQNamesToPaths.isEmpty()) {
- predicates = childrenToPredicates();
- } else {
- predicates = ImmutableMap.of();
- }
- return NodeIdentifierWithPredicates.of(schema.getQName(), predicates);
- }
-
- private Map<QName, Object> childrenToPredicates() {
- final Object[] values = new Object[childrenQNamesToPaths.size()];
- int offset = 0;
- for (Entry<QName, PathArgument> entry : childrenQNamesToPaths.entrySet()) {
- values[offset++] = nonnullKeyValue(entry.getKey(), getChild(entry.getValue())).body();
- }
- return ImmutableMapTemplate.ordered(childrenQNamesToPaths.keySet()).instantiateWithValues(values);
- }
-
- private Map<QName, Object> keyDefToPredicates(final Collection<QName> keys) {
- final Object[] values = new Object[keys.size()];
- int offset = 0;
- for (QName key : keys) {
- values[offset++] = nonnullKeyValue(key, getChild(childrenQNamesToPaths.get(key))).body();
- }
- return ImmutableMapTemplate.ordered(keys).instantiateWithValues(values);
- }
-
- private DataContainerChild nonnullKeyValue(final QName key, final @Nullable DataContainerChild value) {
- if (value != null) {
- return value;
- }
- throw new IllegalListKeyException("Key value not present for key: %s, in: %s values %s", key, schema.getQName(),
- buildValue());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.Collections;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-public class ImmutableMapNodeSchemaAwareBuilder extends ImmutableMapNodeBuilder {
- private final ListSchemaNode schema;
-
- protected ImmutableMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
- this.schema = requireNonNull(schema);
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- protected ImmutableMapNodeSchemaAwareBuilder(final ListSchemaNode schema, final ImmutableMapNode node) {
- super(node);
- this.schema = requireNonNull(schema);
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final ListSchemaNode schema) {
- return new ImmutableMapNodeSchemaAwareBuilder(schema);
- }
-
- public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final ListSchemaNode schema,
- final SystemMapNode node) {
- if (!(node instanceof ImmutableMapNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
- }
-
- return new ImmutableMapNodeSchemaAwareBuilder(schema, (ImmutableMapNode) node);
- }
-
- @Override
- public ImmutableMapNodeBuilder withChild(final MapEntryNode child) {
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
- schema, Collections.singleton(schema.getQName()));
- return super.withChild(child);
- }
-
- @Override
- public ImmutableMapNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-}
import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.spi.node.AbstractNormalizedNode;
-public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, UserLeafSetNode<T>> {
+public final class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, UserLeafSetNode<T>> {
private Map<NodeWithValue, LeafSetEntryNode<T>> value;
private NodeIdentifier nodeIdentifier;
private boolean dirty;
- protected ImmutableUserLeafSetNodeBuilder() {
+ private ImmutableUserLeafSetNodeBuilder() {
value = new LinkedHashMap<>();
dirty = false;
}
- protected ImmutableUserLeafSetNodeBuilder(final ImmutableUserLeafSetNode<T> node) {
+ private ImmutableUserLeafSetNodeBuilder(final ImmutableUserLeafSetNode<T> node) {
nodeIdentifier = node.getIdentifier();
value = node.getChildren();
dirty = true;
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static java.util.Objects.requireNonNull;
-
-import java.util.Collections;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-
-public final class ImmutableUserLeafSetNodeSchemaAwareBuilder<T> extends ImmutableUserLeafSetNodeBuilder<T> {
- private final LeafListSchemaNode schema;
-
- private ImmutableUserLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
- this.schema = requireNonNull(schema);
- super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
- }
-
- public ImmutableUserLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema,
- final ImmutableUserLeafSetNode<T> node) {
- super(node);
- this.schema = requireNonNull(schema);
- // FIXME: Preconditions.checkArgument(schema.getQName().equals(node.getIdentifier()));
- super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
- }
-
- public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(final LeafListSchemaNode schema) {
- return new ImmutableUserLeafSetNodeSchemaAwareBuilder<>(schema);
- }
-
- public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(final LeafListSchemaNode schema,
- final UserLeafSetNode<T> node) {
- if (!(node instanceof ImmutableUserLeafSetNode<?>)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
- }
-
- return new ImmutableUserLeafSetNodeSchemaAwareBuilder<>(schema, (ImmutableUserLeafSetNode<T>) node);
- }
-
- @Override
- public ImmutableUserLeafSetNodeBuilder<T> withChildValue(final T childValue) {
- // TODO check value type
- return super.withChildValue(childValue);
- }
-
- @Override
- public ImmutableUserLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
- checkArgument(schema.getQName().equals(child.getNodeType()), "Incompatible node type, should be: %s, is: %s",
- schema.getQName(), child.getNodeType());
- // TODO check value type using TypeProvider ?
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
- schema, Collections.singleton(schema.getQName()));
- return super.withChild(child);
- }
-
- @Override
- public ImmutableUserLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-}
import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.spi.node.AbstractNormalizedNode;
-public class ImmutableUserMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, UserMapNode> {
+public final class ImmutableUserMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, UserMapNode> {
private static final int DEFAULT_CAPACITY = 4;
private Map<NodeIdentifierWithPredicates, MapEntryNode> value;
private NodeIdentifier nodeIdentifier;
private boolean dirty;
- protected ImmutableUserMapNodeBuilder() {
+ private ImmutableUserMapNodeBuilder() {
this.value = new LinkedHashMap<>(DEFAULT_CAPACITY);
this.dirty = false;
}
- protected ImmutableUserMapNodeBuilder(final int sizeHint) {
+ private ImmutableUserMapNodeBuilder(final int sizeHint) {
if (sizeHint >= 0) {
this.value = new LinkedHashMap<>(sizeHint + sizeHint / 3);
} else {
this.dirty = false;
}
- protected ImmutableUserMapNodeBuilder(final ImmutableUserMapNode node) {
+ private ImmutableUserMapNodeBuilder(final ImmutableUserMapNode node) {
this.nodeIdentifier = node.getIdentifier();
this.value = node.children;
this.dirty = true;
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.Collections;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-public class ImmutableUserMapNodeSchemaAwareBuilder extends ImmutableUserMapNodeBuilder {
- private final ListSchemaNode schema;
-
- protected ImmutableUserMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
- this.schema = requireNonNull(schema);
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- protected ImmutableUserMapNodeSchemaAwareBuilder(final ListSchemaNode schema,
- final ImmutableUserMapNode node) {
- super(node);
- this.schema = requireNonNull(schema);
- super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
- }
-
- public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final ListSchemaNode schema) {
- return new ImmutableUserMapNodeSchemaAwareBuilder(schema);
- }
-
- public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final ListSchemaNode schema,
- final UserMapNode node) {
- if (!(node instanceof ImmutableUserMapNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
- }
-
- return new ImmutableUserMapNodeSchemaAwareBuilder(schema, (ImmutableUserMapNode) node);
- }
-
- @Override
- public CollectionNodeBuilder<MapEntryNode, UserMapNode> withChild(final MapEntryNode child) {
- DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
- schema, Collections.singleton(schema.getQName()));
- return super.withChild(child);
- }
-
- @Override
- public CollectionNodeBuilder<MapEntryNode, UserMapNode> withNodeIdentifier(
- final NodeIdentifier withNodeIdentifier) {
- throw new UnsupportedOperationException("Node identifier created from schema");
- }
-}
package org.opendaylight.yangtools.yang.data.impl.leafref.context;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThrows;
import java.util.HashMap;
import java.util.Map;
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.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
- final DataTreeModification initialDataTreeModification = inMemoryDataTree
- .takeSnapshot().newModification();
+ final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
- final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
- .get();
-
- final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);
+ final ContainerNode odlProjectContainer = createOdlContainer();
final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
initialDataTreeModification.write(path, odlProjectContainer);
private static void writeContributors() throws DataValidationFailedException {
- final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
- .findDataChildByName(odlContributor).get();
-
- final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);
+ final ContainerNode contributorContainer = createBasicContributorContainer();
- final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
- .of(odlContributor);
- final DataTreeModification writeModification = inMemoryDataTree
- .takeSnapshot().newModification();
+ final YangInstanceIdentifier contributorPath = YangInstanceIdentifier.of(odlContributor);
+ final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
writeModification.write(contributorPath, contributorContainer);
writeModification.ready();
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
- boolean exception = false;
- try {
- LeafRefValidation.validate(writeContributorsCandidate,
- rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- assertEquals(3, e.getValidationsErrorsCount());
- exception = true;
- }
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext));
+ assertEquals(3, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(writeContributorsCandidate);
LOG.debug("After write of contributors: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
-
- assertTrue(exception);
-
}
private static void writeIntoMapEntry() throws DataValidationFailedException {
-
final Map<QName, Object> keys = new HashMap<>();
keys.put(name, "New Project");
final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
- final YangInstanceIdentifier leaderPath = YangInstanceIdentifier
- .of(odl).node(project).node(mapEntryPath).node(lead);
+ final YangInstanceIdentifier leaderPath = YangInstanceIdentifier.of(odl).node(project).node(mapEntryPath)
+ .node(lead);
- final LeafNode<String> leader = ImmutableNodes.leafNode(lead,
- "Updated leader");
+ final LeafNode<String> leader = ImmutableNodes.leafNode(lead, "Updated leader");
- final DataTreeModification writeModification = inMemoryDataTree
- .takeSnapshot().newModification();
+ final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
writeModification.write(leaderPath, leader);
writeModification.ready();
- final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
- .prepare(writeModification);
+ final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);
LOG.debug("*************************");
LOG.debug("Before write into map entry (update of leader name): ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
- boolean exception = false;
- try {
- LeafRefValidation.validate(writeContributorsCandidate,
- rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- assertEquals(1, e.getValidationsErrorsCount());
- exception = true;
- }
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext));
+ assertEquals(1, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(writeContributorsCandidate);
LOG.debug("After write into map entry (update of leader name): ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
-
- assertTrue(exception);
-
}
private static void writeMapEntry() throws DataValidationFailedException {
+ final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, name, "New Project");
- final Map<QName, Object> keys = new HashMap<>();
- keys.put(name, "New Project");
- final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(project, keys);
-
- final YangInstanceIdentifier newOdlProjectMapEntryPath = YangInstanceIdentifier
- .of(odl).node(project).node(mapEntryPath);
-
- final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
- .get();
- final ListSchemaNode projListSchemaNode = (ListSchemaNode) odlProjContSchemaNode.findDataChildByName(project)
- .get();
final MapEntryNode newProjectMapEntry = createProjectListEntry(
"New Project", "New Project description ...",
- "Leader of New Project", "Owner of New Project",
- projListSchemaNode);
+ "Leader of New Project", "Owner of New Project");
- final DataTreeModification writeModification = inMemoryDataTree
- .takeSnapshot().newModification();
- writeModification.write(newOdlProjectMapEntryPath, newProjectMapEntry);
+ final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
+ writeModification.write(YangInstanceIdentifier.of(odl).node(project).node(mapEntryPath), newProjectMapEntry);
writeModification.ready();
- final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
- .prepare(writeModification);
+ final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);
LOG.debug("*************************");
LOG.debug("Before map entry write: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
- boolean exception = false;
- try {
- LeafRefValidation.validate(writeContributorsCandidate,
- rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- assertEquals(2, e.getValidationsErrorsCount());
- exception = true;
- }
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext));
+ assertEquals(2, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(writeContributorsCandidate);
LOG.debug("After map entry write: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
-
- assertTrue(exception);
-
}
private static void write() throws DataValidationFailedException {
+ final ContainerNode contributorContainer = createContributorContainer(
+ (ContainerSchemaNode) valModule.getDataChildByName(odlContributor));
- final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
- .findDataChildByName(odlContributor).get();
-
- final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);
-
- final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
- .of(odlContributor);
- final DataTreeModification writeModification = inMemoryDataTree
- .takeSnapshot().newModification();
+ final YangInstanceIdentifier contributorPath = YangInstanceIdentifier.of(odlContributor);
+ final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
writeModification.write(contributorPath, contributorContainer);
writeModification.write(YangInstanceIdentifier.of(l1),
- ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
- writeModification
- .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
- l2, "Leafref target l2 under the root"));
+ ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
+ writeModification.write(YangInstanceIdentifier.of(l2),
+ ImmutableNodes.leafNode(l2, "Leafref target l2 under the root"));
writeModification.ready();
- final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
- .prepare(writeModification);
+ final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);
LOG.debug("*************************");
LOG.debug("Before write: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
- boolean exception = false;
- try {
- LeafRefValidation.validate(writeContributorsCandidate,
- rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- assertEquals(12, e.getValidationsErrorsCount());
- exception = true;
- }
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext));
+ assertEquals(12, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(writeContributorsCandidate);
LOG.debug("After write: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
-
- assertTrue(exception);
}
private static void write2() throws DataValidationFailedException {
-
- final ContainerSchemaNode odlCon = (ContainerSchemaNode) valModule.findDataChildByName(odl).get();
- final ContainerSchemaNode con1Con = (ContainerSchemaNode) odlCon.findDataChildByName(con1).get();
- final LeafNode<String> l1Leaf = ImmutableNodes.leafNode(l1, "l1 value");
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
- .containerBuilder(con1Con);
- containerBuilder.addChild(l1Leaf);
- final ContainerNode con1Node = containerBuilder.build();
-
- final YangInstanceIdentifier con1Path = YangInstanceIdentifier.of(odl)
- .node(con1);
- final DataTreeModification writeModification = inMemoryDataTree
- .takeSnapshot().newModification();
- writeModification.write(con1Path, con1Node);
-
- final ChoiceNode choiceNode = createChoiceNode();
- final YangInstanceIdentifier choicePath = YangInstanceIdentifier
- .of(odl).node(ch1);
- writeModification.write(choicePath, choiceNode);
-
- final ContainerNode con3Node = createCon3Node();
- final YangInstanceIdentifier con3Path = YangInstanceIdentifier.of(odl)
- .node(con3);
- writeModification.write(con3Path, con3Node);
-
- final LeafSetNode<?> leafListNode = createLeafRefLeafListNode();
- final YangInstanceIdentifier leafListPath = YangInstanceIdentifier.of(
- odl).node(leafrefLeafList);
- writeModification.write(leafListPath, leafListNode);
+ final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
+ writeModification.write(YangInstanceIdentifier.of(odl).node(con1), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(con1))
+ .addChild(ImmutableNodes.leafNode(l1, "l1 value"))
+ .build());
+ writeModification.write(YangInstanceIdentifier.of(odl).node(ch1), createChoiceNode());
+ writeModification.write(YangInstanceIdentifier.of(odl).node(con3), createCon3Node());
+ writeModification.write(YangInstanceIdentifier.of(odl).node(leafrefLeafList), createLeafRefLeafListNode());
writeModification.ready();
- final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
- .prepare(writeModification);
+ final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);
LOG.debug("*************************");
LOG.debug("Before write2: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
- boolean exception = false;
- try {
- LeafRefValidation.validate(writeContributorsCandidate,
- rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- assertEquals(6, e.getValidationsErrorsCount());
- exception = true;
- }
-
- assertTrue(exception);
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext));
+ assertEquals(6, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(writeContributorsCandidate);
LOG.debug("After write2: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
-
}
private static @NonNull LeafSetNode<Object> createLeafRefLeafListNode() {
}
private static ContainerNode createCon3Node() {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder = Builders.mapBuilder();
- mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
-
- mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
- mapBuilder.addChild(createList3Entry("k2", "val2", "valB", "valY"));
-
- final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
- .choiceBuilder();
- choiceBuilder.withNodeIdentifier(new NodeIdentifier(choiceInCon3));
-
- choiceBuilder.addChild(mapBuilder.build());
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
- .containerBuilder();
- containerBuilder.withNodeIdentifier(new NodeIdentifier(con3));
-
- containerBuilder.addChild(choiceBuilder.build());
-
- return containerBuilder.build();
+ return Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(con3))
+ .addChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(choiceInCon3))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(list3InChoice))
+ .addChild(createList3Entry("k1", "val1", "valA", "valX"))
+ .addChild(createList3Entry("k2", "val2", "valB", "valY"))
+ .build())
+ .build())
+ .build();
}
- private static MapEntryNode createList3Entry(final String keyVal,
- final String l3Val1, final String l3Val2, final String l3Val3) {
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
- .mapEntryBuilder();
- mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(list3InChoice, k, keyVal));
-
- final ListNodeBuilder<Object, SystemLeafSetNode<Object>> leafSetBuilder = Builders.leafSetBuilder();
- leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
-
- leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
- leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val2));
- leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val3));
-
- mapEntryBuilder.addChild(ImmutableNodes.leafNode(k, keyVal));
- mapEntryBuilder.addChild(leafSetBuilder.build());
-
- return mapEntryBuilder.build();
+ private static MapEntryNode createList3Entry(final String keyVal,final String l3Val1, final String l3Val2,
+ final String l3Val3) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(list3InChoice, k, keyVal))
+ .addChild(ImmutableNodes.leafNode(k, keyVal))
+ .addChild(Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(l3))
+ .addChild(createLeafSetEntry(l3, l3Val1))
+ .addChild(createLeafSetEntry(l3, l3Val2))
+ .addChild(createLeafSetEntry(l3, l3Val3))
+ .build())
+ .build();
}
- private static LeafSetEntryNode<Object> createLeafSetEntry(
- final QName qname, final String val) {
- final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder = Builders
- .leafSetEntryBuilder();
- leafSetEntryBuilder.withNodeIdentifier(new NodeWithValue<>(qname, val));
- leafSetEntryBuilder.withValue(val);
- return leafSetEntryBuilder.build();
+ private static LeafSetEntryNode<Object> createLeafSetEntry(final QName qname, final String val) {
+ return Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(qname, val))
+ .withValue(val)
+ .build();
}
private static ChoiceNode createChoiceNode() {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listInChoiceBuilder = Builders.mapBuilder();
- listInChoiceBuilder.withNodeIdentifier(new NodeIdentifier(listInChoice));
-
- listInChoiceBuilder.addChild(createListInChoiceEntry("key1", "leafref-in-choice value", "val1"));
- listInChoiceBuilder.addChild(createListInChoiceEntry("key2", "l1 value", "val2"));
- listInChoiceBuilder.addChild(createListInChoiceEntry("key3", "l1 value", "val3"));
-
- final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders.choiceBuilder();
- choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
-
- choice2Builder.addChild(listInChoiceBuilder.build());
-
- final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders.choiceBuilder();
- choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
- choiceBuilder.addChild(choice2Builder.build());
-
- return choiceBuilder.build();
+ return Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(ch1))
+ .addChild(Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(ch2))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(listInChoice))
+ .addChild(createListInChoiceEntry("key1", "leafref-in-choice value", "val1"))
+ .addChild(createListInChoiceEntry("key2", "l1 value", "val2"))
+ .addChild(createListInChoiceEntry("key3", "l1 value", "val3"))
+ .build())
+ .build())
+ .build();
}
- private static MapEntryNode createListInChoiceEntry(final String keyVal,
- final String leafrefInChoiceVal,
+ private static MapEntryNode createListInChoiceEntry(final String keyVal, final String leafrefInChoiceVal,
final String leafrefInChoiceToChoiceVal) {
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders
- .mapEntryBuilder();
-
- mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(
- listInChoice, listInChoiceKey, keyVal));
-
- mapEntryBuilder.addChild(ImmutableNodes.leafNode(listInChoiceKey,
- keyVal));
- mapEntryBuilder.addChild(ImmutableNodes.leafNode(leafrefInChoice,
- leafrefInChoiceVal));
- mapEntryBuilder.addChild(ImmutableNodes.leafNode(
- leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal));
-
- return mapEntryBuilder.build();
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(listInChoice, listInChoiceKey, keyVal))
+ .addChild(ImmutableNodes.leafNode(listInChoiceKey, keyVal))
+ .addChild(ImmutableNodes.leafNode(leafrefInChoice, leafrefInChoiceVal))
+ .addChild(ImmutableNodes.leafNode(leafrefInChoiceToChoice, leafrefInChoiceToChoiceVal))
+ .build();
}
private static void delete() throws DataValidationFailedException {
-
- final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
- .of(odlContributor);
- final DataTreeModification delete = inMemoryDataTree.takeSnapshot()
- .newModification();
- delete.delete(contributorPath);
+ final DataTreeModification delete = inMemoryDataTree.takeSnapshot().newModification();
+ delete.delete(YangInstanceIdentifier.of(odlContributor));
delete.ready();
final DataTreeCandidate deleteContributorsCanditate = inMemoryDataTree.prepare(delete);
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
- boolean exception = false;
- try {
- LeafRefValidation.validate(deleteContributorsCanditate,
- rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- assertEquals(6, e.getValidationsErrorsCount());
- exception = true;
- }
- assertTrue(exception);
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(deleteContributorsCanditate, rootLeafRefContext));
+ assertEquals(6, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(deleteContributorsCanditate);
LOG.debug("After delete: ");
LOG.debug("*************************");
LOG.debug(inMemoryDataTree.toString());
-
}
- private static ContainerNode createContributorContainer(
- final ContainerSchemaNode contributorContSchemaNode) {
-
- final ListSchemaNode contributorListSchemaNode =
- (ListSchemaNode) contributorContSchemaNode.findDataChildByName(contributor).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr =
- Builders.containerBuilder(contributorContSchemaNode);
-
- final SystemMapNode contributorMap = createContributorList(contributorListSchemaNode);
- contributorContainerBldr.addChild(contributorMap);
-
- final ContainerNode contributorContainer = contributorContainerBldr.build();
-
- return contributorContainer;
+ private static ContainerNode createContributorContainer(final ContainerSchemaNode contributorCont) {
+ return Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(odlContributor))
+ .addChild(createContributorList((ListSchemaNode) contributorCont.findDataChildByName(contributor).get()))
+ .build();
}
- private static SystemMapNode createContributorList(
- final ListSchemaNode contributorListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> contributorMapBldr =
- Builders.mapBuilder(contributorListSchemaNode);
-
- final MapEntryNode contributorMapEntry1 = createContributorListEntry(
- "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
- "Yangtools description ...", contributorListSchemaNode);
- final MapEntryNode contributorMapEntry2 = createContributorListEntry(
- "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
- "MD-SAL description ...", contributorListSchemaNode);
- final MapEntryNode contributorMapEntry3 = createContributorListEntry(
- "Leader of Controller", "Controller Leader name", "Controller",
- "Controller description ...", contributorListSchemaNode);
-
- final MapEntryNode contributorMapEntry4 = createContributorListEntry(
- "jdoe", "John Doe", "MD-SAL", "Yangtools description ...",
- contributorListSchemaNode);
-
- final MapEntryNode contributorMapEntry5 = createContributorListEntry(
- "foo", "foo name", "Controller", "MD-SAL description ...",
- contributorListSchemaNode);
-
- final MapEntryNode contributorMapEntry6 = createContributorListEntry(
- "bar", "bar name", "Yangtools", "Controller description ...",
- contributorListSchemaNode);
-
- final MapEntryNode contributorMapEntry7 = createContributorListEntry(
- "baz", "baz name", "Unknown Project",
- "Unknown Project description ...", contributorListSchemaNode);
-
- final MapEntryNode contributorMapEntry8 = createContributorListEntry(
- "pk", "pk name", "Unknown Project 2",
- "Controller description ...", contributorListSchemaNode);
-
- contributorMapBldr.addChild(contributorMapEntry1);
- contributorMapBldr.addChild(contributorMapEntry2);
- contributorMapBldr.addChild(contributorMapEntry3);
- contributorMapBldr.addChild(contributorMapEntry4);
- contributorMapBldr.addChild(contributorMapEntry5);
- contributorMapBldr.addChild(contributorMapEntry6);
- contributorMapBldr.addChild(contributorMapEntry7);
- contributorMapBldr.addChild(contributorMapEntry8);
-
- return contributorMapBldr.build();
+ private static SystemMapNode createContributorList(final ListSchemaNode contributorListSchemaNode) {
+ return Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(contributor))
+ .addChild(createContributorListEntry("Leader of Yangtools", "Yangtools Leader name", "Yangtools",
+ "Yangtools description ..."))
+ .addChild(createContributorListEntry("Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
+ "MD-SAL description ..."))
+ .addChild(createContributorListEntry("Leader of Controller", "Controller Leader name", "Controller",
+ "Controller description ..."))
+ .addChild(createContributorListEntry("jdoe", "John Doe", "MD-SAL", "Yangtools description ..."))
+ .addChild(createContributorListEntry("foo", "foo name", "Controller", "MD-SAL description ..."))
+ .addChild(createContributorListEntry("bar", "bar name", "Yangtools", "Controller description ..."))
+ .addChild(createContributorListEntry("baz", "baz name", "Unknown Project",
+ "Unknown Project description ..."))
+ .addChild(createContributorListEntry("pk", "pk name", "Unknown Project 2", "Controller description ..."))
+ .build();
}
- private static MapEntryNode createContributorListEntry(
- final String loginVal, final String contributorNameVal,
- final String odlProjectNameVal, final String odlProjectDescVal,
- final ListSchemaNode contributorListSchemaNode) {
-
- final LeafNode<String> loginLeaf = ImmutableNodes.leafNode(login, loginVal);
- final LeafNode<String> contributorNameLeaf = ImmutableNodes.leafNode(contributorName, contributorNameVal);
- final LeafNode<String> odlProjectNameLeafRef = ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal);
- final LeafNode<String> odlProjectDescLeafRef = ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal);
-
- return Builders.mapEntryBuilder(contributorListSchemaNode)
- .addChild(loginLeaf)
- .addChild(contributorNameLeaf)
- .addChild(odlProjectNameLeafRef)
- .addChild(odlProjectDescLeafRef)
- .build();
+ private static MapEntryNode createContributorListEntry(final String loginVal, final String contributorNameVal,
+ final String odlProjectNameVal, final String odlProjectDescVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(contributor, login, loginVal))
+ .addChild(ImmutableNodes.leafNode(login, loginVal))
+ .addChild(ImmutableNodes.leafNode(contributorName, contributorNameVal))
+ .addChild(ImmutableNodes.leafNode(odlProjectName, odlProjectNameVal))
+ .addChild(ImmutableNodes.leafNode(odlProjectDesc, odlProjectDescVal))
+ .build();
}
- private static ContainerNode createOdlContainer(
- final ContainerSchemaNode container) {
-
- final ListSchemaNode projListSchemaNode = (ListSchemaNode) container.findDataChildByName(project).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
- .containerBuilder(container);
-
- final SystemMapNode projectMap = createProjectList(projListSchemaNode);
- odlProjectContainerBldr.addChild(projectMap);
-
- final ContainerNode odlProjectContainer = odlProjectContainerBldr
- .build();
-
- return odlProjectContainer;
+ private static ContainerNode createOdlContainer() {
+ return Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(odl))
+ .addChild(createProjectList())
+ .build();
}
- private static SystemMapNode createProjectList(
- final ListSchemaNode projListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> projectMapBldr = Builders
- .mapBuilder(projListSchemaNode);
-
- final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
- "Yangtools description ...", "Leader of Yangtools",
- "Owner of Yangtools", projListSchemaNode);
- final MapEntryNode projMapEntry2 = createProjectListEntry("MD-SAL",
- "MD-SAL description ...", "Leader of MD-SAL",
- "Owner of MD-SAL", projListSchemaNode);
- final MapEntryNode projMapEntry3 = createProjectListEntry("Controller",
- "Controller description ...", "Leader of Controller",
- "Owner of Controller", projListSchemaNode);
-
- projectMapBldr.addChild(projMapEntry1);
- projectMapBldr.addChild(projMapEntry2);
- projectMapBldr.addChild(projMapEntry3);
-
- return projectMapBldr.build();
+ private static SystemMapNode createProjectList() {
+ return Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(project))
+ .addChild(createProjectListEntry("Yangtools", "Yangtools description ...", "Leader of Yangtools",
+ "Owner of Yangtools"))
+ .addChild(createProjectListEntry("MD-SAL", "MD-SAL description ...", "Leader of MD-SAL", "Owner of MD-SAL"))
+ .addChild(createProjectListEntry("Controller", "Controller description ...", "Leader of Controller",
+ "Owner of Controller")).build();
}
- private static MapEntryNode createProjectListEntry(final String nameVal,
- final String descVal, final String leadVal, final String ownerVal,
- final ListSchemaNode projListSchemaNode) {
-
- final LeafNode<String> nameLeaf = ImmutableNodes
- .leafNode(name, nameVal);
- final LeafNode<String> descLeaf = ImmutableNodes
- .leafNode(desc, descVal);
- final LeafNode<String> leadLeafRef = ImmutableNodes.leafNode(lead,
- leadVal);
- final LeafNode<String> ownerLeafRef = ImmutableNodes.leafNode(owner,
- ownerVal);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> projMapEntryBldr = Builders
- .mapEntryBuilder(projListSchemaNode);
-
- projMapEntryBldr.addChild(nameLeaf);
- projMapEntryBldr.addChild(descLeaf);
- projMapEntryBldr.addChild(leadLeafRef);
- projMapEntryBldr.addChild(ownerLeafRef);
- final MapEntryNode projMapEntry = projMapEntryBldr.build();
-
- return projMapEntry;
+ private static MapEntryNode createProjectListEntry(final String nameVal, final String descVal, final String leadVal,
+ final String ownerVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(project, name, nameVal))
+ .addChild(ImmutableNodes.leafNode(name, nameVal))
+ .addChild(ImmutableNodes.leafNode(desc, descVal))
+ .addChild(ImmutableNodes.leafNode(lead, leadVal))
+ .addChild(ImmutableNodes.leafNode(owner, ownerVal))
+ .build();
}
- private static ContainerNode createBasicContributorContainer(
- final ContainerSchemaNode contributorContSchemaNode) {
-
- final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
- .findDataChildByName(contributor).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
- .containerBuilder(contributorContSchemaNode);
-
- final SystemMapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
- contributorContainerBldr.addChild(contributorMap);
-
- final ContainerNode contributorContainer = contributorContainerBldr
- .build();
-
- return contributorContainer;
-
+ private static ContainerNode createBasicContributorContainer() {
+ return Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(odlContributor))
+ .addChild(createBasicContributorList())
+ .build();
}
- private static SystemMapNode createBasicContributorList(
- final ListSchemaNode contributorListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> contributorMapBldr =
- Builders.mapBuilder(contributorListSchemaNode);
-
- final MapEntryNode contributorMapEntry1 = createContributorListEntry(
- "Leader of Yangtools", "Yangtools Leader name", "Yangtools",
- "Yangtools description ...", contributorListSchemaNode);
- final MapEntryNode contributorMapEntry2 = createContributorListEntry(
- "Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
- "MD-SAL description ...", contributorListSchemaNode);
- final MapEntryNode contributorMapEntry3 = createContributorListEntry(
- "Leader of Controller", "Controller Leader name", "Controller",
- "Controller description ...", contributorListSchemaNode);
-
- contributorMapBldr.addChild(contributorMapEntry1);
- contributorMapBldr.addChild(contributorMapEntry2);
- contributorMapBldr.addChild(contributorMapEntry3);
-
- return contributorMapBldr.build();
+ private static SystemMapNode createBasicContributorList() {
+ return Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(contributor))
+ .addChild(createContributorListEntry("Leader of Yangtools", "Yangtools Leader name", "Yangtools",
+ "Yangtools description ..."))
+ .addChild(createContributorListEntry("Leader of MD-SAL", "MD-SAL Leader name", "MD-SAL",
+ "MD-SAL description ..."))
+ .addChild(createContributorListEntry("Leader of Controller", "Controller Leader name", "Controller",
+ "Controller description ...")).build();
}
}
package org.opendaylight.yangtools.yang.data.impl.leafref.context;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThrows;
+import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
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.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
private static QName devices;
private static QName device;
- private static QName typeChoice;
private static QName typeText;
private static QName devDesc;
private static QName sn;
private static QName desc;
private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidateValidatorTest2.class);
- private static final String NEW_LINE = System.getProperty("line.separator");
@BeforeClass
public static void init() throws DataValidationFailedException {
inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
- final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(chips)
- .get();
- final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode);
- final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips);
- initialDataTreeModification.write(path1, chipsContainer);
-
- final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule
- .findDataChildByName(deviceTypeStr).get();
- final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode);
- final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr);
- initialDataTreeModification.write(path2, deviceTypesContainer);
+ initialDataTreeModification.write(YangInstanceIdentifier.of(chips), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(chips))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(chip))
+ .addChild(createChipsListEntry("dev_type_1", "desc1"))
+ .addChild(createChipsListEntry("dev_type_2", "desc2"))
+ .build())
+ .build());
+
+ initialDataTreeModification.write(YangInstanceIdentifier.of(deviceTypeStr), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(deviceTypeStr))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(deviceType))
+ .addChild(createDevTypeListEntry("dev_type_1", "typedesc1"))
+ .addChild(createDevTypeListEntry("dev_type_2", "typedesc2"))
+ .addChild(createDevTypeListEntry("dev_type_3", "typedesc3"))
+ .build())
+ .build());
initialDataTreeModification.ready();
final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification);
}
private static void writeDevices() throws DataValidationFailedException {
-
- final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
- .get();
-
- final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode);
-
- final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices);
final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
- writeModification.write(devicesPath, devicesContainer);
+ writeModification.write(YangInstanceIdentifier.of(devices), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(devices))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(device))
+ .addChild(createDeviceListEntry("dev_type_1", "typedesc1", 123456, "192.168.0.1"))
+ .addChild(createDeviceListEntry("dev_type_2", "typedesc2", 123457, "192.168.0.1"))
+ .addChild(createDeviceListEntry("dev_type_2", "typedesc3", 123457, "192.168.0.1"))
+ .addChild(createDeviceListEntry("dev_type_1", "typedesc2", 123458, "192.168.0.1"))
+ .addChild(createDeviceListEntry("unknown", "unknown", 123457, "192.168.0.1"))
+ .build())
+ .build());
writeModification.ready();
final DataTreeCandidate writeDevicesCandidate = inMemoryDataTree.prepare(writeModification);
LOG.debug("*************************");
LOG.debug("{}", inMemoryDataTree);
- boolean exception = false;
- try {
- LeafRefValidation.validate(writeDevicesCandidate, rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
-
- assertEquals(4, e.getValidationsErrorsCount());
- exception = true;
- }
-
- assertTrue(exception);
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(writeDevicesCandidate, rootLeafRefContext));
+ assertEquals(4, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(writeDevicesCandidate);
LOG.debug("{}", inMemoryDataTree);
}
- private static ContainerNode createDevTypeStrContainer(final ContainerSchemaNode container) {
-
- final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.findDataChildByName(deviceType).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devTypeContainerBldr =
- Builders.containerBuilder(container);
-
- final SystemMapNode devTypeMap = createDevTypeList(devTypeListSchemaNode);
- devTypeContainerBldr.addChild(devTypeMap);
-
- return devTypeContainerBldr.build();
- }
-
- private static SystemMapNode createDevTypeList(final ListSchemaNode devTypeListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devTypeMapBldr =
- Builders.mapBuilder(devTypeListSchemaNode);
-
- devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_1", "typedesc1", devTypeListSchemaNode));
- devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_2", "typedesc2", devTypeListSchemaNode));
- devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_3", "typedesc3", devTypeListSchemaNode));
-
- return devTypeMapBldr.build();
- }
-
- private static MapEntryNode createDevTypeListEntry(final String typeVal, final String descVal,
- final ListSchemaNode devTypeListSchemaNode) {
-
- final LeafNode<String> typeLeaf = ImmutableNodes.leafNode(type, typeVal);
- final LeafNode<String> descLeaf = ImmutableNodes.leafNode(desc, descVal);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> devTypeMapEntryBldr =
- Builders.mapEntryBuilder(devTypeListSchemaNode);
-
- devTypeMapEntryBldr.addChild(typeLeaf);
- devTypeMapEntryBldr.addChild(descLeaf);
-
- return devTypeMapEntryBldr.build();
- }
-
- private static ContainerNode createChipsContainer(final ContainerSchemaNode container) {
-
- final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container.findDataChildByName(chip).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> chipsContainerBldr = Builders
- .containerBuilder(container);
-
- final SystemMapNode chipsMap = createChipsList(chipsListSchemaNode);
- chipsContainerBldr.addChild(chipsMap);
-
- return chipsContainerBldr.build();
- }
-
- private static SystemMapNode createChipsList(final ListSchemaNode chipsListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> chipsMapBldr =
- Builders.mapBuilder(chipsListSchemaNode);
-
- chipsMapBldr.addChild(createChipsListEntry("dev_type_1", "desc1", chipsListSchemaNode));
- chipsMapBldr.addChild(createChipsListEntry("dev_type_2", "desc2", chipsListSchemaNode));
-
- return chipsMapBldr.build();
- }
-
- private static MapEntryNode createChipsListEntry(final String devTypeVal, final String chipDescVal,
- final ListSchemaNode chipsListSchemaNode) {
-
- final LeafNode<String> devTypeLeaf = ImmutableNodes.leafNode(devType, devTypeVal);
- final LeafNode<String> chipDescLeaf = ImmutableNodes.leafNode(chipDesc, chipDescVal);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> chipsMapEntryBldr = Builders
- .mapEntryBuilder(chipsListSchemaNode);
-
- chipsMapEntryBldr.addChild(devTypeLeaf);
- chipsMapEntryBldr.addChild(chipDescLeaf);
-
- return chipsMapEntryBldr.build();
- }
-
- private static ContainerNode createDevicesContainer(final ContainerSchemaNode container) {
-
- final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.findDataChildByName(device).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
- .containerBuilder(container);
-
- final SystemMapNode devicesMap = createDeviceList(devicesListSchemaNode);
- devicesContainerBldr.addChild(devicesMap);
-
- return devicesContainerBldr.build();
+ private static MapEntryNode createDevTypeListEntry(final String typeVal, final String descVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(deviceType, type, typeVal))
+ .addChild(ImmutableNodes.leafNode(type, typeVal))
+ .addChild(ImmutableNodes.leafNode(desc, descVal))
+ .build();
}
- private static SystemMapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devicesMapBldr =
- Builders.mapBuilder(deviceListSchemaNode);
-
- devicesMapBldr.addChild(createDeviceListEntry("dev_type_1", "typedesc1", 123456, "192.168.0.1",
- deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("dev_type_2", "typedesc2", 123457, "192.168.0.1",
- deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("dev_type_2", "typedesc3", 123457, "192.168.0.1",
- deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("dev_type_1", "typedesc2", 123458, "192.168.0.1",
- deviceListSchemaNode));
- devicesMapBldr
- .addChild(createDeviceListEntry("unknown", "unknown", 123457, "192.168.0.1", deviceListSchemaNode));
-
- return devicesMapBldr.build();
+ private static MapEntryNode createChipsListEntry(final String devTypeVal, final String chipDescVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(chip, devType, devTypeVal))
+ .addChild(ImmutableNodes.leafNode(devType, devTypeVal))
+ .addChild(ImmutableNodes.leafNode(chipDesc, chipDescVal))
+ .build();
}
private static MapEntryNode createDeviceListEntry(final String typeTextVal, final String descVal, final int snVal,
- final String defaultIpVal, final ListSchemaNode devicesListSchemaNode) {
-
- final LeafNode<String> typeTextLeaf = ImmutableNodes.leafNode(typeText, typeTextVal);
- final LeafNode<String> descLeaf = ImmutableNodes.leafNode(devDesc, descVal);
- final LeafNode<Integer> snValLeaf = ImmutableNodes.leafNode(sn, snVal);
- final LeafNode<String> defaultIpLeaf = ImmutableNodes.leafNode(defaultIp, defaultIpVal);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> devicesMapEntryBldr = Builders
- .mapEntryBuilder(devicesListSchemaNode);
-
- devicesMapEntryBldr.addChild(typeTextLeaf);
- devicesMapEntryBldr.addChild(descLeaf);
- devicesMapEntryBldr.addChild(snValLeaf);
- devicesMapEntryBldr.addChild(defaultIpLeaf);
-
- return devicesMapEntryBldr.build();
+ final String defaultIpVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(device, Map.of(typeText, typeTextVal, sn, snVal)))
+ .addChild(ImmutableNodes.leafNode(typeText, typeTextVal))
+ .addChild(ImmutableNodes.leafNode(devDesc, descVal))
+ .addChild(ImmutableNodes.leafNode(sn, snVal))
+ .addChild(ImmutableNodes.leafNode(defaultIp, defaultIpVal))
+ .build();
}
}
package org.opendaylight.yangtools.yang.data.impl.leafref.context;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThrows;
+import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
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.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.slf4j.Logger;
final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
- final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(chips)
- .get();
- final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode);
- final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips);
- initialDataTreeModification.write(path1, chipsContainer);
-
- final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule
- .findDataChildByName(deviceTypeStr).get();
- final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode);
- final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr);
- initialDataTreeModification.write(path2, deviceTypesContainer);
+ initialDataTreeModification.write(YangInstanceIdentifier.of(chips), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(chips))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(chip))
+ .addChild(createChipsListEntry("dev_type_1", "desc1"))
+ .addChild(createChipsListEntry("dev_type_2", "desc2"))
+ .build())
+ .build());
+
+ initialDataTreeModification.write(YangInstanceIdentifier.of(deviceTypeStr), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(deviceTypeStr))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(deviceType))
+ .addChild(createDevTypeListEntry("dev_type1_1", "dev_type2_1", "dev_type3_1", "typedesc1"))
+ .addChild(createDevTypeListEntry("dev_type1_2", "dev_type2_2", "dev_type3_2", "typedesc2"))
+ .addChild(createDevTypeListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc3"))
+ .build())
+ .build());
initialDataTreeModification.ready();
final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification);
}
private static void writeDevices() throws DataValidationFailedException {
- final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
- .get();
- final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode);
- final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices);
final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
- writeModification.write(devicesPath, devicesContainer);
+ writeModification.write(YangInstanceIdentifier.of(devices), Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(devices))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(device))
+ .addChild(createDeviceListEntry("dev_type1_1", "dev_type2_1", "dev_type3_1", "typedesc1", 123456,
+ "192.168.0.1"))
+ .addChild(createDeviceListEntry("dev_type1_2", "dev_type2_2", "dev_type3_2", "typedesc1", 123457,
+ "192.168.0.1"))
+ .addChild(createDeviceListEntry("dev_type1_1", "dev_type2_2", "dev_type3_3", "typedesc2", 123458,
+ "192.168.0.1"))
+ .addChild(createDeviceListEntry("unk11", "unk22", "unk33", "unk_desc2", 123457, "192.168.0.1"))
+ .build())
+ .build());
writeModification.ready();
final DataTreeCandidate writeDevicesCandidate = inMemoryDataTree.prepare(writeModification);
LOG.debug("*************************");
LOG.debug("{}", inMemoryDataTree);
- boolean exception = false;
- try {
- LeafRefValidation.validate(writeDevicesCandidate, rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- assertEquals(6, e.getValidationsErrorsCount());
- exception = true;
- }
-
- assertTrue(exception);
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(writeDevicesCandidate, rootLeafRefContext));
+ assertEquals(6, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(writeDevicesCandidate);
}
private static void mergeDevices() throws DataValidationFailedException {
-
- final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
- .get();
-
- final ContainerNode devicesContainer = createDevices2Container(devicesContSchemaNode);
+ final ContainerNode devicesContainer = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(devices))
+ .addChild(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(device))
+ .addChild(createDeviceListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc3", 123459,
+ "192.168.0.1"))
+ .addChild(createDeviceListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc2", 123460,
+ "192.168.0.1"))
+ .addChild(createDeviceListEntry("dev_type1_3", "dev_type2_2", "dev_type3_1", "typedesc1", 123461,
+ "192.168.0.1"))
+ .addChild(createDeviceListEntry("unk1", "unk2", "unk3", "unk_desc", 123462, "192.168.0.1"))
+ .build())
+ .build();
final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices);
final DataTreeModification mergeModification = inMemoryDataTree.takeSnapshot().newModification();
LOG.debug("*************************");
LOG.debug("{}", inMemoryDataTree);
- boolean exception = false;
- try {
- LeafRefValidation.validate(mergeDevicesCandidate, rootLeafRefContext);
- } catch (final LeafRefDataValidationFailedException e) {
- LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
- // :TODO verify errors count gz
- assertEquals(6, e.getValidationsErrorsCount());
- exception = true;
- }
+ final LeafRefDataValidationFailedException ex = assertThrows(LeafRefDataValidationFailedException.class,
+ () -> LeafRefValidation.validate(mergeDevicesCandidate, rootLeafRefContext));
+ // :TODO verify errors count gz
+ assertEquals(6, ex.getValidationsErrorsCount());
inMemoryDataTree.commit(mergeDevicesCandidate);
LOG.debug("After mergeDevices: ");
LOG.debug("*************************");
LOG.debug("{}", inMemoryDataTree);
-
- assertTrue(exception);
- }
-
- private static ContainerNode createDevTypeStrContainer(final ContainerSchemaNode container) {
-
- final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.findDataChildByName(deviceType).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devTypeContainerBldr = Builders
- .containerBuilder(container);
-
- final SystemMapNode devTypeMap = createDevTypeList(devTypeListSchemaNode);
- devTypeContainerBldr.addChild(devTypeMap);
-
- return devTypeContainerBldr.build();
- }
-
- private static SystemMapNode createDevTypeList(final ListSchemaNode devTypeListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devTypeMapBldr =
- Builders.mapBuilder(devTypeListSchemaNode);
-
- devTypeMapBldr.addChild(createDevTypeListEntry("dev_type1_1", "dev_type2_1", "dev_type3_1", "typedesc1",
- devTypeListSchemaNode));
- devTypeMapBldr.addChild(createDevTypeListEntry("dev_type1_2", "dev_type2_2", "dev_type3_2", "typedesc2",
- devTypeListSchemaNode));
- devTypeMapBldr.addChild(createDevTypeListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc3",
- devTypeListSchemaNode));
-
- return devTypeMapBldr.build();
}
private static MapEntryNode createDevTypeListEntry(final String type1Val, final String type2Val,
- final String type3Val, final String descVal, final ListSchemaNode devTypeListSchemaNode) {
-
- final LeafNode<String> type1Leaf = ImmutableNodes.leafNode(type1, type1Val);
- final LeafNode<String> type2Leaf = ImmutableNodes.leafNode(type2, type2Val);
- final LeafNode<String> type3Leaf = ImmutableNodes.leafNode(type3, type3Val);
- final LeafNode<String> descLeaf = ImmutableNodes.leafNode(desc, descVal);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> devTypeMapEntryBldr = Builders
- .mapEntryBuilder(devTypeListSchemaNode);
-
- devTypeMapEntryBldr.addChild(type1Leaf);
- devTypeMapEntryBldr.addChild(type2Leaf);
- devTypeMapEntryBldr.addChild(type3Leaf);
- devTypeMapEntryBldr.addChild(descLeaf);
-
- return devTypeMapEntryBldr.build();
- }
-
- private static ContainerNode createChipsContainer(final ContainerSchemaNode container) {
-
- final ListSchemaNode chipsListSchemaNode = (ListSchemaNode) container.findDataChildByName(chip).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> chipsContainerBldr = Builders
- .containerBuilder(container);
-
- final SystemMapNode chipsMap = createChipsList(chipsListSchemaNode);
- chipsContainerBldr.addChild(chipsMap);
-
- return chipsContainerBldr.build();
- }
-
- private static SystemMapNode createChipsList(final ListSchemaNode chipsListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> chipsMapBldr =
- Builders.mapBuilder(chipsListSchemaNode);
-
- chipsMapBldr.addChild(createChipsListEntry("dev_type_1", "desc1", chipsListSchemaNode));
- chipsMapBldr.addChild(createChipsListEntry("dev_type_2", "desc2", chipsListSchemaNode));
-
- return chipsMapBldr.build();
- }
-
- private static MapEntryNode createChipsListEntry(final String devTypeVal, final String chipDescVal,
- final ListSchemaNode chipsListSchemaNode) {
-
- final LeafNode<String> devTypeLeaf = ImmutableNodes.leafNode(devType, devTypeVal);
- final LeafNode<String> chipDescLeaf = ImmutableNodes.leafNode(chipDesc, chipDescVal);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> chipsMapEntryBldr = Builders
- .mapEntryBuilder(chipsListSchemaNode);
-
- chipsMapEntryBldr.addChild(devTypeLeaf);
- chipsMapEntryBldr.addChild(chipDescLeaf);
-
- return chipsMapEntryBldr.build();
- }
-
- private static ContainerNode createDevicesContainer(final ContainerSchemaNode container) {
-
- final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.findDataChildByName(device).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
- .containerBuilder(container);
-
- final SystemMapNode devicesMap = createDeviceList(devicesListSchemaNode);
- devicesContainerBldr.addChild(devicesMap);
-
- return devicesContainerBldr.build();
- }
-
- private static SystemMapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devicesMapBldr =
- Builders.mapBuilder(deviceListSchemaNode);
-
- devicesMapBldr.addChild(createDeviceListEntry("dev_type1_1", "dev_type2_1", "dev_type3_1", "typedesc1", 123456,
- "192.168.0.1", deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("dev_type1_2", "dev_type2_2", "dev_type3_2", "typedesc1", 123457,
- "192.168.0.1", deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("dev_type1_1", "dev_type2_2", "dev_type3_3", "typedesc2", 123458,
- "192.168.0.1", deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("unk11", "unk22", "unk33", "unk_desc2", 123457, "192.168.0.1",
- deviceListSchemaNode));
-
- return devicesMapBldr.build();
+ final String type3Val, final String descVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(deviceType,
+ Map.of(type1, type1Val, type2, type2Val, type3, type3Val)))
+ .addChild(ImmutableNodes.leafNode(type1, type1Val))
+ .addChild(ImmutableNodes.leafNode(type2, type2Val))
+ .addChild(ImmutableNodes.leafNode(type3, type3Val))
+ .addChild(ImmutableNodes.leafNode(desc, descVal))
+ .build();
}
- private static ContainerNode createDevices2Container(final ContainerSchemaNode container) {
-
- final ListSchemaNode devicesListSchemaNode = (ListSchemaNode) container.findDataChildByName(device).get();
-
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
- .containerBuilder(container);
-
- final SystemMapNode devicesMap = createDevice2List(devicesListSchemaNode);
- devicesContainerBldr.addChild(devicesMap);
-
- return devicesContainerBldr.build();
- }
-
- private static SystemMapNode createDevice2List(final ListSchemaNode deviceListSchemaNode) {
-
- final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devicesMapBldr =
- Builders.mapBuilder(deviceListSchemaNode);
-
- devicesMapBldr.addChild(createDeviceListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc3", 123459,
- "192.168.0.1", deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc2", 123460,
- "192.168.0.1", deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("dev_type1_3", "dev_type2_2", "dev_type3_1", "typedesc1", 123461,
- "192.168.0.1", deviceListSchemaNode));
- devicesMapBldr.addChild(createDeviceListEntry("unk1", "unk2", "unk3", "unk_desc", 123462, "192.168.0.1",
- deviceListSchemaNode));
-
- return devicesMapBldr.build();
+ private static MapEntryNode createChipsListEntry(final String devTypeVal, final String chipDescVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(chip, devType, devTypeVal))
+ .addChild(ImmutableNodes.leafNode(devType, devTypeVal))
+ .addChild(ImmutableNodes.leafNode(chipDesc, chipDescVal))
+ .build();
}
private static MapEntryNode createDeviceListEntry(final String type1TextVal, final String type2TextVal,
- final String type3TextVal, final String descVal, final int snVal, final String defaultIpVal,
- final ListSchemaNode devicesListSchemaNode) {
-
- final LeafNode<String> typeText1Leaf = ImmutableNodes.leafNode(typeText1, type1TextVal);
- final LeafNode<String> typeText2Leaf = ImmutableNodes.leafNode(typeText2, type2TextVal);
- final LeafNode<String> typeText3Leaf = ImmutableNodes.leafNode(typeText3, type3TextVal);
- final LeafNode<String> descLeaf = ImmutableNodes.leafNode(devDesc, descVal);
- final LeafNode<Integer> snValLeaf = ImmutableNodes.leafNode(sn, snVal);
- final LeafNode<String> defaultIpLeaf = ImmutableNodes.leafNode(defaultIp, defaultIpVal);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> devicesMapEntryBldr = Builders
- .mapEntryBuilder(devicesListSchemaNode);
-
- devicesMapEntryBldr.addChild(typeText1Leaf);
- devicesMapEntryBldr.addChild(typeText2Leaf);
- devicesMapEntryBldr.addChild(typeText3Leaf);
- devicesMapEntryBldr.addChild(descLeaf);
- devicesMapEntryBldr.addChild(snValLeaf);
- devicesMapEntryBldr.addChild(defaultIpLeaf);
-
- return devicesMapEntryBldr.build();
+ final String type3TextVal, final String descVal, final int snVal, final String defaultIpVal) {
+ return Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(device, Map.of(typeText1, type1TextVal, sn, snVal)))
+ .addChild(ImmutableNodes.leafNode(typeText1, type1TextVal))
+ .addChild(ImmutableNodes.leafNode(typeText2, type2TextVal))
+ .addChild(ImmutableNodes.leafNode(typeText3, type3TextVal))
+ .addChild(ImmutableNodes.leafNode(devDesc, descVal))
+ .addChild(ImmutableNodes.leafNode(sn, snVal))
+ .addChild(ImmutableNodes.leafNode(defaultIp, defaultIpVal))
+ .build();
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
-import static org.mockito.Mockito.mock;
import java.io.File;
import java.net.URISyntaxException;
import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
final UserMapNode orderedMapNodeCreateNode = ImmutableUserMapNodeBuilder.create(orderedMapNodeCreateNull)
.removeChild(mapEntryPath)
.build();
- final UserMapNode orderedMapNodeSchemaAware = ImmutableUserMapNodeSchemaAwareBuilder.create(list)
+ final UserMapNode orderedMapNodeSchemaAware = ImmutableUserMapNodeBuilder.create()
+ .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
.withChild(LIST_MAIN_CHILD_1)
.build();
- final UserMapNode orderedMapNodeSchemaAwareMapNodeConst = ImmutableUserMapNodeSchemaAwareBuilder.create(
- list, getImmutableUserMapNode())
+ final UserMapNode orderedMapNodeSchemaAwareMapNodeConst =
+ ImmutableUserMapNodeBuilder.create(getImmutableUserMapNode())
.build();
- assertNotNull(Builders.orderedMapBuilder(list));
assertEquals(SIZE, orderedMapNodeCreateNull.size());
assertEquals(orderedMapNodeCreateNode.size(), orderedMapNodeCreateNull.size() - 1);
assertEquals(NODE_IDENTIFIER_LIST, orderedMapNodeCreateSize.getIdentifier());
final LinkedList<LeafSetNode<?>> mapEntryNodeColl = new LinkedList<>();
mapEntryNodeColl.add(orderedLeafSet);
final UnmodifiableCollection<?> leafSetCollection = (UnmodifiableCollection<?>)orderedLeafSet.body();
- final NormalizedNode orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeSchemaAwareBuilder.create(
- leafList).withChildValue("baz").build();
+ final NormalizedNode orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeBuilder.create()
+ .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
+ .withChildValue("baz")
+ .build();
final UnmodifiableCollection<?> SchemaAwareleafSetCollection =
(UnmodifiableCollection<?>) orderedMapNodeSchemaAware.body();
- final NormalizedNode orderedLeafSetShemaAware = ImmutableUserLeafSetNodeSchemaAwareBuilder.create(
- leafList, (UserLeafSetNode<?>) orderedLeafSet).build();
- assertNotNull(Builders.orderedLeafSetBuilder(leafList));
assertNotNull(Builders.anyXmlBuilder());
- assertNotNull(orderedLeafSetShemaAware);
assertEquals(1, ((UserLeafSetNode<?>)orderedLeafSet).size());
assertEquals("baz", orderedLeafSet.childAt(0).body());
assertNull(orderedLeafSet.childByArg(BAR_PATH));
collectionNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST);
collectionNodeBuilder.withValue(mapEntryNodeColl);
final SystemMapNode mapNode = collectionNodeBuilder.build();
- final SystemMapNode mapNodeSchemaAware = ImmutableMapNodeSchemaAwareBuilder.create(list,
- getImmutableMapNode()).build();
- assertNotNull(mapNodeSchemaAware);
assertNotNull(Builders.mapBuilder(mapNode));
}
}
- @Test(expected = NullPointerException.class)
+ @Test
public void immutableAugmentationNodeBuilderExceptionTest() {
- ImmutableAugmentationNodeBuilder.create(1).build();
+ final var builder = ImmutableAugmentationNodeBuilder.create(1);
+ assertThrows(NullPointerException.class, builder::build);
}
- @Test(expected = NullPointerException.class)
+ @Test
public void immutableContainerNodeBuilderExceptionTest() {
final ContainerNode immutableContainerNode = ImmutableContainerNodeBuilder.create(1)
.withNodeIdentifier(NODE_IDENTIFIER_LIST)
.build();
assertNotNull(immutableContainerNode);
- final ContainerSchemaNode containerSchemaNode = mock(ContainerSchemaNode.class);
- ImmutableContainerNodeSchemaAwareBuilder.create(containerSchemaNode, immutableContainerNode)
- .withNodeIdentifier(NODE_IDENTIFIER_LIST)
- .build();
}
- @Test(expected = NullPointerException.class)
+ @Test
public void immutableLeafSetNodeBuilderExceptionTest() {
final SystemLeafSetNode<Object> leafSetNode = ImmutableLeafSetNodeBuilder.create(1)
- .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).build();
+ .withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
+ .build();
assertNotNull(leafSetNode);
- ImmutableLeafSetNodeSchemaAwareBuilder.create(mock(LeafListSchemaNode.class), leafSetNode).build();
}
- @Test(expected = UnsupportedOperationException.class)
- public void immutableLeafSetEntryNodeSchemaAwareBuilderExceptionTest() {
- final LeafListSchemaNode leafListSchemaNode = mock(LeafListSchemaNode.class);
- ImmutableLeafSetEntryNodeSchemaAwareBuilder.create(leafListSchemaNode).withNodeIdentifier(BAR_PATH).build();
- }
-
- @Test(expected = NullPointerException.class)
+ @Test
public void immutableMapEntryNodeBuilderExceptionTest() {
- ImmutableMapEntryNodeBuilder.create(1).build();
+ final var builder = ImmutableMapEntryNodeBuilder.create(1);
+ assertThrows(NullPointerException.class, builder::build);
}
- @Test(expected = UnsupportedOperationException.class)
+ @Test
public void immutableUnkeyedListNodeBuilderExceptionTest() {
- ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF)
- .removeChild(NODE_IDENTIFIER_LIST).build();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void immutableMapNodeSchemaAwareExceptionTest() {
- ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).withNodeIdentifier(NODE_IDENTIFIER_LIST)
- .build();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void immutableOrderedMapSchemaAwareExceptionTest1() {
- ImmutableUserMapNodeSchemaAwareBuilder.create(list).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void immutableUserLeafSetNodeSchemaAwareExceptionTest1() {
- ImmutableUserLeafSetNodeSchemaAwareBuilder.create(leafList).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
- .build();
- }
-
- private static SystemLeafSetNode<String> getImmutableLeafSetNode() {
- final ListNodeBuilder<String, SystemLeafSetNode<String>> leafSetBuilder = Builders.leafSetBuilder();
- leafSetBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST);
- leafSetBuilder.addChild(LEAF_SET_ENTRY_NODE);
- return leafSetBuilder.build();
+ final var builder = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LEAF);
+ assertThrows(UnsupportedOperationException.class, () -> builder.removeChild(NODE_IDENTIFIER_LIST));
}
private static SystemMapNode getImmutableMapNode() {
- return ImmutableMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST).withChild(LIST_MAIN_CHILD_1)
- .build();
+ return ImmutableMapNodeBuilder.create()
+ .withNodeIdentifier(NODE_IDENTIFIER_LIST)
+ .withChild(LIST_MAIN_CHILD_1)
+ .build();
}
private static UserMapNode getImmutableUserMapNode() {
- return ImmutableUserMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST)
- .withChild(LIST_MAIN_CHILD_1).build();
+ return ImmutableUserMapNodeBuilder.create()
+ .withNodeIdentifier(NODE_IDENTIFIER_LIST)
+ .withChild(LIST_MAIN_CHILD_1)
+ .build();
}
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema;
-import static com.google.common.base.Preconditions.checkState;
-
import com.google.common.collect.ImmutableSet;
-import java.io.File;
-import java.net.URISyntaxException;
import java.util.Collections;
-import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
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.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class NormalizedDataBuilderTest {
-
- private ContainerSchemaNode containerNode;
- private SchemaContext schema;
-
- @Before
- public void setUp() throws URISyntaxException {
- schema = YangParserTestUtils.parseYangFiles(new File(getClass().getResource("test.yang").toURI()));
- containerNode = (ContainerSchemaNode) getSchemaNode(schema, "test", "container");
- }
-
@Test
public void testSchemaUnaware() {
// Container
.withValue(11).build());
}
- @Test
- public void testSchemaAware() {
- DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = Builders.containerBuilder(containerNode);
-
- LeafSchemaNode schemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "uint32");
- LeafNode<String> leafChild = Builders.<String>leafBuilder(schemaNode).withValue("String").build();
- builder.withChild(leafChild);
-
- LeafListSchemaNode leafListSchemaNode = (LeafListSchemaNode) getSchemaNode(schema, "test", "leafList");
- LeafSetNode<Integer> leafList = Builders.<Integer>leafSetBuilder(leafListSchemaNode)
- .withChildValue(1)
- .withChild(Builders.<Integer>leafSetEntryBuilder(leafListSchemaNode).withValue(3).build())
- .build();
- builder.withChild(leafList);
-
- ListSchemaNode listSchema = (ListSchemaNode) getSchemaNode(schema, "test", "list");
- LeafSchemaNode uint32InListSchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "uint32InList");
- ContainerSchemaNode containerInListSchemaNode = (ContainerSchemaNode) getSchemaNode(schema, "test",
- "containerInList");
-
- MapEntryNode listChild1 = Builders.mapEntryBuilder(listSchema)
- .withChild(Builders.<Integer>leafBuilder(uint32InListSchemaNode).withValue(1).build())
- .withChild(Builders.containerBuilder(containerInListSchemaNode).build()).build();
-
- MapNode list = ImmutableMapNodeSchemaAwareBuilder.create(listSchema).withChild(listChild1).build();
- builder.withChild(list);
-
- LeafSchemaNode augmentUint32SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentUint32");
- AugmentationSchemaNode augmentationSchema = getAugmentationSchemaForChild(containerNode,
- augmentUint32SchemaNode.getQName());
-
- AugmentationNode augmentation = Builders.augmentationBuilder(augmentationSchema)
- .withChild(Builders.<Integer>leafBuilder(augmentUint32SchemaNode).withValue(11).build()).build();
-
- builder.withChild(augmentation);
-
- // This should fail with schema, since the leaf comes from augmentation
- // builder.withChild(ImmutableLeafNodeSchemaAwareBuilder.<Integer>get(augmentUint32SchemaNode).withValue(11)
- // .build());
-
- LeafSchemaNode augumentString1SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentString1");
- LeafSchemaNode augumentString2SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentString2");
-
- ChoiceSchemaNode choice1SchemaNode = (ChoiceSchemaNode) getSchemaNode(schema, "test", "choice");
- ChoiceNode choice = ImmutableChoiceNodeSchemaAwareBuilder.create(choice1SchemaNode)
- .withChild(Builders.<String>leafBuilder(augumentString1SchemaNode).withValue("case1").build())
- // This should fail, since child node belongs to different case
- // .withChild(Builders.<String>leafBuilder(augumentString2SchemaNode).withValue("case2")
- // .build())
- .build();
-
- builder.withChild(choice);
-
- // This should fail, child from case
- // builder.withChild(Builders.<String>leafBuilder(augumentString1SchemaNode).withValue("case1")
- // .build());
- }
-
- private static AugmentationSchemaNode getAugmentationSchemaForChild(final ContainerSchemaNode containerNode,
- final QName qname) {
- for (AugmentationSchemaNode augmentationSchema : containerNode.getAvailableAugmentations()) {
- if (augmentationSchema.findDataChildByName(qname).isPresent()) {
- return augmentationSchema;
- }
- }
- throw new IllegalStateException("Unable to find child augmentation in " + containerNode);
- }
-
private static <T> NodeWithValue<T> getNodeWithValueIdentifier(final String localName, final T value) {
return new NodeWithValue<>(getQName(localName), value);
}
private static NodeIdentifier getNodeIdentifier(final String localName) {
return new NodeIdentifier(getQName(localName));
}
-
- public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName,
- final String childNodeName) {
- for (Module module : context.getModules()) {
- if (module.getName().equals(moduleName)) {
- DataSchemaNode found = findChildNode(module, childNodeName);
- checkState(found != null, "Unable to find %s", childNodeName);
- return found;
- }
- }
- throw new IllegalStateException("Unable to find child node " + childNodeName);
- }
-
- private static DataSchemaNode findChildNode(final DataNodeContainer container, final String name) {
- for (DataSchemaNode dataSchemaNode : container.getChildNodes()) {
- if (dataSchemaNode.getQName().getLocalName().equals(name)) {
- return dataSchemaNode;
- }
- if (dataSchemaNode instanceof DataNodeContainer) {
- DataSchemaNode retVal = findChildNode((DataNodeContainer) dataSchemaNode, name);
- if (retVal != null) {
- return retVal;
- }
- } else if (dataSchemaNode instanceof ChoiceSchemaNode) {
- for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) dataSchemaNode).getCases()) {
- DataSchemaNode retVal = findChildNode(caseNode, name);
- if (retVal != null) {
- return retVal;
- }
- }
- }
- }
- return null;
- }
}
+++ /dev/null
-// vi: set smarttab et sw=4 tabstop=4:
-module test {
- yang-version 1;
- namespace "urn:opendaylight:params:xml:ns:yang:controller:test";
- prefix "test";
-
- organization "Cisco Systems, Inc.";
-
- revision "2014-03-13" {
- description
- "Initial revision";
- }
-
- identity a {}
-
- identity b {
- base "test:a";
- }
-
- grouping listGroup {
- list list {
- key "uint32InList";
-
- leaf uint32InList {
- type uint32;
- }
-
- container containerInList{
- leaf uint32 {
- type uint32;
- }
- leaf uint16 {
- type uint16;
- }
-
- leaf identityr {
- type identityref {
- base "test:a";
- }
- }
-
- leaf uint16-ref {
- type leafref {
- path "../uint16";
- }
- }
-
- leaf instance-id {
- type instance-identifier;
- }
-
- anyxml anyX;
- }
- }
- }
-
- grouping innerContainerGrouping {
- container innerContainer {
- leaf uint16 {
- type uint16;
- }
-
- container innerInnerContainer {
-
- leaf uint16 {
- type uint16;
- }
-
- leaf uint32 {
- type uint32;
- }
- }
- }
- }
-
- container container {
- leaf uint32 {
- type uint32;
- }
-
- leaf decimal64 {
- type decimal64 {
- fraction-digits 2;
- }
- }
-
- leaf boolean {
- type boolean;
- }
-
- leaf binary {
- type binary;
- }
-
- leaf string {
- type string;
- }
-
- uses listGroup {
- augment "list/" {
- leaf stringAugmentedToList{
- type string;
- }
-
- choice choiceInList {
- case caseInList1 {
- leaf stringAugmentedToListInCase1 {
- type string;
- }
- }
- case caseInList2 {
- leaf stringAugmentedToListInCase2 {
- type string;
- }
- }
- }
- }
- }
-
- list directList {
- leaf stringInDirectList {
- type string;
- }
- }
-
- uses innerContainerGrouping;
-
- choice choice{}
- choice choice2{}
-
- leaf-list leafList {
- type string;
- }
-
- leaf identityRef {
- type identityref {
- base test-identity;
- }
- }
-
- /* TODO test modification with empty type
- leaf empty {
- type empty;
- }
- */
- }
-
- augment "/container/" {
- leaf augmentUint32 {
- type uint32;
- }
- }
-
- augment "/container/directList/" {
- leaf augmentedString {
- type uint32;
- }
- }
-
- augment "/container/choice/" {
- case test-identity-augment {
- when "/container/identityRef = 'test-identity'";
- leaf augmentString1 {
- type string;
- }
-
- leaf augmentInt1 {
- type uint32;
- }
- }
- case test-identity-augment2 {
- when "/container/identityRef = 'test-identity2'";
- leaf augmentString2 {
- type string;
- }
-
- leaf augmentInt2 {
- type uint32;
- }
- }
- }
-
- augment "/container/choice/test-identity-augment/" {
-
- choice augmentedChoiceInCase {
-
- case augmentedCaseInAugmentedChoice {
- leaf stringInAugmentedCaseInAugmentedChoice {
- type string;
- }
- }
-
- case augmentedCaseInAugmentedChoice2 {
- leaf stringInAugmentedCaseInAugmentedChoice2 {
- type string;
- }
- }
- }
- }
-
- augment "/container/choice/test-identity-augment/augmentedChoiceInCase/" {
- case augmentedCaseInAugmentedChoiceFromAugment {
- leaf stringInAugmentedCaseInAugmentedChoiceFromAugment {
- type string;
- }
- }
- }
-
- augment "/container/choice2/" {
- case test-identity-augment {
- when "/container/identityRef = 'test-identity'";
- container augmentContainer {
- leaf augmentStringInaugmentContainer {
- type string;
- }
- }
- }
- case test-identity-augment2 {
- when "/container/identityRef = 'test-identity2'";
- list augmentedList {
- leaf augmentStringInaugmentList {
- type string;
- }
- }
- }
- }
-
-
- augment "/container/choice2/test-identity-augment2/augmentedList/" {
-
- container augmentedContainerInAugmentedListInAugmentedCase {
- leaf-list leafInAugmentedContainerInAugmentedListInAugmentedCase {
- type uint32;
- }
- }
-
- list augmentedListInAugmentedListInAugmentedCase {
- leaf-list leafInAugmentedListInAugmentedListInAugmentedCase {
- type uint32;
- }
- }
- }
-
- identity test-identity {}
- identity test-identity2 {
- base test-identity;
- }
-
-}