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.getPackageName().contains("augment._abstract.topology")) {
55 if (type.getName().equals("InterfaceKey")) {
56 gtInterfaceKey = (GeneratedTransferObject) type;
57 } else if (type.getName().equals("Interface")) {
58 gtInterface = (GeneratedType) type;
59 } else if (type.getName().equals("Tunnel")) {
60 gtTunnel = (GeneratedType) type;
61 } else if (type.getName().equals("TunnelKey")) {
62 gtTunnelKey = (GeneratedTransferObject) type;
63 } else if (type.getName().equals("NetworkLink2")) {
64 gtNetworkLink2 = (GeneratedType) type;
69 assertNotNull("gtInterface is null", gtInterface);
70 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
71 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
72 MethodSignature getIfcKeyMethod = null;
73 for (final MethodSignature method : gtInterfaceMethods) {
74 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
75 getIfcKeyMethod = method;
79 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
80 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
81 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
82 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
83 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType()
84 .getName().equals("InterfaceKey"));
86 MethodSignature getHigherLayerIfMethod = null;
87 for (final MethodSignature method : gtInterfaceMethods) {
88 if (method.getName().equals("getHigherLayerIf")) {
89 getHigherLayerIfMethod = method;
93 assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
94 assertNotNull("getHigherLayerIf method return type is null", getHigherLayerIfMethod.getReturnType());
95 assertTrue("getHigherLayerIf method return type name must be List", getHigherLayerIfMethod.getReturnType()
96 .getName().equals("List"));
99 assertNotNull("InterfaceKey is null", gtInterfaceKey);
100 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
101 assertNotNull("properties is null", properties);
102 GeneratedProperty gtInterfaceId = null;
103 for (final GeneratedProperty property : properties) {
104 if (property.getName().equals("interfaceId")) {
105 gtInterfaceId = property;
109 assertNotNull("interfaceId is null", gtInterfaceId);
110 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
111 assertTrue("interfaceId return type name must be String",
112 gtInterfaceId.getReturnType().getName().equals("String"));
115 assertNotNull("Tunnel is null", gtTunnel);
116 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
117 assertNotNull("Tunnel methods are null", tunnelMethods);
118 MethodSignature getTunnelKeyMethod = null;
119 for (MethodSignature method : tunnelMethods) {
120 if (BindingMapping.IDENTIFIABLE_KEY_NAME.equals(method.getName())) {
121 getTunnelKeyMethod = method;
125 assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
126 assertNotNull("getKey method return type is null", getTunnelKeyMethod.getReturnType());
127 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
128 .equals("TunnelKey"));
131 assertNotNull("TunnelKey is null", gtTunnelKey);
132 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
133 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
135 GeneratedProperty gtTunnelId = null;
136 for (final GeneratedProperty property : tunnelKeyProperties) {
137 if (property.getName().equals("tunnelId")) {
138 gtTunnelId = property;
141 assertNotNull("tunnelId is null", gtTunnelId);
142 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
143 assertTrue("tunnelId returnType name must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
146 assertNotNull("NetworkLink2 is null", gtNetworkLink2);
148 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
149 assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
151 MethodSignature getIfcMethod = null;
152 for (MethodSignature method : networkLink2Methods) {
153 if (method.getName().equals("getInterface")) {
154 getIfcMethod = method;
159 assertNotNull("getInterface method is null", getIfcMethod);
160 assertNotNull("getInterface method return type is null", getIfcMethod.getReturnType());
161 assertTrue("getInterface method return type name must be String", getIfcMethod.getReturnType().getName()
166 public void augmentedNetworkLinkTest() {
171 public void augmentedTopologyTunnelsTest() {