Bharat saraswal
Committed by Gerrit Code Review

YANG translator error handler framework and UT fixes.

Change-Id: Icb4d65540ed7ea8d6ecbd8458d44d7d86df969fa
Showing 35 changed files with 449 additions and 462 deletions
......@@ -43,6 +43,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotificatio
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
import org.onosproject.yangutils.translator.exception.TranslatorException;
/**
* Factory to create data model objects based on the target file type.
......@@ -68,7 +69,7 @@ public final class YangDataModelFactory {
return new YangJavaModule();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -86,7 +87,7 @@ public final class YangDataModelFactory {
return new YangJavaAugment();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -104,7 +105,7 @@ public final class YangDataModelFactory {
return new YangJavaCase();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -122,7 +123,7 @@ public final class YangDataModelFactory {
return new YangJavaChoice();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -140,7 +141,7 @@ public final class YangDataModelFactory {
return new YangJavaContainer();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -158,7 +159,7 @@ public final class YangDataModelFactory {
return new YangJavaGrouping();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -176,7 +177,7 @@ public final class YangDataModelFactory {
return new YangJavaList();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -194,7 +195,7 @@ public final class YangDataModelFactory {
return new YangJavaSubModule();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -212,7 +213,7 @@ public final class YangDataModelFactory {
return new YangJavaTypeDef();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -230,7 +231,7 @@ public final class YangDataModelFactory {
return new YangJavaUses();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -248,7 +249,7 @@ public final class YangDataModelFactory {
return new YangJavaNotification();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -266,7 +267,7 @@ public final class YangDataModelFactory {
return new YangJavaRpc();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -284,7 +285,7 @@ public final class YangDataModelFactory {
return new YangJavaInput();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......@@ -302,7 +303,7 @@ public final class YangDataModelFactory {
return new YangJavaOutput();
}
default: {
throw new RuntimeException("Only YANG to Java is supported.");
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
......@@ -27,6 +28,7 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
......@@ -36,6 +38,7 @@ import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
......@@ -94,16 +97,7 @@ public class YangUtilManager extends AbstractMojo {
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private String searchDir;
private String codeGenDir;
/**
* Set current project.
*
* @param curProject maven project
*/
public void setCurrentProject(final MavenProject curProject) {
project = curProject;
}
private YangNode rootNode;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
......@@ -125,6 +119,7 @@ public class YangUtilManager extends AbstractMojo {
String yangFile = yangFileIterator.next();
try {
YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
setRootNode(yangNode);
generateJavaCode(yangNode, codeGenDir);
} catch (ParserException e) {
String logInfo = "Error in file: " + e.getFileName();
......@@ -143,8 +138,52 @@ public class YangUtilManager extends AbstractMojo {
addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project);
} catch (Exception e) {
getLog().info(e);
try {
translatorErrorHandler(getRootNode());
clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
} catch (IOException | DataModelException ex) {
throw new MojoExecutionException("Error handler failed to delete files for data model node.");
}
throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage());
}
}
/**
* Set current project.
*
* @param curProject maven project
*/
public void setCurrentProject(MavenProject curProject) {
project = curProject;
}
/**
* Returns current project.
*
* @return current project
*/
public MavenProject getCurrentProject() {
return project;
}
/**
* Returns current root YANG node of data-model tree.
*
* @return current root YANG node of data-model tree
*/
public YangNode getRootNode() {
return rootNode;
}
/**
* Sets current root YANG node of data-model tree.
*
* @param rootNode current root YANG node of data-model tree
*/
public void setRootNode(YangNode rootNode) {
this.rootNode = rootNode;
}
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList;
......@@ -63,7 +64,7 @@ public final class JavaAttributeInfo {
}
/**
* Construct object of java attribute info.
* Creates object of java attribute info.
*
* @param attrType YANG type
* @param name attribute name
......@@ -85,7 +86,7 @@ public final class JavaAttributeInfo {
public YangType<?> getAttributeType() {
if (attrType == null) {
throw new RuntimeException("Expected java attribute type is null");
throw new TranslatorException("Expected java attribute type is null");
}
return attrType;
}
......@@ -96,7 +97,6 @@ public final class JavaAttributeInfo {
* @param type the data type info of attribute
*/
public void setAttributeType(YangType<?> type) {
attrType = type;
}
......@@ -108,7 +108,7 @@ public final class JavaAttributeInfo {
public String getAttributeName() {
if (name == null) {
throw new RuntimeException("Expected java attribute name is null");
throw new TranslatorException("Expected java attribute name is null");
}
return name;
}
......@@ -119,7 +119,6 @@ public final class JavaAttributeInfo {
* @param attrName name of the attribute
*/
public void setAttributeName(String attrName) {
name = attrName;
}
......@@ -129,7 +128,6 @@ public final class JavaAttributeInfo {
* @return the if the added attribute is a list of info
*/
public boolean isListAttr() {
return isListAttr;
}
......@@ -139,7 +137,6 @@ public final class JavaAttributeInfo {
* @param isList if the added attribute is a list of info
*/
public void setListAttr(boolean isList) {
isListAttr = isList;
}
......@@ -151,7 +148,6 @@ public final class JavaAttributeInfo {
* qualified manner.
*/
public boolean isQualifiedName() {
return isQualifiedName;
}
......@@ -163,7 +159,6 @@ public final class JavaAttributeInfo {
* qualified manner
*/
public void setIsQualifiedAccess(boolean isQualified) {
isQualifiedName = isQualified;
}
......@@ -174,7 +169,6 @@ public final class JavaAttributeInfo {
* @return import info
*/
public JavaQualifiedTypeInfo getImportInfo() {
return importInfo;
}
......@@ -184,7 +178,6 @@ public final class JavaAttributeInfo {
* @param importInfo import info for the attribute type
*/
public void setImportInfo(JavaQualifiedTypeInfo importInfo) {
this.importInfo = importInfo;
}
......@@ -204,23 +197,14 @@ public final class JavaAttributeInfo {
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
JavaAttributeInfo newAttr = new JavaAttributeInfo();
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
attributeType, attributeName, isListAttribute);
newAttr.setImportInfo(importInfo);
newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(
curNode, importInfo));
newAttr.setAttributeName(getCamelCase(attributeName));
newAttr.setListAttr(isListAttribute);
newAttr.setImportInfo(importInfo);
newAttr.setAttributeType(attributeType);
return newAttr;
return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
}
/**
......@@ -237,12 +221,6 @@ public final class JavaAttributeInfo {
public static JavaAttributeInfo getCurNodeAsAttributeInParent(
YangNode curNode, YangNode parentNode, boolean isListNode) {
JavaAttributeInfo newAttr = new JavaAttributeInfo();
// if (curNode instanceof HasJavaFileInfo) {
// throw new RuntimeException("translator data model node does not have java info");
// }
String curNodeName = ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName();
/*
......@@ -251,16 +229,8 @@ public final class JavaAttributeInfo {
*/
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode,
curNodeName, isListNode);
newAttr.setImportInfo(qualifiedTypeInfo);
newAttr.setIsQualifiedAccess(
getIsQualifiedAccessOrAddToImportList(parentNode,
qualifiedTypeInfo));
newAttr.setAttributeName(getCamelCase(curNodeName));
newAttr.setListAttr(isListNode);
newAttr.setImportInfo(qualifiedTypeInfo);
newAttr.setAttributeType(null);
return newAttr;
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, parentNode, isListNode);
}
/**
......@@ -279,8 +249,6 @@ public final class JavaAttributeInfo {
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
JavaAttributeInfo newAttr = new JavaAttributeInfo();
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
......@@ -288,9 +256,26 @@ public final class JavaAttributeInfo {
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
attributeType, attributeName, isListAttribute);
AttributesJavaDataType.addImportInfo(importInfo);
return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
}
/**
* Returns java attribute info.
*
* @param importInfo java qualified type info
* @param attributeName attribute name
* @param attributeType attribute type
* @param curNode current YANG node
* @param isListAttribute is list attribute
* @return java attribute info.
*/
private static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName,
YangType<?> attributeType, YangNode curNode, boolean isListAttribute) {
JavaAttributeInfo newAttr = new JavaAttributeInfo();
newAttr.setImportInfo(importInfo);
newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(
curNode, importInfo));
newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(curNode, importInfo));
newAttr.setAttributeName(getCamelCase(attributeName));
newAttr.setListAttr(isListAttribute);
newAttr.setImportInfo(importInfo);
......
......@@ -19,6 +19,13 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
import static org.onosproject.yangutils.translator.tojava.TraversalType.ROOT;
import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING;
/**
* Implementation of Java code generator based on application schema.
......@@ -26,12 +33,36 @@ import org.onosproject.yangutils.datamodel.YangNode;
public final class JavaCodeGeneratorUtil {
/**
* Current YANG node.
*/
private static YangNode curNode;
/**
* Default constructor.
*/
private JavaCodeGeneratorUtil() {
}
/**
* Returns current YANG node.
*
* @return current YANG node
*/
public static YangNode getCurNode() {
return curNode;
}
/**
* Sets current YANG node.
*
* @param node current YANG node
*/
public static void setCurNode(YangNode node) {
curNode = node;
}
/**
* Generate Java code files corresponding to the YANG schema.
*
* @param rootNode root node of the data model tree
......@@ -40,23 +71,25 @@ public final class JavaCodeGeneratorUtil {
* node
*/
public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException {
YangNode curNode = rootNode;
TraversalType curTraversal = TraversalType.ROOT;
TraversalType curTraversal = ROOT;
while (!(curNode == null)) {
if (curTraversal != TraversalType.PARENT) {
if (curTraversal != PARENT) {
setCurNode(curNode);
generateCodeEntry(curNode, codeGenDir);
}
if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) {
curTraversal = TraversalType.CHILD;
if (curTraversal != PARENT && curNode.getChild() != null) {
curTraversal = CHILD;
curNode = curNode.getChild();
} else if (curNode.getNextSibling() != null) {
generateCodeExit(curNode);
curTraversal = TraversalType.SIBILING;
curTraversal = SIBILING;
curNode = curNode.getNextSibling();
} else {
generateCodeExit(curNode);
curTraversal = TraversalType.PARENT;
curTraversal = PARENT;
curNode = curNode.getParent();
}
}
......@@ -76,8 +109,8 @@ public final class JavaCodeGeneratorUtil {
if (curNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) curNode).generateCodeEntry(codeGenDir);
} else {
throw new RuntimeException(
"Gnenerated data model node cannot be translated to target language code");
throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
}
}
......@@ -93,8 +126,113 @@ public final class JavaCodeGeneratorUtil {
if (curNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) curNode).generateCodeExit();
} else {
throw new RuntimeException(
"Gnenerated data model node cannot be translated to target language code");
throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
}
}
/**
* Free other YANG nodes of data-model tree when error occurs while file generation of current node.
*
* @throws DataModelException when fails to do datamodel operations
*/
public static void freeRestResources() throws DataModelException {
YangNode curNode = getCurNode();
YangNode tempNode = curNode;
TraversalType curTraversal = ROOT;
while (!(curNode == tempNode.getParent())) {
if (curTraversal != PARENT && curNode.getChild() != null) {
curTraversal = CHILD;
curNode = curNode.getChild();
} else if (curNode.getNextSibling() != null) {
curTraversal = SIBILING;
if (curNode != tempNode) {
free(curNode);
}
curNode = curNode.getNextSibling();
} else {
curTraversal = PARENT;
if (curNode != tempNode) {
free(curNode);
}
curNode = curNode.getParent();
}
}
}
/**
* Free the current node.
*
* @param node YANG node
* @throws DataModelException when fails to do datamodel operations
*/
private static void free(YangNode node) throws DataModelException {
YangNode parent = node.getParent();
parent.setChild(null);
if (node.getNextSibling() != null) {
parent.setChild(node.getNextSibling());
} else if (node.getPreviousSibling() != null) {
parent.setChild(node.getPreviousSibling());
}
node = null;
}
/**
* Delete Java code files corresponding to the YANG schema.
*
* @param rootNode root node of data-model tree
* @throws IOException when fails to delete java code file the current node
* @throws DataModelException when fails to do datamodel operations
*/
public static void translatorErrorHandler(YangNode rootNode) throws IOException, DataModelException {
/**
* Free other resources where translator has failed.
*/
freeRestResources();
/**
* Start removing all open files.
*/
YangNode curNode = rootNode;
setCurNode(curNode.getChild());
TraversalType curTraversal = ROOT;
while (!(curNode == null)) {
if (curTraversal != PARENT) {
close(curNode);
}
if (curTraversal != PARENT && curNode.getChild() != null) {
curTraversal = CHILD;
curNode = curNode.getChild();
} else if (curNode.getNextSibling() != null) {
curTraversal = SIBILING;
curNode = curNode.getNextSibling();
} else {
curTraversal = PARENT;
curNode = curNode.getParent();
}
}
freeRestResources();
curNode = null;
}
/**
* Closes all the current open file handles of node and delete all generated files.
*
* @param curNode current YANG node
* @throws IOException when fails to do IO operations
*/
private static void close(YangNode curNode) throws IOException {
if (((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() != null) {
((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().close(true);
}
}
}
......
......@@ -16,11 +16,14 @@
package org.onosproject.yangutils.translator.tojava;
import org.onosproject.yangutils.translator.exception.TranslatorException;
/**
* Cached java file handle, which supports the addition of member attributes and
* methods.
*/
public class JavaFileInfo {
/**
* The type(s) of java source file(s) to be generated when the cached file
* handle is closed.
......@@ -93,8 +96,9 @@ public class JavaFileInfo {
* @return the java package
*/
public String getPackage() {
if (pkg == null) {
throw new RuntimeException("Referencing package of a generated java file which is not set");
throw new TranslatorException("Referencing package of a generated java file which is not set");
}
return pkg;
}
......
......@@ -21,6 +21,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
......@@ -64,7 +65,6 @@ public class JavaImportData {
* @return true if any of the attribute needs to be maintained as a list.
*/
public boolean getIfListImported() {
return isListToImport;
}
......@@ -74,7 +74,6 @@ public class JavaImportData {
* @param isList status to mention list is bing imported.
*/
public void setIfListImported(boolean isList) {
isListToImport = isList;
}
......@@ -84,7 +83,6 @@ public class JavaImportData {
* @return the set containing the imported class/interface info
*/
public SortedSet<JavaQualifiedTypeInfo> getImportSet() {
return importSet;
}
......@@ -94,7 +92,6 @@ public class JavaImportData {
* @param importSet the set containing the imported class/interface info
*/
private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) {
this.importSet = importSet;
}
......@@ -116,7 +113,7 @@ public class JavaImportData {
public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) {
if (!(curNode instanceof HasJavaImportData)) {
throw new RuntimeException("missing import info in data model node");
throw new TranslatorException("missing import info in data model node");
}
for (JavaQualifiedTypeInfo curImportInfo : ((HasJavaImportData) curNode).getJavaImportData().getImportSet()) {
if (curImportInfo.getClassInfo()
......@@ -165,7 +162,6 @@ public class JavaImportData {
* @return import for hash and equals method
*/
public String getImportForHashAndEquals() {
return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS;
}
......@@ -175,15 +171,13 @@ public class JavaImportData {
* @return import for to string method
*/
public String getImportForToString() {
return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS;
}
/**
* Sets import for to list.
* Sets import for the list attribute.
*/
private static String setImportForList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
}
}
......
......@@ -20,6 +20,7 @@ import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import com.google.common.base.MoreObjects;
......@@ -51,7 +52,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* @return the imported package info
*/
public String getPkgInfo() {
return pkgInfo;
}
......@@ -61,7 +61,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* @param pkgInfo the imported package info
*/
public void setPkgInfo(String pkgInfo) {
this.pkgInfo = pkgInfo;
}
......@@ -71,7 +70,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* @return the imported class/interface info
*/
public String getClassInfo() {
return classInfo;
}
......@@ -81,7 +79,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* @param classInfo the imported class/interface info
*/
public void setClassInfo(String classInfo) {
this.classInfo = classInfo;
}
......@@ -105,7 +102,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
if (attrType == null) {
throw new RuntimeException("missing data type of leaf " + attributeName);
throw new TranslatorException("missing data type of leaf " + attributeName);
}
/*
......@@ -121,7 +118,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
importInfo.setClassInfo(className);
String classPkg = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr, className);
if (classPkg == null) {
throw new RuntimeException("import package cannot be null when the class is used");
throw new TranslatorException("import package cannot be null when the class is used");
}
importInfo.setPkgInfo(classPkg);
} else {
......@@ -131,7 +128,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
*/
String dataTypeName = AttributesJavaDataType.getJavaDataType(attrType);
if (dataTypeName == null) {
throw new RuntimeException("not supported data type");
throw new TranslatorException("not supported data type");
}
importInfo.setClassInfo(dataTypeName);
}
......@@ -155,7 +152,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
if (!(curNode instanceof HasJavaFileInfo)) {
throw new RuntimeException("missing java file information to get the package details "
throw new TranslatorException("missing java file information to get the package details "
+ "of attribute corresponding to child node");
}
/*
......@@ -184,7 +181,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
boolean isImportPkgEqualCurNodePkg;
if (!(curNode instanceof HasJavaFileInfo)) {
throw new RuntimeException("missing java file info for getting the qualified access");
throw new TranslatorException("missing java file info for getting the qualified access");
}
if (importInfo.getClassInfo().contentEquals(
((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName())) {
......@@ -211,7 +208,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* If the current data model node is not supposed to import
* data, then this is a usage issue and needs to be fixed.
*/
throw new RuntimeException("Current node needs to support Imports");
throw new TranslatorException("Current node needs to support Imports");
}
boolean isImportAdded = ((HasJavaImportData) curNode).getJavaImportData()
......@@ -241,7 +238,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
YangNode curNode, JavaQualifiedTypeInfo importInfo) {
if (!(curNode instanceof HasJavaFileInfo)) {
throw new RuntimeException("missing java file info for the data model node");
throw new TranslatorException("missing java file info for the data model node");
}
return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage()
.contentEquals(importInfo.getPkgInfo()
......@@ -250,7 +247,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
@Override
public int hashCode() {
return Objects.hash(pkgInfo, classInfo);
}
......@@ -275,7 +271,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* @return if equal or not
*/
public boolean exactMatch(JavaQualifiedTypeInfo importInfo) {
return equals(importInfo)
&& Objects.equals(pkgInfo, importInfo.getPkgInfo())
&& Objects.equals(classInfo, importInfo.getClassInfo());
......@@ -283,7 +278,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("pkgInfo", pkgInfo)
.add("classInfo", classInfo).toString();
......@@ -296,7 +290,6 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
*/
@Override
public int compareTo(JavaQualifiedTypeInfo other) {
return getClassInfo().compareTo(other.getClassInfo());
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -76,7 +77,7 @@ public class YangJavaAugment extends YangAugment
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -88,7 +89,6 @@ public class YangJavaAugment extends YangAugment
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -99,7 +99,6 @@ public class YangJavaAugment extends YangAugment
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -111,7 +110,6 @@ public class YangJavaAugment extends YangAugment
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -122,11 +120,6 @@ public class YangJavaAugment extends YangAugment
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -137,7 +130,6 @@ public class YangJavaAugment extends YangAugment
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -76,7 +77,7 @@ public class YangJavaCase extends YangCase
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -88,7 +89,6 @@ public class YangJavaCase extends YangCase
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -99,7 +99,6 @@ public class YangJavaCase extends YangCase
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -111,7 +110,6 @@ public class YangJavaCase extends YangCase
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -122,11 +120,6 @@ public class YangJavaCase extends YangCase
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -137,7 +130,6 @@ public class YangJavaCase extends YangCase
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -76,7 +77,7 @@ public class YangJavaChoice extends YangChoice
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -88,7 +89,6 @@ public class YangJavaChoice extends YangChoice
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -99,7 +99,6 @@ public class YangJavaChoice extends YangChoice
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -111,7 +110,6 @@ public class YangJavaChoice extends YangChoice
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -122,11 +120,6 @@ public class YangJavaChoice extends YangChoice
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -137,7 +130,6 @@ public class YangJavaChoice extends YangChoice
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -76,7 +77,7 @@ public class YangJavaContainer extends YangContainer
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -88,7 +89,6 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -99,7 +99,6 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -111,7 +110,6 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -122,11 +120,6 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("Missing temp file handle for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -137,7 +130,6 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......@@ -177,7 +169,6 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -76,7 +77,7 @@ public class YangJavaGrouping extends YangGrouping
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -88,7 +89,6 @@ public class YangJavaGrouping extends YangGrouping
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -99,7 +99,6 @@ public class YangJavaGrouping extends YangGrouping
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -111,7 +110,6 @@ public class YangJavaGrouping extends YangGrouping
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -122,11 +120,6 @@ public class YangJavaGrouping extends YangGrouping
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -137,7 +130,6 @@ public class YangJavaGrouping extends YangGrouping
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -78,7 +79,7 @@ public class YangJavaInput extends YangInput
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -90,7 +91,6 @@ public class YangJavaInput extends YangInput
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -101,7 +101,6 @@ public class YangJavaInput extends YangInput
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -113,7 +112,6 @@ public class YangJavaInput extends YangInput
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -124,11 +122,6 @@ public class YangJavaInput extends YangInput
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("Missing temporary file handle for" +
"current node " + getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -139,7 +132,6 @@ public class YangJavaInput extends YangInput
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......@@ -179,7 +171,6 @@ public class YangJavaInput extends YangInput
*/
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -77,7 +78,7 @@ public class YangJavaList extends YangList
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -89,7 +90,6 @@ public class YangJavaList extends YangList
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -100,7 +100,6 @@ public class YangJavaList extends YangList
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -112,7 +111,6 @@ public class YangJavaList extends YangList
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -123,11 +121,6 @@ public class YangJavaList extends YangList
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -138,7 +131,6 @@ public class YangJavaList extends YangList
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......@@ -180,7 +172,6 @@ public class YangJavaList extends YangList
*/
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -76,7 +77,7 @@ public class YangJavaModule extends YangModule
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -88,7 +89,6 @@ public class YangJavaModule extends YangModule
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -99,7 +99,6 @@ public class YangJavaModule extends YangModule
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -111,7 +110,6 @@ public class YangJavaModule extends YangModule
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -122,11 +120,6 @@ public class YangJavaModule extends YangModule
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -137,7 +130,6 @@ public class YangJavaModule extends YangModule
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......@@ -170,7 +162,6 @@ public class YangJavaModule extends YangModule
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
return;
}
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
......@@ -76,7 +77,7 @@ public class YangJavaNotification extends YangNotification
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -88,7 +89,6 @@ public class YangJavaNotification extends YangNotification
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -99,7 +99,6 @@ public class YangJavaNotification extends YangNotification
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -111,7 +110,6 @@ public class YangJavaNotification extends YangNotification
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -122,11 +120,6 @@ public class YangJavaNotification extends YangNotification
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("Missing temporary file handle for" +
"current node " + getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -137,7 +130,6 @@ public class YangJavaNotification extends YangNotification
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -78,7 +79,7 @@ public class YangJavaOutput extends YangOutput
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -90,7 +91,6 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -101,7 +101,6 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -113,7 +112,6 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -124,11 +122,6 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("Missing temporary file handle for" +
"current node " + getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -139,7 +132,6 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......@@ -179,7 +171,6 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
}
......
......@@ -19,6 +19,7 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangBelongsTo;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -77,7 +78,7 @@ public class YangJavaSubModule extends YangSubModule
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -89,7 +90,6 @@ public class YangJavaSubModule extends YangSubModule
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -100,7 +100,6 @@ public class YangJavaSubModule extends YangSubModule
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -112,7 +111,6 @@ public class YangJavaSubModule extends YangSubModule
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -123,11 +121,6 @@ public class YangJavaSubModule extends YangSubModule
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -138,7 +131,6 @@ public class YangJavaSubModule extends YangSubModule
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......@@ -150,7 +142,6 @@ public class YangJavaSubModule extends YangSubModule
* @return the name space string of the module.
*/
private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
// TODO Auto-generated method stub
return "";
}
......@@ -190,6 +181,5 @@ public class YangJavaSubModule extends YangSubModule
@Override
public void generateCodeExit() {
// TODO Auto-generated method stub
}
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
......@@ -75,7 +76,7 @@ public class YangJavaTypeDef extends YangTypeDef
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -87,7 +88,6 @@ public class YangJavaTypeDef extends YangTypeDef
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
......@@ -98,7 +98,6 @@ public class YangJavaTypeDef extends YangTypeDef
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
......@@ -110,7 +109,6 @@ public class YangJavaTypeDef extends YangTypeDef
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
......@@ -121,11 +119,6 @@ public class YangJavaTypeDef extends YangTypeDef
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
......@@ -136,7 +129,6 @@ public class YangJavaTypeDef extends YangTypeDef
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
......@@ -170,11 +162,11 @@ public class YangJavaTypeDef extends YangTypeDef
/**
* Create a java file using the YANG grouping info.
*
* @throws IOException IO operations fails
*/
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
......@@ -61,8 +62,9 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
......@@ -106,6 +108,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava
*/
@Override
public void generateCodeEntry(String codeGenDir) {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
......
......@@ -47,6 +47,8 @@ public final class JavaIdentifierSyntax {
private static final int INDEX_ZERO = 0;
private static final int INDEX_ONE = 1;
private static final int INDEX_TWO = 2;
private static final int VALUE_CHECK = 10;
private static final String ZERO = "0";
/**
* Default constructor.
......@@ -103,12 +105,12 @@ public final class JavaIdentifierSyntax {
String pkg;
if (!(curNode instanceof HasJavaFileInfo)
|| curNode.getParent() == null) {
throw new RuntimeException("missing parent node to get current node's package");
throw new TranslatorException("missing parent node to get current node's package");
}
YangNode parentNode = getParentNodeInGenCode(curNode);
if (!(parentNode instanceof HasJavaFileInfo)) {
throw new RuntimeException("missing parent java node to get current node's package");
throw new TranslatorException("missing parent java node to get current node's package");
}
JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo();
pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
......@@ -122,7 +124,6 @@ public final class JavaIdentifierSyntax {
* @return version
*/
private static String getYangVersion(byte ver) {
return VERSION_PREFIX + ver;
}
......@@ -164,8 +165,8 @@ public final class JavaIdentifierSyntax {
for (int i = INDEX_ONE; i < revisionArr.length; i++) {
Integer val = Integer.parseInt(revisionArr[i]);
if (val < 10) {
rev = rev + "0";
if (val < VALUE_CHECK) {
rev = rev + ZERO;
}
rev = rev + val;
}
......@@ -242,7 +243,6 @@ public final class JavaIdentifierSyntax {
* @return corresponding java identifier
*/
public static String getCaptialCase(String yangIdentifier) {
return yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
}
......@@ -254,7 +254,6 @@ public final class JavaIdentifierSyntax {
* @return corresponding java identifier
*/
public static String getSmallCase(String yangIdentifier) {
return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
}
......@@ -265,7 +264,6 @@ public final class JavaIdentifierSyntax {
* @return java package
*/
public static String getJavaPackageFromPackagePath(String packagePath) {
return packagePath.replace(SLASH, PERIOD);
}
......@@ -276,7 +274,6 @@ public final class JavaIdentifierSyntax {
* @return java package
*/
public static String getPackageDirPathFromJavaJPackage(String packagePath) {
return packagePath.replace(PERIOD, SLASH);
}
}
......
......@@ -34,17 +34,18 @@ public final class UtilConstants {
/**
* JavaDocs for impl class.
*/
public static final String IMPL_CLASS_JAVA_DOC = " * Provides the implementation of ";
public static final String IMPL_CLASS_JAVA_DOC = " * Reperesents the implementation of ";
/**
* JavaDocs for builder class.
*/
public static final String BUILDER_CLASS_JAVA_DOC = " * Provides the builder implementation of ";
public static final String BUILDER_CLASS_JAVA_DOC = " * Reperesents the builder implementation of ";
/**
* JavaDocs for interface class.
*/
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which provides functionalities of ";
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which Reperesents the"
+ " functionalities of ";
/**
* JavaDocs for builder interface class.
......@@ -102,14 +103,9 @@ public final class UtilConstants {
public static final String JAVA_DOC_GETTERS = " * Returns the attribute ";
/**
* JavaDocs's description for default constructor.
*/
public static final String JAVA_DOC_DEFAULT_CONSTRUCTOR = " * Default Constructor.\n";
/**
* JavaDocs's description for constructor.
*/
public static final String JAVA_DOC_CONSTRUCTOR = " * Construct the object of ";
public static final String JAVA_DOC_CONSTRUCTOR = " * Creates an instance of ";
/**
* JavaDocs's description for build method.
......
......@@ -30,7 +30,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
......@@ -164,7 +163,7 @@ public final class JavaDocGen {
} else if (type.equals(JavaDocType.OF_METHOD)) {
javaDoc = generateForOf(name);
} else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) {
javaDoc = generateForDefaultConstructors();
javaDoc = generateForDefaultConstructors(name);
} else if (type.equals(JavaDocType.BUILD_METHOD)) {
javaDoc = generateForBuild(name);
} else {
......@@ -226,7 +225,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForOf(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
......@@ -241,7 +239,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForTypeDefSetter(String attribute) {
return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute
......@@ -255,7 +252,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForTypeDefConstructor(String attribute) {
return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
......@@ -269,7 +265,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForImplClass(String className) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
}
......@@ -280,7 +275,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForBuilderClass(String className) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + BUILDER_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
......@@ -292,7 +286,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForInterface(String interfaceName) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
......@@ -304,7 +297,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForBuilderInterface(String builderforName) {
return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
......@@ -316,19 +308,18 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForPackage(String packageName) {
return JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
}
/**
* Generate javaDocs for default constructor.
*
* @param className class name
* @return javaDocs
*/
private static String generateForDefaultConstructors() {
return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_DEFAULT_CONSTRUCTOR
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
private static String generateForDefaultConstructors(String className) {
return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className
+ PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
......@@ -338,7 +329,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForConstructors(String className) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE
+ FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
......@@ -353,7 +343,6 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForBuild(String buildName) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD
+ buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
......
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
......@@ -69,7 +69,7 @@ public class AttributesJavaDataTypeTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -78,7 +78,6 @@ public class AttributesJavaDataTypeTest {
*/
@Test
public void testgetJavaClassInfo() {
test = getJavaImportClass(getStubYangType(TYPE1), false);
assertThat(true, is(test.equals(CLASS_INFO1)));
......@@ -97,7 +96,6 @@ public class AttributesJavaDataTypeTest {
*/
@Test
public void testgetJavaDataType() {
test = getJavaDataType(getStubYangType(TYPE1));
assertThat(true, is(test.equals(CLASS_INFO1)));
......@@ -116,7 +114,6 @@ public class AttributesJavaDataTypeTest {
*/
@Test
public void testgetJavaPkgInfo() {
test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1);
assertThat(true, is(test.equals(JAVA_LANG)));
......@@ -137,7 +134,6 @@ public class AttributesJavaDataTypeTest {
* @return YANG type
*/
private YangType<?> getStubYangType(YangDataTypes dataTypes) {
YangType<?> type = new YangType();
type.setDataType(dataTypes);
return type;
......
......@@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
......@@ -62,7 +62,7 @@ public final class ClassDefinitionGeneratorTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -71,7 +71,6 @@ public final class ClassDefinitionGeneratorTest {
*/
@Test
public void generateBuilderClassDefinitionTest() {
String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME);
assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF)));
}
......@@ -81,7 +80,6 @@ public final class ClassDefinitionGeneratorTest {
*/
@Test
public void generateBuilderInterfaceDefinitionTest() {
String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME);
assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF)));
}
......@@ -91,7 +89,6 @@ public final class ClassDefinitionGeneratorTest {
*/
@Test
public void generateImplDefinitionTest() {
String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME);
assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF)));
}
......@@ -101,7 +98,6 @@ public final class ClassDefinitionGeneratorTest {
*/
@Test
public void generateinterfaceDefinitionTest() {
String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME);
assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF)));
}
......@@ -111,7 +107,6 @@ public final class ClassDefinitionGeneratorTest {
*/
@Test
public void generateTypeDefTest() {
String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME);
assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF)));
}
......
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.IsNot.not;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
......@@ -75,7 +75,7 @@ public class JavaCodeSnippetGenTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -84,7 +84,6 @@ public class JavaCodeSnippetGenTest {
*/
@Test
public void testForImportText() {
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
importInfo.setPkgInfo(PKG_INFO);
importInfo.setClassInfo(CLASS_INFO);
......@@ -99,11 +98,9 @@ public class JavaCodeSnippetGenTest {
*/
@Test
public void testForJavaClassDefStart() {
String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME);
assertThat(true, is(classDef
.equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
}
/**
......@@ -111,7 +108,6 @@ public class JavaCodeSnippetGenTest {
*/
@Test
public void testForListAttribute() {
String listAttribute = getListAttribute(STRING_DATA_TYPE);
assertThat(true,
is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET)));
......@@ -122,7 +118,6 @@ public class JavaCodeSnippetGenTest {
*/
@Test
public void testForJavaClassDefClose() {
String interfaceDef = getJavaClassDefClose();
assertThat(true, is(interfaceDef.equals(CLOSE_CURLY_BRACKET)));
}
......
......@@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
......@@ -30,7 +30,6 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getYangRevisionStr;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......@@ -79,7 +78,7 @@ public final class JavaIdentifierSyntaxTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -88,7 +87,6 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getRootPackageTest() {
String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
......@@ -99,7 +97,6 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getRootPackageWithSpecialCharactersTest() {
String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
......@@ -113,7 +110,6 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getRootPackageWithRevTest() {
String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2);
assertThat(rootPkgWithRev.equals(
DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
......@@ -125,7 +121,6 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getCapitalCaseTest() {
String capitalCase = getCaptialCase(WITHOUT_CAPITAL);
assertThat(capitalCase.equals(WITH_CAPITAL), is(true));
}
......@@ -135,7 +130,6 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getCamelCaseTest() {
String camelCase = getCamelCase(WITHOUT_CAMEL_CASE);
assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
}
......@@ -145,7 +139,6 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getSmallCaseTest() {
String smallCase = getSmallCase(WITHOUT_CAPITAL);
assertThat(smallCase.equals(WITH_SMALL), is(true));
}
......@@ -155,7 +148,6 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getPackageFromPathTest() {
String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE);
assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true));
}
......@@ -165,18 +157,7 @@ public final class JavaIdentifierSyntaxTest {
*/
@Test
public void getPathFromPackageTest() {
String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD);
assertThat(path.equals(PARENT_PACKAGE), is(true));
}
/**
* Unit test for getting the camel case for the received string.
*/
@Test
public void getYangRevTest() {
String rev = getYangRevisionStr(DATE1);
assertThat(rev.equals(DATE_WITH_REV1), is(true));
}
}
......
......@@ -25,7 +25,7 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
......@@ -108,7 +108,7 @@ public final class MethodsGeneratorTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -117,7 +117,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getTypeDefConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String test = getTypeDefConstructor(testAttr, CLASS_NAME);
assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
......@@ -128,7 +127,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getBuildTest() {
String method = getBuild(CLASS_NAME);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
......@@ -142,7 +140,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getBuildForInterfaceTest() {
String method = getBuildForInterface(CLASS_NAME);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + CLASS_NAME + SPACE + BUILD +
OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE)));
......@@ -153,7 +150,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getCheckNotNullTest() {
String method = getCheckNotNull(CLASS_NAME);
assertThat(true, is(method.equals(EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS
+ CLASS_NAME + COMMA + SPACE + CLASS_NAME + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE)));
......@@ -164,7 +160,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getConstructor(CLASS_NAME, testAttr);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
......@@ -176,7 +171,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getConstructorStartTest() {
String method = getConstructorStart(CLASS_NAME);
assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
......@@ -188,7 +182,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getEqualsMethodTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getEqualsMethod(testAttr);
assertThat(true, is(method.contains(SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD
......@@ -200,7 +193,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getToStringMethodTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getToStringMethod(testAttr);
assertThat(true, is(method.equals(
......@@ -213,7 +205,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getGetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getGetterForClass(testAttr);
assertThat(true, is(method.contains(PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
......@@ -224,7 +215,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getGetterForInterfaceTest() {
String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false);
assertThat(true, is(method.contains(STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
}
......@@ -234,7 +224,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getSetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(testAttr, CLASS_NAME);
assertThat(true, is(
......@@ -248,7 +237,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getSetterForInterfaceTest() {
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false);
assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
}
......@@ -258,7 +246,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getOfMethodest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getOfMethod(CLASS_NAME, testAttr);
assertThat(true, is(method.contains(PUBLIC + SPACE + STATIC + SPACE + CLASS_NAME + SPACE + OF + OPEN_PARENTHESIS
......@@ -270,7 +257,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getSetterForTypeDefClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForTypeDefClass(testAttr);
assertThat(true, is(method.contains(PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX)));
......@@ -281,7 +267,6 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getOverRideStringTest() {
String method = getOverRideString();
assertThat(true, is(method.contains(OVERRIDE)));
}
......@@ -292,7 +277,6 @@ public final class MethodsGeneratorTest {
* @return java attribute
*/
private JavaAttributeInfo getTestAttribute() {
JavaAttributeInfo testAttr = new JavaAttributeInfo(getTestYangType(), ATTRIBUTE_NAME, false, false);
testAttr.setAttributeName(ATTRIBUTE_NAME);
testAttr.setAttributeType(getTestYangType());
......@@ -306,7 +290,6 @@ public final class MethodsGeneratorTest {
* @return java qualified info
*/
private JavaQualifiedTypeInfo getTestJavaQualifiedTypeInfo() {
JavaQualifiedTypeInfo info = new JavaQualifiedTypeInfo();
info.setPkgInfo(JAVA_LANG);
info.setClassInfo(STRING_DATA_TYPE);
......@@ -319,7 +302,6 @@ public final class MethodsGeneratorTest {
* @return test YANG type
*/
private YangType<?> getTestYangType() {
YangType<?> attrType = new YangType<>();
attrType.setDataTypeName(STRING_DATA_TYPE);
attrType.setDataType(STRING);
......
......@@ -16,12 +16,15 @@
package org.onosproject.yangutils.utils;
import org.junit.Test;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import static org.junit.Assert.assertNotNull;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
/**
* Test case for testing the util constants.
......@@ -45,11 +48,11 @@ public final class UtilConstantsTest {
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {UtilConstants.class};
Class<?>[] classesToConstruct = {UtilConstants.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
}
\ No newline at end of file
......
......@@ -16,27 +16,24 @@
package org.onosproject.yangutils.utils.io.impl;
import org.junit.Test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import static org.apache.commons.io.FileUtils.contentEquals;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNotNull;
import org.slf4j.Logger;
import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* Unit Tests for the CopyrightHeader contents.
*/
......@@ -65,41 +62,28 @@ public final class CopyrightHeaderTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
/**
* This test case checks the received copyright header contents.
*
* @throws IOException when fails to do IO operations
*/
@Test
public void testGetCopyrightHeader() throws IOException {
CopyrightHeader.parseCopyrightHeader();
String licenseHeader = CopyrightHeader.getCopyrightHeader();
ClassLoader classLoader = CopyrightHeaderTest.class.getClassLoader();
String baseDir = System.getProperty("basedir");
String path = "/src/test/resources/CopyrightHeader.txt";
String licenseHeader = getCopyrightHeader();
File test = new File("target/TestCopyrightHeader.txt");
FileWriter out = new FileWriter(test);
out.write(licenseHeader);
out.close();
File temp = new File("target/temp.txt");
InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt");
OutputStream outStream = new FileOutputStream(temp);
int i;
while ((i = stream.read()) != -1) {
outStream.write(i);
}
outStream.close();
stream.close();
BufferedReader br1 = new BufferedReader(new FileReader(test));
BufferedReader br2 = new BufferedReader(new FileReader(temp));
while (br1.readLine() != null && br2.readLine() != null) {
assertThat(true, is((br1.readLine()).equals(br2.readLine())));
}
br1.close();
br2.close();
assertThat(true, is(contentEquals(test, new File(baseDir + path))));
}
}
\ No newline at end of file
......
......@@ -22,10 +22,16 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.onosproject.yangutils.utils.UtilConstants;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.doesPackageExist;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
* Tests the file handle utilities.
......@@ -57,7 +63,7 @@ public final class FileSystemUtilTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -69,17 +75,17 @@ public final class FileSystemUtilTest {
@Test
public void updateFileHandleTest() throws IOException {
File dir = new File(BASE_PKG + File.separator + "File1");
File dir = new File(BASE_PKG + SLASH + "File1");
dir.mkdirs();
File createFile = new File(dir + "testFile");
createFile.createNewFile();
File createSourceFile = new File(dir + "sourceTestFile");
createSourceFile.createNewFile();
FileSystemUtil.updateFileHandle(createFile, TEST_DATA_1, false);
FileSystemUtil.updateFileHandle(createFile, TEST_DATA_2, false);
FileSystemUtil.updateFileHandle(createFile, TEST_DATA_3, false);
FileSystemUtil.appendFileContents(createFile, createSourceFile);
FileSystemUtil.updateFileHandle(createFile, null, true);
updateFileHandle(createFile, TEST_DATA_1, false);
updateFileHandle(createFile, TEST_DATA_2, false);
updateFileHandle(createFile, TEST_DATA_3, false);
appendFileContents(createFile, createSourceFile);
updateFileHandle(createFile, null, true);
}
/**
......@@ -92,12 +98,12 @@ public final class FileSystemUtilTest {
String dirPath = "exist1.exist2.exist3";
String strPath = BASE_DIR_PKG + dirPath;
File createDir = new File(strPath.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
File createDir = new File(strPath.replace(PERIOD, SLASH));
createDir.mkdirs();
File createFile = new File(createDir + File.separator + "package-info.java");
File createFile = new File(createDir + SLASH + "package-info.java");
createFile.createNewFile();
assertTrue(FileSystemUtil.doesPackageExist(strPath));
FileSystemUtil.createPackage(strPath, PKG_INFO_CONTENT);
assertThat(true, is(doesPackageExist(strPath)));
createPackage(strPath, PKG_INFO_CONTENT);
createDir.delete();
}
......
......@@ -16,22 +16,37 @@
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.JavaDocGen.JavaDocType;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_SETTER_METHOD;
/**
* Tests the java doc that is generated.
*/
public final class JavaDocGenTest {
private static final String TEST_NAME = "testName";
private static final String END_STRING = " */\n";
@Rule
public ExpectedException thrown = ExpectedException.none();
......@@ -40,10 +55,9 @@ public final class JavaDocGenTest {
*/
@Test
public void builderClassGenerationTest() {
String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1", false);
assertTrue(builderClassJavaDoc.contains("Provides the builder implementation of")
&& builderClassJavaDoc.contains(" */\n"));
String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false);
assertThat(true, is(builderClassJavaDoc.contains("Reperesents the builder implementation of")
&& builderClassJavaDoc.contains(END_STRING)));
}
/**
......@@ -51,9 +65,9 @@ public final class JavaDocGenTest {
*/
@Test
public void builderInterfaceGenerationTest() {
String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1", false);
assertTrue(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(" */\n"));
String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false);
assertThat(true,
is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING)));
}
/**
......@@ -61,9 +75,8 @@ public final class JavaDocGenTest {
*/
@Test
public void buildGenerationTest() {
String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD_METHOD, "testGeneration1", false);
assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n"));
String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false);
assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING)));
}
/**
......@@ -84,7 +97,7 @@ public final class JavaDocGenTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -93,12 +106,10 @@ public final class JavaDocGenTest {
*/
@Test
public void constructorGenerationTest() {
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"));
JavaDocType.valueOf(JavaDocType.CONSTRUCTOR.toString());
String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false);
assertThat(true,
is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of")
&& constructorDoc.contains("@param") && constructorDoc.contains("*/\n")));
}
/**
......@@ -106,9 +117,9 @@ public final class JavaDocGenTest {
*/
@Test
public void defaultConstructorGenerationTest() {
String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1", false);
assertTrue(defaultConstructorDoc.contains("Default Constructor") && defaultConstructorDoc.contains(" */\n"));
String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false);
assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ")
&& defaultConstructorDoc.contains(END_STRING)));
}
/**
......@@ -116,9 +127,8 @@ public final class JavaDocGenTest {
*/
@Test
public void getterGenerationTest() {
String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER_METHOD, "testGeneration1", false);
assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n"));
String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false);
assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
}
/**
......@@ -126,8 +136,10 @@ public final class JavaDocGenTest {
*/
@Test
public void implClassGenerationTest() {
String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1", false);
assertTrue(implClassJavaDoc.contains("Provides the implementation of") && implClassJavaDoc.contains(" */\n"));
String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false);
assertThat(true,
is(implClassJavaDoc.contains("Reperesents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
}
/**
......@@ -135,10 +147,10 @@ public final class JavaDocGenTest {
*/
@Test
public void interfaceGenerationTest() {
String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1", false);
assertTrue(interfaceJavaDoc.contains("Abstraction of an entity which provides functionalities of")
&& interfaceJavaDoc.contains(" */\n"));
String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false);
assertThat(true,
is(interfaceJavaDoc.contains("Abstraction of an entity which Reperesents the functionalities of")
&& interfaceJavaDoc.contains(END_STRING)));
}
/**
......@@ -146,9 +158,8 @@ public final class JavaDocGenTest {
*/
@Test
public void packageInfoGenerationTest() {
String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1", false);
assertTrue(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(" */\n"));
String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false);
assertThat(true, is(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(END_STRING)));
}
/**
......@@ -156,9 +167,9 @@ public final class JavaDocGenTest {
*/
@Test
public void setterGenerationTest() {
String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER_METHOD, "testGeneration1", false);
assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n"));
String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false);
assertThat(true,
is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING)));
}
/**
......@@ -166,8 +177,7 @@ public final class JavaDocGenTest {
*/
@Test
public void typeDefSetterGenerationTest() {
String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER_METHOD, "testGeneration1", false);
assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n"));
String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false);
assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING)));
}
}
\ No newline at end of file
......
......@@ -28,10 +28,15 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getJavaFiles;
import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles;
import static org.slf4j.LoggerFactory.getLogger;
import static java.io.File.separator;
/**
* Test the file scanner service.
*/
......@@ -62,23 +67,25 @@ public final class YangFileScannerTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
/**
* This test case checks for a .java file inside the specified dir.
*
* @throws IOException when fails to do IO operations
*/
@Test
public void checkJavaFileInsideDirTest() throws IOException {
String dir = baseDir + File.separator + "scanner2";
String dir = baseDir + separator + "scanner2";
File path = createDirectory(dir);
createFile(path, "testScanner.java");
List<String> dirContents = YangFileScanner.getJavaFiles(path.toString());
List<String> dirContents = getJavaFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
expectedContents.add(path.getCanonicalPath() + File.separator + "testScanner.java");
assertEquals(dirContents, expectedContents);
expectedContents.add(path.getCanonicalPath() + separator + "testScanner.java");
assertThat(true, is(dirContents.equals(expectedContents)));
}
/**
......@@ -87,7 +94,7 @@ public final class YangFileScannerTest {
* @param path where directories should be created
* @return the directory path that is created
*/
public File createDirectory(String path) {
private File createDirectory(String path) {
File myDir = new File(path);
myDir.mkdirs();
......@@ -100,67 +107,59 @@ public final class YangFileScannerTest {
* @param myDir the path where file has to be created inside
* @param fileName the name of the file to be created
*/
public void createFile(File myDir, String fileName) throws IOException {
private void createFile(File myDir, String fileName) throws IOException {
File file = null;
file = new File(myDir + File.separator + fileName);
file = new File(myDir + separator + fileName);
file.createNewFile();
}
/**
* This testcase checks for a java file inside an empty directory.
*
* @throws IOException when fails to do IO operations
*/
@Test
public void emptyDirJavaScannerTest() throws IOException {
String emptyDir = baseDir + File.separator + "scanner1";
String emptyDir = baseDir + separator + "scanner1";
File path = createDirectory(emptyDir);
List<String> emptyDirContents = YangFileScanner.getJavaFiles(path.toString());
List<String> emptyDirContents = getJavaFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
assertEquals(emptyDirContents, expectedContents);
assertThat(true, is(emptyDirContents.equals(expectedContents)));
}
/**
* This testcase checks for a yang file inside an empty directory.
*
* @throws IOException when fails to do IO operations
*/
@Test
public void emptyDirYangScannerTest() throws IOException {
String emptyYangDir = baseDir + File.separator + "scanner1";
String emptyYangDir = baseDir + separator + "scanner1";
File path = createDirectory(emptyYangDir);
List<String> emptyDirContents = YangFileScanner.getYangFiles(path.toString());
List<String> emptyDirContents = getYangFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
assertEquals(emptyDirContents, expectedContents);
assertThat(true, is(emptyDirContents.equals(expectedContents)));
}
/**
* This test case checks with the sub directories in the given path for java files.
*
* @throws IOException when fails to do IO operations
*/
@Test
public void emptySubDirScannerTest() throws IOException {
String dir = baseDir + File.separator + "scanner3";
String dir = baseDir + separator + "scanner3";
File path = createDirectory(dir);
String subDir = path.toString() + File.separator + "subDir1";
String subDir = path.toString() + separator + "subDir1";
createDirectory(subDir);
createFile(path, "invalidFile.txt");
List<String> emptySubDirContents = YangFileScanner.getJavaFiles(path.toString());
List<String> emptySubDirContents = getJavaFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
assertEquals(emptySubDirContents, expectedContents);
assertThat(true, is(emptySubDirContents.equals(expectedContents)));
}
/**
* This test case checks with the sub directories in the given path for java files.
@Test
public void exceptionHandleTest() throws IOException {
String dir = baseDir + File.separator + "scanner4";
thrown.expect(IOException.class);
List<String> invalidContents = YangFileScanner.getJavaFiles(dir);
File path = createDirectory(dir);
createFile(path, "except.java");
List<String> dirWithFileName = YangFileScanner
.getJavaFiles(path + File.separator + "except.java" + File.separator + "scanner5");
}*/
}
......
/*
* Copyright 2016 Open Networking Laboratory
*
......@@ -31,7 +30,7 @@ import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
......@@ -40,7 +39,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirector
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
* Unit tests for YANG io utils.
* Unit tests for YANG IO utils.
*/
public final class YangIoUtilsTest {
......@@ -119,7 +118,7 @@ public final class YangIoUtilsTest {
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertNotNull(constructor.newInstance());
assertThat(null, not(constructor.newInstance()));
}
}
......@@ -183,4 +182,5 @@ public final class YangIoUtilsTest {
String test = trimAtLast(CHECK_STRING, "six");
assertThat(test.contains(TRIM_STRING), is(true));
}
}
......