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
26 public class LazyNodeToNodeMapTest {
28 private LazyNodeToNodeMap lazyN2N;
29 private CompositeNode tree;
36 public void setUp() throws Exception {
37 lazyN2N = new LazyNodeToNodeMap();
39 QName qName = QName.create(
40 new URI("urn:ietf:params:xml:ns:netconf:base:1.0"),
41 new Date(42), "yang-data-impl-mutableTest");
43 tree = NodeHelper.buildTestConfigTree(qName);
47 * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}.
50 public void testGetMutableEquivalent() {
51 MutableCompositeNode mutableTree = (MutableCompositeNode) lazyN2N.getMutableEquivalent(tree);
53 Assert.assertNull(mutableTree.getParent());
54 Assert.assertEquals(tree.getNodeType(), mutableTree.getNodeType());
55 Assert.assertEquals(1, lazyN2N.getKeyNodes().size());
57 Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
58 Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
60 Assert.assertNotNull(subMutant.getParent());
61 Assert.assertEquals(subNode.getNodeType(), subMutant.getNodeType());
62 Assert.assertEquals(2, lazyN2N.getKeyNodes().size());
64 Assert.assertEquals(mutableTree, subMutant.getParent());
65 Assert.assertEquals(mutableTree.getValue().size(), 1);
66 Assert.assertEquals(mutableTree.getValue().iterator().next(), subMutant);
70 * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableRoot()}.
73 public void testGetMutableRoot() {
74 Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
75 Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
77 Assert.assertNotNull(subMutant.getParent());
78 Assert.assertEquals(subMutant.getParent(), lazyN2N.getMutableRoot());