[ONOS-5400][ONOS-5614] identity ref support in yangtools and defect fixes.

Change-Id: Ia1f32a6772e9d468717340953cf7598c61d9f1ed
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
index 4c35db6..8c7def0 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListenerTest.java
@@ -66,6 +66,20 @@
         ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
                 .getPatternList().listIterator();
         assertThat(patternListIterator.next(), is("[a-zA-Z]"));
+
+        leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("ipv4-address"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
+        assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
+        stringRestriction = (YangStringRestriction) leafInfo
+                .getDataType().getDataTypeExtendedInfo();
+        patternListIterator = stringRestriction.getPatternRestriction()
+                .getPatternList().listIterator();
+        assertThat(patternListIterator.next(), is(
+                "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}" +
+                        "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" +
+                        "(%[\\p{N}\\p{L}]+)?"));
     }
 
     /**
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/CompilerAnnotationTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/CompilerAnnotationTest.java
new file mode 100644
index 0000000..f5891bf
--- /dev/null
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/CompilerAnnotationTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.onosproject.yangutils.plugin.manager;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.onosproject.yangutils.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Unit test case for compiler annotation.
+ */
+public class CompilerAnnotationTest {
+    private final YangUtilManager utilManager = new YangUtilManager();
+    private static final String DIR = "target/compiler/";
+    private static final String COMP = System.getProperty("user.dir") + File
+            .separator + DIR;
+
+
+    /**
+     * Checks compiler annotation translation should not result in any exception.
+     *
+     * @throws MojoExecutionException
+     */
+    @Test
+    public void processTranslator() throws IOException,
+            ParserException, MojoExecutionException {
+        deleteDirectory(DIR);
+        String searchDir = "src/test/resources/compilerAnnotation";
+        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+        utilManager.parseYangFileInfoSet();
+        utilManager.createYangNodeSet();
+        utilManager.resolveDependenciesUsingLinker();
+
+        YangPluginConfig yangPluginConfig = new YangPluginConfig();
+        yangPluginConfig.setCodeGenDir(DIR);
+        utilManager.translateToJava(yangPluginConfig);
+        compileCode(COMP);
+        deleteDirectory(DIR);
+    }
+}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
index adeb42f..683867d 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
@@ -39,12 +39,12 @@
             .separator + DIR;
 
     /**
-     * Checks augment translation should not result in any exception.
+     * Checks translation should not result in any exception.
      *
      * @throws MojoExecutionException
      */
     @Test
-    public void processChoiceAugmentInterTranslator() throws IOException,
+    public void processTranslator() throws IOException,
             ParserException, MojoExecutionException {
         deleteDirectory(DIR);
         String searchDir = "src/test/resources/identityTranslator";
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
index 45bc03d..fe46f72 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileIdentityLinkingTest.java
@@ -33,8 +33,10 @@
 import org.onosproject.yangutils.linker.exceptions.LinkerException;
 import org.onosproject.yangutils.linker.impl.YangLinkerManager;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
 import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ListIterator;
 
@@ -43,6 +45,8 @@
 import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
 import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
 import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yangutils.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
 
 /**
  * Test cases for testing inter file linking for identity.
@@ -140,6 +144,23 @@
 
     }
 
+    @Test
+    public void processTranslator() throws IOException, ParserException, MojoExecutionException {
+
+        deleteDirectory("target/identityTranslator/");
+        String searchDir = "src/test/resources/interfileidentityimport";
+        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+        utilManager.parseYangFileInfoSet();
+        utilManager.createYangNodeSet();
+        utilManager.resolveDependenciesUsingLinker();
+
+        YangPluginConfig yangPluginConfig = new YangPluginConfig();
+        yangPluginConfig.setCodeGenDir("target/identityTranslator/");
+        utilManager.translateToJava(yangPluginConfig);
+        compileCode(System.getProperty("user.dir") + File
+                .separator + "target/identityTranslator/");
+    }
+
     /**
      * Checks inter file feature linking with included file.
      */
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
index 501e2bc..d1cfe08 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
@@ -57,7 +57,7 @@
         yangPluginConfig.setCodeGenDir(DIR);
         utilManager.translateToJava(yangPluginConfig);
         compileCode(COMP);
-        //deleteDirectory(DIR);
+        deleteDirectory(DIR);
     }
 
 }
diff --git a/plugin/maven/src/test/resources/ValidPatternStatement.yang b/plugin/maven/src/test/resources/ValidPatternStatement.yang
index 556db31..0c93e9d 100644
--- a/plugin/maven/src/test/resources/ValidPatternStatement.yang
+++ b/plugin/maven/src/test/resources/ValidPatternStatement.yang
@@ -7,4 +7,24 @@
             pattern "[a-zA-Z]";
          }
     }
