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 org.junit.BeforeClass;
11 import org.junit.Test;
12 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
13 import org.opendaylight.controller.sal.binding.model.api.*;
14 import org.opendaylight.controller.yang.model.api.Module;
15 import org.opendaylight.controller.yang.model.api.SchemaContext;
16 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
17 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
20 import java.util.ArrayList;
21 import java.util.List;
24 import static org.junit.Assert.*;
26 public class AugmentedTypeTest {
28 private final static List<File> augmentModels = new ArrayList<>();
29 private final static String augmentFolderPath = AugmentedTypeTest.class
30 .getResource("/augment-test-models").getPath();
33 public static void loadTestResources() {
34 final File augFolder = new File(augmentFolderPath);
36 for (final File fileEntry : augFolder.listFiles()) {
37 if (fileEntry.isFile()) {
38 augmentModels.add(fileEntry);
44 public void augmentedAbstractTopologyTest() {
45 final YangModelParser parser = new YangParserImpl();
46 final Set<Module> modules = parser.parseYangModels(augmentModels);
47 final SchemaContext context = parser.resolveSchemaContext(modules);
49 assertNotNull("context is null", context);
50 final BindingGenerator bindingGen = new BindingGeneratorImpl();
51 final List<Type> genTypes = bindingGen.generateTypes(context);
53 assertNotNull("genTypes is null", genTypes);
54 assertFalse("genTypes is empty", genTypes.isEmpty());
56 GeneratedTransferObject gtInterfaceKey = null;
57 GeneratedType gtInterface = null;
58 GeneratedType gtTunnel = null;
59 GeneratedTransferObject gtTunnelKey = null;
60 GeneratedType gtNetworkLink2 = null;
62 for (final Type type : genTypes) {
63 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
64 gtInterfaceKey = (GeneratedTransferObject) type;
65 } else if (type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
66 gtInterface = (GeneratedType) type;
67 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
68 gtTunnel = (GeneratedType) type;
69 } else if (type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
70 gtTunnelKey = (GeneratedTransferObject) type;
71 } else if (type.getName().equals("NetworkLink2") && type.getPackageName().contains("augment._abstract.topology")) {
72 gtNetworkLink2 = (GeneratedType) type;
77 assertNotNull("gtInterface is null", gtInterface);
78 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
79 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
80 MethodSignature getIfcKeyMethod = null;
81 for (final MethodSignature method : gtInterfaceMethods) {
82 if (method.getName().equals("getInterfaceKey")) {
83 getIfcKeyMethod = method;
87 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
88 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
89 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
90 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
91 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",
92 getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
94 MethodSignature getHigherLayerIfMethod = null;
95 for (final MethodSignature method : gtInterfaceMethods) {
96 if (method.getName().equals("getHigherLayerIf")) {
97 getHigherLayerIfMethod = method;
101 assertNotNull("getHigherLayerIfMethod is null", getHigherLayerIfMethod);
102 assertNotNull("getHigherLayerIfMethod.getReturnType() is null",
103 getHigherLayerIfMethod.getReturnType());
104 assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void",
105 getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));
106 assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List",
107 getHigherLayerIfMethod.getReturnType().getName().equals("List"));
110 assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
111 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
112 assertNotNull("properties is null", properties);
113 GeneratedProperty gtInterfaceId = null;
114 for (final GeneratedProperty property : properties) {
115 if (property.getName().equals("InterfaceId")) {
116 gtInterfaceId = property;
120 assertNotNull("gtInterfaceId is null", gtInterfaceId);
121 assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
122 assertFalse("gtInterfaceId.getReturnType() should not be Void",
123 gtInterfaceId.getReturnType().equals("java.lang.Void"));
124 assertTrue("gtInterfaceId.getReturnType().getName() must be String",
125 gtInterfaceId.getReturnType().getName().equals("String"));
128 assertNotNull("gtTunnel is null", gtTunnel);
129 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
130 assertNotNull("tunnelMethods is null", tunnelMethods);
131 MethodSignature getTunnelKeyMethod = null;
132 for (MethodSignature method : tunnelMethods) {
133 if (method.getName().equals("getTunnelKey")) {
134 getTunnelKeyMethod = method;
138 assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
139 assertNotNull("getTunnelKeyMethod.getReturnType()",
140 getTunnelKeyMethod.getReturnType());
141 assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",
142 getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
143 assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",
144 getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
147 assertNotNull("gtTunnelKey is null", gtTunnelKey);
148 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
149 assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
151 GeneratedProperty gtTunnelId = null;
152 for (final GeneratedProperty property : tunnelKeyProperties) {
153 if (property.getName().equals("TunnelId")) {
154 gtTunnelId = property;
157 assertNotNull("gtTunnelId is null", gtTunnelId);
158 assertNotNull("gtTunnelId.getReturnType() is null",
159 gtTunnelId.getReturnType());
160 assertFalse("gtTunnelId.getReturnType() should not be Void",
161 gtTunnelId.getReturnType().equals("java.lang.Void"));
162 assertTrue("gtTunnelId.getReturnType().getName() must be Integer",
163 gtTunnelId.getReturnType().getName().equals("Integer"));
166 assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);
168 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
169 assertNotNull("networkLink2Methods is null", networkLink2Methods);
171 // FIXME: in some cases getIfcMethod is null which causes test fail. fix ASAP
172 // MethodSignature getIfcMethod = null;
173 // for (MethodSignature method : networkLink2Methods) {
174 // if (method.getName().equals("getInterface")) {
175 // getIfcMethod = method;
180 // assertNotNull("getIfcMethod is null", getIfcMethod);
181 // assertNotNull("getIfcMethod.getReturnType() is null", getIfcMethod.getReturnType());
182 // assertFalse("getIfcMethod.getReturnType() should not be Void", getIfcMethod.getReturnType().equals("java.lang.Void"));
183 // assertTrue("getIfcMethod.getReturnType().getName() must be String", getIfcMethod.getReturnType().getName().equals("String"));
187 public void augmentedNetworkLinkTest() {
192 public void augmentedTopologyTunnelsTest() {