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 extends AbstractTypesTest {
27 public AugmentRelativeXPathTest() {
28 super(AugmentRelativeXPathTest.class.getResource("/augment-relative-xpath-models"));
32 public void testAugmentationWithRelativeXPath() {
33 final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(
34 YangParserTestUtils.parseYangFiles(testModels));
35 assertNotNull("genTypes is null", genTypes);
36 assertEquals(26, genTypes.size());
38 GeneratedTransferObject gtInterfaceKey = null;
39 GeneratedType gtInterface = null;
40 GeneratedType gtTunnel = null;
41 GeneratedTransferObject gtTunnelKey = null;
43 for (final GeneratedType type : genTypes) {
44 if (!type.getPackageName().contains("augment._abstract.topology")) {
48 if (type.getName().equals("InterfaceKey")) {
49 gtInterfaceKey = (GeneratedTransferObject) type;
51 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
52 assertNotNull("InterfaceKey properties are null", properties);
53 assertEquals(1, properties.size());
55 final GeneratedProperty property = properties.get(0);
56 assertEquals("interfaceId", property.getName());
57 assertNotNull("interfaceId return type is null", property.getReturnType());
58 assertEquals(JavaTypeName.create(String.class), property.getReturnType().getIdentifier());
59 } else if (type.getName().equals("Interface")) {
62 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
63 assertNotNull("Interface methods are null", gtInterfaceMethods);
64 assertEquals(7, gtInterfaceMethods.size());
66 MethodSignature getIfcKeyMethod = null;
67 for (final MethodSignature method : gtInterfaceMethods) {
68 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
69 getIfcKeyMethod = method;
73 assertNotNull("getKey method is null", getIfcKeyMethod);
74 assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
75 assertEquals(JavaTypeName.create(
76 "org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology.rev130503.topology.interfaces",
78 getIfcKeyMethod.getReturnType().getIdentifier());
79 } else if (type.getName().equals("Tunnel")) {
82 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
83 assertNotNull("Tunnel methods are null", tunnelMethods);
84 assertEquals(6, tunnelMethods.size());
86 MethodSignature getTunnelKeyMethod = null;
87 for (MethodSignature method : tunnelMethods) {
88 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
89 getTunnelKeyMethod = method;
93 assertNotNull("getKey method is null", getTunnelKeyMethod);
94 assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
95 assertEquals(JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model.augment._abstract.topology"
96 + ".rev130503.topology.network.links.network.link.tunnels", "TunnelKey"),
97 getTunnelKeyMethod.getReturnType().getIdentifier());
98 } else if (type.getName().equals("TunnelKey")) {
99 assertThat(type, instanceOf(GeneratedTransferObject.class));
101 gtTunnelKey = (GeneratedTransferObject) type;
103 final List<GeneratedProperty> properties = gtTunnelKey.getProperties();
104 assertNotNull("TunnelKey properties are null", properties);
105 assertEquals(1, properties.size());
107 final GeneratedProperty property = properties.get(0);
108 assertEquals("tunnelId", property.getName());
109 assertNotNull("tunnelId return type is null", property.getReturnType());
111 JavaTypeName.create("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev130208", "Uri"),
112 property.getReturnType().getIdentifier());
116 assertNotNull("Interface is null", gtInterface);
117 assertNotNull("InterfaceKey is null", gtInterfaceKey);
118 assertNotNull("Tunnel is null", gtTunnel);
119 assertNotNull("TunnelKey is null", gtTunnelKey);