[ONOS-4411,ONOS-4413,ONOS-4526] Yang Enumeration Translator and Defect fixes.

Change-Id: Ie5b6b5d6d6df283a57ae06b1979f0d03022f3baf
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
new file mode 100644
index 0000000..2a950fc
--- /dev/null
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.translator.tojava.utils;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Unit test case for enum translator.
+ */
+public final class EnumTranslatorTest {
+
+    private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+    /**
+     * Checks enum translation should not result in any exception.
+     */
+    @Test
+    public void processEnumTranslator()
+            throws IOException, ParserException {
+
+        String userDir = System.getProperty("user.dir");
+        YangNode node = manager.getDataModel("src/test/resources/EnumTranslator.yang");
+
+        YangPluginConfig yangPluginConfig = new YangPluginConfig();
+        yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
+
+        generateJavaCode(node, yangPluginConfig);
+
+        deleteDirectory(userDir + "/target/EnumTestGenFile/");
+    }
+    // TODO enhance the test cases, after having a framework of translator test.
+}
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
index 0d97cf0..9819445 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
@@ -22,6 +22,7 @@
 import java.lang.reflect.InvocationTargetException;
 
 import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
 
@@ -41,20 +42,23 @@
 public final class FileSystemUtilTest {
 
     private static final String BASE_DIR_PKG = "target.UnitTestCase.";
-    private static final String PKG_INFO_CONTENT = "testGeneration6";
     private static final String BASE_PKG = "target/UnitTestCase";
     private static final String TEST_DATA_1 = "This is to append a text to the file first1\n";
     private static final String TEST_DATA_2 = "This is next second line\n";
     private static final String TEST_DATA_3 = "This is next third line in the file";
+    private static final String TEST_FILE = "testFile";
+    private static final String SOURCE_TEST_FILE = "sourceTestFile";
+    private static final String DIR_PATH = "exist1.exist2.exist3";
+    private static final String PKG_INFO = "package-info.java";
 
     /**
      * A private constructor is tested.
      *
-     * @throws SecurityException         if any security violation is observed
-     * @throws NoSuchMethodException     if when the method is not found
-     * @throws IllegalArgumentException  if there is illegal argument found
-     * @throws InstantiationException    if instantiation is provoked for the private constructor
-     * @throws IllegalAccessException    if instance is provoked or a method is provoked
+     * @throws SecurityException if any security violation is observed
+     * @throws NoSuchMethodException if when the method is not found
+     * @throws IllegalArgumentException if there is illegal argument found
+     * @throws InstantiationException if instantiation is provoked for the private constructor
+     * @throws IllegalAccessException if instance is provoked or a method is provoked
      * @throws InvocationTargetException when an exception occurs by the method or constructor
      */
     @Test
@@ -62,7 +66,7 @@
             throws SecurityException, NoSuchMethodException, IllegalArgumentException,
             InstantiationException, IllegalAccessException, InvocationTargetException {
 
-        Class<?>[] classesToConstruct = {FileSystemUtil.class};
+        Class<?>[] classesToConstruct = {FileSystemUtil.class };
         for (Class<?> clazz : classesToConstruct) {
             Constructor<?> constructor = clazz.getDeclaredConstructor();
             constructor.setAccessible(true);
@@ -76,14 +80,13 @@
      * @throws IOException when fails to create a test file
      */
     @Test
-    public void updateFileHandleTest()
-            throws IOException {
+    public void updateFileHandleTest() throws IOException {
 
-        File dir = new File(BASE_PKG + SLASH + "File1");
+        File dir = new File(BASE_PKG + SLASH + TEST_FILE);
         dir.mkdirs();
-        File createFile = new File(dir + "testFile");
+        File createFile = new File(dir + TEST_FILE);
         createFile.createNewFile();
-        File createSourceFile = new File(dir + "sourceTestFile");
+        File createSourceFile = new File(dir + SOURCE_TEST_FILE);
         createSourceFile.createNewFile();
         updateFileHandle(createFile, TEST_DATA_1, false);
         updateFileHandle(createFile, TEST_DATA_2, false);
@@ -98,23 +101,31 @@
      * @throws IOException when failed to create a test file
      */
     @Test
-    public void packageExistTest()
-            throws IOException {
+    public void packageExistTest() throws IOException {
 
-        String dirPath = "exist1.exist2.exist3";
-        String strPath = BASE_DIR_PKG + dirPath;
+        String strPath = BASE_DIR_PKG + DIR_PATH;
         File createDir = new File(strPath.replace(PERIOD, SLASH));
         createDir.mkdirs();
-        File createFile = new File(createDir + SLASH + "package-info.java");
+        File createFile = new File(createDir + SLASH + PKG_INFO);
         createFile.createNewFile();
         assertThat(true, is(doesPackageExist(strPath)));
-        JavaFileInfo javaFileInfo = new JavaFileInfo();
-        javaFileInfo.setBaseCodeGenPath(BASE_DIR_PKG);
-        javaFileInfo.setPackageFilePath(dirPath);
-        YangJavaModule moduleNode = new YangJavaModule();
-        moduleNode.setJavaFileInfo(javaFileInfo);
-        createPackage(moduleNode);
+        createPackage(getStubNode());
         createDir.delete();
     }
 
+    /**
+     * Returns stub YANG node.
+     *
+     * @return stub node
+     */
+    private YangNode getStubNode() {
+        YangJavaModule module = new YangJavaModule();
+        module.setName(TEST_DATA_1);
+        JavaFileInfo javafileInfo = new JavaFileInfo();
+        javafileInfo.setJavaName(TEST_DATA_1);
+        javafileInfo.setBaseCodeGenPath("");
+        javafileInfo.setPackageFilePath(BASE_PKG);
+        module.setJavaFileInfo(javafileInfo);
+        return module;
+    }
 }
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
index 23541e0..0284ea0 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
@@ -51,7 +51,7 @@
     public ExpectedException thrown = ExpectedException.none();
 
     /**
-     * This test case checks the content recieved for the builder class java doc.
+     * This test case checks the content received for the builder class java doc.
      */
     @Test
     public void builderClassGenerationTest() {
@@ -61,7 +61,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the builder interface ge java doc.
+     * This test case checks the content received for the builder interface ge java doc.
      */
     @Test
     public void builderInterfaceGenerationTest() {
@@ -71,7 +71,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the build  java doc.
+     * This test case checks the content received for the build  java doc.
      */
     @Test
     public void buildGenerationTest() {
@@ -102,7 +102,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the constructor java doc.
+     * This test case checks the content received for the constructor java doc.
      */
     @Test
     public void constructorGenerationTest() {
@@ -113,7 +113,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the default constructor java doc.
+     * This test case checks the content received for the default constructor java doc.
      */
     @Test
     public void defaultConstructorGenerationTest() {
@@ -123,7 +123,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the getter java doc.
+     * This test case checks the content received for the getter java doc.
      */
     @Test
     public void getterGenerationTest() {
@@ -132,7 +132,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the impl class java doc.
+     * This test case checks the content received for the impl class java doc.
      */
     @Test
     public void implClassGenerationTest() {
@@ -143,7 +143,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the interface java doc.
+     * This test case checks the content received for the interface java doc.
      */
     @Test
     public void interfaceGenerationTest() {
@@ -154,7 +154,7 @@
     }
 
     /**
-     * This test case checks the content recieved for the package info  java doc.
+     * This test case checks the content received for the package info  java doc.
      */
     @Test
     public void packageInfoGenerationTest() {
@@ -163,7 +163,17 @@
     }
 
     /**
-     * This test case checks the content recieved for the setter java doc.
+     * This test case checks the content received for the package info  java doc.
+     */
+    @Test
+    public void packageInfoGenerationForChildNodeTest() {
+        String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true);
+        assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes")
+                && packageInfo.contains(END_STRING)));
+    }
+
+    /**
+     * This test case checks the content received for the setter java doc.
      */
     @Test
     public void setterGenerationTest() {
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
index b939516..204bd7b 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
@@ -47,6 +47,10 @@
     private static final String CREATE_PATH = BASE_DIR + File.separator + "dir1/dir2/dir3/dir4/";
     private static final String CHECK_STRING = "one, two, three, four, five, six";
     private static final String TRIM_STRING = "one, two, three, four, five, ";
+    private static final String CHECK1 = "check1";
+    private static final String PKG_INFO = "package-info.java";
+    private static final String PATH = "src/main/yangmodel/";
+    private static final String MSG = "Exception occured while creating package info file.";
 
     /**
      * Expected exceptions.
@@ -64,8 +68,8 @@
 
         File dirPath = new File(CREATE_PATH);
         dirPath.mkdirs();
-        addPackageInfo(dirPath, "check1", CREATE_PATH);
-        File filePath = new File(dirPath + File.separator + "package-info.java");
+        addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
+        File filePath = new File(dirPath + File.separator + PKG_INFO);
         assertThat(filePath.isFile(), is(true));
     }
 
@@ -79,8 +83,23 @@
 
         File dirPath = new File(CREATE_PATH);
         dirPath.mkdirs();
-        addPackageInfo(dirPath, "check1", "src/main/yangmodel/" + CREATE_PATH);
-        File filePath = new File(dirPath + File.separator + "package-info.java");
+        addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false);
+        File filePath = new File(dirPath + File.separator + PKG_INFO);
+        assertThat(filePath.isFile(), is(true));
+    }
+
+    /**
+     * This test case checks with a child node.
+     *
+     * @throws IOException when fails to do IO operations for test case
+     */
+    @Test
+    public void addPackageInfoWithChildNode() throws IOException {
+
+        File dirPath = new File(CREATE_PATH);
+        dirPath.mkdirs();
+        addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true);
+        File filePath = new File(dirPath + File.separator + PKG_INFO);
         assertThat(filePath.isFile(), is(true));
     }
 
@@ -94,9 +113,9 @@
 
         File dirPath = new File("invalid/check");
         thrown.expect(IOException.class);
-        thrown.expectMessage("Exception occured while creating package info file.");
-        addPackageInfo(dirPath, "check1", CREATE_PATH);
-        File filePath1 = new File(dirPath + File.separator + "package-info.java");
+        thrown.expectMessage(MSG);
+        addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
+        File filePath1 = new File(dirPath + File.separator + PKG_INFO);
         assertThat(filePath1.isFile(), is(false));
     }
 
diff --git a/src/test/resources/EnumTranslator.yang b/src/test/resources/EnumTranslator.yang
new file mode 100644
index 0000000..1957c1f
--- /dev/null
+++ b/src/test/resources/EnumTranslator.yang
@@ -0,0 +1,17 @@
+module Sfc {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf test{
+        type string;
+    }
+    leaf myenum {
+      type enumeration {
+         enum zero;
+         enum one;
+         enum seven {
+              value 7;
+             }
+         }
+     }
+}