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 AugmentationWithRelativeXPathTest() {
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.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
51 gtInterfaceKey = (GeneratedTransferObject) type;
52 } else if (type.getName().equals("Interface")
53 && type.getPackageName().contains("augment._abstract.topology")) {
54 gtInterface = (GeneratedType) type;
55 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
56 gtTunnel = (GeneratedType) type;
57 } else if (type.getName().equals("TunnelKey")
58 && type.getPackageName().contains("augment._abstract.topology")) {
59 gtTunnelKey = (GeneratedTransferObject) type;
64 assertNotNull("Interface is null", gtInterface);
65 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
66 assertNotNull("Interface methods are null", gtInterfaceMethods);
67 MethodSignature getIfcKeyMethod = null;
68 for (final MethodSignature method : gtInterfaceMethods) {
69 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
70 getIfcKeyMethod = method;
74 assertNotNull("getKey method is null", getIfcKeyMethod);
75 assertNotNull("getKey method return type is null", getIfcKeyMethod.getReturnType());
76 assertTrue("getKey method return type name must be InterfaceKey", getIfcKeyMethod.getReturnType().getName()
77 .equals("InterfaceKey"));
80 assertNotNull("InterfaceKey is null", gtInterfaceKey);
81 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
82 assertNotNull("InterfaceKey properties are null", properties);
83 GeneratedProperty gtInterfaceId = null;
84 for (final GeneratedProperty property : properties) {
85 if (property.getName().equals("interfaceId")) {
86 gtInterfaceId = property;
90 assertNotNull("interfaceId is null", gtInterfaceId);
91 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
92 assertTrue("interfaceId return type name must be String",
93 gtInterfaceId.getReturnType().getName().equals("String"));
96 assertNotNull("Tunnel is null", gtTunnel);
97 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
98 assertNotNull("Tunnel methods are null", tunnelMethods);
99 MethodSignature getTunnelKeyMethod = null;
100 for (MethodSignature method : tunnelMethods) {
101 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
102 getTunnelKeyMethod = method;
106 assertNotNull("getKey method is null", getTunnelKeyMethod);
107 assertNotNull("getKey method return type", getTunnelKeyMethod.getReturnType());
108 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
109 .equals("TunnelKey"));
112 assertNotNull("TunnelKey is null", gtTunnelKey);
113 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
114 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
116 GeneratedProperty gtTunnelId = null;
117 for (final GeneratedProperty property : tunnelKeyProperties) {
118 if (property.getName().equals("tunnelId")) {
119 gtTunnelId = property;
122 assertNotNull("tunnelId is null", gtTunnelId);
123 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
124 assertTrue("tunnelId return type name must be Uri", gtTunnelId.getReturnType().getName().equals("Uri"));