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.yangtools.sal.binding.generator.impl;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
20 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
21 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
22 import org.opendaylight.mdsal.binding.model.api.Type;
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() throws Exception {
30 File abstractTopology = new File(getClass().getResource(
31 "/augment-test-models/abstract-topology@2013-02-08.yang").toURI());
32 File augmentTopology = new File(getClass().getResource(
33 "/augment-test-models/augment-abstract-topology@2013-05-03.yang").toURI());
34 File augmentNetworkLink = new File(getClass().getResource(
35 "/augment-test-models/augment-network-link-attributes@2013-05-03.yang").toURI());
36 File augmentTopologyTunnels = new File(getClass().getResource(
37 "/augment-test-models/augment-topology-tunnels@2013-05-03.yang").toURI());
38 File ietfInterfaces = new File(getClass().getResource("/augment-test-models/ietf-interfaces@2012-11-15.yang")
41 final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, augmentTopology,
42 augmentNetworkLink, augmentTopologyTunnels, ietfInterfaces);
43 assertNotNull("Schema Context is null", context);
45 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
46 final List<Type> genTypes = bindingGen.generateTypes(context);
48 assertNotNull("genTypes is null", genTypes);
49 assertFalse("genTypes is empty", genTypes.isEmpty());
51 GeneratedTransferObject gtInterfaceKey = null;
52 GeneratedType gtInterface = null;
53 GeneratedType gtTunnel = null;
54 GeneratedTransferObject gtTunnelKey = null;
55 GeneratedType gtNetworkLink2 = null;
57 for (final Type type : genTypes) {
58 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
59 gtInterfaceKey = (GeneratedTransferObject) type;
60 } else if (type.getName().equals("Interface")
61 && type.getPackageName().contains("augment._abstract.topology")) {
62 gtInterface = (GeneratedType) type;
63 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
64 gtTunnel = (GeneratedType) type;
65 } else if (type.getName().equals("TunnelKey")
66 && type.getPackageName().contains("augment._abstract.topology")) {
67 gtTunnelKey = (GeneratedTransferObject) type;
68 } else if (type.getName().equals("NetworkLink2")
69 && type.getPackageName().contains("augment._abstract.topology")) {
70 gtNetworkLink2 = (GeneratedType) type;
75 assertNotNull("gtInterface is null", gtInterface);
76 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
77 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
78 MethodSignature getIfcKeyMethod = null;
79 for (final MethodSignature method : gtInterfaceMethods) {
80 if (method.getName().equals("getKey")) {
81 getIfcKeyMethod = method;
85 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
86 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
87 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
88 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
89 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType()
90 .getName().equals("InterfaceKey"));
92 MethodSignature getHigherLayerIfMethod = null;
93 for (final MethodSignature method : gtInterfaceMethods) {
94 if (method.getName().equals("getHigherLayerIf")) {
95 getHigherLayerIfMethod = method;
99 assertNotNull("getHigherLayerIf method is null", getHigherLayerIfMethod);
100 assertNotNull("getHigherLayerIf method return type is null", getHigherLayerIfMethod.getReturnType());
101 assertTrue("getHigherLayerIf method return type name must be List", getHigherLayerIfMethod.getReturnType()
102 .getName().equals("List"));
105 assertNotNull("InterfaceKey is null", gtInterfaceKey);
106 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
107 assertNotNull("properties is null", properties);
108 GeneratedProperty gtInterfaceId = null;
109 for (final GeneratedProperty property : properties) {
110 if (property.getName().equals("interfaceId")) {
111 gtInterfaceId = property;
115 assertNotNull("interfaceId is null", gtInterfaceId);
116 assertNotNull("interfaceId return type is null", gtInterfaceId.getReturnType());
117 assertTrue("interfaceId return type name must be String",
118 gtInterfaceId.getReturnType().getName().equals("String"));
121 assertNotNull("Tunnel is null", gtTunnel);
122 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
123 assertNotNull("Tunnel methods are null", tunnelMethods);
124 MethodSignature getTunnelKeyMethod = null;
125 for (MethodSignature method : tunnelMethods) {
126 if (method.getName().equals("getKey")) {
127 getTunnelKeyMethod = method;
131 assertNotNull("getKey method of Tunnel is null", getTunnelKeyMethod);
132 assertNotNull("getKey method return type is null", getTunnelKeyMethod.getReturnType());
133 assertTrue("getKey method return type name must be TunnelKey", getTunnelKeyMethod.getReturnType().getName()
134 .equals("TunnelKey"));
137 assertNotNull("TunnelKey is null", gtTunnelKey);
138 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
139 assertNotNull("TunnelKey properties are null", tunnelKeyProperties);
141 GeneratedProperty gtTunnelId = null;
142 for (final GeneratedProperty property : tunnelKeyProperties) {
143 if (property.getName().equals("tunnelId")) {
144 gtTunnelId = property;
147 assertNotNull("tunnelId is null", gtTunnelId);
148 assertNotNull("tunnelId return type is null", gtTunnelId.getReturnType());
149 assertTrue("tunnelId returnType name must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
152 assertNotNull("NetworkLink2 is null", gtNetworkLink2);
154 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
155 assertNotNull("NetworkLink2 methods are null", networkLink2Methods);
157 MethodSignature getIfcMethod = null;
158 for (MethodSignature method : networkLink2Methods) {
159 if (method.getName().equals("getInterface")) {
160 getIfcMethod = method;
165 assertNotNull("getInterface method is null", getIfcMethod);
166 assertNotNull("getInterface method return type is null", getIfcMethod.getReturnType());
167 assertTrue("getInterface method return type name must be String", getIfcMethod.getReturnType().getName()
172 public void augmentedNetworkLinkTest() {
177 public void augmentedTopologyTunnelsTest() {