X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futil%2FTestModel.java;h=c613d6cf62ccb4b55d3afa20ceaa114897252c12;hb=1d0370feb32b84119bf4c570b9e6e9abbe8d9511;hp=770a2ffb3e9b9d20d9ec5daa03a7b45ff471db89;hpb=a56f747b898f4b9556a69b835861a5d522df35b5;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java index 770a2ffb3e..c613d6cf62 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java @@ -5,7 +5,6 @@ * 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 static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; @@ -16,14 +15,12 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.io.InputStream; import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; @@ -36,23 +33,20 @@ 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.MapNode; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; 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.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder; 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.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class TestModel { +public final class TestModel { public static final QName TEST_QNAME = QName.create( "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", @@ -97,12 +91,12 @@ public class TestModel { public static final QName CHOICE_QNAME = QName.create(TEST_QNAME, "choice"); public static final QName SHOE_QNAME = QName.create(TEST_QNAME, "shoe"); public static final QName ANY_XML_QNAME = QName.create(TEST_QNAME, "any"); + public static final QName EMPTY_QNAME = QName.create(TEST_QNAME, "empty-leaf"); public static final QName INVALID_QNAME = QName.create(TEST_QNAME, "invalid"); private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang"; private static final String DATASTORE_AUG_YANG = "/odl-datastore-augmentation.yang"; private static final String DATASTORE_TEST_NOTIFICATION_YANG = "/odl-datastore-test-notification.yang"; - public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME); public static final YangInstanceIdentifier DESC_PATH = YangInstanceIdentifier .builder(TEST_PATH).node(DESC_QNAME).build(); @@ -156,15 +150,19 @@ public class TestModel { .build()) // .build(); - public static final InputStream getDatastoreTestInputStream() { + private TestModel() { + throw new UnsupportedOperationException(); + } + + public static InputStream getDatastoreTestInputStream() { return getInputStream(DATASTORE_TEST_YANG); } - public static final InputStream getDatastoreAugInputStream() { + public static InputStream getDatastoreAugInputStream() { return getInputStream(DATASTORE_AUG_YANG); } - public static final InputStream getDatastoreTestNotificationInputStream() { + public static InputStream getDatastoreTestNotificationInputStream() { return getInputStream(DATASTORE_TEST_NOTIFICATION_YANG); } @@ -172,66 +170,21 @@ public class TestModel { return TestModel.class.getResourceAsStream(resourceName); } - public static SchemaContext createTestContext() { - List inputStreams = new ArrayList<>(); - inputStreams.add(getDatastoreTestInputStream()); - inputStreams.add(getDatastoreAugInputStream()); - inputStreams.add(getDatastoreTestNotificationInputStream()); - - return resolveSchemaContext(inputStreams); - } - - public static SchemaContext createTestContextWithoutTestSchema() { - List inputStreams = new ArrayList<>(); - inputStreams.add(getDatastoreTestNotificationInputStream()); - - return resolveSchemaContext(inputStreams); + public static EffectiveModelContext createTestContext() { + return YangParserTestUtils.parseYangResources(TestModel.class, DATASTORE_TEST_YANG, DATASTORE_AUG_YANG, + DATASTORE_TEST_NOTIFICATION_YANG); } - - public static SchemaContext createTestContextWithoutAugmentationSchema() { - List inputStreams = new ArrayList<>(); - inputStreams.add(getDatastoreTestInputStream()); - inputStreams.add(getDatastoreTestNotificationInputStream()); - - return resolveSchemaContext(inputStreams); + public static EffectiveModelContext createTestContextWithoutTestSchema() { + return YangParserTestUtils.parseYangResource(DATASTORE_TEST_NOTIFICATION_YANG); } - private static SchemaContext resolveSchemaContext(final List streams) { - try { - return YangParserTestUtils.parseYangStreams(streams); - } catch (ReactorException e) { - throw new RuntimeException("Unable to build schema context from " + streams, e); - } + public static EffectiveModelContext createTestContextWithoutAugmentationSchema() { + return YangParserTestUtils.parseYangResources(TestModel.class, DATASTORE_TEST_YANG, + DATASTORE_TEST_NOTIFICATION_YANG); } - /** - * Returns a test document. - *

- *

- *

-     * test
-     *     outer-list
-     *          id 1
-     *     outer-list
-     *          id 2
-     *          inner-list
-     *                  name "one"
-     *          inner-list
-     *                  name "two"
-     *
-     * 
- */ - public static NormalizedNode createDocumentOne(final SchemaContext schemaContext) { - return ImmutableContainerNodeBuilder - .create() - .withNodeIdentifier( - new NodeIdentifier(schemaContext.getQName())) - .withChild(createTestContainer()).build(); - - } - - public static DataContainerNodeAttrBuilder createBaseTestContainerBuilder() { + public static DataContainerNodeBuilder createBaseTestContainerBuilder() { // Create a list of shoes // This is to test leaf list entry final LeafSetEntryNode nike = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( @@ -292,20 +245,21 @@ public class TestModel { MapEntryNode augMapEntry = createAugmentedListEntry(1, "First Test"); // Create a bits leaf - NormalizedNodeAttrBuilder> + NormalizedNodeBuilder> myBits = Builders.leafBuilder() .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "my-bits"))) .withValue(ImmutableSet.of("foo", "bar")); // Create unkeyed list entry - UnkeyedListEntryNode unkeyedListEntry = - Builders.unkeyedListEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier( - UNKEYED_LIST_QNAME)).withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name")).build(); + UnkeyedListEntryNode unkeyedListEntry = Builders.unkeyedListEntryBuilder() + .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)) + .withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name")) + .build(); // Create YangInstanceIdentifier with all path arg types. YangInstanceIdentifier instanceID = YangInstanceIdentifier.create( new NodeIdentifier(QName.create(TEST_QNAME, "qname")), - new NodeIdentifierWithPredicates(QName.create(TEST_QNAME, "list-entry"), + NodeIdentifierWithPredicates.of(QName.create(TEST_QNAME, "list-entry"), QName.create(TEST_QNAME, "key"), 10), new AugmentationIdentifier(ImmutableSet.of( QName.create(TEST_QNAME, "aug1"), QName.create(TEST_QNAME, "aug2"))), @@ -318,24 +272,24 @@ public class TestModel { // Create the document return ImmutableContainerNodeBuilder .create() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)) + .withNodeIdentifier(new NodeIdentifier(TEST_QNAME)) .withChild(myBits.build()) .withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC)) .withChild(ImmutableNodes.leafNode(BOOLEAN_LEAF_QNAME, ENABLED)) .withChild(ImmutableNodes.leafNode(SHORT_LEAF_QNAME, SHORT_ID)) .withChild(ImmutableNodes.leafNode(BYTE_LEAF_QNAME, BYTE_ID)) - .withChild(ImmutableNodes.leafNode(TestModel.BIGINTEGER_LEAF_QNAME, BigInteger.valueOf(100))) + .withChild(ImmutableNodes.leafNode(TestModel.BIGINTEGER_LEAF_QNAME, Uint64.valueOf(100))) .withChild(ImmutableNodes.leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, BigDecimal.valueOf(1.2))) .withChild(ImmutableNodes.leafNode(SOME_REF_QNAME, instanceID)) .withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME)) .withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_QNAME)) + .withNodeIdentifier(new NodeIdentifier(UNKEYED_LIST_QNAME)) .withChild(unkeyedListEntry).build()) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TWO_THREE_QNAME)) + .withNodeIdentifier(new NodeIdentifier(TWO_THREE_QNAME)) .withChild(ImmutableNodes.leafNode(TWO_QNAME, "two")).build()) .withChild(Builders.orderedMapBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ORDERED_LIST_QNAME)) + .withNodeIdentifier(new NodeIdentifier(ORDERED_LIST_QNAME)) .withValue(ImmutableList.builder().add( mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "1").build(), mapEntryBuilder(ORDERED_LIST_QNAME, ORDERED_LIST_ENTRY_QNAME, "2").build()).build()) @@ -355,53 +309,44 @@ public class TestModel { } public static MapEntryNode createAugmentedListEntry(final int id, final String name) { - Set 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(); - + ContainerNode augCont = ImmutableContainerNodeBuilder.create() + .withNodeIdentifier(new NodeIdentifier(AUG_CONT_QNAME)) + .withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name)) + .build(); - final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier = - new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations); + final AugmentationIdentifier augmentationIdentifier = new 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)) + return ImmutableMapEntryNodeBuilder.create() + .withNodeIdentifier(NodeIdentifierWithPredicates.of(AUGMENTED_LIST_QNAME, ID_QNAME, id)) .withChild(ImmutableNodes.leafNode(ID_QNAME, id)) .withChild(augmentationNode).build(); } - public static ContainerNode createFamily() { - final DataContainerNodeAttrBuilder + final DataContainerNodeBuilder familyContainerBuilder = ImmutableContainerNodeBuilder.create().withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(FAMILY_QNAME)); + new NodeIdentifier(FAMILY_QNAME)); final CollectionNodeBuilder childrenBuilder = mapNodeBuilder(CHILDREN_QNAME); - final DataContainerNodeBuilder + final DataContainerNodeBuilder firstChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID); - final DataContainerNodeBuilder + final DataContainerNodeBuilder secondChildBuilder = mapEntryBuilder(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID); - final DataContainerNodeBuilder + final DataContainerNodeBuilder firstGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME, FIRST_GRAND_CHILD_ID); - final DataContainerNodeBuilder + final DataContainerNodeBuilder secondGrandChildBuilder = mapEntryBuilder(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME, SECOND_GRAND_CHILD_ID); @@ -413,31 +358,27 @@ public class TestModel { FIRST_GRAND_CHILD_NAME)); secondGrandChildBuilder.withChild( - ImmutableNodes - .leafNode(GRAND_CHILD_NUMBER_QNAME, SECOND_GRAND_CHILD_ID)) - .withChild( - ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME, - SECOND_GRAND_CHILD_NAME)); + ImmutableNodes.leafNode(GRAND_CHILD_NUMBER_QNAME, SECOND_GRAND_CHILD_ID)) + .withChild(ImmutableNodes.leafNode(GRAND_CHILD_NAME_QNAME, SECOND_GRAND_CHILD_NAME)); firstChildBuilder .withChild(ImmutableNodes.leafNode(CHILD_NUMBER_QNAME, FIRST_CHILD_ID)) .withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, FIRST_CHILD_NAME)) - .withChild( - mapNodeBuilder(GRAND_CHILDREN_QNAME).withChild( - firstGrandChildBuilder.build()).build()); + .withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME) + .withChild(firstGrandChildBuilder.build()) + .build()); secondChildBuilder .withChild(ImmutableNodes.leafNode(CHILD_NUMBER_QNAME, SECOND_CHILD_ID)) .withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, SECOND_CHILD_NAME)) - .withChild( - mapNodeBuilder(GRAND_CHILDREN_QNAME).withChild( - firstGrandChildBuilder.build()).build()); + .withChild(mapNodeBuilder(GRAND_CHILDREN_QNAME) + .withChild(firstGrandChildBuilder.build()) + .build()); childrenBuilder.withChild(firstChildBuilder.build()); childrenBuilder.withChild(secondChildBuilder.build()); return familyContainerBuilder.withChild(childrenBuilder.build()).build(); } - }