2 * Copyright (c) 2014 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.restconf.utils;
10 import static junit.framework.Assert.assertNotNull;
11 import static org.junit.Assert.assertEquals;
13 import java.io.InputStream;
15 import javassist.ClassPool;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
26 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
27 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
30 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
32 public class RestconfUtilsTest {
34 private RuntimeGeneratedMappingServiceImpl mappingService;
38 this.mappingService = new RuntimeGeneratedMappingServiceImpl(new ClassPool());
40 final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
41 moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
42 this.mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get());
46 public void firstTest() { // test static state collisions with the other test
47 final InstanceIdentifier<Topology> instanceIdentifier = InstanceIdentifier.builder(NetworkTopology.class)
48 .child(Topology.class, new TopologyKey(new TopologyId("example-pcep-topology"))).toInstance();
49 final InputStream is = this.getClass().getClassLoader().getResourceAsStream("topology-bug1196-linux.xml");
50 RestconfUtils.toRestconfIdentifier(instanceIdentifier, this.mappingService,
51 this.mappingService.getSchemaContext()).getValue();
55 public void testToDataObjectMappingWithNestedAugmentations() {
56 final InstanceIdentifier<Topology> topologyIdentifier = InstanceIdentifier.builder(NetworkTopology.class)
57 .child(Topology.class).build();
58 final InputStream is = this.getClass().getClassLoader().getResourceAsStream("topology.xml");
59 final DataSchemaNode dataSchema = RestconfUtils.toRestconfIdentifier(topologyIdentifier, this.mappingService,
60 this.mappingService.getSchemaContext()).getValue();
61 final Topology topology = (Topology) RestconfUtils.dataObjectFromInputStream(topologyIdentifier, is,
62 this.mappingService.getSchemaContext(), this.mappingService, dataSchema);
64 assertNotNull(topology);
65 assertEquals(1, topology.getNode().size());
66 final Node node = topology.getNode().get(0);
67 assertEquals("bgpls://IsisLevel2:1/type=node&as=72&domain=673720360&router=0000.0000.0042", node.getNodeId()
70 final Node1 node1 = node.getAugmentation(Node1.class);
72 assertNotNull(node1.getIgpNodeAttributes());
73 assertEquals("Of-9k-02", node1.getIgpNodeAttributes().getName().getValue());
75 final IgpNodeAttributes1 igpAttributes1 = node1.getIgpNodeAttributes()
76 .getAugmentation(IgpNodeAttributes1.class);
77 assertNotNull(igpAttributes1);
78 assertNotNull(igpAttributes1.getIsisNodeAttributes());
79 assertEquals("66", igpAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());