2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.yang.data.impl;
\r
10 import java.net.URI;
\r
11 import java.util.Date;
\r
13 import junit.framework.Assert;
\r
15 import org.junit.Before;
\r
16 import org.junit.Test;
\r
17 import org.opendaylight.controller.yang.common.QName;
\r
18 import org.opendaylight.controller.yang.data.api.CompositeNode;
\r
19 import org.opendaylight.controller.yang.data.api.MutableCompositeNode;
\r
20 import org.opendaylight.controller.yang.data.api.MutableSimpleNode;
\r
21 import org.opendaylight.controller.yang.data.api.SimpleNode;
\r
22 import org.opendaylight.controller.yang.model.api.SchemaContext;
\r
23 import org.w3c.dom.Document;
\r
26 * @author michal.rehak
\r
29 public class NodeModificationBuilderImplTest {
\r
31 private SchemaContext schemaCtx;
\r
32 private QName qName;
\r
33 private CompositeNode network;
\r
34 private NodeModificationBuilderImpl nodeModificationBuilder;
\r
37 * prepare schemaContext
\r
38 * @throws Exception
\r
41 public void setUp() throws Exception {
\r
42 schemaCtx = NodeHelper.loadSchemaContext();
\r
45 new URI("urn:opendaylight:controller:network"),
\r
46 new Date(1369000800000L), "topos");
\r
47 network = NodeHelper.buildTestConfigTree(qName);
\r
49 nodeModificationBuilder = new NodeModificationBuilderImpl(network, schemaCtx);
\r
54 * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
\r
56 * @throws Exception
\r
59 public void testBuildDiffTree() throws Exception {
\r
60 Document networkShadow = NodeUtils.buildShadowDomTree(network);
\r
61 SimpleNode<String> needle = NodeUtils.findNodeByXpath(networkShadow,
\r
62 "//node[node-id='nodeId_19']//termination-point[2]/tp-id");
\r
64 @SuppressWarnings("unchecked")
\r
65 MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)
\r
66 nodeModificationBuilder.getMutableEquivalent(needle);
\r
68 mutableNeedle.setValue("tpId_18x");
\r
69 nodeModificationBuilder.replaceNode(mutableNeedle);
\r
70 CompositeNode diffTree = nodeModificationBuilder.buildDiffTree();
\r
72 Document diffShadow = NodeUtils.buildShadowDomTree(diffTree);
\r
73 NodeHelper.dumpDoc(diffShadow, System.out);
\r
78 * {@link org.opendaylight.controller.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.controller.yang.data.api.Node)}
\r
82 public void testGetMutableEquivalent() {
\r
83 MutableCompositeNode rootMutable = (MutableCompositeNode)
\r
84 nodeModificationBuilder.getMutableEquivalent(network);
\r
86 CompositeNode topologies = network.getCompositesByName("topologies").iterator().next();
\r
87 CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next();
\r
89 Assert.assertSame(topologiesMutable, nodeModificationBuilder.getMutableEquivalent(topologies));
\r