Added model generation from ietf-topology models
[yangtools.git] / code-generator / binding-generator-impl / src / test / java / org / opendaylight / yangtools / sal / binding / generator / impl / GenEnumResolvingTest.java
index 89389dd1736112b8ea4bb9d33acd1c39591e814f..e9ed3a982f0b9ad682c9a7679778ee4a65a37078 100644 (file)
-/*
- * 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.*;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.Test;
-import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
-import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
-import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
-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 GenEnumResolvingTest {
-
-    private SchemaContext resolveSchemaContextFromFiles(
-            final String... yangFiles) {
-        final YangModelParser parser = new YangParserImpl();
-
-        final List<File> inputFiles = new ArrayList<File>();
-        for (int i = 0; i < yangFiles.length; ++i) {
-            inputFiles.add(new File(yangFiles[i]));
-        }
-
-        final Set<Module> modules = parser.parseYangModels(inputFiles);
-        return parser.resolveSchemaContext(modules);
-    }
-
-    @Test
-    public void testLeafEnumResolving() {
-        final String ietfInterfacesPath = getClass().getResource(
-                "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath();
-        final String ifTypePath = getClass().getResource(
-                "/enum-test-models/iana-if-type@2012-06-05.yang").getPath();
-        final String yangTypesPath = getClass().getResource(
-                "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath();
-
-        final SchemaContext context = resolveSchemaContextFromFiles(
-                ietfInterfacesPath, ifTypePath, yangTypesPath);
-        assertTrue(context != null);
-
-        final BindingGenerator bindingGen = new BindingGeneratorImpl();
-        final List<Type> genTypes = bindingGen.generateTypes(context);
-        assertTrue(genTypes != null);
-
-        assertEquals("Expected count of all Generated Types from yang models " +
-                "is 22", 25, genTypes.size());
-
-        GeneratedType genInterface = null;
-        for (final Type type : genTypes) {
-            if (type instanceof GeneratedType) {
-                if (type.getName().equals("Interface")) {
-                    genInterface = (GeneratedType) type;
-                }
-            }
-        }
-        assertNotNull("Generated Type Interface is not present in list of " +
-                "Generated Types", genInterface);
-
-        Enumeration linkUpDownTrapEnable = null;
-        Enumeration operStatus = null;
-        final List<Enumeration> enums = genInterface.getEnumerations();
-        assertNotNull("Generated Type Interface cannot contain NULL reference" +
-                " to Enumeration types!", enums);
-        assertEquals("Generated Type Interface MUST contain 2 Enumeration " +
-                "Types", 2, enums.size());
-        for (final Enumeration e : enums) {
-            if (e.getName().equals("LinkUpDownTrapEnable")) {
-                linkUpDownTrapEnable = e;
-            } else if (e.getName().equals("OperStatus")) {
-                operStatus = e;
-            }
-        }
-
-        assertNotNull("Expected Enum LinkUpDownTrapEnable, but was NULL!",
-                linkUpDownTrapEnable);
-        assertNotNull("Expected Enum OperStatus, but was NULL!", operStatus);
-
-        assertNotNull("Enum LinkUpDownTrapEnable MUST contain Values definition " +
-                "not NULL reference!", linkUpDownTrapEnable.getValues());
-        assertNotNull("Enum OperStatus MUST contain Values definition not " +
-                "NULL reference!", operStatus.getValues());
-        assertEquals("Enum LinkUpDownTrapEnable MUST contain 2 values!", 2,
-                linkUpDownTrapEnable.getValues().size());
-        assertEquals("Enum OperStatus MUST contain 7 values!", 7,
-                operStatus.getValues().size());
-
-        final List<MethodSignature> methods = genInterface
-                .getMethodDefinitions();
-
-        assertNotNull("Generated Interface cannot contain NULL reference for " +
-                "Method Signature Definitions!", methods);
-
-        assertEquals("Expected count of method signature definitions is 14",
-                14, methods.size());
-        Enumeration ianaIfType = null;
-        for (final MethodSignature method : methods) {
-            if (method.getName().equals("getType")) {
-                if (method.getReturnType() instanceof Enumeration) {
-                    ianaIfType = (Enumeration)method.getReturnType();
-                }
-            }
-        }
-
-        assertNotNull("Method getType MUST return Enumeration Type, " +
-                "not NULL reference!", ianaIfType);
-        assertEquals("Enumeration getType MUST contain 272 values!", 272,
-                ianaIfType.getValues().size());
-    }
-
-    @Test
-    public void testTypedefEnumResolving() {
-        final String ianaIfTypePath = getClass().getResource(
-                "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath();
-
-        final SchemaContext context = resolveSchemaContextFromFiles(ianaIfTypePath);
-        assertTrue(context != null);
-        final BindingGenerator bindingGen = new BindingGeneratorImpl();
-        final List<Type> genTypes = bindingGen.generateTypes(context);
-        assertTrue(genTypes != null);
-        assertEquals(3, genTypes.size());
-
-        final Type type = genTypes.get(1);
-        assertTrue(type instanceof Enumeration);
-
-        final Enumeration enumer = (Enumeration) type;
-        assertEquals("Enumeration type MUST contain 272 values!", 272,
-                enumer.getValues().size());
-    }
-
-    @Test
-    public void testLeafrefEnumResolving() {
-        final String ietfInterfacesPath = getClass().getResource(
-                "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath();
-        final String ifTypePath = getClass().getResource(
-                "/enum-test-models/iana-if-type@2012-06-05.yang").getPath();
-        final String yangTypesPath = getClass().getResource(
-                "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath();
-        final String topologyPath = getClass().getResource(
-                "/enum-test-models/abstract-topology@2013-02-08.yang")
-                .getPath();
-        final String inetTypesPath = getClass().getResource(
-                "/enum-test-models/ietf-inet-types@2010-09-24.yang")
-                .getPath();
-        final SchemaContext context = resolveSchemaContextFromFiles(
-                ietfInterfacesPath, ifTypePath, yangTypesPath, topologyPath,
-                inetTypesPath);
-
-        assertNotNull(context);
-        final BindingGenerator bindingGen = new BindingGeneratorImpl();
-        final List<Type> genTypes = bindingGen.generateTypes(context);
-        assertNotNull(genTypes);
-        assertTrue(!genTypes.isEmpty());
-
-        GeneratedType genInterface = null;
-        for (final Type type : genTypes) {
-            if (type instanceof GeneratedType) {
-                if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev201328.topology.interfaces")
-                        && type.getName().equals("Interface")) {
-                    genInterface = (GeneratedType) type;
-                }
-            }
-        }
-        assertNotNull("Generated Type Interface is not present in list of " +
-                "Generated Types", genInterface);
-
-        Type linkUpDownTrapEnable = null;
-        Type operStatus = null;
-        final List<MethodSignature> methods = genInterface.getMethodDefinitions();
-        assertNotNull("Generated Type Interface cannot contain NULL reference" +
-                " to Enumeration types!", methods);
-        assertEquals("Generated Type Interface MUST contain 4 Methods ",
-                4, methods.size());
-        for (final MethodSignature method : methods) {
-            if (method.getName().equals("getLinkUpDownTrapEnable")) {
-                linkUpDownTrapEnable = method.getReturnType();
-            } else if (method.getName().equals("getOperStatus")) {
-                operStatus = method.getReturnType();
-            }
-        }
-
-        assertNotNull("Expected Referenced Enum LinkUpDownTrapEnable, but was NULL!",
-                linkUpDownTrapEnable);
-        assertTrue("Expected LinkUpDownTrapEnable of type ReferencedTypeImpl",
-                linkUpDownTrapEnable instanceof ReferencedTypeImpl);
-        assertEquals(linkUpDownTrapEnable.getPackageName(),
-                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface");
-
-        assertNotNull("Expected Referenced Enum OperStatus, but was NULL!",
-                operStatus);
-        assertTrue("Expected OperStatus of type ReferencedTypeImpl",
-                operStatus instanceof  ReferencedTypeImpl);
-        assertEquals(operStatus.getPackageName(),
-                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface");
-    }
-}
+/*\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.*;\r
+\r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;\r
+import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;\r
+import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;\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 GenEnumResolvingTest {\r
+\r
+    private SchemaContext resolveSchemaContextFromFiles(\r
+            final String... yangFiles) {\r
+        final YangModelParser parser = new YangParserImpl();\r
+\r
+        final List<File> inputFiles = new ArrayList<File>();\r
+        for (int i = 0; i < yangFiles.length; ++i) {\r
+            inputFiles.add(new File(yangFiles[i]));\r
+        }\r
+\r
+        final Set<Module> modules = parser.parseYangModels(inputFiles);\r
+        return parser.resolveSchemaContext(modules);\r
+    }\r
+\r
+    @Test\r
+    public void testLeafEnumResolving() {\r
+        final String ietfInterfacesPath = getClass().getResource(\r
+                "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath();\r
+        final String ifTypePath = getClass().getResource(\r
+                "/enum-test-models/iana-if-type@2012-06-05.yang").getPath();\r
+        final String yangTypesPath = getClass().getResource(\r
+                "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath();\r
+\r
+        final SchemaContext context = resolveSchemaContextFromFiles(\r
+                ietfInterfacesPath, ifTypePath, yangTypesPath);\r
+        assertTrue(context != null);\r
+\r
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
+        final List<Type> genTypes = bindingGen.generateTypes(context);\r
+        assertTrue(genTypes != null);\r
+\r
+        assertEquals("Expected count of all Generated Types", 20, genTypes.size());\r
+\r
+        GeneratedType genInterface = null;\r
+        for (final Type type : genTypes) {\r
+            if (type instanceof GeneratedType) {\r
+                if (type.getName().equals("Interface")) {\r
+                    genInterface = (GeneratedType) type;\r
+                }\r
+            }\r
+        }\r
+        assertNotNull("Generated Type Interface is not present in list of " +\r
+                "Generated Types", genInterface);\r
+\r
+        Enumeration linkUpDownTrapEnable = null;\r
+        Enumeration operStatus = null;\r
+        final List<Enumeration> enums = genInterface.getEnumerations();\r
+        assertNotNull("Generated Type Interface cannot contain NULL reference" +\r
+                " to Enumeration types!", enums);\r
+        assertEquals("Generated Type Interface MUST contain 2 Enumeration " +\r
+                "Types", 2, enums.size());\r
+        for (final Enumeration e : enums) {\r
+            if (e.getName().equals("LinkUpDownTrapEnable")) {\r
+                linkUpDownTrapEnable = e;\r
+            } else if (e.getName().equals("OperStatus")) {\r
+                operStatus = e;\r
+            }\r
+        }\r
+\r
+        assertNotNull("Expected Enum LinkUpDownTrapEnable, but was NULL!",\r
+                linkUpDownTrapEnable);\r
+        assertNotNull("Expected Enum OperStatus, but was NULL!", operStatus);\r
+\r
+        assertNotNull("Enum LinkUpDownTrapEnable MUST contain Values definition " +\r
+                "not NULL reference!", linkUpDownTrapEnable.getValues());\r
+        assertNotNull("Enum OperStatus MUST contain Values definition not " +\r
+                "NULL reference!", operStatus.getValues());\r
+        assertEquals("Enum LinkUpDownTrapEnable MUST contain 2 values!", 2,\r
+                linkUpDownTrapEnable.getValues().size());\r
+        assertEquals("Enum OperStatus MUST contain 7 values!", 7,\r
+                operStatus.getValues().size());\r
+\r
+        final List<MethodSignature> methods = genInterface\r
+                .getMethodDefinitions();\r
+\r
+        assertNotNull("Generated Interface cannot contain NULL reference for " +\r
+                "Method Signature Definitions!", methods);\r
+\r
+        assertEquals("Expected count of method signature definitions is 14",\r
+                14, methods.size());\r
+        Enumeration ianaIfType = null;\r
+        for (final MethodSignature method : methods) {\r
+            if (method.getName().equals("getType")) {\r
+                if (method.getReturnType() instanceof Enumeration) {\r
+                    ianaIfType = (Enumeration)method.getReturnType();\r
+                }\r
+            }\r
+        }\r
+\r
+        assertNotNull("Method getType MUST return Enumeration Type, " +\r
+                "not NULL reference!", ianaIfType);\r
+        assertEquals("Enumeration getType MUST contain 272 values!", 272,\r
+                ianaIfType.getValues().size());\r
+    }\r
+\r
+    @Test\r
+    public void testTypedefEnumResolving() {\r
+        final String ianaIfTypePath = getClass().getResource(\r
+                "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath();\r
+\r
+        final SchemaContext context = resolveSchemaContextFromFiles(ianaIfTypePath);\r
+        assertTrue(context != null);\r
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
+        final List<Type> genTypes = bindingGen.generateTypes(context);\r
+        assertTrue(genTypes != null);\r
+        assertEquals(1, genTypes.size());\r
+\r
+        final Type type = genTypes.get(0);\r
+        assertTrue(type instanceof Enumeration);\r
+\r
+        final Enumeration enumer = (Enumeration) type;\r
+        assertEquals("Enumeration type MUST contain 272 values!", 272,\r
+                enumer.getValues().size());\r
+    }\r
+\r
+    @Test\r
+    public void testLeafrefEnumResolving() {\r
+        final String ietfInterfacesPath = getClass().getResource(\r
+                "/enum-test-models/ietf-interfaces@2012-11-15.yang").getPath();\r
+        final String ifTypePath = getClass().getResource(\r
+                "/enum-test-models/iana-if-type@2012-06-05.yang").getPath();\r
+        final String yangTypesPath = getClass().getResource(\r
+                "/enum-test-models/ietf-yang-types@2010-09-24.yang").getPath();\r
+        final String topologyPath = getClass().getResource(\r
+                "/enum-test-models/abstract-topology@2013-02-08.yang")\r
+                .getPath();\r
+        final String inetTypesPath = getClass().getResource(\r
+                "/enum-test-models/ietf-inet-types@2010-09-24.yang")\r
+                .getPath();\r
+        final SchemaContext context = resolveSchemaContextFromFiles(\r
+                ietfInterfacesPath, ifTypePath, yangTypesPath, topologyPath,\r
+                inetTypesPath);\r
+\r
+        assertNotNull(context);\r
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
+        final List<Type> genTypes = bindingGen.generateTypes(context);\r
+        assertNotNull(genTypes);\r
+        assertTrue(!genTypes.isEmpty());\r
+\r
+        GeneratedType genInterface = null;\r
+        for (final Type type : genTypes) {\r
+            if (type instanceof GeneratedType) {\r
+                if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev201328.topology.interfaces")\r
+                        && type.getName().equals("Interface")) {\r
+                    genInterface = (GeneratedType) type;\r
+                }\r
+            }\r
+        }\r
+        assertNotNull("Generated Type Interface is not present in list of " +\r
+                "Generated Types", genInterface);\r
+\r
+        Type linkUpDownTrapEnable = null;\r
+        Type operStatus = null;\r
+        final List<MethodSignature> methods = genInterface.getMethodDefinitions();\r
+        assertNotNull("Generated Type Interface cannot contain NULL reference" +\r
+                " to Enumeration types!", methods);\r
+        assertEquals("Generated Type Interface MUST contain 4 Methods ",\r
+                4, methods.size());\r
+        for (final MethodSignature method : methods) {\r
+            if (method.getName().equals("getLinkUpDownTrapEnable")) {\r
+                linkUpDownTrapEnable = method.getReturnType();\r
+            } else if (method.getName().equals("getOperStatus")) {\r
+                operStatus = method.getReturnType();\r
+            }\r
+        }\r
+\r
+        assertNotNull("Expected Referenced Enum LinkUpDownTrapEnable, but was NULL!",\r
+                linkUpDownTrapEnable);\r
+        assertTrue("Expected LinkUpDownTrapEnable of type ReferencedTypeImpl",\r
+                linkUpDownTrapEnable instanceof ReferencedTypeImpl);\r
+        assertEquals(linkUpDownTrapEnable.getPackageName(),\r
+                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface");\r
+\r
+        assertNotNull("Expected Referenced Enum OperStatus, but was NULL!",\r
+                operStatus);\r
+        assertTrue("Expected OperStatus of type ReferencedTypeImpl",\r
+                operStatus instanceof  ReferencedTypeImpl);\r
+        assertEquals(operStatus.getPackageName(),\r
+                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface");\r
+    }\r
+}\r