Fix leafref-to-enum encoding
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / GeneratedTypesTest.java
index ffa7bdf78975006f3373e648aa3272dcdc2782f3..c45534dcffcdc87ab0c9d3a4b1d004b6cf8fc3be 100644 (file)
@@ -19,6 +19,7 @@ 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.test.util.YangParserTestUtils;
 
@@ -59,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;
@@ -115,7 +116,7 @@ public class GeneratedTypesTest {
         }
 
         assertEquals(1, getFooMethodCounter);
-        assertEquals("Short", getFooMethodReturnTypeName);
+        assertEquals("Uint8", getFooMethodReturnTypeName);
 
         assertEquals(1, getBarMethodCounter);
         assertEquals("String", getBarMethodReturnTypeName);
@@ -143,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;
@@ -154,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();
@@ -198,7 +202,7 @@ public class GeneratedTypesTest {
         }
 
         assertEquals(1, getFooMethodCounter);
-        assertEquals("Short", getFooMethodReturnTypeName);
+        assertEquals("Uint8", getFooMethodReturnTypeName);
 
         assertEquals(1, getBarMethodCounter);
         assertEquals("List", getBarMethodReturnTypeName);
@@ -253,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")) {
@@ -297,8 +310,8 @@ public class GeneratedTypesTest {
             }
         }
 
-        assertEquals(1, listParentContainerMethodsCount);
-        assertEquals(1, listChildContainerMethodsCount);
+        assertEquals(3, listParentContainerMethodsCount);
+        assertEquals(2, listChildContainerMethodsCount);
         assertEquals(1, getSimpleListKeyMethodCount);
         assertEquals(1, listKeyClassCount);
 
@@ -323,7 +336,7 @@ public class GeneratedTypesTest {
         assertEquals(0, setSimpleLeafListMethodCount);
         assertEquals(1, getBarMethodCount);
 
-        assertEquals(6, simpleListMethodsCount);
+        assertEquals(7, simpleListMethodsCount);
     }
 
     @Test