BUG-990: fixed deserialization of enums.
[yangtools.git] / code-generator / binding-generator-impl / src / test / java / org / opendaylight / yangtools / sal / binding / generator / impl / AugmentedTypeTest.java
index f2cf8ebc9ef4d5e73614b015f9cf3b137f5a4ebe..933db8dc8a7c6c4c0e8b44f2942fe8e05bdc885e 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.sal.binding.generator.impl;\r
-\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.io.File;\r
-import java.net.URISyntaxException;\r
-import java.net.URL;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.junit.BeforeClass;\r
-import org.junit.Test;\r
-import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;\r
-import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;\r
-import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;\r
-import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;\r
-import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;\r
-import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
-import org.opendaylight.yangtools.yang.model.api.Module;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;\r
-import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;\r
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;\r
-\r
-public class AugmentedTypeTest {\r
-\r
-    private final static List<File> augmentModels = new ArrayList<>();\r
-    private final static URL augmentFolderPath = AugmentedTypeTest.class\r
-            .getResource("/augment-test-models");\r
-\r
-    @BeforeClass\r
-    public static void loadTestResources() throws URISyntaxException {\r
-        final File augFolder = new File(augmentFolderPath.toURI());\r
-\r
-        for (final File fileEntry : augFolder.listFiles()) {\r
-            if (fileEntry.isFile()) {\r
-                augmentModels.add(fileEntry);\r
-            }\r
-        }\r
-    }\r
-\r
-    @Test\r
-    public void augmentedAbstractTopologyTest() {\r
-        final YangModelParser parser = new YangParserImpl();\r
-        final Set<Module> modules = parser.parseYangModels(augmentModels);\r
-        final SchemaContext context = parser.resolveSchemaContext(modules);\r
-\r
-        assertNotNull("context is null", context);\r
-        final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
-        final List<Type> genTypes = bindingGen.generateTypes(context);\r
-\r
-        assertNotNull("genTypes is null", genTypes);\r
-        assertFalse("genTypes is empty", genTypes.isEmpty());\r
-\r
-        GeneratedTransferObject gtInterfaceKey = null;\r
-        GeneratedType gtInterface = null;\r
-        GeneratedType gtTunnel = null;\r
-        GeneratedTransferObject gtTunnelKey = null;\r
-        GeneratedType gtNetworkLink2 = null;\r
-\r
-        for (final Type type : genTypes) {\r
-            if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {\r
-                gtInterfaceKey = (GeneratedTransferObject) type;\r
-            } else if (type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {\r
-                gtInterface = (GeneratedType) type;\r
-            } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {\r
-                gtTunnel = (GeneratedType) type;\r
-            } else if (type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {\r
-                gtTunnelKey = (GeneratedTransferObject) type;\r
-            } else if (type.getName().equals("NetworkLink2") && type.getPackageName().contains("augment._abstract.topology")) {\r
-                gtNetworkLink2 = (GeneratedType) type;\r
-            }\r
-        }\r
-\r
-        // 'Interface\r
-        assertNotNull("gtInterface is null", gtInterface);\r
-        final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();\r
-        assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);\r
-        MethodSignature getIfcKeyMethod = null;\r
-        for (final MethodSignature method : gtInterfaceMethods) {\r
-            if (method.getName().equals("getKey")) {\r
-                getIfcKeyMethod = method;\r
-                break;\r
-            }\r
-        }\r
-        assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);\r
-        assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());\r
-        assertFalse("getIfcKeyMethod.getReturnType() should not be Void",\r
-                getIfcKeyMethod.getReturnType().equals("java.lang.Void"));\r
-        assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",\r
-                getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));\r
-\r
-        MethodSignature getHigherLayerIfMethod = null;\r
-        for (final MethodSignature method : gtInterfaceMethods) {\r
-            if (method.getName().equals("getHigherLayerIf")) {\r
-                getHigherLayerIfMethod = method;\r
-                break;\r
-            }\r
-        }\r
-        assertNotNull("getHigherLayerIfMethod is null", getHigherLayerIfMethod);\r
-        assertNotNull("getHigherLayerIfMethod.getReturnType() is null",\r
-                getHigherLayerIfMethod.getReturnType());\r
-        assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void",\r
-                getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));\r
-        assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List",\r
-                getHigherLayerIfMethod.getReturnType().getName().equals("List"));\r
-\r
-        // 'InterfaceKey'\r
-        assertNotNull("gtInterfaceKey is null", gtInterfaceKey);\r
-        final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();\r
-        assertNotNull("properties is null", properties);\r
-        GeneratedProperty gtInterfaceId = null;\r
-        for (final GeneratedProperty property : properties) {\r
-            if (property.getName().equals("interfaceId")) {\r
-                gtInterfaceId = property;\r
-                break;\r
-            }\r
-        }\r
-        assertNotNull("gtInterfaceId is null", gtInterfaceId);\r
-        assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());\r
-        assertFalse("gtInterfaceId.getReturnType() should not be Void",\r
-                gtInterfaceId.getReturnType().equals("java.lang.Void"));\r
-        assertTrue("gtInterfaceId.getReturnType().getName() must be String",\r
-                gtInterfaceId.getReturnType().getName().equals("String"));\r
-\r
-        // 'Tunnel'\r
-        assertNotNull("gtTunnel is null", gtTunnel);\r
-        final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();\r
-        assertNotNull("tunnelMethods is null", tunnelMethods);\r
-        MethodSignature getTunnelKeyMethod = null;\r
-        for (MethodSignature method : tunnelMethods) {\r
-            if (method.getName().equals("getKey")) {\r
-                getTunnelKeyMethod = method;\r
-                break;\r
-            }\r
-        }\r
-        assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);\r
-        assertNotNull("getTunnelKeyMethod.getReturnType()",\r
-                getTunnelKeyMethod.getReturnType());\r
-        assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",\r
-                getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));\r
-        assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",\r
-                getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));\r
-\r
-        // 'TunnelKey'\r
-        assertNotNull("gtTunnelKey is null", gtTunnelKey);\r
-        final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();\r
-        assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);\r
-\r
-        GeneratedProperty gtTunnelId = null;\r
-        for (final GeneratedProperty property : tunnelKeyProperties) {\r
-            if (property.getName().equals("tunnelId")) {\r
-                gtTunnelId = property;\r
-            }\r
-        }\r
-        assertNotNull("gtTunnelId is null", gtTunnelId);\r
-        assertNotNull("gtTunnelId.getReturnType() is null",\r
-                gtTunnelId.getReturnType());\r
-        assertFalse("gtTunnelId.getReturnType() should not be Void",\r
-                gtTunnelId.getReturnType().equals("java.lang.Void"));\r
-        assertTrue("gtTunnelId.getReturnType().getName() must be Integer",\r
-                gtTunnelId.getReturnType().getName().equals("Integer"));\r
-\r
-        // 'NetworkLink2'\r
-        assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);\r
-\r
-        final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();\r
-        assertNotNull("networkLink2Methods is null", networkLink2Methods);\r
-\r
-//        FIXME: in some cases getIfcMethod is null which causes test fail. fix ASAP\r
-//      MethodSignature getIfcMethod = null;\r
-//      for (MethodSignature method : networkLink2Methods) {\r
-//          if (method.getName().equals("getInterface")) {\r
-//              getIfcMethod = method;\r
-//              break;\r
-//          }\r
-//      }\r
-//\r
-//      assertNotNull("getIfcMethod is null", getIfcMethod);\r
-//      assertNotNull("getIfcMethod.getReturnType() is null", getIfcMethod.getReturnType());\r
-//      assertFalse("getIfcMethod.getReturnType() should not be Void", getIfcMethod.getReturnType().equals("java.lang.Void"));\r
-//      assertTrue("getIfcMethod.getReturnType().getName() must be String", getIfcMethod.getReturnType().getName().equals("String"));\r
-    }\r
-\r
-    @Test\r
-    public void augmentedNetworkLinkTest() {\r
-\r
-    }\r
-\r
-    @Test\r
-    public void augmentedTopologyTunnelsTest() {\r
-\r
-    }\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+public class AugmentedTypeTest {
+
+    private final static List<File> augmentModels = new ArrayList<>();
+    private final static URL augmentFolderPath = AugmentedTypeTest.class
+            .getResource("/augment-test-models");
+
+    @BeforeClass
+    public static void loadTestResources() throws URISyntaxException {
+        final File augFolder = new File(augmentFolderPath.toURI());
+
+        for (final File fileEntry : augFolder.listFiles()) {
+            if (fileEntry.isFile()) {
+                augmentModels.add(fileEntry);
+            }
+        }
+    }
+
+    @Test
+    public void augmentedAbstractTopologyTest() {
+        final YangModelParser parser = new YangParserImpl();
+        final Set<Module> modules = parser.parseYangModels(augmentModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        assertNotNull("context is null", context);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
+        final List<Type> genTypes = bindingGen.generateTypes(context);
+
+        assertNotNull("genTypes is null", genTypes);
+        assertFalse("genTypes is empty", genTypes.isEmpty());
+
+        GeneratedTransferObject gtInterfaceKey = null;
+        GeneratedType gtInterface = null;
+        GeneratedType gtTunnel = null;
+        GeneratedTransferObject gtTunnelKey = null;
+        GeneratedType gtNetworkLink2 = null;
+
+        for (final Type type : genTypes) {
+            if (type.getName().equals("InterfaceKey") && type.getPackageName().contains("augment._abstract.topology")) {
+                gtInterfaceKey = (GeneratedTransferObject) type;
+            } else if (type.getName().equals("Interface") && type.getPackageName().contains("augment._abstract.topology")) {
+                gtInterface = (GeneratedType) type;
+            } else if (type.getName().equals("Tunnel") && type.getPackageName().contains("augment._abstract.topology")) {
+                gtTunnel = (GeneratedType) type;
+            } else if (type.getName().equals("TunnelKey") && type.getPackageName().contains("augment._abstract.topology")) {
+                gtTunnelKey = (GeneratedTransferObject) type;
+            } else if (type.getName().equals("NetworkLink2") && type.getPackageName().contains("augment._abstract.topology")) {
+                gtNetworkLink2 = (GeneratedType) type;
+            }
+        }
+
+        // 'Interface
+        assertNotNull("gtInterface is null", gtInterface);
+        final List<MethodSignature> gtInterfaceMethods = gtInterface.getMethodDefinitions();
+        assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
+        MethodSignature getIfcKeyMethod = null;
+        for (final MethodSignature method : gtInterfaceMethods) {
+            if (method.getName().equals("getKey")) {
+                getIfcKeyMethod = method;
+                break;
+            }
+        }
+        assertNotNull("getIfcKeyMethod is null", getIfcKeyMethod);
+        assertNotNull("getIfcKeyMethod.getReturnType() is null", getIfcKeyMethod.getReturnType());
+        assertFalse("getIfcKeyMethod.getReturnType() should not be Void",
+                getIfcKeyMethod.getReturnType().equals("java.lang.Void"));
+        assertTrue("getIfcKeyMethod.getReturnType().getName() must be InterfaceKey",
+                getIfcKeyMethod.getReturnType().getName().equals("InterfaceKey"));
+
+        MethodSignature getHigherLayerIfMethod = null;
+        for (final MethodSignature method : gtInterfaceMethods) {
+            if (method.getName().equals("getHigherLayerIf")) {
+                getHigherLayerIfMethod = method;
+                break;
+            }
+        }
+        assertNotNull("getHigherLayerIfMethod is null", getHigherLayerIfMethod);
+        assertNotNull("getHigherLayerIfMethod.getReturnType() is null",
+                getHigherLayerIfMethod.getReturnType());
+        assertFalse("getHigherLayerIfMethod.getReturnType() should not be Void",
+                getHigherLayerIfMethod.getReturnType().equals("java.lang.Void"));
+        assertTrue("getHigherLayerIfMethod.getReturnType().getName() must be List",
+                getHigherLayerIfMethod.getReturnType().getName().equals("List"));
+
+        // 'InterfaceKey'
+        assertNotNull("gtInterfaceKey is null", gtInterfaceKey);
+        final List<GeneratedProperty> properties = gtInterfaceKey.getProperties();
+        assertNotNull("properties is null", properties);
+        GeneratedProperty gtInterfaceId = null;
+        for (final GeneratedProperty property : properties) {
+            if (property.getName().equals("interfaceId")) {
+                gtInterfaceId = property;
+                break;
+            }
+        }
+        assertNotNull("gtInterfaceId is null", gtInterfaceId);
+        assertNotNull("gtInterfaceId.getReturnType() is null", gtInterfaceId.getReturnType());
+        assertFalse("gtInterfaceId.getReturnType() should not be Void",
+                gtInterfaceId.getReturnType().equals("java.lang.Void"));
+        assertTrue("gtInterfaceId.getReturnType().getName() must be String",
+                gtInterfaceId.getReturnType().getName().equals("String"));
+
+        // 'Tunnel'
+        assertNotNull("gtTunnel is null", gtTunnel);
+        final List<MethodSignature> tunnelMethods = gtTunnel.getMethodDefinitions();
+        assertNotNull("tunnelMethods is null", tunnelMethods);
+        MethodSignature getTunnelKeyMethod = null;
+        for (MethodSignature method : tunnelMethods) {
+            if (method.getName().equals("getKey")) {
+                getTunnelKeyMethod = method;
+                break;
+            }
+        }
+        assertNotNull("getTunnelKeyMethod is null", getTunnelKeyMethod);
+        assertNotNull("getTunnelKeyMethod.getReturnType()",
+                getTunnelKeyMethod.getReturnType());
+        assertFalse("getTunnelKeyMethod.getReturnType() should not be Void",
+                getTunnelKeyMethod.getReturnType().equals("java.lang.Void"));
+        assertTrue("getTunnelKeyMethod.getReturnType().getName() must be TunnelKey",
+                getTunnelKeyMethod.getReturnType().getName().equals("TunnelKey"));
+
+        // 'TunnelKey'
+        assertNotNull("gtTunnelKey is null", gtTunnelKey);
+        final List<GeneratedProperty> tunnelKeyProperties = gtTunnelKey.getProperties();
+        assertNotNull("tunnelKeyProperties is null", tunnelKeyProperties);
+
+        GeneratedProperty gtTunnelId = null;
+        for (final GeneratedProperty property : tunnelKeyProperties) {
+            if (property.getName().equals("tunnelId")) {
+                gtTunnelId = property;
+            }
+        }
+        assertNotNull("gtTunnelId is null", gtTunnelId);
+        assertNotNull("gtTunnelId.getReturnType() is null",
+                gtTunnelId.getReturnType());
+        assertFalse("gtTunnelId.getReturnType() should not be Void",
+                gtTunnelId.getReturnType().equals("java.lang.Void"));
+        assertTrue("gtTunnelId.getReturnType().getName() must be Integer",
+                gtTunnelId.getReturnType().getName().equals("Integer"));
+
+        // 'NetworkLink2'
+        assertNotNull("gtNetworkLink2 is null", gtNetworkLink2);
+
+        final List<MethodSignature> networkLink2Methods = gtNetworkLink2.getMethodDefinitions();
+        assertNotNull("networkLink2Methods is null", networkLink2Methods);
+
+//        FIXME: in some cases getIfcMethod is null which causes test fail. fix ASAP
+//      MethodSignature getIfcMethod = null;
+//      for (MethodSignature method : networkLink2Methods) {
+//          if (method.getName().equals("getInterface")) {
+//              getIfcMethod = method;
+//              break;
+//          }
+//      }
+//
+//      assertNotNull("getIfcMethod is null", getIfcMethod);
+//      assertNotNull("getIfcMethod.getReturnType() is null", getIfcMethod.getReturnType());
+//      assertFalse("getIfcMethod.getReturnType() should not be Void", getIfcMethod.getReturnType().equals("java.lang.Void"));
+//      assertTrue("getIfcMethod.getReturnType().getName() must be String", getIfcMethod.getReturnType().getName().equals("String"));
+    }
+
+    @Test
+    public void augmentedNetworkLinkTest() {
+
+    }
+
+    @Test
+    public void augmentedTopologyTunnelsTest() {
+
+    }
+}