2 * Copyright (c) 2016 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.mdsal.binding.generator.impl;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
20 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
21 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
22 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class AugmentRelativeXPathTest {
27 public void testAugmentationWithRelativeXPath() {
28 final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(
29 YangParserTestUtils.parseYangResourceDirectory("/augment-relative-xpath-models"));
30 assertNotNull("genTypes is null", genTypes);
31 assertEquals(26, genTypes.size());
33 GeneratedTransferObject gtInterfaceKey = null;
34 GeneratedType gtInterface = null;
35 GeneratedType gtTunnel = null;
36 GeneratedTransferObject gtTunnelKey = null;
38 for (final GeneratedType type : genTypes) {
39 if (!type.getPackageName().contains("augment._abstract.topology")) {
43 if (type.getName().equals("InterfaceKey")) {
44 gtInterfaceKey = (GeneratedTransferObject) type;
46 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
47 assertNotNull("InterfaceKey properties are null", properties);
48 assertEquals(1, properties.size());
50 final GeneratedProperty property = properties.get(0);
51 assertEquals("interfaceId", property.getName());
52 assertNotNull("interfaceId return type is null", property.getReturnType());
53 assertEquals(JavaTypeName.create(String.class), property.getReturnType().getIdentifier());
54 } else if (type.getName().equals("Interface")) {
57 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
58 assertNotNull("Interface methods are null", gtInterfaceMethods);
59 assertEquals(9, gtInterfaceMethods.size());
61 MethodSignature getIfcKeyMethod = null;
62 for (final MethodSignature method : gtInterfaceMethods) {
63 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
64 getIfcKeyMethod = method;
68 assertNotNull("getKey method is null", getIfcKeyMethod);
69 assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
70 assertEquals(JavaTypeName.create(
71 "org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology.rev130503.topology.interfaces",
73 getIfcKeyMethod.getReturnType().getIdentifier());
74 } else if (type.getName().equals("Tunnel")) {
77 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
78 assertNotNull("Tunnel methods are null", tunnelMethods);
79 assertEquals(7, tunnelMethods.size());
81 MethodSignature getTunnelKeyMethod = null;
82 for (MethodSignature method : tunnelMethods) {
83 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
84 getTunnelKeyMethod = method;
88 assertNotNull("getKey method is null", getTunnelKeyMethod);
89 assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
90 assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology"
91 + ".rev130503.topology.network.links.network.link.tunnels", "TunnelKey"),
92 getTunnelKeyMethod.getReturnType().getIdentifier());
93 } else if (type.getName().equals("TunnelKey")) {
94 assertThat(type, instanceOf(GeneratedTransferObject.class));
96 gtTunnelKey = (GeneratedTransferObject) type;
98 final List<GeneratedProperty> properties = gtTunnelKey.getProperties();
99 assertNotNull("TunnelKey properties are null", properties);
100 assertEquals(1, properties.size());
102 final GeneratedProperty property = properties.get(0);
103 assertEquals("tunnelId", property.getName());
104 assertNotNull("tunnelId return type is null", property.getReturnType());
106 JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev130208", "Uri"),
107 property.getReturnType().getIdentifier());
111 assertNotNull("Interface is null", gtInterface);
112 assertNotNull("InterfaceKey is null", gtInterfaceKey);
113 assertNotNull("Tunnel is null", gtTunnel);
114 assertNotNull("TunnelKey is null", gtTunnelKey);