ST defect fixes and review comments fixes
Change-Id: Ib8c56a88c19cd9aa23918d0f9e37c89e74cb0d13
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/CachedJavaFileHandleTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/CachedJavaFileHandleTest.java
index 2aa1daa..6b7228d 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/CachedJavaFileHandleTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/CachedJavaFileHandleTest.java
@@ -20,6 +20,10 @@
import java.io.IOException;
import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.CachedFileHandle;
@@ -33,7 +37,7 @@
*/
public class CachedJavaFileHandleTest {
- private static final String DIR_PKG = "target/unit/cachedfile/";
+ private static final String DIR_PKG = "target/unit/cachedfile/yangmodel/";
private static final String PKG = "org.onosproject.unittest";
private static final String CHILD_PKG = "target/unit/cachedfile/child";
private static final String YANG_NAME = "Test1";
@@ -42,7 +46,7 @@
/**
* Unit test case for add attribute info.
*
- * @throws IOException when fails to add an attribute.
+ * @throws IOException when fails to add an attribute
*/
@Test
public void testForAddAttributeInfo() throws IOException {
@@ -55,39 +59,23 @@
/**
* Unit test case for close of cached files.
*
- * @throws IOException when fails to generate files.
+ * @throws IOException when fails to generate files
*/
@Test
public void testForClose() throws IOException {
- // TODO: update to new framework.
- // CopyrightHeader.parseCopyrightHeader();
- //
- // AttributeInfo attr = getAttr();
- // attr.setListAttr(false);
- // CachedFileHandle handle = getFileHandle();
- // handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr());
- // handle.close();
- //
- // assertThat(true, is(getStubDir().exists()));
- // assertThat(true, is(getStubPkgInfo().exists()));
- // assertThat(true, is(getStubInterfaceFile().exists()));
- // assertThat(true, is(getStubBuilderFile().exists()));
- }
-
- /**
- * Unit test case for setting child's package.
- *
- * @throws IOException when fails to add child's package
- */
- @Test
- public void testForSetChildsPackage() throws IOException {
+ CopyrightHeader.parseCopyrightHeader();
AttributeInfo attr = getAttr();
attr.setListAttr(false);
CachedFileHandle handle = getFileHandle();
handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr());
+ handle.close();
+ assertThat(true, is(getStubDir().exists()));
+ assertThat(true, is(getStubPkgInfo().exists()));
+ assertThat(true, is(getStubInterfaceFile().exists()));
+ assertThat(true, is(getStubBuilderFile().exists()));
}
/**
@@ -113,14 +101,14 @@
/**
* Returns cached java file handle.
*
- * @return java file handle.
+ * @return java file handle
*/
private CachedFileHandle getFileHandle() throws IOException {
CopyrightHeader.parseCopyrightHeader();
FileSystemUtil.createPackage(DIR_PKG + File.separator + PKG, YANG_NAME);
CachedFileHandle fileHandle = FileSystemUtil.createSourceFiles(PKG, YANG_NAME, GEN_TYPE);
- fileHandle.setRelativeFilePath(DIR_PKG + PKG.replace(".", "/"));
-
+ fileHandle.setRelativeFilePath(PKG.replace(".", "/"));
+ fileHandle.setCodeGenFilePath(DIR_PKG);
return fileHandle;
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
index 6d0056e..d2cb823 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
@@ -16,17 +16,16 @@
package org.onosproject.yangutils.translator.tojava.utils;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
import org.junit.Test;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
import org.onosproject.yangutils.translator.tojava.TraversalType;
import org.onosproject.yangutils.utils.UtilConstants;
-import static org.hamcrest.core.Is.is;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
@@ -40,18 +39,14 @@
* @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 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 = {
- ClassDefinitionGenerator.class };
+ public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ InstantiationException, IllegalAccessException, InvocationTargetException {
+ Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
@@ -105,14 +100,14 @@
}
/**
- * Unit test for invalid generated type.
+ * Unit test for typedef generated type.
*/
@Test
- public void generateInvalidDefinitionTest() {
+ public void generateTypeDefTest() {
- // String invalidDefinition = ClassDefinitionGenerator
- // .generateClassDefinition(GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER, "invalid");
- // assertThat(true, is(invalidDefinition == null));
+ String typeDef = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.GENERATE_TYPEDEF_CLASS,
+ "invalid");
+ assertThat(true, is(typeDef.contains(UtilConstants.CLASS)));
}
/**
@@ -123,5 +118,6 @@
TraversalType.valueOf(TraversalType.CHILD.toString());
GeneratedMethodTypes.valueOf(GeneratedMethodTypes.CONSTRUCTOR.toString());
+ TempDataStoreTypes.valueOf(TempDataStoreTypes.CONSTRUCTOR.toString());
}
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
index fbd4183..f810ec9 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
@@ -25,8 +25,12 @@
import org.onosproject.yangutils.utils.UtilConstants;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.Is.is;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
/**
* Unit test cases for java code snippet generator.
*/
@@ -40,6 +44,27 @@
private static final String STRING = "String";
/**
+ * Unit test for private 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,
+ InstantiationException, IllegalAccessException, InvocationTargetException {
+ Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class };
+ for (Class<?> clazz : classesToConstruct) {
+ Constructor<?> constructor = clazz.getDeclaredConstructor();
+ constructor.setAccessible(true);
+ assertNotNull(constructor.newInstance());
+ }
+ }
+
+ /**
* Unit test case for import text.
*/
@Test
@@ -64,27 +89,6 @@
is(classDef.equals(UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE
+ UtilConstants.SPACE + YANG_NAME + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
+ UtilConstants.NEW_LINE)));
- }
-
- /**
- * Unit test case for java attribute info.
- */
- @SuppressWarnings("rawtypes")
- @Test
- public void testForJavaAttributeInfo() {
- // TODO: need to update for new framework
- // String attributeWithType
- // = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, getType());
- // assertThat(true, is(attributeWithType.equals(UtilConstants.PRIVATE + UtilConstants.SPACE
- // + getType().getDataTypeName() + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
- //
- // String attributeWithoutType
- // = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, null);
- // assertThat(true,
- // is(attributeWithoutType.equals(
- // UtilConstants.PRIVATE
- // + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
- // + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
}
@@ -99,29 +103,62 @@
}
/**
- * Unit test case for java method info.
+ * Unit test case for java class interface definition close.
*/
@Test
- public void testForJavaMethodInfo() {
- //TODO: update to new framework.
- // String method
- // = JavaCodeSnippetGen.getJavaMethodInfo(FILE_GEN_TYPE, YANG_NAME, METHOD_GEN_TYPE, getType());
- // assertThat(true,
- // is(method.equals(UtilConstants.FOUR_SPACE_INDENTATION
- // + JavaIdentifierSyntax.getCaptialCase(getType().getDataTypeName())
- // + UtilConstants.SPACE
- // + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
- // + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS
- // + UtilConstants.SEMI_COLAN)));
+ public void testForJavaClassDefInterfaceClose() {
+ String interfaceDef = JavaCodeSnippetGen.getJavaClassDefClose(FILE_GEN_TYPE, YANG_NAME);
+ assertThat(true, is(interfaceDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
}
/**
- * Unit test case for java class definition close.
+ * Unit test case for java class builder class definition close.
*/
@Test
- public void testForJavaClassDefClose() {
- String classDef = JavaCodeSnippetGen.getJavaClassDefClose(FILE_GEN_TYPE, YANG_NAME);
- assertThat(true, is(classDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
+ public void testForJavaClassDefBuilderClassClose() {
+ String builderClassDef = JavaCodeSnippetGen.getJavaClassDefClose(GeneratedFileType.BUILDER_CLASS_MASK,
+ YANG_NAME);
+ assertThat(true, is(builderClassDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
+ }
+
+ /**
+ * Unit test case for java class typedef definition close.
+ */
+ @Test
+ public void testForJavaClassDefTypeDefClose() {
+ String typeDef = JavaCodeSnippetGen.getJavaClassDefClose(GeneratedFileType.GENERATE_TYPEDEF_CLASS, YANG_NAME);
+ assertThat(true, is(typeDef.equals(UtilConstants.CLOSE_CURLY_BRACKET)));
+ }
+
+ /**
+ * Unit test case for java attribute info.
+ */
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void testForJavaAttributeInfo() {
+
+ String attributeWithoutTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, "String", YANG_NAME,
+ false);
+ assertThat(true, is(attributeWithoutTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + "String"
+ + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
+ String attributeWithTypePkg = JavaCodeSnippetGen.getJavaAttributeDefination("java.lang", "String", YANG_NAME,
+ false);
+ assertThat(true, is(attributeWithTypePkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + "java.lang."
+ + "String" + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
+ String attributeWithListPkg = JavaCodeSnippetGen.getJavaAttributeDefination("java.lang", "String", YANG_NAME,
+ true);
+ assertThat(true,
+ is(attributeWithListPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST
+ + UtilConstants.DIAMOND_OPEN_BRACKET + "java.lang."
+ + "String" + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME
+ + UtilConstants.SEMI_COLAN)));
+ String attributeWithListWithoutPkg = JavaCodeSnippetGen.getJavaAttributeDefination(null, "String", YANG_NAME,
+ true);
+ assertThat(true,
+ is(attributeWithListWithoutPkg.equals(UtilConstants.PRIVATE + UtilConstants.SPACE + UtilConstants.LIST
+ + UtilConstants.DIAMOND_OPEN_BRACKET + "String"
+ + UtilConstants.DIAMOND_CLOSE_BRACKET + UtilConstants.SPACE + YANG_NAME
+ + UtilConstants.SEMI_COLAN)));
}
/**
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index 6e89d93..b7bbbec 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -36,8 +36,8 @@
public static final String DATE2 = "1992-01-25";
public static final String PARENT_WITH_PERIOD = "test5.test6.test7";
public static final String CHILD_WITH_PERIOD = "test1.test2.test3";
- public static final String DATE_WITH_REV1 = "rev000105";
- public static final String DATE_WITH_REV2 = "rev920125";
+ public static final String DATE_WITH_REV1 = "rev20000105";
+ public static final String DATE_WITH_REV2 = "rev19920125";
public static final String VERSION_NUMBER = "v1";
public static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
public static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index 5ee059c..91a723f 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -16,18 +16,18 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import org.junit.Test;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertNotNull;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.tojava.AttributeInfo;
+import org.onosproject.yangutils.translator.tojava.ImportInfo;
+import org.onosproject.yangutils.utils.UtilConstants;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import org.junit.Test;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.translator.GeneratedFileType;
-import org.onosproject.yangutils.translator.tojava.AttributeInfo;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
/**
* Unit tests for generated methods from the file type.
*/
@@ -42,19 +42,15 @@
* @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 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 {
+ InstantiationException, IllegalAccessException, InvocationTargetException {
- Class<?>[] classesToConstruct = {
- MethodsGenerator.class };
+ Class<?>[] classesToConstruct = {MethodsGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
@@ -63,27 +59,100 @@
}
/**
- * Unit test for checking the values received from constructor, default
- * constructor and build string formation.
+ * Unit test case for checking the parse builder and typedef constructor.
+ */
+ @Test
+ public void getParseBuilderInterfaceMethodConstructorTest() {
+ ImportInfo forSetter = new ImportInfo();
+ attrType.setDataTypeName("binary");
+ attrType.getDataTypeName();
+ attrType.setDataType(YangDataTypes.BINARY);
+ attrType.getDataType();
+ testAttr.setAttributeName("attributeTest");
+ testAttr.setAttributeType(attrType);
+ forSetter.setPkgInfo("test1/test3");
+ forSetter.setClassInfo("This class contains");
+ testAttr.setImportInfo(forSetter);
+ String parseBuilderInterface = MethodsGenerator.parseBuilderInterfaceMethodString(testAttr, "newTestName");
+ assertThat(parseBuilderInterface.contains("attributeTest") && parseBuilderInterface.contains("newTestName"),
+ is(true));
+ String parseBuilderInterfaceBuild = MethodsGenerator.parseBuilderInterfaceBuildMethodString("testname7");
+ assertThat(parseBuilderInterfaceBuild.contains("Builds object of")
+ && parseBuilderInterfaceBuild.contains("testname7"), is(true));
+ String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname");
+ }
+
+ /**
+ * Unit test case for checking the values received from constructor, default constructor and build string formation.
*/
@Test
public void getValuesTest() {
String stringConstructor = MethodsGenerator.getConstructorString("testname");
- assertThat(
- stringConstructor.contains("Construct the object of testnameImpl.")
- && stringConstructor.contains("@param testnameObject builder object of testname")
- && stringConstructor.contains("public testnameImpl(testnameBuilder testnameObject) {"),
- is(true));
- String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString(
- GeneratedFileType.BUILDER_CLASS_MASK,
- "testname");
- assertThat(stringDefaultConstructor.contains("Default Constructor.")
- && stringDefaultConstructor.contains("public testnameBuilder() {")
- && stringDefaultConstructor.contains("}"), is(true));
+ assertThat(stringConstructor.contains(UtilConstants.JAVA_DOC_CONSTRUCTOR)
+ && stringConstructor.contains(UtilConstants.JAVA_DOC_PARAM)
+ && stringConstructor.contains(UtilConstants.BUILDER_OBJECT), is(true));
+ String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString("testnameBuilder", "public");
+ assertThat(stringDefaultConstructor.contains(UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR)
+ && stringDefaultConstructor.contains(UtilConstants.BUILDER)
+ && stringDefaultConstructor.contains("testname"), is(true));
String stringBuild = MethodsGenerator.getBuildString("testname");
- assertThat(
- stringBuild.contains("public testname build() {")
- && stringBuild.contains("return new testnameImpl(this);") && stringBuild.contains("}"),
- is(true));
+ assertThat(stringBuild.contains(UtilConstants.OVERRIDE) && stringBuild.contains(UtilConstants.BUILD)
+ && stringBuild.contains(UtilConstants.RETURN), is(true));
+
}
-}
\ No newline at end of file
+
+ /**
+ * Unit test for checking the values received for class getter, class and typedef setters with list data type.
+ */
+ @Test
+ public void getGetterSetterTest() {
+
+ ImportInfo forGetterSetter = new ImportInfo();
+ attrType.setDataTypeName("int");
+ attrType.getDataTypeName();
+ attrType.setDataType(YangDataTypes.UINT8);
+ attrType.getDataType();
+ testAttr.setAttributeName("AttributeTest1");
+ testAttr.setAttributeType(attrType);
+ forGetterSetter.setPkgInfo(null);
+ forGetterSetter.setClassInfo("This class contains");
+ testAttr.setImportInfo(forGetterSetter);
+ testAttr.setListAttr(true);
+ String getterForClass = MethodsGenerator.getGetterForClass(testAttr);
+ assertThat(getterForClass.contains(UtilConstants.GET_METHOD_PREFIX) && getterForClass.contains("List<")
+ && getterForClass.contains("attributeTest1"), is(true));
+ String setterForClass = MethodsGenerator.getSetterForClass(testAttr, "TestThis");
+ assertThat(setterForClass.contains(UtilConstants.SET_METHOD_PREFIX) && setterForClass.contains("List<")
+ && setterForClass.contains("attributeTest1"), is(true));
+ String typeDefSetter = MethodsGenerator.getSetterForTypeDefClass(testAttr);
+ assertThat(typeDefSetter.contains(UtilConstants.SET_METHOD_PREFIX) && typeDefSetter.contains("List<")
+ && typeDefSetter.contains("attributeTest1") && typeDefSetter.contains("this."), is(true));
+ }
+
+ /**
+ * Unit test case for checking the parse builder and typedef constructor with list data type.
+ */
+ @Test
+ public void getConstructorWithListTypeTest() {
+ ImportInfo forSetter = new ImportInfo();
+ attrType.setDataTypeName("binary");
+ attrType.getDataTypeName();
+ attrType.setDataType(YangDataTypes.BINARY);
+ attrType.getDataType();
+ testAttr.setAttributeName("attributeTest");
+ testAttr.setAttributeType(attrType);
+ forSetter.setPkgInfo(null);
+ forSetter.setClassInfo("This class contains");
+ testAttr.setImportInfo(forSetter);
+ testAttr.setListAttr(true);
+ String parseBuilderInterface = MethodsGenerator.parseBuilderInterfaceMethodString(testAttr, "newTestName");
+ assertThat(parseBuilderInterface.contains("attributeTest") && parseBuilderInterface.contains("List<"),
+ is(true));
+ String parseBuilderInterfaceBuild = MethodsGenerator.parseBuilderInterfaceBuildMethodString("testname7");
+ assertThat(parseBuilderInterfaceBuild.contains("Builds object of")
+ && parseBuilderInterfaceBuild.contains("testname7"), is(true));
+ String stringTypeDef = MethodsGenerator.getTypeDefConstructor(testAttr, "Testname");
+ assertThat(stringTypeDef.contains("(List<") && stringTypeDef.contains("Testname")
+ && stringTypeDef.contains(UtilConstants.THIS), is(true));
+ }
+}
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
+}