X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2Ftree%2FStoreTreeNodesTest.java;h=32df7e0420ed28b7e1f6a4d57853892192759612;hb=8f2876d895936b36aba1fc3ec65b18900e559184;hp=20b35b34698e0fcdb6b010d21ab20a9338f35cee;hpb=0ac42f9585b8309fb5a0f3d7429719c23b02a836;p=yangtools.git diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java index 20b35b3469..32df7e0420 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StoreTreeNodesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015 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, @@ -15,20 +15,23 @@ import static org.junit.Assert.fail; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; -import com.google.common.base.Optional; + import java.util.Map; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration; import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNodes; import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory; import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,34 +43,37 @@ public class StoreTreeNodesTest { private static final String TWO_ONE_NAME = "one"; private static final String TWO_TWO_NAME = "two"; - private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) // + private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder( + TestModel.OUTER_LIST_PATH) + .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) .build(); - private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) - .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // + private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder( + TestModel.OUTER_LIST_PATH) + .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) .build(); private static final YangInstanceIdentifier TWO_TWO_PATH = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH) - .node(TestModel.INNER_LIST_QNAME) // - .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME) // + .node(TestModel.INNER_LIST_QNAME) + .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME) .build(); - private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) // - .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) // - .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME)) // - .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME)) // - .build()) // + private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) + .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) + .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_ONE_NAME)) + .withChild(mapEntry(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, TWO_TWO_NAME)) + .build()) .build(); private SchemaContext schemaContext; private RootModificationApplyOperation rootOper; @Before - public void prepare() { + public void prepare() throws ReactorException { schemaContext = TestModel.createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); - rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext)); + rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, + DataTreeConfiguration.DEFAULT_OPERATIONAL)); } public NormalizedNode createDocumentOne() { @@ -78,7 +84,7 @@ public class StoreTreeNodesTest { } - private ContainerNode createTestContainer() { + private static ContainerNode createTestContainer() { return ImmutableContainerNodeBuilder .create() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) @@ -97,34 +103,34 @@ public class StoreTreeNodesTest { @Test public void findNodeTestNodeFound() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - Optional node = StoreTreeNodes.findNode(rootNode, OUTER_LIST_1_PATH); + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final Optional node = StoreTreeNodes.findNode(rootNode, OUTER_LIST_1_PATH); assertPresentAndType(node, TreeNode.class); } @Test public void findNodeTestNodeNotFound() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3) // .build(); - Optional node = StoreTreeNodes.findNode(rootNode, outerList1InvalidPath); + final Optional node = StoreTreeNodes.findNode(rootNode, outerList1InvalidPath); assertFalse(node.isPresent()); } @Test public void findNodeCheckedTestNodeFound() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); TreeNode foundNode = null; try { foundNode = StoreTreeNodes.findNodeChecked(rootNode, OUTER_LIST_1_PATH); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { fail("Illegal argument exception was thrown and should not have been" + e.getMessage()); } assertNotNull(foundNode); @@ -132,36 +138,37 @@ public class StoreTreeNodesTest { @Test public void findNodeCheckedTestNodeNotFound() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); final YangInstanceIdentifier outerList1InvalidPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH) .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3) // .build(); try { StoreTreeNodes.findNodeChecked(rootNode, outerList1InvalidPath); fail("Illegal argument exception should have been thrown"); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { LOG.debug("Illegal argument exception was thrown as expected: '{}' - '{}'", e.getClass(), e.getMessage()); } } @Test public void findClosestOrFirstMatchTestNodeExists() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - Optional expectedNode = StoreTreeNodes.findNode(rootNode, TWO_TWO_PATH); + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final Optional expectedNode = StoreTreeNodes.findNode(rootNode, TWO_TWO_PATH); assertPresentAndType(expectedNode, TreeNode.class); - Map.Entry actualNode = StoreTreeNodes.findClosest(rootNode, TWO_TWO_PATH); + final Map.Entry actualNode = StoreTreeNodes.findClosest(rootNode, + TWO_TWO_PATH); assertEquals("Expected node and actual node are not the same", expectedNode.get(), actualNode.getValue()); } @Test public void findClosestOrFirstMatchTestNodeDoesNotExist() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); final YangInstanceIdentifier outerListInnerListPath = YangInstanceIdentifier.builder(OUTER_LIST_2_PATH) .node(TestModel.INNER_LIST_QNAME) .build(); @@ -169,28 +176,29 @@ public class StoreTreeNodesTest { .node(TestModel.INNER_LIST_QNAME) // .nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "three") // .build(); - Optional expectedNode = StoreTreeNodes.findNode(rootNode, outerListInnerListPath); + final Optional expectedNode = StoreTreeNodes.findNode(rootNode, outerListInnerListPath); assertPresentAndType(expectedNode, TreeNode.class); - Map.Entry actualNode = StoreTreeNodes.findClosest(rootNode, twoTwoInvalidPath); + final Map.Entry actualNode = StoreTreeNodes.findClosest(rootNode, + twoTwoInvalidPath); assertEquals("Expected node and actual node are not the same", expectedNode.get(), actualNode.getValue()); } @Test public void getChildTestChildFound() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - Optional node = StoreTreeNodes.getChild(Optional.fromNullable(rootNode), + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final Optional node = StoreTreeNodes.getChild(Optional.ofNullable(rootNode), TestModel.TEST_PATH.getLastPathArgument()); assertPresentAndType(node, TreeNode.class); } @Test public void getChildTestChildNotFound() { - InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, + final InMemoryDataTreeSnapshot inMemoryDataTreeSnapshot = new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper); - TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); - Optional node = StoreTreeNodes.getChild(Optional.fromNullable(rootNode), + final TreeNode rootNode = inMemoryDataTreeSnapshot.getRootNode(); + final Optional node = StoreTreeNodes.getChild(Optional.ofNullable(rootNode), TestModel.OUTER_LIST_PATH.getLastPathArgument()); assertFalse(node.isPresent()); }