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.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
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.MethodSignature;
21 import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class AugmentedTypeTest {
27 public void augmentedAbstractTopologyTest() {
28 final EffectiveModelContext context = YangParserTestUtils.parseYangResources(AugmentedTypeTest.class,
29 "/augment-test-models/abstract-topology@2013-02-08.yang",
30 "/augment-test-models/augment-abstract-topology@2013-05-03.yang",
31 "/augment-test-models/augment-network-link-attributes@2013-05-03.yang",
32 "/augment-test-models/augment-topology-tunnels@2013-05-03.yang",
33 "/augment-test-models/ietf-interfaces@2012-11-15.yang");
34 assertNotNull("Schema Context is null", context);
36 final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(context);
37 assertEquals(28, genTypes.size());
39 GeneratedTransferObject gtInterfaceKey = null;
40 GeneratedType gtInterface = null;
41 GeneratedType gtTunnel = null;
42 GeneratedTransferObject gtTunnelKey = null;
43 GeneratedType gtNetworkLink2 = null;
45 for (final GeneratedType type : genTypes) {
46 if (!type.getPackageName().contains("augment._abstract.topology")) {
50 if (type.getName().equals("InterfaceKey")) {
51 gtInterfaceKey = (GeneratedTransferObject) type;
52 } else if (type.getName().equals("Interface")) {
54 } else if (type.getName().equals("Tunnel")) {
56 } else if (type.getName().equals("TunnelKey")) {
57 gtTunnelKey = (GeneratedTransferObject) type;
58 } else if (type.getName().equals("NetworkLink2")) {
59 gtNetworkLink2 = type;
64 assertNotNull("gtInterface is null", gtInterface);
65 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
66 assertNotNull("gtInterfaceMethods is 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("getIfcKeyMethod is null", getIfcKeyMethod);
75 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
76 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
77 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
78 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType()
79 .getName().equals("InterfaceKey"));
81 MethodSignature getHigherLayerIfMethod = null;
82 for (final MethodSignature method : gtInterfaceMethods) {
83 if (method.getName().equals("getHigherLayerIf")) {
84 getHigherLayerIfMethod = method;
88 assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
89 assertNotNull("getHigherLayerIf method return type is null", getHigherLayerIfMethod.getReturnType());
90 assertTrue("getHigherLayerIf method return type name must be List", getHigherLayerIfMethod.getReturnType()
91 .getName().equals("List"));
94 assertNotNull("InterfaceKey is null", gtInterfaceKey);
95 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
96 assertNotNull("properties is null", properties);
97 GeneratedProperty gtInterfaceId = null;
98 for (final GeneratedProperty property : properties) {
99 if (property.getName().equals("interfaceId")) {
100 gtInterfaceId = property;
104 assertNotNull("interfaceId is null", gtInterfaceId);
105 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
106 assertTrue("interfaceId return type name must be String",
107 gtInterfaceId.getReturnType().getName().equals("String"));
110 assertNotNull("Tunnel is null", gtTunnel);
111 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
112 assertNotNull("Tunnel methods are null", tunnelMethods);
113 MethodSignature getTunnelKeyMethod = null;
114 for (MethodSignature method : tunnelMethods) {
115 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
116 getTunnelKeyMethod = method;
120 assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
121 assertNotNull("getKey method return type is null", getTunnelKeyMethod.getReturnType());
122 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
123 .equals("TunnelKey"));
126 assertNotNull("TunnelKey is null", gtTunnelKey);
127 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
128 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
130 GeneratedProperty gtTunnelId = null;
131 for (final GeneratedProperty property : tunnelKeyProperties) {
132 if (property.getName().equals("tunnelId")) {
133 gtTunnelId = property;
136 assertNotNull("tunnelId is null", gtTunnelId);
137 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
138 assertTrue("tunnelId returnType name must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
141 assertNotNull("NetworkLink2 is null", gtNetworkLink2);
143 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
144 assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
146 MethodSignature getIfcMethod = null;
147 for (MethodSignature method : networkLink2Methods) {
148 if (method.getName().equals("getInterface")) {
149 getIfcMethod = method;
154 assertNotNull("getInterface method is null", getIfcMethod);
155 assertNotNull("getInterface method return type is null", getIfcMethod.getReturnType());
156 assertTrue("getInterface method return type name must be String", getIfcMethod.getReturnType().getName()