+/*
+ *
+ * Copyright (c) 2014 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.controller.cluster.datastore.util;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
"urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test",
"2014-03-13", "test");
- public static final QName AUG_QNAME = QName.create(
+ public static final QName AUG_NAME_QNAME = QName.create(
"urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:aug",
"2014-03-13", "name");
+ public static final QName AUG_CONT_QNAME = QName.create(
+ "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:aug",
+ "2014-03-13", "cont");
+
+
public static final QName DESC_QNAME = QName.create(TEST_QNAME, "desc");
+ public static final QName POINTER_QNAME = QName.create(TEST_QNAME, "pointer");
+ public static final QName SOME_REF_QNAME = QName.create(TEST_QNAME,
+ "some-ref");
+ public static final QName MYIDENTITY_QNAME = QName.create(TEST_QNAME,
+ "myidentity");
+ public static final QName SWITCH_FEATURES_QNAME = QName.create(TEST_QNAME,
+ "switch-features");
+
+ public static final QName AUGMENTED_LIST_QNAME = QName.create(TEST_QNAME,
+ "augmented-list");
+
public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME,
"outer-list");
public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME,
.of(TEST_QNAME);
public static final YangInstanceIdentifier DESC_PATH = YangInstanceIdentifier
.builder(TEST_PATH).node(DESC_QNAME).build();
- public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier
- .builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
+ public static final YangInstanceIdentifier OUTER_LIST_PATH =
+ YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two");
public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three");
public static final QName GRAND_CHILD_NAME_QNAME = QName.create(FAMILY_QNAME,
"grand-child-name");
- public static final YangInstanceIdentifier FAMILY_PATH = YangInstanceIdentifier
- .of(FAMILY_QNAME);
- public static final YangInstanceIdentifier FAMILY_DESC_PATH = YangInstanceIdentifier
- .builder(FAMILY_PATH).node(DESC_QNAME).build();
- public static final YangInstanceIdentifier CHILDREN_PATH = YangInstanceIdentifier
- .builder(FAMILY_PATH).node(CHILDREN_QNAME).build();
+ public static final YangInstanceIdentifier FAMILY_PATH =
+ YangInstanceIdentifier.of(FAMILY_QNAME);
+ public static final YangInstanceIdentifier FAMILY_DESC_PATH =
+ YangInstanceIdentifier.builder(FAMILY_PATH).node(DESC_QNAME).build();
+ public static final YangInstanceIdentifier CHILDREN_PATH =
+ YangInstanceIdentifier.builder(FAMILY_PATH).node(CHILDREN_QNAME).build();
private static final Integer FIRST_CHILD_ID = 1;
private static final Integer SECOND_CHILD_ID = 2;
private static final String SECOND_GRAND_CHILD_NAME = "second grand child";
// first child
- private static final YangInstanceIdentifier CHILDREN_1_PATH = YangInstanceIdentifier
- .builder(CHILDREN_PATH)
- .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID) //
- .build();
+ private static final YangInstanceIdentifier CHILDREN_1_PATH =
+ YangInstanceIdentifier.builder(CHILDREN_PATH)
+ .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID) //
+ .build();
private static final YangInstanceIdentifier CHILDREN_1_NAME_PATH =
YangInstanceIdentifier.builder(CHILDREN_PATH)
.nodeWithKey(CHILDREN_QNAME, CHILD_NAME_QNAME, FIRST_CHILD_NAME) //
.build();
- private static final YangInstanceIdentifier CHILDREN_2_PATH = YangInstanceIdentifier
- .builder(CHILDREN_PATH)
- .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID) //
- .build();
+ private static final YangInstanceIdentifier CHILDREN_2_PATH =
+ YangInstanceIdentifier.builder(CHILDREN_PATH)
+ .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID) //
+ .build();
private static final YangInstanceIdentifier CHILDREN_2_NAME_PATH =
YangInstanceIdentifier.builder(CHILDREN_PATH)
.nodeWithKey(CHILDREN_QNAME, CHILD_NAME_QNAME, SECOND_CHILD_NAME) //
private static final YangInstanceIdentifier GRAND_CHILD_1_PATH =
- YangInstanceIdentifier.builder(CHILDREN_1_PATH)
+ YangInstanceIdentifier
+ .builder(CHILDREN_1_PATH)
.node(GRAND_CHILDREN_QNAME)
//
.nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
.build();
private static final YangInstanceIdentifier GRAND_CHILD_1_NAME_PATH =
- YangInstanceIdentifier.builder(CHILDREN_1_PATH)
+ YangInstanceIdentifier
+ .builder(CHILDREN_1_PATH)
.node(GRAND_CHILDREN_QNAME)
//
.nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NAME_QNAME,
.build();
private static final YangInstanceIdentifier GRAND_CHILD_2_PATH =
- YangInstanceIdentifier.builder(CHILDREN_2_PATH)
+ YangInstanceIdentifier
+ .builder(CHILDREN_2_PATH)
.node(GRAND_CHILDREN_QNAME)
//
.nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME,
.build();
private static final YangInstanceIdentifier GRAND_CHILD_2_NAME_PATH =
- YangInstanceIdentifier.builder(CHILDREN_2_PATH)
+ YangInstanceIdentifier
+ .builder(CHILDREN_2_PATH)
.node(GRAND_CHILDREN_QNAME)
//
.nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NAME_QNAME,
SECOND_GRAND_CHILD_NAME) //
.build();
- private static final YangInstanceIdentifier DESC_PATH_ID = YangInstanceIdentifier
- .builder(DESC_PATH).build();
+ private static final YangInstanceIdentifier DESC_PATH_ID =
+ YangInstanceIdentifier.builder(DESC_PATH).build();
private static final YangInstanceIdentifier OUTER_LIST_1_PATH =
YangInstanceIdentifier.builder(OUTER_LIST_PATH)
.nodeWithKey(OUTER_LIST_QNAME, ID_QNAME, ONE_ID) //
.nodeWithKey(OUTER_LIST_QNAME, ID_QNAME, TWO_ID) //
.build();
- private static final YangInstanceIdentifier TWO_TWO_PATH = YangInstanceIdentifier
- .builder(OUTER_LIST_2_PATH).node(INNER_LIST_QNAME) //
- .nodeWithKey(INNER_LIST_QNAME, NAME_QNAME, TWO_TWO_NAME) //
- .build();
+ private static final YangInstanceIdentifier TWO_TWO_PATH =
+ YangInstanceIdentifier.builder(OUTER_LIST_2_PATH).node(INNER_LIST_QNAME) //
+ .nodeWithKey(INNER_LIST_QNAME, NAME_QNAME, TWO_TWO_NAME) //
+ .build();
private static final YangInstanceIdentifier TWO_TWO_VALUE_PATH =
YangInstanceIdentifier.builder(TWO_TWO_PATH).node(VALUE_QNAME) //
/**
* Returns a test document
+ * <p/>
*
* <pre>
* test
public static ContainerNode createTestContainer() {
+ // Create a list of shoes
+ // This is to test leaf list entry
final LeafSetEntryNode<Object> nike =
ImmutableLeafSetEntryNodeBuilder
.create()
.withNodeIdentifier(
- new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
- "shoe"), "nike")).withValue("nike").build();
+ new YangInstanceIdentifier.NodeWithValue(QName.create(
+ TEST_QNAME, "shoe"), "nike")).withValue("nike").build();
+
final LeafSetEntryNode<Object> puma =
ImmutableLeafSetEntryNodeBuilder
.create()
.withNodeIdentifier(
- new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
- "shoe"), "puma")).withValue("puma").build();
+ new YangInstanceIdentifier.NodeWithValue(QName.create(
+ TEST_QNAME, "shoe"), "puma")).withValue("puma").build();
+
final LeafSetNode<Object> shoes =
ImmutableLeafSetNodeBuilder
.create()
.withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_QNAME,
- "shoe"))).withChild(nike).withChild(puma).build();
+ new YangInstanceIdentifier.NodeIdentifier(QName.create(
+ TEST_QNAME, "shoe"))).withChild(nike).withChild(puma)
+ .build();
+
+
+ // Test a leaf-list where each entry contains an identity
+ final LeafSetEntryNode<Object> cap1 =
+ ImmutableLeafSetEntryNodeBuilder
+ .create()
+ .withNodeIdentifier(
+ new YangInstanceIdentifier.NodeWithValue(QName.create(
+ TEST_QNAME, "capability"), DESC_QNAME))
+ .withValue(DESC_QNAME).build();
+
+ final LeafSetNode<Object> capabilities =
+ ImmutableLeafSetNodeBuilder
+ .create()
+ .withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(QName.create(
+ TEST_QNAME, "capability"))).withChild(cap1).build();
+ ContainerNode switchFeatures =
+ ImmutableContainerNodeBuilder
+ .create()
+ .withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(SWITCH_FEATURES_QNAME))
+ .withChild(capabilities).build();
+ // Create a leaf list with numbers
final LeafSetEntryNode<Object> five =
ImmutableLeafSetEntryNodeBuilder
.create()
.withNodeIdentifier(
- (new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
- "number"), 5))).withValue(5).build();
+ (new YangInstanceIdentifier.NodeWithValue(QName.create(
+ TEST_QNAME, "number"), 5))).withValue(5).build();
final LeafSetEntryNode<Object> fifteen =
ImmutableLeafSetEntryNodeBuilder
.create()
.withNodeIdentifier(
- (new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME,
- "number"), 15))).withValue(15).build();
+ (new YangInstanceIdentifier.NodeWithValue(QName.create(
+ TEST_QNAME, "number"), 15))).withValue(15).build();
final LeafSetNode<Object> numbers =
ImmutableLeafSetNodeBuilder
.create()
.withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_QNAME,
- "number"))).withChild(five).withChild(fifteen).build();
+ new YangInstanceIdentifier.NodeIdentifier(QName.create(
+ TEST_QNAME, "number"))).withChild(five).withChild(fifteen)
+ .build();
- Set<QName> childAugmentations = new HashSet<>();
- childAugmentations.add(AUG_QNAME);
- final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier =
- new YangInstanceIdentifier.AugmentationIdentifier(null, childAugmentations);
- final AugmentationNode augmentationNode =
- Builders.augmentationBuilder()
- .withNodeIdentifier(augmentationIdentifier)
- .withChild(ImmutableNodes.leafNode(AUG_QNAME, "First Test"))
- .build();
+ // Create augmentations
+ MapEntryNode mapEntry = createAugmentedListEntry(1, "First Test");
+
+
+ // Create the document
return ImmutableContainerNodeBuilder
.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME))
+ .withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME))
.withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC))
- .withChild(augmentationNode)
+ .withChild(ImmutableNodes.leafNode(POINTER_QNAME, "pointer"))
+ .withChild(
+ ImmutableNodes.leafNode(SOME_REF_QNAME, YangInstanceIdentifier
+ .builder().build()))
+ .withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME))
+
+ // .withChild(augmentationNode)
.withChild(shoes)
.withChild(numbers)
+ .withChild(switchFeatures)
+ .withChild(
+ mapNodeBuilder(AUGMENTED_LIST_QNAME).withChild(mapEntry).build())
.withChild(
mapNodeBuilder(OUTER_LIST_QNAME)
.withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID))
}
+ public static MapEntryNode createAugmentedListEntry(int id, String name) {
+
+ Set<QName> childAugmentations = new HashSet<>();
+ childAugmentations.add(AUG_CONT_QNAME);
+
+ ContainerNode augCont =
+ ImmutableContainerNodeBuilder
+ .create()
+ .withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(AUG_CONT_QNAME))
+ .withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name)).build();
+
+
+ final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier =
+ new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations);
+
+ final AugmentationNode augmentationNode =
+ Builders.augmentationBuilder()
+ .withNodeIdentifier(augmentationIdentifier).withChild(augCont)
+ .build();
+
+ return ImmutableMapEntryNodeBuilder
+ .create()
+ .withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+ AUGMENTED_LIST_QNAME, ID_QNAME, id))
+ .withChild(ImmutableNodes.leafNode(ID_QNAME, id))
+ .withChild(augmentationNode).build();
+ }
+
public static ContainerNode createFamily() {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> familyContainerBuilder =
.withChild(
ImmutableNodes.leafNode(GRAND_CHILD_NUMBER_QNAME,
FIRST_GRAND_CHILD_ID)).withChild(
- ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME,
- FIRST_GRAND_CHILD_NAME));
+ ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME,
+ FIRST_GRAND_CHILD_NAME));
secondGrandChildBuilder.withChild(
ImmutableNodes