Merge "OF plugin classes must have a strict dependency on Connection Service"
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-impl / src / test / java / org / opendaylight / controller / sal / binding / generator / impl / AugmentedTypeTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.binding.generator.impl;
9
10 import static org.junit.Assert.*;
11
12 import java.io.File;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Set;
16
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.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
28 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
29
30 public class AugmentedTypeTest {
31
32     private final static List<File> augmentModels = new ArrayList<>();
33     private final static String augmentFolderPath = AugmentedTypeTest.class
34             .getResource("/augment-test-models").getPath();
35
36     @BeforeClass
37     public static void loadTestResources() {
38         final File augFolder = new File(augmentFolderPath);
39
40         for (final File fileEntry : augFolder.listFiles()) {
41             if (fileEntry.isFile()) {
42                 augmentModels.add(fileEntry);
43             }
44         }
45     }
46
47     @Test
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);
52
53         assertNotNull("context is null", context);
54         final BindingGenerator bindingGen = new BindingGeneratorImpl();
55         final List<Type> genTypes = bindingGen.generateTypes(context);
56
57         assertNotNull("genTypes is null", genTypes);
58         assertFalse("genTypes is empty", genTypes.isEmpty());
59
60         GeneratedTransferObject gtInterfaceKey = null;
61         GeneratedType gtInterface = null;
62         GeneratedType gtTunnel = null;
63         GeneratedTransferObject gtTunnelKey = null;
64         GeneratedType gtNetworkLink2 = null;
65
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;
77             }
78         }
79
80         // 'Interface
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;
88                 break;
89             }
90         }
91         assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
92         assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
93         assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
94                 getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
95         assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",
96                 getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
97
98         MethodSignature getHigherLayerIfMethod = null;
99         for (final MethodSignature method : gtInterfaceMethods) {
100             if (method.getName().equals("getHigherLayerIf")) {
101                 getHigherLayerIfMethod = method;
102                 break;
103             }
104         }
105         assertNotNull("getHigherLayerIfMethod is null", getHigherLayerIfMethod);
106         assertNotNull("getHigherLayerIfMethod.getReturnType() is null",
107                 getHigherLayerIfMethod.getReturnType());
108         assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void",
109                 getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));
110         assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List",
111                 getHigherLayerIfMethod.getReturnType().getName().equals("List"));
112
113         // 'InterfaceKey'
114         assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
115         final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
116         assertNotNull("properties is null", properties);
117         GeneratedProperty gtInterfaceId = null;
118         for (final GeneratedProperty property : properties) {
119             if (property.getName().equals("InterfaceId")) {
120                 gtInterfaceId = property;
121                 break;
122             }
123         }
124         assertNotNull("gtInterfaceId is null", gtInterfaceId);
125         assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
126         assertFalse("gtInterfaceId.getReturnType() should not be Void",
127                 gtInterfaceId.getReturnType().equals("java.lang.Void"));
128         assertTrue("gtInterfaceId.getReturnType().getName() must be String",
129                 gtInterfaceId.getReturnType().getName().equals("String"));
130
131         // 'Tunnel'
132         assertNotNull("gtTunnel is null", gtTunnel);
133         final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
134         assertNotNull("tunnelMethods is null", tunnelMethods);
135         MethodSignature getTunnelKeyMethod = null;
136         for (MethodSignature method : tunnelMethods) {
137             if (method.getName().equals("getTunnelKey")) {
138                 getTunnelKeyMethod = method;
139                 break;
140             }
141         }
142         assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
143         assertNotNull("getTunnelKeyMethod.getReturnType()",
144                 getTunnelKeyMethod.getReturnType());
145         assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",
146                 getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
147         assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",
148                 getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
149
150         // 'TunnelKey'
151         assertNotNull("gtTunnelKey is null", gtTunnelKey);
152         final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
153         assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
154
155         GeneratedProperty gtTunnelId = null;
156         for (final GeneratedProperty property : tunnelKeyProperties) {
157             if (property.getName().equals("TunnelId")) {
158                 gtTunnelId = property;
159             }
160         }
161         assertNotNull("gtTunnelId is null", gtTunnelId);
162         assertNotNull("gtTunnelId.getReturnType() is null",
163                 gtTunnelId.getReturnType());
164         assertFalse("gtTunnelId.getReturnType() should not be Void",
165                 gtTunnelId.getReturnType().equals("java.lang.Void"));
166         assertTrue("gtTunnelId.getReturnType().getName() must be Integer",
167                 gtTunnelId.getReturnType().getName().equals("Integer"));
168
169         // 'NetworkLink2'
170         assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);
171
172         final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
173         assertNotNull("networkLink2Methods is null", networkLink2Methods);
174
175 //        FIXME: in some cases getIfcMethod is null which causes test fail. fix ASAP
176 //      MethodSignature getIfcMethod = null;
177 //      for (MethodSignature method : networkLink2Methods) {
178 //          if (method.getName().equals("getInterface")) {
179 //              getIfcMethod = method;
180 //              break;
181 //          }
182 //      }
183 //
184 //      assertNotNull("getIfcMethod is null", getIfcMethod);
185 //      assertNotNull("getIfcMethod.getReturnType() is null", getIfcMethod.getReturnType());
186 //      assertFalse("getIfcMethod.getReturnType() should not be Void", getIfcMethod.getReturnType().equals("java.lang.Void"));
187 //      assertTrue("getIfcMethod.getReturnType().getName() must be String", getIfcMethod.getReturnType().getName().equals("String"));
188     }
189
190     @Test
191     public void augmentedNetworkLinkTest() {
192
193     }
194
195     @Test
196     public void augmentedTopologyTunnelsTest() {
197
198     }
199 }