2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.impl;
11 import java.util.Date;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
18 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
19 import org.opendaylight.yangtools.yang.data.api.Node;
22 * @author michal.rehak
25 public class LazyNodeToNodeMapTest {
27 private LazyNodeToNodeMap lazyN2N;
28 private CompositeNode tree;
35 public void setUp() throws Exception {
36 lazyN2N = new LazyNodeToNodeMap();
38 QName qName = QName.create(
39 new URI("urn:ietf:params:xml:ns:netconf:base:1.0"),
40 new Date(42), "yang-data-impl-mutableTest");
42 tree = NodeHelper.buildTestConfigTree(qName);
46 * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}.
49 public void testGetMutableEquivalent() {
50 MutableCompositeNode mutableTree = (MutableCompositeNode) lazyN2N.getMutableEquivalent(tree);
52 Assert.assertNull(mutableTree.getParent());
53 Assert.assertEquals(tree.getNodeType(), mutableTree.getNodeType());
54 Assert.assertEquals(1, lazyN2N.getKeyNodes().size());
56 Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
57 Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
59 Assert.assertNotNull(subMutant.getParent());
60 Assert.assertEquals(subNode.getNodeType(), subMutant.getNodeType());
61 Assert.assertEquals(2, lazyN2N.getKeyNodes().size());
63 Assert.assertEquals(mutableTree, subMutant.getParent());
64 Assert.assertEquals(mutableTree.getValue().size(), 1);
65 Assert.assertEquals(mutableTree.getValue().iterator().next(), subMutant);
69 * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableRoot()}.
72 public void testGetMutableRoot() {
73 Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
74 Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
76 Assert.assertNotNull(subMutant.getParent());
77 Assert.assertEquals(subMutant.getParent(), lazyN2N.getMutableRoot());