Fixed incorrect test location.
[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 public class LazyNodeToNodeMapTest {
26
27     private LazyNodeToNodeMap lazyN2N;
28     private CompositeNode tree;
29
30     /**
31      * prepare test values
32      * @throws Exception
33      */
34     @Before
35     public void setUp() throws Exception {
36         lazyN2N = new LazyNodeToNodeMap();
37
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");
41
42         tree = NodeHelper.buildTestConfigTree(qName);
43     }
44
45     /**
46      * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}.
47      */
48     @Test
49     public void testGetMutableEquivalent() {
50         MutableCompositeNode mutableTree = (MutableCompositeNode) lazyN2N.getMutableEquivalent(tree);
51
52         Assert.assertNull(mutableTree.getParent());
53         Assert.assertEquals(tree.getNodeType(), mutableTree.getNodeType());
54         Assert.assertEquals(1, lazyN2N.getKeyNodes().size());
55
56         Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
57         Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
58
59         Assert.assertNotNull(subMutant.getParent());
60         Assert.assertEquals(subNode.getNodeType(), subMutant.getNodeType());
61         Assert.assertEquals(2, lazyN2N.getKeyNodes().size());
62
63         Assert.assertEquals(mutableTree, subMutant.getParent());
64         Assert.assertEquals(mutableTree.getValue().size(), 1);
65         Assert.assertEquals(mutableTree.getValue().iterator().next(), subMutant);
66     }
67
68     /**
69      * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableRoot()}.
70      */
71     @Test
72     public void testGetMutableRoot() {
73         Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
74         Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
75
76         Assert.assertNotNull(subMutant.getParent());
77         Assert.assertEquals(subMutant.getParent(), lazyN2N.getMutableRoot());
78     }
79
80 }