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;
14 import java.util.ArrayList;
15 import java.util.List;
17 import javassist.ClassPool;
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;
35 import com.google.common.collect.Lists;
37 public class RestconfUtilsTest {
39 private RuntimeGeneratedMappingServiceImpl mappingService;
43 this.mappingService = new RuntimeGeneratedMappingServiceImpl();
44 this.mappingService.setPool(new ClassPool());
45 this.mappingService.init();
47 final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
48 moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
49 this.mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get());
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);
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()
68 final Node1 node1 = node.getAugmentation(Node1.class);
70 assertNotNull(node1.getIgpNodeAttributes());
71 assertEquals("Of-9k-02", node1.getIgpNodeAttributes().getName().getValue());
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());