BUG-1472: deprecated CompositeNode and friends
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / LazyNodeToNodeMapTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.impl;
9
10 import java.net.URI;
11 import java.util.Date;
12
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;
20
21 /**
22  * @author michal.rehak
23  *
24  */
25 @Deprecated
26 public class LazyNodeToNodeMapTest {
27
28     private LazyNodeToNodeMap lazyN2N;
29     private CompositeNode tree;
30
31     /**
32      * prepare test values
33      * @throws Exception
34      */
35     @Before
36     public void setUp() throws Exception {
37         lazyN2N = new LazyNodeToNodeMap();
38
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");
42
43         tree = NodeHelper.buildTestConfigTree(qName);
44     }
45
46     /**
47      * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}.
48      */
49     @Test
50     public void testGetMutableEquivalent() {
51         MutableCompositeNode mutableTree = (MutableCompositeNode) lazyN2N.getMutableEquivalent(tree);
52
53         Assert.assertNull(mutableTree.getParent());
54         Assert.assertEquals(tree.getNodeType(), mutableTree.getNodeType());
55         Assert.assertEquals(1, lazyN2N.getKeyNodes().size());
56
57         Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
58         Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
59
60         Assert.assertNotNull(subMutant.getParent());
61         Assert.assertEquals(subNode.getNodeType(), subMutant.getNodeType());
62         Assert.assertEquals(2, lazyN2N.getKeyNodes().size());
63
64         Assert.assertEquals(mutableTree, subMutant.getParent());
65         Assert.assertEquals(mutableTree.getValue().size(), 1);
66         Assert.assertEquals(mutableTree.getValue().iterator().next(), subMutant);
67     }
68
69     /**
70      * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableRoot()}.
71      */
72     @Test
73     public void testGetMutableRoot() {
74         Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
75         Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
76
77         Assert.assertNotNull(subMutant.getParent());
78         Assert.assertEquals(subMutant.getParent(), lazyN2N.getMutableRoot());
79     }
80
81 }