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.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.net.URISyntaxException;
17 import java.util.ArrayList;
18 import java.util.List;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
24 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
25 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
26 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
27 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
28 import org.opendaylight.yangtools.sal.binding.model.api.Type;
29 import org.opendaylight.yangtools.yang.model.api.Module;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
31 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
32 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
34 public class AugmentedTypeTest {
36 private final static List<File> augmentModels = new ArrayList<>();
37 private final static URL augmentFolderPath = AugmentedTypeTest.class
38 .getResource("/augment-test-models");
41 public static void loadTestResources() throws URISyntaxException {
42 final File augFolder = new File(augmentFolderPath.toURI());
44 for (final File fileEntry : augFolder.listFiles()) {
45 if (fileEntry.isFile()) {
46 augmentModels.add(fileEntry);
52 public void augmentedAbstractTopologyTest() {
53 final YangModelParser parser = new YangParserImpl();
54 final Set<Module> modules = parser.parseYangModels(augmentModels);
55 final SchemaContext context = parser.resolveSchemaContext(modules);
57 assertNotNull("context is null", context);
58 final BindingGenerator bindingGen = new BindingGeneratorImpl();
59 final List<Type> genTypes = bindingGen.generateTypes(context);
61 assertNotNull("genTypes is null", genTypes);
62 assertFalse("genTypes is empty", genTypes.isEmpty());
64 GeneratedTransferObject gtInterfaceKey = null;
65 GeneratedType gtInterface = null;
66 GeneratedType gtTunnel = null;
67 GeneratedTransferObject gtTunnelKey = null;
68 GeneratedType gtNetworkLink2 = null;
70 for (final Type type : genTypes) {
71 if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
72 gtInterfaceKey = (GeneratedTransferObject) type;
73 } else if (type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
74 gtInterface = (GeneratedType) type;
75 } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
76 gtTunnel = (GeneratedType) type;
77 } else if (type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
78 gtTunnelKey = (GeneratedTransferObject) type;
79 } else if (type.getName().equals("NetworkLink2") && type.getPackageName().contains("augment._abstract.topology")) {
80 gtNetworkLink2 = (GeneratedType) type;
85 assertNotNull("gtInterface is null", gtInterface);
86 final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
87 assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
88 MethodSignature getIfcKeyMethod = null;
89 for (final MethodSignature method : gtInterfaceMethods) {
90 if (method.getName().equals("getKey")) {
91 getIfcKeyMethod = method;
95 assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
96 assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
97 assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
98 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
99 assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",
100 getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
102 MethodSignature getHigherLayerIfMethod = null;
103 for (final MethodSignature method : gtInterfaceMethods) {
104 if (method.getName().equals("getHigherLayerIf")) {
105 getHigherLayerIfMethod = method;
109 assertNotNull("getHigherLayerIfMethod is null", getHigherLayerIfMethod);
110 assertNotNull("getHigherLayerIfMethod.getReturnType() is null",
111 getHigherLayerIfMethod.getReturnType());
112 assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void",
113 getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));
114 assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List",
115 getHigherLayerIfMethod.getReturnType().getName().equals("List"));
118 assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
119 final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
120 assertNotNull("properties is null", properties);
121 GeneratedProperty gtInterfaceId = null;
122 for (final GeneratedProperty property : properties) {
123 if (property.getName().equals("interfaceId")) {
124 gtInterfaceId = property;
128 assertNotNull("gtInterfaceId is null", gtInterfaceId);
129 assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
130 assertFalse("gtInterfaceId.getReturnType() should not be Void",
131 gtInterfaceId.getReturnType().equals("java.lang.Void"));
132 assertTrue("gtInterfaceId.getReturnType().getName() must be String",
133 gtInterfaceId.getReturnType().getName().equals("String"));
136 assertNotNull("gtTunnel is null", gtTunnel);
137 final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
138 assertNotNull("tunnelMethods is null", tunnelMethods);
139 MethodSignature getTunnelKeyMethod = null;
140 for (MethodSignature method : tunnelMethods) {
141 if (method.getName().equals("getKey")) {
142 getTunnelKeyMethod = method;
146 assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
147 assertNotNull("getTunnelKeyMethod.getReturnType()",
148 getTunnelKeyMethod.getReturnType());
149 assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",
150 getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
151 assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",
152 getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
155 assertNotNull("gtTunnelKey is null", gtTunnelKey);
156 final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
157 assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
159 GeneratedProperty gtTunnelId = null;
160 for (final GeneratedProperty property : tunnelKeyProperties) {
161 if (property.getName().equals("tunnelId")) {
162 gtTunnelId = property;
165 assertNotNull("gtTunnelId is null", gtTunnelId);
166 assertNotNull("gtTunnelId.getReturnType() is null",
167 gtTunnelId.getReturnType());
168 assertFalse("gtTunnelId.getReturnType() should not be Void",
169 gtTunnelId.getReturnType().equals("java.lang.Void"));
170 assertTrue("gtTunnelId.getReturnType().getName() must be Integer",
171 gtTunnelId.getReturnType().getName().equals("Integer"));
174 assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);
176 final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
177 assertNotNull("networkLink2Methods is null", networkLink2Methods);
179 // FIXME: in some cases getIfcMethod is null which causes test fail. fix ASAP
180 // MethodSignature getIfcMethod = null;
181 // for (MethodSignature method : networkLink2Methods) {
182 // if (method.getName().equals("getInterface")) {
183 // getIfcMethod = method;
188 // assertNotNull("getIfcMethod is null", getIfcMethod);
189 // assertNotNull("getIfcMethod.getReturnType() is null", getIfcMethod.getReturnType());
190 // assertFalse("getIfcMethod.getReturnType() should not be Void", getIfcMethod.getReturnType().equals("java.lang.Void"));
191 // assertTrue("getIfcMethod.getReturnType().getName() must be String", getIfcMethod.getReturnType().getName().equals("String"));
195 public void augmentedNetworkLinkTest() {
200 public void augmentedTopologyTunnelsTest() {