933db8dc8a7c6c4c0e8b44f2942fe8e05bdc885e
[yangtools.git] / code-generator / binding-generator-impl / src / test / java / org / opendaylight / yangtools / 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.yangtools.sal.binding.generator.impl;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.io.File;
15 import java.net.URISyntaxException;
16 import java.net.URL;
17 import java.util.ArrayList;
18 import java.util.List;
19 import java.util.Set;
20
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;
33
34 public class AugmentedTypeTest {
35
36     private final static List<File> augmentModels = new ArrayList<>();
37     private final static URL augmentFolderPath = AugmentedTypeTest.class
38             .getResource("/augment-test-models");
39
40     @BeforeClass
41     public static void loadTestResources() throws URISyntaxException {
42         final File augFolder = new File(augmentFolderPath.toURI());
43
44         for (final File fileEntry : augFolder.listFiles()) {
45             if (fileEntry.isFile()) {
46                 augmentModels.add(fileEntry);
47             }
48         }
49     }
50
51     @Test
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);
56
57         assertNotNull("context is null", context);
58         final BindingGenerator bindingGen = new BindingGeneratorImpl();
59         final List<Type> genTypes = bindingGen.generateTypes(context);
60
61         assertNotNull("genTypes is null", genTypes);
62         assertFalse("genTypes is empty", genTypes.isEmpty());
63
64         GeneratedTransferObject gtInterfaceKey = null;
65         GeneratedType gtInterface = null;
66         GeneratedType gtTunnel = null;
67         GeneratedTransferObject gtTunnelKey = null;
68         GeneratedType gtNetworkLink2 = null;
69
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;
81             }
82         }
83
84         // 'Interface
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;
92                 break;
93             }
94         }
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"));
101
102         MethodSignature getHigherLayerIfMethod = null;
103         for (final MethodSignature method : gtInterfaceMethods) {
104             if (method.getName().equals("getHigherLayerIf")) {
105                 getHigherLayerIfMethod = method;
106                 break;
107             }
108         }
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"));
116
117         // 'InterfaceKey'
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;
125                 break;
126             }
127         }
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"));
134
135         // 'Tunnel'
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;
143                 break;
144             }
145         }
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"));
153
154         // 'TunnelKey'
155         assertNotNull("gtTunnelKey is null", gtTunnelKey);
156         final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
157         assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
158
159         GeneratedProperty gtTunnelId = null;
160         for (final GeneratedProperty property : tunnelKeyProperties) {
161             if (property.getName().equals("tunnelId")) {
162                 gtTunnelId = property;
163             }
164         }
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"));
172
173         // 'NetworkLink2'
174         assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);
175
176         final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
177         assertNotNull("networkLink2Methods is null", networkLink2Methods);
178
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;
184 //              break;
185 //          }
186 //      }
187 //
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"));
192     }
193
194     @Test
195     public void augmentedNetworkLinkTest() {
196
197     }
198
199     @Test
200     public void augmentedTopologyTunnelsTest() {
201
202     }
203 }