2 * Copyright (c) 2013 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.controller.sal.binding.generator.impl;
10 import static org.junit.Assert.*;
13 import java.util.ArrayList;
14 import java.util.List;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
20 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
21 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
22 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
23 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
24 import org.opendaylight.controller.sal.binding.model.api.Type;
25 import org.opendaylight.controller.yang.model.api.Module;
26 import org.opendaylight.controller.yang.model.api.SchemaContext;
27 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
28 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
30 public class AugmentedTypeTest {
32 private final static List<File> augmentModels = new ArrayList<>();
33 private final static String augmentFolderPath = AugmentedTypeTest.class
34 .getResource("/augment-test-models").getPath();
37 public static void loadTestResources() {
38 final File augFolder = new File(augmentFolderPath);
40 for (final File fileEntry : augFolder.listFiles()) {
41 if (fileEntry.isFile()) {
42 augmentModels.add(fileEntry);
48 public void augmentedAbstractTopologyTest() {
49 final YangModelParser parser = new YangParserImpl();
50 final Set<Module> modules = parser.parseYangModels(augmentModels);
51 final SchemaContext context = parser.resolveSchemaContext(modules);
53 assertNotNull("context is null", context);
54 final BindingGenerator bindingGen = new BindingGeneratorImpl();
55 final List<Type> genTypes = bindingGen.generateTypes(context);
57 assertNotNull("genTypes is null", genTypes);
58 assertFalse("genTypes is empty", genTypes.isEmpty());
60 GeneratedTransferObject gtInterfaceKey = null;
61 GeneratedType gtInterface = null;
62 GeneratedType gtTunnel = null;
63 GeneratedTransferObject gtTunnelKey = null;
64 GeneratedType gtNetworkLink2 = null;
66 for(final Type type : genTypes) {
67 if(type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
68 gtInterfaceKey = (GeneratedTransferObject) type;
69 } else if(type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
70 gtInterface = (GeneratedType) type;
71 } else if(type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
72 gtTunnel = (GeneratedType) type;
73 } else if(type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
74 gtTunnelKey = (GeneratedTransferObject) type;
75 } else if(type.getName().equals("NetworkLink2") && type.getPackageName().contains("augment._abstract.topology")) {
76 gtNetworkLink2 = (GeneratedType) type;
81 assertNotNull("gtInterface is null", gtInterface);
82 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
83 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
84 MethodSignature getIfcKeyMethod = null;
85 for (final MethodSignature method : gtInterfaceMethods) {
86 if (method.getName().equals("getInterfaceKey")) {
87 getIfcKeyMethod = method;
91 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
92 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
93 assertFalse("getIfcKeyMethod.getReturnType() should not be Void", getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
94 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey", getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
96 MethodSignature getHigherLayerIfMethod = null;
97 for (final MethodSignature method : gtInterfaceMethods) {
98 if (method.getName().equals("getHigherLayerIf")) {
99 getHigherLayerIfMethod = method;
103 assertNotNull("getHigherLayerIfMethod is null", getHigherLayerIfMethod);
104 assertNotNull("getHigherLayerIfMethod.getReturnType() is null", getHigherLayerIfMethod.getReturnType());
105 assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void", getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));
106 assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List", getHigherLayerIfMethod.getReturnType().getName().equals("List"));
109 assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
110 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
111 assertNotNull("properties is null", properties);
112 GeneratedProperty gtInterfaceId = null;
113 for (final GeneratedProperty property : properties) {
114 if (property.getName().equals("InterfaceId")) {
115 gtInterfaceId = property;
119 assertNotNull("gtInterfaceId is null", gtInterfaceId);
120 assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
121 assertFalse("gtInterfaceId.getReturnType() should not be Void", gtInterfaceId.getReturnType().equals("java.lang.Void"));
122 assertTrue("gtInterfaceId.getReturnType().getName() must be String", gtInterfaceId.getReturnType().getName().equals("String"));
125 assertNotNull("gtTunnel is null", gtTunnel);
126 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
127 assertNotNull("tunnelMethods is null", tunnelMethods);
128 MethodSignature getTunnelKeyMethod = null;
129 for (MethodSignature method : tunnelMethods) {
130 if (method.getName().equals("getTunnelKey")) {
131 getTunnelKeyMethod = method;
135 assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
136 assertNotNull("getTunnelKeyMethod.getReturnType()", getTunnelKeyMethod.getReturnType());
137 assertFalse("getTunnelKeyMethod.getReturnType() should not be Void", getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
138 assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey", getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
141 assertNotNull("gtTunnelKey is null", gtTunnelKey);
142 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
143 assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
145 GeneratedProperty gtTunnelId = null;
146 for (final GeneratedProperty property : tunnelKeyProperties) {
147 if (property.getName().equals("TunnelId")) {
148 gtTunnelId = property;
151 assertNotNull("gtTunnelId is null", gtTunnelId);
152 assertNotNull("gtTunnelId.getReturnType() is null", gtTunnelId.getReturnType());
153 assertFalse("gtTunnelId.getReturnType() should not be Void", gtTunnelId.getReturnType().equals("java.lang.Void"));
154 assertTrue("gtTunnelId.getReturnType().getName() must be Integer", gtTunnelId.getReturnType().getName().equals("Integer"));
157 assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);
159 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
160 assertNotNull("networkLink2Methods is null", networkLink2Methods);
161 // FIXME: in some cases getIfcMethod is null which causes test fail. fix ASAP
162 // MethodSignature getIfcMethod = null;
163 // for (MethodSignature method : networkLink2Methods) {
164 // if (method.getName().equals("getInterface")) {
165 // getIfcMethod = method;
170 // assertNotNull("getIfcMethod is null", getIfcMethod);
171 // assertNotNull("getIfcMethod.getReturnType() is null", getIfcMethod.getReturnType());
172 // assertFalse("getIfcMethod.getReturnType() should not be Void", getIfcMethod.getReturnType().equals("java.lang.Void"));
173 // assertTrue("getIfcMethod.getReturnType().getName() must be String", getIfcMethod.getReturnType().getName().equals("String"));
177 public void augmentedNetworkLinkTest() {
182 public void augmentedTopologyTunnelsTest() {