3fc33384e7d5f0217afe06edc69a8b2995634d49
[yangtools.git] / restconf / restconf-util / src / test / java / org / opendaylight / yangtools / restconf / utils / RestconfUtilsTest.java
1 /*
2  * Copyright (c) 2014 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.restconf.utils;
9
10 import static junit.framework.Assert.assertNotNull;
11 import static org.junit.Assert.assertEquals;
12
13 import java.io.InputStream;
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import javassist.ClassPool;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
28 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
29 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
32 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
33 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
34
35 import com.google.common.collect.Lists;
36
37 public class RestconfUtilsTest {
38
39     private RuntimeGeneratedMappingServiceImpl mappingService;
40
41     @Before
42     public void setup() {
43         this.mappingService = new RuntimeGeneratedMappingServiceImpl();
44         this.mappingService.setPool(new ClassPool());
45         this.mappingService.init();
46
47         final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
48         moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
49         this.mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get());
50     }
51
52     @Test
53     public void testToDataObjectMappingWithNestedAugmentations() {
54         final InstanceIdentifier<Topology> topologyIdentifier = InstanceIdentifier.builder(NetworkTopology.class)
55                 .child(Topology.class).build();
56         final InputStream is = this.getClass().getClassLoader().getResourceAsStream("topology.xml");
57         final DataSchemaNode dataSchema = RestconfUtils.toRestconfIdentifier(topologyIdentifier, this.mappingService,
58                 this.mappingService.getSchemaContext()).getValue();
59         final Topology topology = (Topology) RestconfUtils.dataObjectFromInputStream(topologyIdentifier, is,
60                 this.mappingService.getSchemaContext(), this.mappingService, dataSchema);
61
62         assertNotNull(topology);
63         assertEquals(1, topology.getNode().size());
64         final Node node = topology.getNode().get(0);
65         assertEquals("bgpls://IsisLevel2:1/type=node&as=72&domain=673720360&router=0000.0000.0042", node.getNodeId()
66                 .getValue());
67
68         final Node1 node1 = node.getAugmentation(Node1.class);
69         assertNotNull(node1);
70         assertNotNull(node1.getIgpNodeAttributes());
71         assertEquals("Of-9k-02", node1.getIgpNodeAttributes().getName().getValue());
72
73         final IgpNodeAttributes1 igpAttributes1 = node1.getIgpNodeAttributes()
74                 .getAugmentation(IgpNodeAttributes1.class);
75         assertNotNull(igpAttributes1);
76         assertNotNull(igpAttributes1.getIsisNodeAttributes());
77         assertEquals("66", igpAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
78     }
79
80 }