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.network.topology.Topology;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
24 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
25 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
28 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
30 public class RestconfUtilsTest {
32 private RuntimeGeneratedMappingServiceImpl mappingService;
36 this.mappingService = new RuntimeGeneratedMappingServiceImpl(new ClassPool());
38 final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
39 moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
40 this.mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get());
44 public void testToDataObjectMappingWithNestedAugmentations() {
45 final InstanceIdentifier<Topology> topologyIdentifier = InstanceIdentifier.builder(NetworkTopology.class)
46 .child(Topology.class).build();
47 final InputStream is = this.getClass().getClassLoader().getResourceAsStream("topology.xml");
48 final DataSchemaNode dataSchema = RestconfUtils.toRestconfIdentifier(topologyIdentifier, this.mappingService,
49 this.mappingService.getSchemaContext()).getValue();
50 final Topology topology = (Topology) RestconfUtils.dataObjectFromInputStream(topologyIdentifier, is,
51 this.mappingService.getSchemaContext(), this.mappingService, dataSchema);
53 assertNotNull(topology);
54 assertEquals(1, topology.getNode().size());
55 final Node node = topology.getNode().get(0);
56 assertEquals("bgpls://IsisLevel2:1/type=node&as=72&domain=673720360&router=0000.0000.0042", node.getNodeId()
59 final Node1 node1 = node.getAugmentation(Node1.class);
61 assertNotNull(node1.getIgpNodeAttributes());
62 assertEquals("Of-9k-02", node1.getIgpNodeAttributes().getName().getValue());
64 final IgpNodeAttributes1 igpAttributes1 = node1.getIgpNodeAttributes()
65 .getAugmentation(IgpNodeAttributes1.class);
66 assertNotNull(igpAttributes1);
67 assertNotNull(igpAttributes1.getIsisNodeAttributes());
68 assertEquals("66", igpAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());