/* * 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.yangtools.yang.data.impl.schema.tree; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; 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 org.junit.Before; 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.schema.ContainerNode; 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.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; 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.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; /** * * Schema structure of document is * *
* container root { * list list-a { * key leaf-a; * leaf leaf-a; * choice choice-a { * case one { * leaf one; * } * case two-three { * leaf two; * leaf three; * } * } * list list-b { * key leaf-b; * leaf leaf-b; * } * } * } ** */ public class ModificationMetadataTreeTest { private static final Short ONE_ID = 1; private static final Short TWO_ID = 2; 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) // .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) // .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) // .build(); private static final YangInstanceIdentifier TWO_TWO_VALUE_PATH = YangInstanceIdentifier.builder(TWO_TWO_PATH) .node(TestModel.VALUE_QNAME) // .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() { schemaContext = TestModel.createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext)); } /** * Returns a test document * *
* test * outer-list * id 1 * outer-list * id 2 * inner-list * name "one" * inner-list * name "two" * ** * @return */ public NormalizedNode, ?> createDocumentOne() { return ImmutableContainerNodeBuilder .create() .withNodeIdentifier(new NodeIdentifier(schemaContext.getQName())) .withChild(createTestContainer()).build(); } private static ContainerNode createTestContainer() { return ImmutableContainerNodeBuilder .create() .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) .withChild( mapNodeBuilder(TestModel.OUTER_LIST_QNAME) .withChild(mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID)) .withChild(BAR_NODE).build()).build(); } @Test public void basicReadWrites() { DataTreeModification modificationTree = new InMemoryDataTreeModification(new InMemoryDataTreeSnapshot(schemaContext, TreeNodeFactory.createTreeNodeRecursively(createDocumentOne(), Version.initial()), rootOper), rootOper); Optional