DTOs for anydata/anyxml are not generated within a list
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / GeneratedTypesTest.java
index 3a5bfee0c5432b85cd93028146c36059f481aeb7..0824dd41750043c9ae7ef310c58ea9727bccd761 100644 (file)
@@ -11,9 +11,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
 import java.util.List;
 import org.junit.Test;
 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
@@ -22,22 +19,19 @@ import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
 import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class GeneratedTypesTest {
 
     @Test
-    public void testMultipleModulesResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
-        File abstractTopology = new File(getClass().getResource("/abstract-topology.yang").toURI());
-        File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
-
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInetTypes);
+    public void testMultipleModulesResolving() {
+        final SchemaContext context = YangParserTestUtils.parseYangResources(GeneratedTypesTest.class,
+            "/abstract-topology.yang", "/ietf/ietf-inet-types.yang");
         assertNotNull(context);
 
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertNotNull(genTypes);
@@ -45,12 +39,11 @@ public class GeneratedTypesTest {
     }
 
     @Test
-    public void testContainerResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
-        final File testFile = new File(getClass().getResource("/simple-container-demo.yang").toURI());
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+    public void testContainerResolving() {
+        final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-container-demo.yang");
         assertNotNull(context);
 
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertNotNull(genTypes);
@@ -67,8 +60,8 @@ public class GeneratedTypesTest {
         }
         assertNotNull(simpleContainer);
         assertNotNull(nestedContainer);
-        assertEquals(3, simpleContainer.getMethodDefinitions().size());
-        assertEquals(2, nestedContainer.getMethodDefinitions().size());
+        assertEquals(4, simpleContainer.getMethodDefinitions().size());
+        assertEquals(3, nestedContainer.getMethodDefinitions().size());
 
         int getFooMethodCounter = 0;
         int getBarMethodCounter = 0;
@@ -130,12 +123,11 @@ public class GeneratedTypesTest {
     }
 
     @Test
-    public void testLeafListResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
-        final File testFile = new File(getClass().getResource("/simple-leaf-list-demo.yang").toURI());
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+    public void testLeafListResolving() {
+        final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-leaf-list-demo.yang");
         assertNotNull(context);
 
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertNotNull(genTypes);
@@ -152,8 +144,8 @@ public class GeneratedTypesTest {
         }
         assertNotNull(simpleContainer);
         assertNotNull(nestedContainer);
-        assertEquals(3, simpleContainer.getMethodDefinitions().size());
-        assertEquals(2, nestedContainer.getMethodDefinitions().size());
+        assertEquals(4, simpleContainer.getMethodDefinitions().size());
+        assertEquals(3, nestedContainer.getMethodDefinitions().size());
 
         int getFooMethodCounter = 0;
         int getBarMethodCounter = 0;
@@ -163,6 +155,9 @@ public class GeneratedTypesTest {
         String getBarMethodReturnTypeName = "";
         String getNestedContainerReturnTypeName = "";
         for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
+            if (method.isDefault()) {
+                continue;
+            }
             if (method.getName().equals("getFoo")) {
                 getFooMethodCounter++;
                 getFooMethodReturnTypeName = method.getReturnType().getName();
@@ -214,12 +209,11 @@ public class GeneratedTypesTest {
     }
 
     @Test
-    public void testListResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
-        final File testFile = new File(getClass().getResource("/simple-list-demo.yang").toURI());
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+    public void testListResolving() {
+        final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-list-demo.yang");
         assertNotNull(context);
 
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertNotNull(genTypes);
@@ -263,22 +257,31 @@ public class GeneratedTypesTest {
                     simpleListMethodsCount = genType.getMethodDefinitions().size();
                     final List<MethodSignature> methods = genType.getMethodDefinitions();
                     for (final MethodSignature method : methods) {
-                        if (method.getName().equals("getKey")) {
-                            getSimpleListKeyMethodCount++;
-                            getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
-                        } else if (method.getName().equals("getListChildContainer")) {
-                            getListChildContainerMethodCount++;
-                            getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
-                        } else if (method.getName().equals("getFoo")) {
-                            getFooMethodCount++;
-                        } else if (method.getName().equals("setFoo")) {
-                            setFooMethodCount++;
-                        } else if (method.getName().equals("getSimpleLeafList")) {
-                            getSimpleLeafListMethodCount++;
-                        } else if (method.getName().equals("setSimpleLeafList")) {
-                            setSimpleLeafListMethodCount++;
-                        } else if (method.getName().equals("getBar")) {
-                            getBarMethodCount++;
+                        switch (method.getName()) {
+                            case BindingMapping.IDENTIFIABLE_KEY_NAME:
+                                getSimpleListKeyMethodCount++;
+                                getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
+                                break;
+                            case "getListChildContainer":
+                                getListChildContainerMethodCount++;
+                                getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
+                                break;
+                            case "getFoo":
+                                getFooMethodCount++;
+                                break;
+                            case "setFoo":
+                                setFooMethodCount++;
+                                break;
+                            case "getSimpleLeafList":
+                                getSimpleLeafListMethodCount++;
+                                break;
+                            case "setSimpleLeafList":
+                                setSimpleLeafListMethodCount++;
+                                break;
+                            case "getBar":
+                                getBarMethodCount++;
+                                break;
+                            default:
                         }
                     }
                 } else if (genType.getName().equals("ListChildContainer")) {
@@ -307,8 +310,8 @@ public class GeneratedTypesTest {
             }
         }
 
-        assertEquals(1, listParentContainerMethodsCount);
-        assertEquals(1, listChildContainerMethodsCount);
+        assertEquals(3, listParentContainerMethodsCount);
+        assertEquals(2, listChildContainerMethodsCount);
         assertEquals(1, getSimpleListKeyMethodCount);
         assertEquals(1, listKeyClassCount);
 
@@ -333,16 +336,15 @@ public class GeneratedTypesTest {
         assertEquals(0, setSimpleLeafListMethodCount);
         assertEquals(1, getBarMethodCount);
 
-        assertEquals(6, simpleListMethodsCount);
+        assertEquals(7, simpleListMethodsCount);
     }
 
     @Test
-    public void testListCompositeKeyResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
-        final File testFile = new File(getClass().getResource("/list-composite-key.yang").toURI());
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+    public void testListCompositeKeyResolving() {
+        final SchemaContext context = YangParserTestUtils.parseYangResource("/list-composite-key.yang");
         assertNotNull(context);
 
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertNotNull(genTypes);
@@ -389,12 +391,11 @@ public class GeneratedTypesTest {
     }
 
     @Test
-    public void testGeneratedTypes() throws URISyntaxException, IOException, SourceException, ReactorException {
-        final File testFile = new File(getClass().getResource("/demo-topology.yang").toURI());
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+    public void testGeneratedTypes() {
+        final SchemaContext context = YangParserTestUtils.parseYangResource("/demo-topology.yang");
         assertNotNull(context);
 
-        final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertNotNull(genTypes);