ST defect fixes and review comments fixes
Change-Id: Ib8c56a88c19cd9aa23918d0f9e37c89e74cb0d13
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 cf1cf8d..22a8cac 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
@@ -16,22 +16,25 @@
package org.onosproject.yangutils.utils.io.impl;
+import static org.slf4j.LoggerFactory.getLogger;
+
import org.junit.Test;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.translator.GeneratedFileType;
-import org.onosproject.yangutils.utils.UtilConstants;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+import org.onosproject.yangutils.translator.GeneratedFileType;
+import org.onosproject.yangutils.utils.UtilConstants;
import org.slf4j.Logger;
-import static org.slf4j.LoggerFactory.getLogger;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
+
/**
* Tests the file handle utilities.
@@ -50,12 +53,12 @@
/**
* 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 InvocationTargetException when an exception occurs by the method or constructor.
+ * @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
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
@@ -82,17 +85,18 @@
* This test case checks the contents to be written in the file.
*/
@Test
- public void insertStringInFileTest() throws IOException {
+ public void updateFileHandleTest() throws IOException {
File dir = new File(baseDir + File.separator + "File1");
dir.mkdirs();
File createFile = new File(dir + "testFile");
createFile.createNewFile();
File createSourceFile = new File(dir + "sourceTestFile");
createSourceFile.createNewFile();
- FileSystemUtil.insertStringInFile(createFile, "This is to append a text to the file first1\n");
- FileSystemUtil.insertStringInFile(createFile, "This is next second line\n");
- FileSystemUtil.insertStringInFile(createFile, "This is next third line in the file");
+ FileSystemUtil.updateFileHandle(createFile, "This is to append a text to the file first1\n", false);
+ FileSystemUtil.updateFileHandle(createFile, "This is next second line\n", false);
+ FileSystemUtil.updateFileHandle(createFile, "This is next third line in the file", false);
FileSystemUtil.appendFileContents(createFile, createSourceFile);
+ FileSystemUtil.updateFileHandle(createFile, null, true);
}
/**
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 9e41412..fcee4bf 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
@@ -41,7 +41,7 @@
@Test
public void builderClassGenerationTest() {
- String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1");
+ String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1", false);
assertTrue(builderClassJavaDoc.contains("Provides the builder implementation of")
&& builderClassJavaDoc.contains(" */\n"));
}
@@ -52,7 +52,7 @@
@Test
public void builderInterfaceGenerationTest() {
- String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1");
+ String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1", false);
assertTrue(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(" */\n"));
}
@@ -62,19 +62,19 @@
@Test
public void buildGenerationTest() {
- String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD, "testGeneration1");
+ String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD, "testGeneration1", false);
assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n"));
}
/**
* 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 InvocationTargetException when an exception occurs by the method or constructor.
+ * @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
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
@@ -94,7 +94,7 @@
@Test
public void constructorGenerationTest() {
- String constructorDoc = JavaDocGen.getJavaDoc(JavaDocType.CONSTRUCTOR, "testGeneration1");
+ String constructorDoc = JavaDocGen.getJavaDoc(JavaDocType.CONSTRUCTOR, "testGeneration1", false);
assertTrue(
constructorDoc.contains("Construct the object of") && constructorDoc.contains("builder object of")
&& constructorDoc.contains("@param") && constructorDoc.contains("*/\n"));
@@ -107,7 +107,7 @@
@Test
public void defaultConstructorGenerationTest() {
- String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1");
+ String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1", false);
assertTrue(defaultConstructorDoc.contains("Default Constructor") && defaultConstructorDoc.contains(" */\n"));
}
@@ -117,7 +117,7 @@
@Test
public void getterGenerationTest() {
- String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER, "testGeneration1");
+ String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER, "testGeneration1", false);
assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n"));
}
@@ -126,7 +126,7 @@
*/
@Test
public void implClassGenerationTest() {
- String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1");
+ String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1", false);
assertTrue(implClassJavaDoc.contains("Provides the implementation of") && implClassJavaDoc.contains(" */\n"));
}
@@ -136,7 +136,7 @@
@Test
public void interfaceGenerationTest() {
- String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1");
+ String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1", false);
assertTrue(interfaceJavaDoc.contains("Abstraction of an entity which provides functionalities of")
&& interfaceJavaDoc.contains(" */\n"));
}
@@ -146,10 +146,9 @@
*/
@Test
public void packageInfoGenerationTest() {
- // TODO: udpate to new framework.
- // String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1");
- // assertTrue(packageInfo.contains(
- // "Generated java code for the YANG file") && packageInfo.contains(" */\n"));
+
+ String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1", false);
+ assertTrue(packageInfo.contains("Generated java code corresponding to YANG") && packageInfo.contains(" */\n"));
}
/**
@@ -158,7 +157,17 @@
@Test
public void setterGenerationTest() {
- String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER, "testGeneration1");
+ String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER, "testGeneration1", false);
assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n"));
}
+
+ /**
+ * This test case checks the content received for the typedef setter java doc.
+ */
+ @Test
+ public void typeDefSetterGenerationTest() {
+
+ String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER, "testGeneration1", false);
+ assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n"));
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/TempDataStoreTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/TempDataStoreTest.java
deleted file mode 100644
index 11e31c5..0000000
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/TempDataStoreTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2016 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.utils.io.impl;
-
-import org.junit.Test;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.slf4j.Logger;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertNotNull;
-
-/**
- * Unit tests for the Tempd data store for its contents.
- */
-public final class TempDataStoreTest {
-
- private final Logger log = getLogger(getClass());
- private static final String CLASS_NAME = "YANG";
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- /**
- * 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 InvocationTargetException when an exception occurs by the method or constructor.
- */
- @Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
- InstantiationException, IllegalAccessException, InvocationTargetException {
-
- Class<?>[] classesToConstruct = {TempDataStore.class };
- for (Class<?> clazz : classesToConstruct) {
- Constructor<?> constructor = clazz.getDeclaredConstructor();
- constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
- }
- }
-
- /**
- * This test case checks the attribute info that is read and put into the list.
- */
- @Test
- public void insertAttributeDataTest() throws IOException, ClassNotFoundException, FileNotFoundException {
-
- String attributeData = "attribute content lists this";
- TempDataStore.setTempData(attributeData, TempDataStoreType.ATTRIBUTE, CLASS_NAME);
- List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, CLASS_NAME);
- List<String> expectedinfo = new LinkedList<>();
- expectedinfo.add(attributeData);
- assertThat(true, is(attributeInfo.equals(expectedinfo)));
- TempDataStoreType.valueOf(TempDataStoreType.ATTRIBUTE.toString());
- }
-
- /**
- * This test case checks the builder interface that is read and put into the list.
- */
- @Test
- public void insertBuilderInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
-
- String builderInterfaceMethodsData = "builder interface methods content lists this";
- TempDataStore.setTempData(builderInterfaceMethodsData, TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME);
- List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_INTERFACE_METHODS, CLASS_NAME);
- List<String> expectedinfo = new LinkedList<>();
- expectedinfo.add(builderInterfaceMethodsData);
- assertThat(true, is(attributeInfo.equals(expectedinfo)));
- }
-
- /**
- * This test case checks the builder methods that is read and put into the list.
- */
- @Test
- public void insertBuilderMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
-
- String builderMethodsData = "builder methods content lists this";
- TempDataStore.setTempData(builderMethodsData, TempDataStoreType.BUILDER_METHODS, CLASS_NAME);
- List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.BUILDER_METHODS, CLASS_NAME);
- List<String> expectedinfo = new LinkedList<>();
- expectedinfo.add(builderMethodsData);
- assertThat(true, is(attributeInfo.equals(expectedinfo)));
- }
-
- /**
- * This test case checks the impl methods that is read and put into the list.
- */
- @Test
- public void insertImplMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
-
- String implMethodsData = "impl methods content lists this";
- TempDataStore.setTempData(implMethodsData, TempDataStoreType.IMPL_METHODS, CLASS_NAME);
- List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPL_METHODS, CLASS_NAME);
- List<String> expectedinfo = new LinkedList<>();
- expectedinfo.add(implMethodsData);
- assertThat(true, is(attributeInfo.equals(expectedinfo)));
- }
-
- /**
- * This test case checks the import methods that is read and put into the list.
- */
- @Test
- public void insertImportTest() throws IOException, ClassNotFoundException, FileNotFoundException {
-
- String importData = "interface methods content lists this";
- TempDataStore.setTempData(importData, TempDataStoreType.IMPORT, CLASS_NAME);
- List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.IMPORT, CLASS_NAME);
- List<String> expectedinfo = new LinkedList<>();
- expectedinfo.add(importData);
- assertThat(true, is(attributeInfo.equals(expectedinfo)));
- }
-
- /**
- * This test case checks the interface methods that is read and put into the list.
- */
- @Test
- public void insertInterfaceMethodsTest() throws IOException, ClassNotFoundException, FileNotFoundException {
-
- String interfaceMethodsData = "interface methods content lists this";
- TempDataStore.setTempData(interfaceMethodsData, TempDataStoreType.GETTER_METHODS, CLASS_NAME);
- List<String> attributeInfo = TempDataStore.getTempData(TempDataStoreType.GETTER_METHODS, CLASS_NAME);
- List<String> expectedinfo = new LinkedList<>();
- expectedinfo.add(interfaceMethodsData);
- assertThat(true, is(attributeInfo.equals(expectedinfo)));
- }
-}
\ No newline at end of file
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
index 6441b19..cb2ad75 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
@@ -84,8 +84,8 @@
/**
* Method used for creating multiple directories inside the target file.
*
- * @param path where directories should be created.
- * @return
+ * @param path where directories should be created
+ * @return the directory path that is created
*/
public File createDirectory(String path) {
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 2cfc3b9..bbaa8b9 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
@@ -37,7 +37,7 @@
import java.lang.reflect.InvocationTargetException;
/**
- * Unit tests for adding package-info, creating directories, cleaning the folder and to add sources.
+ * Unit tests for YANG io utils.
*/
public final class YangIoUtilsTest {
@@ -65,6 +65,20 @@
}
/**
+ * This test case checks with an additional info in the path.
+ */
+ @Test
+ public void addPackageInfoWithPathTest() throws IOException {
+
+ File dirPath = new File(createPath);
+ dirPath.mkdirs();
+ CopyrightHeader.parseCopyrightHeader();
+ YangIoUtils.addPackageInfo(dirPath, "check1", "src/main/yangmodel/" + createPath);
+ File filePath = new File(dirPath + File.separator + "package-info.java");
+ assertThat(filePath.isFile(), is(true));
+ }
+
+ /**
* This test case checks whether the package-info file is created when invalid path is given.
*/
@Test
@@ -81,12 +95,12 @@
/**
* 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 InvocationTargetException when an exception occurs by the method or constructor.
+ * @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
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
@@ -146,4 +160,4 @@
sourceDir.mkdirs();
YangIoUtils.addToSource(sourceDir.toString(), project, context);
}
-}
\ No newline at end of file
+}