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 AugmentedTypeTest {
29 public void augmentedAbstractTopologyTest() {
30 final SchemaContext context = YangParserTestUtils.parseYangResources(AugmentedTypeTest.class,
31 "/augment-test-models/abstract-topology@2013-02-08.yang",
32 "/augment-test-models/augment-abstract-topology@2013-05-03.yang",
33 "/augment-test-models/augment-network-link-attributes@2013-05-03.yang",
34 "/augment-test-models/augment-topology-tunnels@2013-05-03.yang",
35 "/augment-test-models/ietf-interfaces@2012-11-15.yang");
36 assertNotNull("Schema 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;
48 GeneratedType gtNetworkLink2 = null;
50 for (final Type type : genTypes) {
51 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
52 gtInterfaceKey = (GeneratedTransferObject) type;
53 } else if (type.getName().equals("Interface")
54 && type.getPackageName().contains("augment._abstract.topology")) {
55 gtInterface = (GeneratedType) type;
56 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
57 gtTunnel = (GeneratedType) type;
58 } else if (type.getName().equals("TunnelKey")
59 && type.getPackageName().contains("augment._abstract.topology")) {
60 gtTunnelKey = (GeneratedTransferObject) type;
61 } else if (type.getName().equals("NetworkLink2")
62 && type.getPackageName().contains("augment._abstract.topology")) {
63 gtNetworkLink2 = (GeneratedType) type;
68 assertNotNull("gtInterface is null", gtInterface);
69 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
70 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
71 MethodSignature getIfcKeyMethod = null;
72 for (final MethodSignature method : gtInterfaceMethods) {
73 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
74 getIfcKeyMethod = method;
78 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
79 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
80 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
81 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
82 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType()
83 .getName().equals("InterfaceKey"));
85 MethodSignature getHigherLayerIfMethod = null;
86 for (final MethodSignature method : gtInterfaceMethods) {
87 if (method.getName().equals("getHigherLayerIf")) {
88 getHigherLayerIfMethod = method;
92 assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
93 assertNotNull("getHigherLayerIf method return type is null", getHigherLayerIfMethod.getReturnType());
94 assertTrue("getHigherLayerIf method return type name must be List", getHigherLayerIfMethod.getReturnType()
95 .getName().equals("List"));
98 assertNotNull("InterfaceKey is null", gtInterfaceKey);
99 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
100 assertNotNull("properties is null", properties);
101 GeneratedProperty gtInterfaceId = null;
102 for (final GeneratedProperty property : properties) {
103 if (property.getName().equals("interfaceId")) {
104 gtInterfaceId = property;
108 assertNotNull("interfaceId is null", gtInterfaceId);
109 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
110 assertTrue("interfaceId return type name must be String",
111 gtInterfaceId.getReturnType().getName().equals("String"));
114 assertNotNull("Tunnel is null", gtTunnel);
115 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
116 assertNotNull("Tunnel methods are null", tunnelMethods);
117 MethodSignature getTunnelKeyMethod = null;
118 for (MethodSignature method : tunnelMethods) {
119 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
120 getTunnelKeyMethod = method;
124 assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
125 assertNotNull("getKey method return type is null", getTunnelKeyMethod.getReturnType());
126 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
127 .equals("TunnelKey"));
130 assertNotNull("TunnelKey is null", gtTunnelKey);
131 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
132 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
134 GeneratedProperty gtTunnelId = null;
135 for (final GeneratedProperty property : tunnelKeyProperties) {
136 if (property.getName().equals("tunnelId")) {
137 gtTunnelId = property;
140 assertNotNull("tunnelId is null", gtTunnelId);
141 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
142 assertTrue("tunnelId returnType name must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
145 assertNotNull("NetworkLink2 is null", gtNetworkLink2);
147 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
148 assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
150 MethodSignature getIfcMethod = null;
151 for (MethodSignature method : networkLink2Methods) {
152 if (method.getName().equals("getInterface")) {
153 getIfcMethod = method;
158 assertNotNull("getInterface method is null", getIfcMethod);
159 assertNotNull("getInterface method return type is null", getIfcMethod.getReturnType());
160 assertTrue("getInterface method return type name must be String", getIfcMethod.getReturnType().getName()
165 public void augmentedNetworkLinkTest() {
170 public void augmentedTopologyTunnelsTest() {