[ONOS-4411,ONOS-4413,ONOS-4526] Yang Enumeration Translator and Defect fixes.
Change-Id: Ie5b6b5d6d6df283a57ae06b1979f0d03022f3baf
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;
+ }
}