+    leaf ipv4-address {
+         type string {
+           pattern
+          '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N}\p{L}]+)?';
+         }
+      description
+        "The ipv4-address type represents an IPv4 address in
+       dotted-quad notation.  The IPv4 address may include a zone
+       index, separated by a % sign.
+
+       The zone index is used to disambiguate identical address
+       values.  For link-local addresses, the zone index will
+       typically be the interface index number or the name of an
+       interface.  If the zone index is not present, the default
+       zone of the device will be used.
+
+       The canonical format for the zone index is the numerical
+       format";
+    }
+
 }
diff --git a/plugin/maven/src/test/resources/augmentTranslator/test.yang b/plugin/maven/src/test/resources/augmentTranslator/test.yang
index 20393a7..a5a0daf 100644
--- a/plugin/maven/src/test/resources/augmentTranslator/test.yang
+++ b/plugin/maven/src/test/resources/augmentTranslator/test.yang
@@ -71,6 +71,20 @@
         }
     }
     augment /choice1 {
+        case case2 {
+            container con1 {
+                leaf in1 {
+                   type int32;
+                }
+            }
+        }
+        case case3 {
+            container con2 {
+                leaf in2 {
+                   type int32;
+                }
+            }
+        }
         leaf-list leaf2 {
            type int32;
         }
diff --git a/plugin/maven/src/test/resources/compilerAnnotation/test.yang b/plugin/maven/src/test/resources/compilerAnnotation/test.yang
new file mode 100644
index 0000000..592e23f
--- /dev/null
+++ b/plugin/maven/src/test/resources/compilerAnnotation/test.yang
@@ -0,0 +1,33 @@
+module test {  
+    namespace "test:test";  
+    prefix test;
+    typedef type1 {
+        type string;
+    }
+    list list1 {
+       key "name sur-name";
+       leaf name {
+          type string;
+       }
+       leaf sur-name {
+           type type1;
+       }
+       choice c1 {
+          case ca1 {
+             leaf a {
+                type int32;
+             }
+          }
+       }
+    }
+    list list2 {
+           key "name sur-name";
+           leaf name {
+              type string;
+           }
+           leaf sur-name {
+               type type1;
+           }
+        }
+}
+    
diff --git a/plugin/maven/src/test/resources/compilerAnnotation/test2.yang b/plugin/maven/src/test/resources/compilerAnnotation/test2.yang
new file mode 100644
index 0000000..704f724
--- /dev/null
+++ b/plugin/maven/src/test/resources/compilerAnnotation/test2.yang
@@ -0,0 +1,21 @@
+module test1 {  
+    namespace "test1:test1";  
+    prefix test1 ;  
+
+    import test {
+       prefix test;
+    }
+    organization "";  
+    contact "";  
+
+    description   
+       "Defines basic service types for L3VPN service.";  
+
+    revision "2015-12-16" {  
+       reference "";  
+    }
+
+    ca:compiler-annotation /test:list1 {
+        ds:app-data-structure "Map";
+    }
+}
\ No newline at end of file
diff --git a/plugin/maven/src/test/resources/identityTranslator/test.yang b/plugin/maven/src/test/resources/identityTranslator/test.yang
index b8a3193..e8c1889 100644
--- a/plugin/maven/src/test/resources/identityTranslator/test.yang
+++ b/plugin/maven/src/test/resources/identityTranslator/test.yang
@@ -1,14 +1,70 @@
-module IdentityInModule{
+module IdentityTest{
     yang-version 1;
     namespace http://huawei.com;
-    prefix IdentityInModule;
+    prefix IdentityTest;
 
     identity ref-address-family {
-        reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+        description "ref-address-family";
     }
-    leaf tunnel {
+
+    identity ipv4-address-family {
+        base ref-address-family;
+    }
+
+    identity ipv6-address-family {
+        base ipv4-address-family;
+    }
+
+    typedef tunnel-type {
         type identityref {
             base ref-address-family;
         }
     }
-}
\ No newline at end of file
+    leaf tunnel1 {
+        type identityref {
+            base ipv4-address-family;
+        }
+    }
+
+    typedef type2 {
+       type identityref {
+            base ipv4-address-family;
+        }
+    }
+    typedef type3 {
+    type union {
+                type type2;
+                type identityref {
+                     base ipv4-address-family;
+                }
+            }
+    }
+    leaf tunnel {
+        type union {
+            type type2;
+            type identityref {
+                 base ipv6-address-family;
+            }
+        }
+    }
+ typedef ipv4-address {
+      type string {
+        pattern
+          '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N}\p{L}]+)?';
+      }
+      description
+        "The ipv4-address type represents an IPv4 address in
+       dotted-quad notation.  The IPv4 address may include a zone
+       index, separated by a % sign.
+
+       The zone index is used to disambiguate identical address
+       values.  For link-local addresses, the zone index will
+       typically be the interface index number or the name of an
+       interface.  If the zone index is not present, the default
+       zone of the device will be used.
+
+       The canonical format for the zone index is the numerical
+       format";
+    }
+
+}