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.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
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.MethodSignature;
21 import org.opendaylight.mdsal.binding.model.api.Type;
22 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class AugmentRelativeXPathTest extends AbstractTypesTest {
28 public AugmentRelativeXPathTest() {
29 super(AugmentRelativeXPathTest.class.getResource("/augment-relative-xpath-models"));
33 public void testAugmentationWithRelativeXPath() {
35 final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
37 assertNotNull("context is null", context);
38 final BindingGenerator bindingGen = new BindingGeneratorImpl();
39 final List<Type> genTypes = bindingGen.generateTypes(context);
41 assertNotNull("genTypes is null", genTypes);
42 assertFalse("genTypes is empty", genTypes.isEmpty());
44 GeneratedTransferObject gtInterfaceKey = null;
45 GeneratedType gtInterface = null;
46 GeneratedType gtTunnel = null;
47 GeneratedTransferObject gtTunnelKey = null;
49 for (final Type type : genTypes) {
50 if (!type.getPackageName().contains("augment._abstract.topology")) {
54 if (type.getName().equals("InterfaceKey")) {
55 gtInterfaceKey = (GeneratedTransferObject) type;
56 } else if (type.getName().equals("Interface")) {
57 gtInterface = (GeneratedType) type;
58 } else if (type.getName().equals("Tunnel")) {
59 gtTunnel = (GeneratedType) type;
60 } else if (type.getName().equals("TunnelKey")) {
61 gtTunnelKey = (GeneratedTransferObject) type;
66 assertNotNull("Interface is null", gtInterface);
67 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
68 assertNotNull("Interface methods are null", gtInterfaceMethods);
69 MethodSignature getIfcKeyMethod = null;
70 for (final MethodSignature method : gtInterfaceMethods) {
71 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
72 getIfcKeyMethod = method;
76 assertNotNull("getKey method is null", getIfcKeyMethod);
77 assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
78 assertTrue("getKey method return type name must be InterfaceKey", getIfcKeyMethod.getReturnType().getName()
79 .equals("InterfaceKey"));
82 assertNotNull("InterfaceKey is null", gtInterfaceKey);
83 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
84 assertNotNull("InterfaceKey properties are null", properties);
85 GeneratedProperty gtInterfaceId = null;
86 for (final GeneratedProperty property : properties) {
87 if (property.getName().equals("interfaceId")) {
88 gtInterfaceId = property;
92 assertNotNull("interfaceId is null", gtInterfaceId);
93 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
94 assertTrue("interfaceId return type name must be String",
95 gtInterfaceId.getReturnType().getName().equals("String"));
98 assertNotNull("Tunnel is null", gtTunnel);
99 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
100 assertNotNull("Tunnel methods are null", tunnelMethods);
101 MethodSignature getTunnelKeyMethod = null;
102 for (MethodSignature method : tunnelMethods) {
103 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
104 getTunnelKeyMethod = method;
108 assertNotNull("getKey method is null", getTunnelKeyMethod);
109 assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
110 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
111 .equals("TunnelKey"));
114 assertNotNull("TunnelKey is null", gtTunnelKey);
115 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
116 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
118 GeneratedProperty gtTunnelId = null;
119 for (final GeneratedProperty property : tunnelKeyProperties) {
120 if (property.getName().equals("tunnelId")) {
121 gtTunnelId = property;
124 assertNotNull("tunnelId is null", gtTunnelId);
125 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
126 assertTrue("tunnelId return type name must be Uri", gtTunnelId.getReturnType().getName().equals("Uri"));