[ONOS-3880, 3881] Yang Listener for Module and Sub-Module
Change-Id: Iee75c3e04af9b66ebc38acb3396aa4c54af5a268
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java
index 50addeb..41d790d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/ParsableDataType.java
@@ -130,7 +130,186 @@
REVISION_DATA,
/**
+ * Identifies the YANG revision date parsed data.
+ */
+ REVISION_DATE_DATA,
+
+ /**
* Identifies the YANG namespace parsed data.
*/
- NAMESPACE_DATA
-}
+ NAMESPACE_DATA,
+
+ /**
+ * Identifies the YANG contact parsed data.
+ */
+ CONTACT_DATA,
+
+ /**
+ * Identifies the YANG config parsed data.
+ */
+ CONFIG_DATA,
+
+ /**
+ * Identifies the YANG description parsed data.
+ */
+ DESCRIPTION_DATA,
+
+ /**
+ * Identifies the YANG key parsed data.
+ */
+ KEY_DATA,
+
+ /**
+ * Identifies the YANG mandatory parsed data.
+ */
+ MANDATORY_DATA,
+
+ /**
+ * Identifies the YANG max element parsed data.
+ */
+ MAX_ELEMENT_DATA,
+
+ /**
+ * Identifies the YANG min element parsed data.
+ */
+ MIN_ELEMENT_DATA,
+
+ /**
+ * Identifies the YANG presence element parsed data.
+ */
+ PRESENCE_DATA,
+
+ /**
+ * Identifies the YANG reference element parsed data.
+ */
+ REFERENCE_DATA,
+
+ /**
+ * Identifies the YANG status element parsed data.
+ */
+ STATUS_DATA,
+
+ /**
+ * Identifies the YANG units element parsed data.
+ */
+ UNITS_DATA,
+
+ /**
+ * Identifies the YANG version element parsed data.
+ */
+ VERSION_DATA,
+
+ /**
+ * Identifies the YANG base element parsed data.
+ */
+ YANGBASE_DATA,
+
+ /**
+ * Identifies the YANG prefix element parsed data.
+ */
+ PREFIX_DATA,
+
+ /**
+ * Identifies the YANG default element parsed data.
+ */
+ DEFAULT_DATA,
+
+ /**
+ * Identifies the YANG organization parsed data.
+ */
+ ORGANIZATION_DATA;
+
+ /**
+ * Returns the YANG construct keyword corresponding to enum values.
+ *
+ * @param parsableDataType enum value for parsable data type.
+ * @return YANG construct keyword.
+ */
+ public static String getParsableDataType(ParsableDataType parsableDataType) {
+
+ switch (parsableDataType) {
+ case MODULE_DATA:
+ return "module";
+ case SUB_MODULE_DATA:
+ return "submodule";
+ case TYPEDEF_DATA:
+ return "typedef";
+ case TYPE_DATA:
+ return "type";
+ case CHOICE_DATA:
+ return "choice";
+ case CASE_DATA:
+ return "case";
+ case ENUMERATION_DATA:
+ return "enumeration";
+ case GROUPING_DATA:
+ return "grouping";
+ case USES_DATA:
+ return "uses";
+ case AUGMENT_DATA:
+ return "augment";
+ case CONTAINER_DATA:
+ return "container";
+ case LIST_DATA:
+ return "list";
+ case BELONGS_TO_DATA:
+ return "belongs-to";
+ case BIT_DATA:
+ return "bit";
+ case BITS_DATA:
+ return "bits";
+ case ENUM_DATA:
+ return "enum";
+ case IMPORT_DATA:
+ return "import";
+ case INCLUDE_DATA:
+ return "include";
+ case LEAF_DATA:
+ return "leaf";
+ case LEAF_LIST_DATA:
+ return "leaf-list";
+ case MUST_DATA:
+ return "must";
+ case REVISION_DATA:
+ return "revision";
+ case REVISION_DATE_DATA:
+ return "revision-date";
+ case NAMESPACE_DATA:
+ return "namespace";
+ case CONTACT_DATA:
+ return "contact";
+ case CONFIG_DATA:
+ return "config";
+ case DESCRIPTION_DATA:
+ return "description";
+ case KEY_DATA:
+ return "key";
+ case MANDATORY_DATA:
+ return "mandatory";
+ case MAX_ELEMENT_DATA:
+ return "max-elements";
+ case MIN_ELEMENT_DATA:
+ return "min-elements";
+ case PRESENCE_DATA:
+ return "presence";
+ case REFERENCE_DATA:
+ return "reference";
+ case STATUS_DATA:
+ return "status";
+ case UNITS_DATA:
+ return "units";
+ case VERSION_DATA:
+ return "version";
+ case YANGBASE_DATA:
+ return "yangbase";
+ case PREFIX_DATA:
+ return "prefix";
+ case ORGANIZATION_DATA:
+ return "organization";
+ case DEFAULT_DATA:
+ return "default";
+ default:
+ return "yang";
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/exceptions/ParserException.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/exceptions/ParserException.java
index 737048c..306828c 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/exceptions/ParserException.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/exceptions/ParserException.java
@@ -19,13 +19,12 @@
/**
* Base class for exceptions in parser operations.
*/
-public class ParserException extends Exception {
+public class ParserException extends RuntimeException {
private static final long serialVersionUID = 20160211L;
private int lineNumber;
private int charPositionInLine;
private String fileName;
- private String msg;
/**
* Create a new parser exception.
@@ -90,15 +89,6 @@
}
/**
- * Returns msg detail of exception in string.
- *
- * @return msg detail of exception in string
- */
- public String getMsg() {
- return this.msg;
- }
-
- /**
* Sets line number of YANG file.
*
* @param line line number of YANG file
@@ -117,15 +107,6 @@
}
/**
- * Sets the detail of exception in string.
- *
- * @param msg the detail of exception in string
- */
- public void setMsg(String msg) {
- this.msg = msg;
- }
-
- /**
* Sets file name in parser exception.
*
* @param fileName YANG file name
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
index 0878191..dcab33a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
@@ -69,16 +69,12 @@
// Add customized error listener to catch errors during parsing.
parser.addErrorListener(parseTreeErrorListener);
- // Begin parsing YANG file and generate parse tree.
- ParseTree tree = parser.yangfile();
+ ParseTree tree;
- /**
- * Throws an parser Exception if exception flag is set i.e. exception has
- * occurred during parsing.
- */
- if (parseTreeErrorListener.isExceptionFlag()) {
- // Get the exception occurred during parsing.
- ParserException parserException = parseTreeErrorListener.getParserException();
+ try {
+ // Begin parsing YANG file and generate parse tree.
+ tree = parser.yangfile();
+ } catch (ParserException parserException) {
parserException.setFileName(yangFile);
throw parserException;
}
@@ -93,18 +89,17 @@
* Walk parse tree, provide call backs to methods in listener and
* build data model tree.
*/
- walker.walk(treeWalker, tree);
-
- // Throws an parser exception which has occurred during listener walk.
- if (treeWalker.getErrorInformation().isErrorFlag()) {
- // Create object of listener exception
- ParserException listenerException = new ParserException();
- listenerException.setMsg(treeWalker.getErrorInformation().getErrorMsg());
+ try {
+ walker.walk(treeWalker, tree);
+ } catch (ParserException listenerException) {
+ // TODO free incomplete data model tree.
listenerException.setFileName(yangFile);
throw listenerException;
+ } finally {
+ // TODO free parsable stack
}
// Returns the Root Node of the constructed data model tree.
return treeWalker.getRootNode();
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
index 355c268..f53a767 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
@@ -16,8 +16,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -48,7 +57,11 @@
* @param ctx context object of the grammar rule.
*/
public static void processYangFileEntry(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
- // TODO method implementation
+
+ // Check if stack is empty.
+ ListenerValidation.checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.ENTRY);
+
}
/**
@@ -59,6 +72,25 @@
* @param ctx context object of the grammar rule.
*/
public static void processYangFileExit(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
+
+ // Data Model tree root node is set.
+ if (listener.getParsedDataStack().peek() instanceof YangModule
+ | listener.getParsedDataStack().peek() instanceof YangSubModule) {
+ listener.setRootNode((YangNode) listener.getParsedDataStack().pop());
+ } else {
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_CHILD,
+ ParsableDataType.YANGBASE_DATA, "",
+ ListenerErrorLocation.EXIT));
+ }
+
+ // Check if stack is empty.
+ ListenerValidation.checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
index efb997e..c8266dc 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
@@ -16,8 +16,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangBelongsTo;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -64,7 +73,18 @@
*/
public static void processBelongsToEntry(TreeWalkListener listener,
GeneratedYangParser.BelongstoStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.BELONGS_TO_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.ENTRY);
+
+ YangBelongsTo belongstoNode = new YangBelongsTo();
+ belongstoNode.setBelongsToModuleName(String.valueOf(ctx.IDENTIFIER().getText()));
+
+ // Push belongsto into the stack.
+ listener.getParsedDataStack().push(belongstoNode);
}
/**
@@ -76,6 +96,47 @@
*/
public static void processBelongsToExit(TreeWalkListener listener,
GeneratedYangParser.BelongstoStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.BELONGS_TO_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ Parsable tmpBelongstoNode = listener.getParsedDataStack().peek();
+ if (tmpBelongstoNode instanceof YangBelongsTo) {
+ listener.getParsedDataStack().pop();
+
+ // Check for stack to be empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.BELONGS_TO_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case SUB_MODULE_DATA: {
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ subModule.setBelongsTo((YangBelongsTo) tmpBelongstoNode);
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.BELONGS_TO_DATA,
+ String.valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
+ } else {
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
+ ParsableDataType.BELONGS_TO_DATA,
+ String.valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContactListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContactListener.java
index 3ad513c..48174b5 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContactListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContactListener.java
@@ -16,8 +16,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -28,8 +37,7 @@
* [contact-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * organization-stmt = organization-keyword sep string
- * optsep stmtend
+ * contact-stmt = contact-keyword sep string optsep stmtend
*
* ANTLR grammar rule
* meta_stmts : organization_stmt? contact_stmt? description_stmt? reference_stmt?
@@ -57,7 +65,7 @@
* | description_stmt? organization_stmt? contact_stmt? reference_stmt?
* | description_stmt? organization_stmt? reference_stmt? contact_stmt?
* ;
- * organization_stmt : ORGANIZATION_KEYWORD string STMTEND;
+ * contact_stmt : CONTACT_KEYWORD string STMTEND;
*/
/**
@@ -81,6 +89,32 @@
* @param ctx context object of the grammar rule.
*/
public static void processContactEntry(TreeWalkListener listener, GeneratedYangParser.ContactStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.CONTACT_DATA,
+ String.valueOf(ctx.string().getText()), ListenerErrorLocation.ENTRY);
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ module.setContact(String.valueOf(ctx.string().getText()));
+ break;
+ }
+ case SUB_MODULE_DATA: {
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ subModule.setContact(String.valueOf(ctx.string().getText()));
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.CONTACT_DATA,
+ String.valueOf(ctx.string().getText()),
+ ListenerErrorLocation.ENTRY));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
index ef53b3d..4740699 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
@@ -16,8 +16,18 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangImport;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -62,7 +72,18 @@
* @param ctx context object of the grammar rule.
*/
public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.IMPORT_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.ENTRY);
+
+ YangImport importNode = new YangImport();
+ importNode.setModuleName(String.valueOf(ctx.IDENTIFIER().getText()));
+
+ // Push import node to the stack.
+ listener.getParsedDataStack().push(importNode);
}
/**
@@ -73,6 +94,52 @@
* @param ctx context object of the grammar rule.
*/
public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.IMPORT_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ Parsable tmpImportNode = listener.getParsedDataStack().peek();
+ if (tmpImportNode instanceof YangImport) {
+ listener.getParsedDataStack().pop();
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.IMPORT_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ module.addImportedInfo((YangImport) tmpImportNode);
+ break;
+ }
+ case SUB_MODULE_DATA: {
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ subModule.addImportedInfo((YangImport) tmpImportNode);
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.IMPORT_DATA,
+ String.valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
+ } else {
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
+ ParsableDataType.IMPORT_DATA, String
+ .valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
index bc78e7d..c4678b8 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
@@ -16,8 +16,18 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangInclude;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -37,7 +47,7 @@
* linkage_stmts : (import_stmt
* | include_stmt)*;
* include_stmt : INCLUDE_KEYWORD IDENTIFIER (STMTEND | LEFT_CURLY_BRACE
- * revision_date_stmt_body? RIGHT_CURLY_BRACE);
+ * revision_date_stmt? RIGHT_CURLY_BRACE);
*/
/**
@@ -61,7 +71,17 @@
* @param ctx context object of the grammar rule.
*/
public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.INCLUDE_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.ENTRY);
+
+ YangInclude includeNode = new YangInclude();
+ includeNode.setSubModuleName(String.valueOf(ctx.IDENTIFIER().getText()));
+
+ listener.getParsedDataStack().push(includeNode);
}
/**
@@ -72,6 +92,52 @@
* @param ctx context object of the grammar rule.
*/
public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.INCLUDE_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ Parsable tmpIncludeNode = listener.getParsedDataStack().peek();
+ if (tmpIncludeNode instanceof YangInclude) {
+ listener.getParsedDataStack().pop();
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.INCLUDE_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ module.addIncludedInfo((YangInclude) tmpIncludeNode);
+ break;
+ }
+ case SUB_MODULE_DATA: {
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ subModule.addIncludedInfo((YangInclude) tmpIncludeNode);
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.INCLUDE_DATA,
+ String.valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
+ } else {
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
+ ParsableDataType.INCLUDE_DATA, String
+ .valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index c83b30d..cf6309a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -16,8 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -58,7 +65,16 @@
* @param ctx context object of the grammar rule.
*/
public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
- // TODO method implementation
+
+ // Check if stack is empty.
+ ListenerValidation
+ .checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER, ParsableDataType.MODULE_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()), ListenerErrorLocation.ENTRY);
+
+ YangModule yangModule = new YangModule();
+ yangModule.setName(ctx.IDENTIFIER().getText());
+
+ listener.getParsedDataStack().push(yangModule);
}
/**
@@ -69,6 +85,21 @@
* @param ctx context object of the grammar rule.
*/
public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.MODULE_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ if (!(listener.getParsedDataStack().peek() instanceof YangModule)) {
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
+ ParsableDataType.MODULE_DATA, String
+ .valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListener.java
index 6f694e1..8386788 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListener.java
@@ -16,8 +16,19 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNameSpace;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
+
+import java.net.URI;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -63,6 +74,53 @@
*/
public static void processNamespaceEntry(TreeWalkListener listener,
GeneratedYangParser.NamespaceStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.NAMESPACE_DATA,
+ String.valueOf(ctx.string().getText()), ListenerErrorLocation.ENTRY);
+
+ if (!validateUriValue(String.valueOf(ctx.string().getText()))) {
+ ParserException parserException = new ParserException("Invalid namespace URI");
+ parserException.setLine(ctx.string().STRING(0).getSymbol().getLine());
+ parserException.setCharPosition(ctx.string().STRING(0).getSymbol().getCharPositionInLine());
+ throw parserException;
+ }
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ YangNameSpace uri = new YangNameSpace();
+ uri.setUri(String.valueOf(ctx.string().getText()));
+ module.setNameSpace(uri);
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.NAMESPACE_DATA,
+ String.valueOf(ctx.string().getText()),
+ ListenerErrorLocation.ENTRY));
+ }
}
-}
+
+ /**
+ * Validate input URI.
+ *
+ * @param uri input namespace URI
+ * @return validation result
+ */
+ private static boolean validateUriValue(String uri) {
+ uri = uri.replace("\"", "");
+ final URI tmpUri;
+ try {
+ tmpUri = URI.create(uri);
+ } catch (Exception e1) {
+ return false;
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListener.java
index e81f15f..edae08e 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListener.java
@@ -16,8 +16,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -28,7 +37,8 @@
* [contact-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * contact-stmt = contact-keyword sep string optsep stmtend
+ * organization-stmt = organization-keyword sep string
+ * optsep stmtend
*
* ANTLR grammar rule
* meta_stmts : organization_stmt? contact_stmt? description_stmt? reference_stmt?
@@ -56,7 +66,7 @@
* | description_stmt? organization_stmt? contact_stmt? reference_stmt?
* | description_stmt? organization_stmt? reference_stmt? contact_stmt?
* ;
- * contact_stmt : CONTACT_KEYWORD string STMTEND;
+ * organization_stmt : ORGANIZATION_KEYWORD string STMTEND;
*/
/**
@@ -81,6 +91,32 @@
*/
public static void processOrganizationEntry(TreeWalkListener listener,
GeneratedYangParser.OrganizationStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.ORGANIZATION_DATA,
+ String.valueOf(ctx.string().getText()), ListenerErrorLocation.ENTRY);
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ module.setOrganization(String.valueOf(ctx.string().getText()));
+ break;
+ }
+ case SUB_MODULE_DATA: {
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ subModule.setOrganization(String.valueOf(ctx.string().getText()));
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.ORGANIZATION_DATA,
+ String.valueOf(ctx.string().getText()),
+ ListenerErrorLocation.ENTRY));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListener.java
index b02d6f4..26bc82c 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListener.java
@@ -16,8 +16,18 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangBelongsTo;
+import org.onosproject.yangutils.datamodel.YangImport;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -63,6 +73,39 @@
* @param ctx context object of the grammar rule.
*/
public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.PREFIX_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.ENTRY);
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ module.setPrefix(ctx.IDENTIFIER().getText());
+ break;
+ }
+ case IMPORT_DATA: {
+ YangImport importNode = (YangImport) tmpNode;
+ importNode.setPrefixId(ctx.IDENTIFIER().getText());
+ break;
+ }
+ case BELONGS_TO_DATA: {
+ YangBelongsTo belongstoNode = (YangBelongsTo) tmpNode;
+ belongstoNode.setPrefix(ctx.IDENTIFIER().getText());
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.PREFIX_DATA, String
+ .valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.ENTRY));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
index c3233ef..3f60aef 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
@@ -16,8 +16,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangImport;
+import org.onosproject.yangutils.datamodel.YangInclude;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -69,6 +78,34 @@
*/
public static void processRevisionDateEntry(TreeWalkListener listener,
GeneratedYangParser.RevisionDateStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.REVISION_DATE_DATA,
+ String.valueOf(ctx.DATE_ARG().getText()),
+ ListenerErrorLocation.ENTRY);
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case IMPORT_DATA: {
+ YangImport importNode = (YangImport) tmpNode;
+ importNode.setRevision(String.valueOf(ctx.DATE_ARG().getText()));
+ break;
+ }
+ case INCLUDE_DATA: {
+ YangInclude includeNode = (YangInclude) tmpNode;
+ includeNode.setRevision(String.valueOf(ctx.DATE_ARG().getText()));
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.REVISION_DATE_DATA,
+ String.valueOf(ctx.DATE_ARG().getText()),
+ ListenerErrorLocation.ENTRY));
+ }
}
-}
+ // TODO Implement the DATE_ARG validation as per RFC 6020.
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
index c473c83..0da2f01 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
@@ -16,8 +16,18 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangRevision;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -59,17 +69,25 @@
private RevisionListener() {
}
- /**
- * It is called when parser receives an input matching the grammar
- * rule (revision), perform validations and update the data model
- * tree.
- *
- * @param listener Listener's object.
- * @param ctx context object of the grammar rule.
- */
- public static void processRevisionEntry(TreeWalkListener listener, GeneratedYangParser.RevisionStatementContext
- ctx) {
- // TODO method implementation
+ public static void processRevisionEntry(TreeWalkListener listener,
+ GeneratedYangParser.RevisionStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.REVISION_DATA,
+ String.valueOf(ctx.DATE_ARG().getText()),
+ ListenerErrorLocation.ENTRY);
+
+ // Validate for reverse chronological order of revision & for revision value.
+ if (!validateRevision(listener, ctx)) {
+ return;
+ // TODO to be implemented.
+ }
+
+ YangRevision revisionNode = new YangRevision();
+ revisionNode.setRevDate(String.valueOf(ctx.DATE_ARG().getText()));
+
+ listener.getParsedDataStack().push(revisionNode);
}
/**
@@ -79,8 +97,66 @@
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
*/
- public static void processRevisionExit(TreeWalkListener listener, GeneratedYangParser.RevisionStatementContext
- ctx) {
- // TODO method implementation
+ public static void processRevisionExit(TreeWalkListener listener,
+ GeneratedYangParser.RevisionStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ ListenerValidation
+ .checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, ParsableDataType.REVISION_DATA,
+ String.valueOf(ctx.DATE_ARG().getText()), ListenerErrorLocation.EXIT);
+
+ Parsable tmpRevisionNode = listener.getParsedDataStack().peek();
+ if (tmpRevisionNode instanceof YangRevision) {
+ listener.getParsedDataStack().pop();
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.REVISION_DATA,
+ String.valueOf(ctx.DATE_ARG().getText()),
+ ListenerErrorLocation.EXIT);
+
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ module.setRevision((YangRevision) tmpRevisionNode);
+ break;
+ }
+ case SUB_MODULE_DATA: {
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ subModule.setRevision((YangRevision) tmpRevisionNode);
+ break;
+ }
+ default:
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.REVISION_DATA,
+ String.valueOf(ctx.DATE_ARG()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
+ } else {
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
+ ParsableDataType.REVISION_DATA, String
+ .valueOf(ctx.DATE_ARG()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
}
-}
+
+ /**
+ * Validate revision.
+ *
+ * @param listener Listener's object.
+ * @param ctx context object of the grammar rule.
+ * @return validation result
+ */
+ private static boolean validateRevision(TreeWalkListener listener,
+ GeneratedYangParser.RevisionStatementContext ctx) {
+ // TODO to be implemented
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index 25f2764..3f6fc40 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -16,8 +16,15 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -60,7 +67,16 @@
*/
public static void processSubModuleEntry(TreeWalkListener listener,
GeneratedYangParser.SubModuleStatementContext ctx) {
- // TODO method implementation
+
+ // Check if stack is empty.
+ ListenerValidation
+ .checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER, ParsableDataType.SUB_MODULE_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()), ListenerErrorLocation.ENTRY);
+
+ YangSubModule yangSubModule = new YangSubModule();
+ yangSubModule.setName(ctx.IDENTIFIER().getText());
+
+ listener.getParsedDataStack().push(yangSubModule);
}
/**
@@ -72,6 +88,21 @@
*/
public static void processSubModuleExit(TreeWalkListener listener,
GeneratedYangParser.SubModuleStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.SUB_MODULE_DATA,
+ String.valueOf(ctx.IDENTIFIER().getText()),
+ ListenerErrorLocation.EXIT);
+
+ if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) {
+ throw new ParserException(
+ ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
+ ParsableDataType.SUB_MODULE_DATA,
+ String.valueOf(ctx.IDENTIFIER()
+ .getText()),
+ ListenerErrorLocation.EXIT));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/VersionListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/VersionListener.java
index 02afdcf..ae9389f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/VersionListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/VersionListener.java
@@ -16,8 +16,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
@@ -73,6 +82,48 @@
*/
public static void processVersionEntry(TreeWalkListener listener,
GeneratedYangParser.YangVersionStatementContext ctx) {
- // TODO method implementation
+
+ // Check for stack to be non empty.
+ ListenerValidation
+ .checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, ParsableDataType.VERSION_DATA,
+ String.valueOf(ctx.INTEGER().getText()), ListenerErrorLocation.ENTRY);
+
+ Integer version = Integer.valueOf(ctx.INTEGER().getText());
+ if (!isVersionValid(version)) {
+ ParserException parserException = new ParserException("Input version not supported");
+ parserException.setLine(ctx.INTEGER().getSymbol().getLine());
+ parserException.setCharPosition(ctx.INTEGER().getSymbol().getCharPositionInLine());
+ throw parserException;
+ }
+
+ // Obtain the node of the stack.
+ Parsable tmpNode = listener.getParsedDataStack().peek();
+ switch (tmpNode.getParsableDataType()) {
+ case MODULE_DATA: {
+ YangModule module = (YangModule) tmpNode;
+ module.setVersion((byte) 1);
+ break;
+ }
+ case SUB_MODULE_DATA: {
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ subModule.setVersion((byte) 1);
+ break;
+ }
+ default:
+ throw new ParserException(ListenerErrorMessageConstruction.
+ constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.VERSION_DATA, String.valueOf(ctx.INTEGER().getText()),
+ ListenerErrorLocation.ENTRY));
+ }
}
-}
+
+ /**
+ * Validates whether the value of YANG version.
+ *
+ * @param version input yang version
+ * @return validation result
+ */
+ private static boolean isVersionValid(Integer version) {
+ return version == 1;
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerError.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerError.java
index d4c8504..c5c3c8b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerError.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerError.java
@@ -21,12 +21,18 @@
*/
public class ListenerError {
- // Maintains the state of Exception.
+ // Maintains the state of exception.
private boolean errorFlag = false;
- // Maintains the reason of Exception.
+ // Maintains the reason of exception.
private String errorMsg;
+ // Maintains the line number of exception.
+ private int lineNumber;
+
+ // Maintains the character position in lin of exception.
+ private int charPositionInLine;
+
/**
* Returns error flag.
*
@@ -37,18 +43,36 @@
}
/**
- * Returns error message.
+ * Returns reason for error.
*
- * @return error msg.
+ * @return error message
*/
public String getErrorMsg() {
return errorMsg;
}
/**
+ * Returns error line number.
+ *
+ * @return error line number.
+ */
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ /**
+ * Returns error position in line.
+ *
+ * @return error character position in line.
+ */
+ public int getCharPositionInLine() {
+ return charPositionInLine;
+ }
+
+ /**
* Set error flag.
*
- * @param errorFlag error existence flag
+ * @param errorFlag error existence flag.
*/
public void setErrorFlag(boolean errorFlag) {
this.errorFlag = errorFlag;
@@ -62,4 +86,22 @@
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
+
+ /**
+ * Set error line number.
+ *
+ * @param lineNumber line number of error.
+ */
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ /**
+ * Set error character position in line.
+ *
+ * @param charPositionInLine error character position in line.
+ */
+ public void setCharPositionInLine(int charPositionInLine) {
+ this.charPositionInLine = charPositionInLine;
+ }
}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorLocation.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorLocation.java
new file mode 100644
index 0000000..b989407
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorLocation.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parserutils;
+
+/**
+ * Maintains listener error location.
+ */
+public enum ListenerErrorLocation {
+ /**
+ * Represents that the error location is before processing.
+ */
+ ENTRY(),
+
+ /**
+ * Represents that the error location is before processing.
+ */
+ EXIT();
+
+ /**
+ * Returns the message corresponding to listener error location.
+ *
+ * @param errorLocation enum value for type of error.
+ * @return message corresponding to listener error location.
+ */
+ public static String getErrorLocationMessage(ListenerErrorLocation errorLocation) {
+
+ switch (errorLocation) {
+ case ENTRY:
+ return "before";
+ case EXIT:
+ return "after";
+ default:
+ return "during";
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorMessageConstruction.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorMessageConstruction.java
new file mode 100644
index 0000000..1de8f44
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorMessageConstruction.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parserutils;
+
+import org.onosproject.yangutils.parser.ParsableDataType;
+
+/**
+ * It's a utility to help construct detailed error message.
+ */
+public final class ListenerErrorMessageConstruction {
+
+ /**
+ * Private constructor.
+ */
+ private ListenerErrorMessageConstruction() {
+ }
+
+ /**
+ * Constructs message for error with extended information and returns the same.
+ *
+ * @param errorType error type needs to be set in error message.
+ * @param parsableDataType type of parsable data in which error occurred.
+ * @param parsableDataTypeName identifier/string of parsable data type in which error occurred.
+ * @param errorLocation location where error occurred.
+ * @param extendedErrorInformation extended error information.
+ * @return constructed error message.
+ */
+ public static String constructExtendedListenerErrorMessage(ListenerErrorType errorType,
+ ParsableDataType parsableDataType,
+ String parsableDataTypeName,
+ ListenerErrorLocation errorLocation,
+ String extendedErrorInformation) {
+ String newErrorMessage;
+ newErrorMessage = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
+ errorLocation) + "\n" + "Error Information: " + extendedErrorInformation;
+ return newErrorMessage;
+ }
+
+ /**
+ * Constructs message for error during listener based tree walk and returns the same.
+ *
+ * @param errorType error type needs to be set in error message.
+ * @param parsableDataType type of parsable data in which error occurred.
+ * @param parsableDataTypeName identifier/string of parsable data type in which error occurred.
+ * @param errorLocation location where error occurred.
+ * @return constructed error message.
+ */
+ public static String constructListenerErrorMessage(ListenerErrorType errorType,
+ ParsableDataType parsableDataType,
+ String parsableDataTypeName,
+ ListenerErrorLocation errorLocation) {
+
+ String errorMessage;
+
+ errorMessage = "Internal parser error detected: " + ListenerErrorType.getErrorType(errorType) + " "
+ + ParsableDataType.getParsableDataType(parsableDataType);
+
+
+ if (!parsableDataTypeName.isEmpty()) {
+ errorMessage = errorMessage + " \"" + parsableDataTypeName + "\" ";
+ } else {
+ errorMessage = errorMessage + " ";
+
+ }
+ errorMessage = errorMessage + ListenerErrorLocation.getErrorLocationMessage(errorLocation) + " processing.";
+ return errorMessage;
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java
new file mode 100644
index 0000000..13925bc
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parserutils;
+
+/**
+ * Maintains listener error type.
+ */
+public enum ListenerErrorType {
+ /**
+ * Represents the parent holder in parsable stack for given YANG construct is invalid.
+ */
+ INVALID_HOLDER(),
+
+ /**
+ * Represents the parent holder in parsable stack for given YANG construct is missing.
+ */
+ MISSING_HOLDER(),
+
+ /**
+ * Represents the current holder in parsable stack for given YANG construct is missing.
+ */
+ MISSING_CURRENT_HOLDER(),
+
+ /**
+ * Represents that the child in parsable stack for given YANG construct is invalid.
+ */
+ INVALID_CHILD(),
+
+ /**
+ * Represents that the cardinality for given YANG construct is invalid.
+ */
+ INVALID_CARDINALITY(),
+
+ /**
+ * Represents that some of earlier parsed data is not handled correctly.
+ */
+ UNHANDLED_PARSED_DATA();
+
+ /**
+ * Returns the message corresponding to listener error type.
+ *
+ * @param errorType enum value for type of error.
+ * @return message corresponding to listener error type.
+ */
+ public static String getErrorType(ListenerErrorType errorType) {
+
+ switch (errorType) {
+ case INVALID_HOLDER:
+ return "Invalid holder for";
+ case MISSING_HOLDER:
+ return "Missing holder at";
+ case MISSING_CURRENT_HOLDER:
+ return "Missing";
+ case INVALID_CHILD:
+ return "Invalid child in";
+ case INVALID_CARDINALITY:
+ return "Invalid cardinality in";
+ case UNHANDLED_PARSED_DATA:
+ return "Unhandled parsed data at";
+ default:
+ return "Problem in";
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerValidation.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerValidation.java
index 6ecded3..4399cc5 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerValidation.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerValidation.java
@@ -16,39 +16,66 @@
package org.onosproject.yangutils.parser.impl.parserutils;
+import org.onosproject.yangutils.parser.ParsableDataType;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
/**
- * Its a utility to carry out listener validation.
+ * It's a utility to carry out listener validation.
*/
public final class ListenerValidation {
/**
- * Creates a new belongto listener.
+ * Creates a new listener validation.
*/
private ListenerValidation() {
}
/**
- * Checks if error is set or parsed data stack is empty.
+ * Checks parsed data stack is not empty.
*
* @param listener Listener's object.
- * @param errNode parsable node for which validation needs to be done.
- * @return validation result.
+ * @param errorType error type needs to be set in error message.
+ * @param parsableDataType type of parsable data in which error occurred.
+ * @param parsableDataTypeName name of parsable data type in which error occurred.
+ * @param errorLocation location where error occurred.
*/
- public static boolean preValidation(TreeWalkListener listener, String errNode) {
-
- // Check whether error found while walking YANG file, if yes return true.
- if (listener.getErrorInformation().isErrorFlag()) {
- return true;
- }
-
- // If stack is empty it indicates error condition
+ public static void checkStackIsNotEmpty(TreeWalkListener listener, ListenerErrorType errorType,
+ ParsableDataType parsableDataType, String parsableDataTypeName,
+ ListenerErrorLocation errorLocation) {
if (listener.getParsedDataStack().empty()) {
- listener.getErrorInformation().setErrorFlag(true);
- listener.getErrorInformation().setErrorMsg("Parsable stack empty at" + errNode + "entry");
- return true;
+ /*
+ * If stack is empty it indicates error condition, value of parsableDataTypeName will be null in case there
+ * is no name attached to parsable data type.
+ */
+ String message = ListenerErrorMessageConstruction.constructListenerErrorMessage(errorType, parsableDataType,
+ parsableDataTypeName, errorLocation);
+ throw new ParserException(message);
}
- return false;
+ }
+
+ /**
+ * Checks parsed data stack is empty.
+ *
+ * @param listener Listener's object.
+ * @param errorType error type needs to be set in error message.
+ * @param parsableDataType type of parsable data in which error occurred.
+ * @param parsableDataTypeName name of parsable data type in which error occurred.
+ * @param errorLocation location where error occurred.
+ */
+
+ public static void checkStackIsEmpty(TreeWalkListener listener, ListenerErrorType errorType,
+ ParsableDataType parsableDataType, String parsableDataTypeName,
+ ListenerErrorLocation errorLocation) {
+
+ if (!listener.getParsedDataStack().empty()) {
+ /*
+ * If stack is empty it indicates error condition, value of parsableDataTypeName will be null in case there
+ * is no name attached to parsable data type.
+ */
+ String message = ListenerErrorMessageConstruction.constructListenerErrorMessage(errorType, parsableDataType,
+ parsableDataTypeName, errorLocation);
+ throw new ParserException(message);
+ }
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ParseTreeErrorListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ParseTreeErrorListener.java
index d3926df..a507e3a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ParseTreeErrorListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ParseTreeErrorListener.java
@@ -29,37 +29,13 @@
*/
public class ParseTreeErrorListener extends BaseErrorListener {
- // Exception of type parser exceptions are catched during parsing.
- private ParserException parserException = new ParserException();
-
- // Flag to indicate presence of exception.
- private boolean exceptionFlag = false;
-
- /**
- * Returns the status of exception flag.
- *
- * @return flag which contains the status of exception.
- */
- public boolean isExceptionFlag() {
- return exceptionFlag;
- }
-
- /**
- * Returns the parser exception object populated with line, character
- * position and message.
- *
- * @return object of parser exception.
- */
- public ParserException getParserException() {
- return parserException;
- }
-
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
String msg, RecognitionException e) {
+
+ ParserException parserException = new ParserException(msg);
parserException.setLine(line);
parserException.setCharPosition(charPositionInLine);
- parserException.setMsg(msg);
- exceptionFlag = true;
+ throw parserException;
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
new file mode 100644
index 0000000..9908da5
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl;
+
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+
+/**
+ * ExpectedException framework can use the Hamcrest matcher's to test
+ * custom/extended exceptions. This class extends the type safe matcher to define
+ * the custom exception matcher.
+ */
+public final class CustomExceptionMatcher extends TypeSafeMatcher<ParserException> {
+
+ /**
+ * Customized exception matcher to match error location.
+ *
+ * @param line error line
+ * @param charPosition error character position
+ * @return
+ */
+ public static CustomExceptionMatcher errorLocation(int line, int charPosition) {
+ return new CustomExceptionMatcher(line, charPosition);
+ }
+
+ private int actualLine;
+ private final int expectedLine;
+ private int actualCharPosition;
+ private final int expectedCharPosition;
+
+ private CustomExceptionMatcher(int expectedLine, int expectedCharPosition) {
+ this.expectedLine = expectedLine;
+ this.expectedCharPosition = expectedCharPosition;
+ }
+
+ @Override
+ protected boolean matchesSafely(final ParserException exception) {
+ actualLine = exception.getLineNumber();
+ actualCharPosition = exception.getCharPositionInLine();
+ return ((actualLine == expectedLine) && (actualCharPosition == expectedCharPosition));
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(" Error reported location ")
+ .appendText("Line " + actualLine + ", " + "CharPosition " + actualCharPosition)
+ .appendText(" instead of expected ")
+ .appendText("Line " + expectedLine + ", " + "CharPosition " + expectedCharPosition);
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListenerTest.java
new file mode 100644
index 0000000..f2415b2
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListenerTest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+/**
+ * Test cases for testing base rule listener functionality.
+ */
+public class BaseFileListenerTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ /**
+ * Checks for exception if stack of parsable data is not empty at the entry
+ * of yang base rule.
+ */
+ @Test
+ public void processYangFileEntryNonEmptyStack() {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("Internal parser error detected: Invalid holder for yangbase before processing.");
+
+ YangModule tmpModule = new YangModule();
+ TreeWalkListener listener = new TreeWalkListener();
+ listener.getParsedDataStack().push(tmpModule);
+ GeneratedYangParser.YangfileContext ctx = null;
+ BaseFileListener.processYangFileEntry(listener, ctx);
+ }
+
+ /**
+ * Checks that exception shouldn't be generated if stack of parsable data is
+ * empty at the entry of yang base rule.
+ */
+ @Test
+ public void processYangFileEntryEmptyStack() {
+
+ TreeWalkListener listener = new TreeWalkListener();
+ GeneratedYangParser.YangfileContext ctx = null;
+ BaseFileListener.processYangFileEntry(listener, ctx);
+ }
+
+ /**
+ * Checks that exception should be generated if stack of parsable data is
+ * not empty at the exit of yang base rule.
+ */
+ @Test
+ public void processYangFileExitEmptyStack() {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("Internal parser error detected: Missing holder at yangbase after processing.");
+
+ TreeWalkListener listener = new TreeWalkListener();
+ GeneratedYangParser.YangfileContext ctx = null;
+ BaseFileListener.processYangFileExit(listener, ctx);
+ }
+
+ /**
+ * Checks that exception shouldn't be generated if stack of parsable data is
+ * empty at the exit of yang base rule.
+ */
+ @Test
+ public void processYangFileExitNonEmptyStack() {
+
+ TreeWalkListener listener = new TreeWalkListener();
+ GeneratedYangParser.YangfileContext ctx = null;
+ BaseFileListener.processYangFileEntry(listener, ctx);
+ }
+
+ /**
+ * Checks that after popping out the parsable node from stack it should be
+ * empty.
+ */
+ @Test
+ public void processYangFileExitStackErrorExtraEntryTest() {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("Internal parser error detected: Invalid holder for yangbase after processing.");
+
+ YangModule tmpModule = new YangModule();
+ YangModule tmpModule2 = new YangModule();
+ TreeWalkListener listener = new TreeWalkListener();
+ listener.getParsedDataStack().push(tmpModule);
+ listener.getParsedDataStack().push(tmpModule2);
+ GeneratedYangParser.YangfileContext ctx = null;
+ BaseFileListener.processYangFileExit(listener, ctx);
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BelongstoListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BelongstoListenerTest.java
new file mode 100644
index 0000000..0bc6586
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BelongstoListenerTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.CustomExceptionMatcher;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing belongsto listener functionality.
+ */
+public class BelongstoListenerTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if mandatory belongsto parameter "prefix" is not present.
+ */
+ @Test
+ public void processBelongsToWithoutPrefix() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("mismatched input '}' expecting 'prefix'");
+ thrown.expect(CustomExceptionMatcher.errorLocation(4, 0));
+ YangNode node = manager.getDataModel("src/test/resources/BelongsToWithoutPrefix.yang");
+ }
+
+ /**
+ * Checks that prefix must be present only once in belongsto.
+ */
+ @Test
+ public void processBelongsToDualPrefix() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("mismatched input 'prefix' expecting '}'");
+ thrown.expect(CustomExceptionMatcher.errorLocation(5, 0));
+ YangNode node = manager.getDataModel("src/test/resources/BelongsToDualPrefix.yang");
+ }
+
+ /**
+ * Checks if belongsto listener updates the date model tree.
+ */
+ @Test
+ public void processBelongsToWithPrefix() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/BelongsToWithPrefix.yang");
+ YangSubModule yangNode = (YangSubModule) node;
+ assertThat(yangNode.getBelongsTo().getBelongsToModuleName(), is("ONOS"));
+ }
+
+ /**
+ * Checks if mandatory parameter "belongsto" is present.
+ */
+ @Test
+ public void processSubModuleWithoutBelongsTo() throws IOException, ParserException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("mismatched input '}' expecting 'belongs-to'");
+ thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
+ YangNode node = manager.getDataModel("src/test/resources/SubModuleWithoutBelongsTo.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ContactListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ContactListenerTest.java
new file mode 100644
index 0000000..9791ba3
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ContactListenerTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing contact listener functionality.
+ */
+public class ContactListenerTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if contact listener updates the data model tree.
+ */
+ @Test
+ public void processContactValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ContactValidEntry.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getContact(), is("\"WG List: <mailto:spring@ietf.org>\nEditor: "
+ + "Stephane Litkowski\n " + "<mailto:stephane.litkowski@orange.com>\""));
+ }
+
+ /**
+ * Checks that contact must be present only once.
+ */
+ @Test(expected = ParserException.class)
+ public void processContactDualEntryTest() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ContactDualEntryTest.yang");
+
+ }
+
+ /**
+ * Checks if contact is not empty.
+ */
+ @Test(expected = ParserException.class)
+ public void processContactWithEmptyString() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ContactWithEmptyString.yang");
+ }
+
+ /**
+ * Checks that contact must be present after namespace.
+ */
+ @Test(expected = ParserException.class)
+ public void processContactIncorrectOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ContactIncorrectOrder.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ImportListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ImportListenerTest.java
new file mode 100644
index 0000000..d003cc2
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ImportListenerTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing import listener functionality.
+ */
+public class ImportListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if mandatory parameter prefix is present in import.
+ */
+ @Test(expected = ParserException.class)
+ public void processImportWithoutPrefix() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ImportWithoutPrefix.yang");
+ }
+
+ /**
+ * Checks that prefix must be present only once in import.
+ */
+ @Test(expected = ParserException.class)
+ public void processImportWithDualPrefix() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ImportWithDualPrefix.yang");
+ }
+
+ /**
+ * Checks for the correct order of prefix in import.
+ */
+ @Test(expected = ParserException.class)
+ public void processImportInvalidOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ImportInvalidOrder.yang");
+ }
+
+ /**
+ * Checks if import listener updates the data model tree.
+ */
+ @Test
+ public void processImportValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ImportValidEntry.yang");
+
+ // Checks for the revision value in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
+ // Checks for the prefix id in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getPrefixId(), is("On2"));
+ // Checks for the module name in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getModuleName(), is("ietf"));
+ }
+
+ /**
+ * Checks if optional parameter revision is not mandatory in import.
+ */
+ @Test
+ public void processImportWithoutRevision() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ImportWithoutRevision.yang");
+
+ // Checks for the prefix id in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getPrefixId(), is("On2"));
+ // Checks for the module name in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getModuleName(), is("ietf"));
+ }
+
+ /**
+ * Checks if multiple imports are allowed.
+ */
+ @Test()
+ public void processImportMultipleInstance() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ImportMultipleInstance.yang");
+
+ // Checks for the prefix id in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getPrefixId(), is("On2"));
+ // Checks for the module name in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getModuleName(), is("ietf"));
+
+ // Checks for the prefix id in data model tree.
+ assertThat(((YangModule) node).getImportList().get(1).getPrefixId(), is("On3"));
+ // Checks for the module name in data model tree.
+ assertThat(((YangModule) node).getImportList().get(1).getModuleName(), is("itut"));
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListenerTest.java
new file mode 100644
index 0000000..313f5e9
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListenerTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing include listener functionality.
+ */
+public class IncludeListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if include listener with ; is valid and updates the data
+ * model tree.
+ */
+ @Test
+ public void processIncludeWithStmtend() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IncludeWithStmtend.yang");
+
+ // Checks for the sub module name in data model tree.
+ assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
+ }
+
+ /**
+ * Checks if include listener with braces and without revision date is valid
+ * and updates the data model tree.
+ */
+ @Test
+ public void processIncludeWithEmptyBody() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IncludeWithEmptyBody.yang");
+
+ // Checks for the sub module name in data model tree.
+ assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
+ }
+
+ /**
+ * Checks if include listener with braces and with revision date is valid
+ * and updates the data model tree.
+ */
+ @Test
+ public void processIncludeWithDate() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IncludeWithDate.yang");
+
+ // Checks for the sub module name in data model tree.
+ assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
+ }
+
+ /**
+ * Checks if include has more than one occurrence.
+ */
+ @Test
+ public void processIncludeMultiInstance() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IncludeMultiInstance.yang");
+
+ // Checks for the sub module name in data model tree.
+ assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn"));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ }
+
+ /**
+ * Checks if include and import can come in any order.
+ */
+ @Test
+ public void processIncludeImportAnyOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IncludeImportAnyOrder.yang");
+
+ // Checks for the sub module name in data model tree.
+ assertThat(((YangModule) node).getIncludeList().get(0).getSubModuleName(), is("itut"));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(1).getSubModuleName(), is("sdn"));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ }
+
+ /**
+ * Checks if syntax of Include is not correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processIncludeInvalidSyntax() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IncludeInvalidSyntax.yang");
+ }
+
+ /**
+ * Checks if syntax of revision date in Include is not correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processIncludeInvalidDateSyntax() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/IncludeInvalidDateSyntax.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListenerTest.java
new file mode 100644
index 0000000..ab7242a
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListenerTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing module listener functionality.
+ */
+public class ModuleListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if module listener updates the data model root node.
+ */
+ @Test
+ public void processModuleValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ModuleValidEntry.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+
+ // Check whether the module name is set correctly.
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+ }
+
+ /**
+ * Checks if module name is set correctly.
+ */
+ @Test(expected = ParserException.class)
+ public void processModuleInvalidEntryTest() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ModuleWithInvalidIdentifier.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListenerTest.java
new file mode 100644
index 0000000..50f8f54
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListenerTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing namespace listener functionality.
+ */
+public class NamespaceListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks that value of namespace shouldn't have invalid spaces.
+ */
+ @Test(expected = ParserException.class)
+ public void processNamespaceWithInvalidSpaces() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/NamespaceWithInvalidSpaces.yang");
+ }
+
+ /**
+ * Checks if namespace with double quotes is allowed.
+ */
+ @Test()
+ public void processNamespaceInDoubleQuotes() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/NamespaceInDoubleQuotes.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getNameSpace().getUri(), is("\"urn:ietf:params:xml:ns:yang:ietf-ospf\""));
+ }
+
+ /**
+ * Checks if namespace without double quotes is allowed.
+ */
+ @Test()
+ public void processNamespaceWithoutQuotes() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/NamespaceWithoutQuotes.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getNameSpace().getUri(), is("urn:ietf:params:xml:ns:yang:ietf-ospf"));
+ }
+
+ /**
+ * Checks if namespace is present only once.
+ */
+ @Test(expected = ParserException.class)
+ public void processNamespaceDualEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/NamespaceDualEntry.yang");
+ }
+
+ /**
+ * Checks if mandatory parameter namespace is present.
+ */
+ @Test(expected = ParserException.class)
+ public void processNamespaceNoEntryTest() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/NamespaceNoEntryTest.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListenerTest.java
new file mode 100644
index 0000000..2c71e17
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListenerTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing organization listener functionality.
+ */
+public class OrganizationListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if organization listener updates the data model tree.
+ */
+ @Test
+ public void processOrganizationValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/OrganizationValidEntry.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getOrganization(), is("\"IETF SPRING Working Group\""));
+ }
+
+ /**
+ * Checks that organization must be present only once.
+ */
+ @Test(expected = ParserException.class)
+ public void processOrganizationDualEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/OrganizationDualEntry.yang");
+ }
+
+ /**
+ * Checks if organization entry syntax is correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processOrganizationMissingValue() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/OrganizationMissingValue.yang");
+ }
+
+ /**
+ * Checks if organization and namespace is present in correct order.
+ */
+ @Test(expected = ParserException.class)
+ public void processOrganizationInvalidOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/OrganizationInvalidOrder.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListenerTest.java
new file mode 100644
index 0000000..b090bd0
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListenerTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing prefix listener functionality.
+ */
+public class PrefixListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if value of prefix is correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processPrefixInvalidValue() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/PrefixInvalidValue.yang");
+ }
+
+ /**
+ * Checks if prefix listener updates the data model tree.
+ */
+ @Test
+ public void processPrefixValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/PrefixValidEntry.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getPrefix(), is("On"));
+ }
+
+ /**
+ * Checks that prefix should be present just once.
+ */
+ @Test(expected = ParserException.class)
+ public void processPrefixDualEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/PrefixDualEntry.yang");
+ }
+
+ /**
+ * Checks if prefix syntax is followed.
+ */
+ @Test(expected = ParserException.class)
+ public void processPrefixMissingValue() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/PrefixMissingValue.yang");
+ }
+
+ /**
+ * Checks that exception should be reported if prefix is missing.
+ */
+ @Test(expected = ParserException.class)
+ public void processPrefixOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/PrefixOrder.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListenerTest.java
new file mode 100644
index 0000000..df56913
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListenerTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing revision date listener functionality.
+ */
+public class RevisionDateListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if revision date syntax is correct in include.
+ */
+ @Test(expected = ParserException.class)
+ public void processRevisionDateInvalidSyntaxAtInclude() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidSyntaxAtInclude.yang");
+ }
+
+ /**
+ * Checks if revision date syntax is correct in import.
+ */
+ @Test(expected = ParserException.class)
+ public void processRevisionDateInvalidSyntaxAtImport() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidSyntaxAtImport.yang");
+ }
+
+ /**
+ * Checks revision date should not be in quotes inside include.
+ */
+ @Test(expected = ParserException.class)
+ public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang");
+ }
+
+ /**
+ * Checks revision date should not be in quotes inside import.
+ */
+ @Test(expected = ParserException.class)
+ public void processRevisionDateInQuotesAtImport() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang");
+ }
+
+ /**
+ * Checks if revision date follows YYYY-MM-DD format.
+ */
+ @Test(expected = ParserException.class)
+ public void processRevisionDateInvalidFormat() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalidFormat.yang");
+ }
+
+ /**
+ * Checks if revision date listener updates the data model tree.
+ */
+ @Test
+ public void processRevisionDateValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionDateValidEntry.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03"));
+ assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03"));
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
new file mode 100644
index 0000000..8226442
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListenerTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing revision listener functionality.
+ */
+public class RevisionListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if revision doesn't have optional parameters "revision and
+ * description".
+ */
+ @Test
+ public void processRevisionNoOptionalParameter() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionNoOptionalParameter.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getRevision().getRevDate(), is("2016-02-03"));
+ }
+
+ /**
+ * Checks if the syntax of revision is correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processRevisionInValidSyntax() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionInValidSyntax.yang");
+ }
+
+ /**
+ * Checks if the correct order is followed.
+ */
+ @Test(expected = ParserException.class)
+ public void processRevisionInValidOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/RevisionInValidOrder.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
new file mode 100644
index 0000000..c3028de
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListenerTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing submodule listener functionality.
+ */
+public class SubModuleListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if the sub module listeners updates the data model tree.
+ */
+ @Test
+ public void processSubModuleValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/SubModuleValidEntry.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangSubModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.SUB_MODULE_NODE));
+
+ YangSubModule yangNode = (YangSubModule) node;
+ // Check whether the module name is set correctly.
+ assertThat(yangNode.getName(), is("Test"));
+ // Checks for the version value in data model tree.
+ assertThat(yangNode.getVersion(), is((byte) 1));
+ // Checks identifier of belongsto in data model tree.
+ assertThat(yangNode.getBelongsTo().getBelongsToModuleName(), is("ONOS"));
+ // Checks for the version value in data model tree.
+ assertThat(yangNode.getBelongsTo().getPrefix(), is("On1"));
+ }
+
+ /**
+ * Checks if the yang version and belongs to can come in any order in sub
+ * module.
+ */
+ @Test
+ public void processSubModuleOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/SubModuleOrder.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangSubModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.SUB_MODULE_NODE));
+
+ YangSubModule yangNode = (YangSubModule) node;
+ // Check whether the module name is set correctly.
+ assertThat(yangNode.getName(), is("Test"));
+ // Checks for the version value in data model tree.
+ assertThat(yangNode.getVersion(), is((byte) 1));
+ // Checks identifier of belongsto in data model tree.
+ assertThat(yangNode.getBelongsTo().getBelongsToModuleName(), is("ONOS"));
+ // Checks for the version value in data model tree.
+ assertThat(yangNode.getBelongsTo().getPrefix(), is("On1"));
+ }
+
+ /**
+ * Checks if yang version is optional.
+ */
+ @Test
+ public void processSubModuleWithoutVersion() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/SubModuleWithoutVersion.yang");
+
+ // Check whether the data model tree returned is of type module.
+ assertThat((node instanceof YangSubModule), is(true));
+
+ // Check whether the node type is set properly to module.
+ assertThat(node.getNodeType(), is(YangNodeType.SUB_MODULE_NODE));
+
+ YangSubModule yangNode = (YangSubModule) node;
+ // Check whether the module name is set correctly.
+ assertThat(yangNode.getName(), is("Test"));
+ // Checks identifier of belongsto in data model tree.
+ assertThat(yangNode.getBelongsTo().getBelongsToModuleName(), is("ONOS"));
+ // Checks for the version value in data model tree.
+ assertThat(yangNode.getBelongsTo().getPrefix(), is("On1"));
+ }
+
+ /**
+ * Checks if sub module name is correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processSubModuleInvalidName() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/SubModuleInvalidName.yang");
+ }
+
+ /**
+ * Checks if sub module has invalid modules construct eg namespace.
+ */
+ @Test(expected = ParserException.class)
+ public void processSubModuleWithNamespace() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/SubModuleWithNamespace.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/VersionListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/VersionListenerTest.java
new file mode 100644
index 0000000..2338604
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/VersionListenerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test cases for testing version listener functionality.
+ */
+public class VersionListenerTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks if value of version is correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processVersionInvalidValue() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/VersionInvalidValue.yang");
+ }
+
+ /**
+ * Checks if version listener updates the data model tree.
+ */
+ @Test
+ public void processVersionValidEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/VersionValidEntry.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getVersion(), is((byte) 1));
+ }
+
+ /**
+ * Checks if version which is optional paramater is not present.
+ */
+ @Test
+ public void processVersionNotPresent() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/VersionNotPresent.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getVersion(), is((byte) 0));
+ }
+
+ /**
+ * Checks that version should be present only once.
+ */
+ @Test(expected = ParserException.class)
+ public void processVersionDualEntry() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/VersionDualEntry.yang");
+ }
+
+ /**
+ * Checks if version can appear in any order in module header.
+ */
+ @Test
+ public void processVersionOrder() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/VersionOrder.yang");
+
+ // Checks for the version value in data model tree.
+ assertThat(((YangModule) node).getVersion(), is((byte) 1));
+ }
+
+ /**
+ * Checks if sytax of version entry is not correct.
+ */
+ @Test(expected = ParserException.class)
+ public void processVersionInvalidSyntax() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/VersionInvalidSyntax.yang");
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java
new file mode 100644
index 0000000..7cbc7f6
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.parseutils;
+
+import org.junit.Test;
+import org.onosproject.yangutils.parser.ParsableDataType;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test case for testing listener error message construction util.
+ */
+public class ListenerErrorMessageConstructionTest {
+
+ /**
+ * Checks for error message construction with parsable data type name.
+ */
+ @Test
+ public void checkErrorMsgConstructionWithName() {
+
+ // Create an test error message
+ String testErrorMessage = ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, ParsableDataType.CONTACT_DATA,
+ "Test Instance", ListenerErrorLocation.ENTRY);
+
+ // Check message.
+ assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact "
+ + "\"Test Instance\" before processing."));
+ }
+
+ /**
+ * Checks for error message construction without parsable data type name.
+ */
+ @Test
+ public void checkErrorMsgConstructionWithoutName() {
+
+ // Create an test error message
+ String testErrorMessage = ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, ParsableDataType.CONTACT_DATA,
+ "Test Instance", ListenerErrorLocation.ENTRY);
+
+ // Check message.
+ assertThat(testErrorMessage,
+ is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
+ + " before processing."));
+ }
+
+ /**
+ * Checks for extended error message construction with parsable data type name.
+ */
+ @Test
+ public void checkExtendedErrorMsgConstructionWithName() {
+
+ // Create an test error message
+ String testErrorMessage = ListenerErrorMessageConstruction
+ .constructExtendedListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.CONTACT_DATA, "Test Instance",
+ ListenerErrorLocation.ENTRY, "Extended Information");
+
+ // Check message.
+ assertThat(testErrorMessage,
+ is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
+ + " before processing.\n" + "Error Information: Extended Information"));
+ }
+
+ /**
+ * Checks for extended error message construction without parsable data type name.
+ */
+ @Test
+ public void checkExtendedErrorMsgConstructionWithoutName() {
+
+ // Create an test error message
+ String testErrorMessage = ListenerErrorMessageConstruction
+ .constructExtendedListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
+ ParsableDataType.CONTACT_DATA, "",
+ ListenerErrorLocation.ENTRY, "Extended Information");
+
+ // Check message.
+ assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
+ + " before processing.\n" + "Error Information: Extended Information"));
+ }
+}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java
index c047f2b..85eb48d 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java
@@ -16,74 +16,54 @@
package org.onosproject.yangutils.parser.parseutils;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangRevision;
+import org.onosproject.yangutils.parser.ParsableDataType;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import org.onosproject.yangutils.parser.impl.parserutils.ListenerError;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
+import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
/**
* Test case for testing listener validation util.
*/
public class ListenerValidationTest {
- /**
- * This test case checks in case error pre-exists, listener validate
- * function returns true.
- */
- @Test
- public void listenerValidationErrorExists() {
-
- // Create an test error.
- ListenerError testError = new ListenerError();
- testError.setErrorFlag(true);
- testError.setErrorMsg("Test Error");
-
- // Create test walker and assign test error to it.
- TreeWalkListener testWalker = new TreeWalkListener();
- testWalker.setErrorInformation(testError);
-
- // Create a temporary node of parsable.
- YangRevision tmpNode = new YangRevision();
- testWalker.getParsedDataStack().push(tmpNode);
-
- boolean errorFlag = ListenerValidation.preValidation(testWalker, "ErrorTest");
-
- /**
- * Check for the values set in syntax error function. If not set properly
- * report an assert.
- */
- assertThat(errorFlag, is(true));
- }
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
/**
- * This test case checks in case parsable stack is empty, listener validate
- * function returns true.
+ * Checks for exception in case parsable stack is empty while validating for
+ * not empty scenario.
*/
@Test
- public void listenerValidationEmptyStack() {
+ public void validateStackIsNotEmptyForEmptyStack() {
+
+ String expectedError = ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_HOLDER, ParsableDataType.YANGBASE_DATA, "",
+ ListenerErrorLocation.EXIT);
+
+ // Get the exception occurred during parsing.
+ thrown.expect(ParserException.class);
+ thrown.expectMessage(expectedError);
// Create test walker and assign test error to it.
TreeWalkListener testWalker = new TreeWalkListener();
- boolean errorFlag = ListenerValidation.preValidation(testWalker, "ErrorTest");
-
- /**
- * Check for the values set in syntax error function. If not set properly
- * report an assert.
- */
- assertThat(errorFlag, is(true));
+ ListenerValidation.checkStackIsNotEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
}
/**
- * This test case checks in case of error doesn't pre-exists and stack is,
- * non empty, listener validate function returns false.
+ * Checks if there is no exception in case parsable stack is not empty while validating
+ * for not empty scenario.
*/
@Test
- public void listenerValidationNoErrorNotExists() {
+ public void validateStackIsNotEmptyForNonEmptyStack() {
// Create test walker and assign test error to it.
TreeWalkListener testWalker = new TreeWalkListener();
@@ -92,12 +72,47 @@
YangRevision tmpNode = new YangRevision();
testWalker.getParsedDataStack().push(tmpNode);
- boolean errorFlag = ListenerValidation.preValidation(testWalker, "ErrorTest");
+ ListenerValidation.checkStackIsNotEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
+ }
- /**
- * Check for the values set in syntax error function. If not set properly
- * report an assert.
- */
- assertThat(errorFlag, is(false));
+ /**
+ * Checks for exception in case parsable stack is not empty while validating
+ * for empty scenario.
+ */
+ @Test
+ public void validateStackIsEmptyForNonEmptyStack() {
+
+ String expectedError = ListenerErrorMessageConstruction
+ .constructListenerErrorMessage(ListenerErrorType.MISSING_HOLDER, ParsableDataType.YANGBASE_DATA, "",
+ ListenerErrorLocation.EXIT);
+
+ // Get the exception occurred during parsing.
+ thrown.expect(ParserException.class);
+ thrown.expectMessage(expectedError);
+
+ // Create test walker and assign test error to it.
+ TreeWalkListener testWalker = new TreeWalkListener();
+
+ // Create a temporary node of parsable.
+ YangRevision tmpNode = new YangRevision();
+ testWalker.getParsedDataStack().push(tmpNode);
+
+ ListenerValidation.checkStackIsEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
+ }
+
+ /**
+ * Checks if there is no exception in case parsable stack is empty while validating
+ * for empty scenario.
+ */
+ @Test
+ public void validateStackIsEmptyForEmptyStack() {
+
+ // Create test walker and assign test error to it.
+ TreeWalkListener testWalker = new TreeWalkListener();
+
+ ListenerValidation.checkStackIsEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
+ ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java
index f91797e..a45ed72 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java
@@ -14,29 +14,26 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.parser.impl.parseutils;
+package org.onosproject.yangutils.parser.parseutils;
import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangLexer;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.CustomExceptionMatcher;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.parser.impl.parserutils.ParseTreeErrorListener;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
/**
* Test case for testing parse tree error listener.
*/
@@ -46,31 +43,16 @@
File file;
BufferedWriter out;
- @Before
- public void setUp() throws Exception {
- file = new File("demo.yang");
- out = new BufferedWriter(new FileWriter(file));
- }
- @After
- public void tearDown() throws Exception {
- file.delete();
- }
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
/**
- * This test case checks whether the error received from parser is correctly
- * handled.
+ * Checks that no exception is generated for YANG file with valid syntax.
*/
@Test
- public void syntaxErrorValidationTest() throws IOException {
+ public void checkValidYangFileForNoSyntaxError() throws IOException {
- out.write("module ONOS {\n");
- out.write("yang-version 1\n");
- out.write("namespace urn:ietf:params:xml:ns:yang:ietf-ospf;\n");
- out.write("prefix On;\n");
- out.write("}\n");
- out.close();
-
- ANTLRInputStream input = new ANTLRFileStream("demo.yang");
+ ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang");
// Create a lexer that feeds off of input char stream.
GeneratedYangLexer lexer = new GeneratedYangLexer(input);
@@ -86,15 +68,34 @@
parser.addErrorListener(parseTreeErrorListener);
// Begin parsing YANG file and generate parse tree.
ParseTree tree = parser.yangfile();
- // Get the exception occurred during parsing.
- ParserException parserException = parseTreeErrorListener.getParserException();
+ }
- /**
- * Check for the values set in syntax error function. If not set properly
- * report an assert.
- */
- assertThat(parseTreeErrorListener.isExceptionFlag(), is(true));
- assertThat(parserException.getLineNumber(), is(3));
- assertThat(parserException.getCharPositionInLine(), is(0));
+ /**
+ * Checks that exception is generated for YANG file with invalid syntax.
+ */
+ @Test
+ public void checkInvalidYangFileForSyntaxError() throws IOException {
+
+ // Get the exception occurred during parsing.
+ thrown.expect(ParserException.class);
+ thrown.expect(CustomExceptionMatcher.errorLocation(3, 0));
+ thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'");
+
+ ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang");
+
+ // Create a lexer that feeds off of input char stream.
+ GeneratedYangLexer lexer = new GeneratedYangLexer(input);
+ // Create a buffer of tokens pulled from the lexer.
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ // Create a parser that feeds off the tokens buffer.
+ GeneratedYangParser parser = new GeneratedYangParser(tokens);
+ // Remove console error listener.
+ parser.removeErrorListeners();
+ // Create instance of customized error listener.
+ ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
+ // Add customized error listener to catch errors during parsing.
+ parser.addErrorListener(parseTreeErrorListener);
+ // Begin parsing YANG file and generate parse tree.
+ ParseTree tree = parser.yangfile();
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/resources/BelongsToDualPrefix.yang b/utils/yangutils/src/test/resources/BelongsToDualPrefix.yang
new file mode 100644
index 0000000..37973da
--- /dev/null
+++ b/utils/yangutils/src/test/resources/BelongsToDualPrefix.yang
@@ -0,0 +1,8 @@
+submodule Test {
+yang-version 1;
+belongs-to ONOS {
+prefix On1;
+prefix On2;
+}
+}
+
diff --git a/utils/yangutils/src/test/resources/BelongsToWithPrefix.yang b/utils/yangutils/src/test/resources/BelongsToWithPrefix.yang
new file mode 100644
index 0000000..75a13ca
--- /dev/null
+++ b/utils/yangutils/src/test/resources/BelongsToWithPrefix.yang
@@ -0,0 +1,6 @@
+submodule Test {
+yang-version 1;
+belongs-to ONOS {
+prefix On1;
+}
+}
diff --git a/utils/yangutils/src/test/resources/BelongsToWithoutPrefix.yang b/utils/yangutils/src/test/resources/BelongsToWithoutPrefix.yang
new file mode 100644
index 0000000..eaf9885
--- /dev/null
+++ b/utils/yangutils/src/test/resources/BelongsToWithoutPrefix.yang
@@ -0,0 +1,6 @@
+submodule Test {
+yang-version 1;
+belongs-to ONOS {
+}
+}
+
diff --git a/utils/yangutils/src/test/resources/ContactDualEntryTest.yang b/utils/yangutils/src/test/resources/ContactDualEntryTest.yang
new file mode 100644
index 0000000..2dca10e
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ContactDualEntryTest.yang
@@ -0,0 +1,9 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+organization "IETF SPRING Working Group";
+contact "WG List";
+contact "Invalid";
+}
+
diff --git a/utils/yangutils/src/test/resources/ContactIncorrectOrder.yang b/utils/yangutils/src/test/resources/ContactIncorrectOrder.yang
new file mode 100644
index 0000000..237d003
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ContactIncorrectOrder.yang
@@ -0,0 +1,7 @@
+module Test {
+yang-version 1;
+contact "Test";
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+organization "IETF SPRING Working Group";
+}
diff --git a/utils/yangutils/src/test/resources/ContactValidEntry.yang b/utils/yangutils/src/test/resources/ContactValidEntry.yang
new file mode 100644
index 0000000..f88e147
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ContactValidEntry.yang
@@ -0,0 +1,9 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+organization "IETF SPRING Working Group";
+contact "WG List: <mailto:spring@ietf.org>
+Editor: Stephane Litkowski
+ <mailto:stephane.litkowski@orange.com>";
+}
diff --git a/utils/yangutils/src/test/resources/ContactWithEmptyString.yang b/utils/yangutils/src/test/resources/ContactWithEmptyString.yang
new file mode 100644
index 0000000..34c6008
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ContactWithEmptyString.yang
@@ -0,0 +1,7 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+organization "IETF SPRING Working Group";
+contact;
+}
diff --git a/utils/yangutils/src/test/resources/ImportInvalidOrder.yang b/utils/yangutils/src/test/resources/ImportInvalidOrder.yang
new file mode 100644
index 0000000..6bfc685
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ImportInvalidOrder.yang
@@ -0,0 +1,10 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+revision-date 2015-02-03;
+prefix On1;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/ImportMultipleInstance.yang b/utils/yangutils/src/test/resources/ImportMultipleInstance.yang
new file mode 100644
index 0000000..175f2ff
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ImportMultipleInstance.yang
@@ -0,0 +1,14 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+import itut {
+prefix On3;
+revision-date 2016-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/ImportValidEntry.yang b/utils/yangutils/src/test/resources/ImportValidEntry.yang
new file mode 100644
index 0000000..b725d39
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ImportValidEntry.yang
@@ -0,0 +1,10 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/ImportWithDualPrefix.yang b/utils/yangutils/src/test/resources/ImportWithDualPrefix.yang
new file mode 100644
index 0000000..8b40bb0
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ImportWithDualPrefix.yang
@@ -0,0 +1,11 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On1;
+prefix On2;
+revision-date 2015-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/ImportWithoutPrefix.yang b/utils/yangutils/src/test/resources/ImportWithoutPrefix.yang
new file mode 100644
index 0000000..ee68e59
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ImportWithoutPrefix.yang
@@ -0,0 +1,9 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+revision-date 2015-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/ImportWithoutRevision.yang b/utils/yangutils/src/test/resources/ImportWithoutRevision.yang
new file mode 100644
index 0000000..af47b7a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ImportWithoutRevision.yang
@@ -0,0 +1,9 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/IncludeImportAnyOrder.yang b/utils/yangutils/src/test/resources/IncludeImportAnyOrder.yang
new file mode 100644
index 0000000..05339a6
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IncludeImportAnyOrder.yang
@@ -0,0 +1,16 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+include itut {
+revision-date 2016-02-03;
+}
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/IncludeInvalidDateSyntax.yang b/utils/yangutils/src/test/resources/IncludeInvalidDateSyntax.yang
new file mode 100644
index 0000000..3716209
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IncludeInvalidDateSyntax.yang
@@ -0,0 +1,16 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 16-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/IncludeInvalidSyntax.yang b/utils/yangutils/src/test/resources/IncludeInvalidSyntax.yang
new file mode 100644
index 0000000..91ae17b
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IncludeInvalidSyntax.yang
@@ -0,0 +1,16 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut; {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/IncludeMultiInstance.yang b/utils/yangutils/src/test/resources/IncludeMultiInstance.yang
new file mode 100644
index 0000000..81a527a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IncludeMultiInstance.yang
@@ -0,0 +1,16 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/IncludeWithDate.yang b/utils/yangutils/src/test/resources/IncludeWithDate.yang
new file mode 100644
index 0000000..9701a2d
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IncludeWithDate.yang
@@ -0,0 +1,13 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/IncludeWithEmptyBody.yang b/utils/yangutils/src/test/resources/IncludeWithEmptyBody.yang
new file mode 100644
index 0000000..471fdb3
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IncludeWithEmptyBody.yang
@@ -0,0 +1,12 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/IncludeWithStmtend.yang b/utils/yangutils/src/test/resources/IncludeWithStmtend.yang
new file mode 100644
index 0000000..e40813b
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IncludeWithStmtend.yang
@@ -0,0 +1,11 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut;
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/ModuleValidEntry.yang b/utils/yangutils/src/test/resources/ModuleValidEntry.yang
new file mode 100644
index 0000000..439ded8
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ModuleValidEntry.yang
@@ -0,0 +1,5 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/ModuleWithInvalidIdentifier.yang b/utils/yangutils/src/test/resources/ModuleWithInvalidIdentifier.yang
new file mode 100644
index 0000000..d89340a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/ModuleWithInvalidIdentifier.yang
@@ -0,0 +1,5 @@
+module Test:Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/NamespaceDualEntry.yang b/utils/yangutils/src/test/resources/NamespaceDualEntry.yang
new file mode 100644
index 0000000..09c9b54
--- /dev/null
+++ b/utils/yangutils/src/test/resources/NamespaceDualEntry.yang
@@ -0,0 +1,6 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+namespace urn:ietf:params:xml:ns:yang:ietf-segment-routing;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/NamespaceInDoubleQuotes.yang b/utils/yangutils/src/test/resources/NamespaceInDoubleQuotes.yang
new file mode 100644
index 0000000..aec0042
--- /dev/null
+++ b/utils/yangutils/src/test/resources/NamespaceInDoubleQuotes.yang
@@ -0,0 +1,5 @@
+module Test {
+yang-version 1;
+namespace "urn:ietf:params:xml:ns:yang:ietf-ospf";
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/NamespaceNoEntryTest.yang b/utils/yangutils/src/test/resources/NamespaceNoEntryTest.yang
new file mode 100644
index 0000000..ac30ae4
--- /dev/null
+++ b/utils/yangutils/src/test/resources/NamespaceNoEntryTest.yang
@@ -0,0 +1,4 @@
+module Test {
+yang-version 1;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/NamespaceWithConcatenationTest.yang b/utils/yangutils/src/test/resources/NamespaceWithConcatenationTest.yang
new file mode 100644
index 0000000..c9ac4b0
--- /dev/null
+++ b/utils/yangutils/src/test/resources/NamespaceWithConcatenationTest.yang
@@ -0,0 +1,6 @@
+module Test {
+yang-version 1;
+namespace "urn:ietf:params:xml:ns:"
+ + "yang:ietf-segment-routing";
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/NamespaceWithInvalidSpaces.yang b/utils/yangutils/src/test/resources/NamespaceWithInvalidSpaces.yang
new file mode 100644
index 0000000..f8f91c5
--- /dev/null
+++ b/utils/yangutils/src/test/resources/NamespaceWithInvalidSpaces.yang
@@ -0,0 +1,5 @@
+module Test {
+yang-version 1;
+namespace "urn:ietf:params:xml :ns:yang:ietf-ospf";
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/NamespaceWithoutQuotes.yang b/utils/yangutils/src/test/resources/NamespaceWithoutQuotes.yang
new file mode 100644
index 0000000..439ded8
--- /dev/null
+++ b/utils/yangutils/src/test/resources/NamespaceWithoutQuotes.yang
@@ -0,0 +1,5 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/OrganizationDualEntry.yang b/utils/yangutils/src/test/resources/OrganizationDualEntry.yang
new file mode 100644
index 0000000..64bf23d
--- /dev/null
+++ b/utils/yangutils/src/test/resources/OrganizationDualEntry.yang
@@ -0,0 +1,18 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "IETF SPRING Working Group";
+organization "ITUT SPRING Working Group";
+}
diff --git a/utils/yangutils/src/test/resources/OrganizationInvalidOrder.yang b/utils/yangutils/src/test/resources/OrganizationInvalidOrder.yang
new file mode 100644
index 0000000..333f2e5
--- /dev/null
+++ b/utils/yangutils/src/test/resources/OrganizationInvalidOrder.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+organization "ONOS";
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut; {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+}
diff --git a/utils/yangutils/src/test/resources/OrganizationMissingValue.yang b/utils/yangutils/src/test/resources/OrganizationMissingValue.yang
new file mode 100644
index 0000000..e9e3f46
--- /dev/null
+++ b/utils/yangutils/src/test/resources/OrganizationMissingValue.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization ;
+}
diff --git a/utils/yangutils/src/test/resources/OrganizationValidEntry.yang b/utils/yangutils/src/test/resources/OrganizationValidEntry.yang
new file mode 100644
index 0000000..25ae1ec
--- /dev/null
+++ b/utils/yangutils/src/test/resources/OrganizationValidEntry.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "IETF SPRING Working Group";
+}
diff --git a/utils/yangutils/src/test/resources/PrefixDualEntry.yang b/utils/yangutils/src/test/resources/PrefixDualEntry.yang
new file mode 100644
index 0000000..e999774
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PrefixDualEntry.yang
@@ -0,0 +1,18 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+prefix On3;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/PrefixInvalidValue.yang b/utils/yangutils/src/test/resources/PrefixInvalidValue.yang
new file mode 100644
index 0000000..40f7617
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PrefixInvalidValue.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix -On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/PrefixMissingValue.yang b/utils/yangutils/src/test/resources/PrefixMissingValue.yang
new file mode 100644
index 0000000..4d92ee1
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PrefixMissingValue.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix ;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/PrefixOrder.yang b/utils/yangutils/src/test/resources/PrefixOrder.yang
new file mode 100644
index 0000000..d14e8b1
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PrefixOrder.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+prefix test;
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/PrefixValidEntry.yang b/utils/yangutils/src/test/resources/PrefixValidEntry.yang
new file mode 100644
index 0000000..826dee4
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PrefixValidEntry.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/RevisionDateInQuotesAtImport.yang b/utils/yangutils/src/test/resources/RevisionDateInQuotesAtImport.yang
new file mode 100644
index 0000000..5f8bcb8
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionDateInQuotesAtImport.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+import ietf {
+prefix On2;
+revision-date "2015-02-03";
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/RevisionDateInQuotesAtInclude.yang b/utils/yangutils/src/test/resources/RevisionDateInQuotesAtInclude.yang
new file mode 100644
index 0000000..de405a3
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionDateInQuotesAtInclude.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date "2016-02-03";
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/RevisionDateInvalidFormat.yang b/utils/yangutils/src/test/resources/RevisionDateInvalidFormat.yang
new file mode 100644
index 0000000..8a6c717
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionDateInvalidFormat.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+import ietf {
+prefix On2;
+revision-date 15-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/RevisionDateInvalidSyntaxAtImport.yang b/utils/yangutils/src/test/resources/RevisionDateInvalidSyntaxAtImport.yang
new file mode 100644
index 0000000..df726bf
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionDateInvalidSyntaxAtImport.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+import ietf {
+prefix On2;
+revision-date 2015/02/03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/RevisionDateInvalidSyntaxAtInclude.yang b/utils/yangutils/src/test/resources/RevisionDateInvalidSyntaxAtInclude.yang
new file mode 100644
index 0000000..ea5631e
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionDateInvalidSyntaxAtInclude.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016/02/03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/RevisionDateValidEntry.yang b/utils/yangutils/src/test/resources/RevisionDateValidEntry.yang
new file mode 100644
index 0000000..dbf4d3a
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionDateValidEntry.yang
@@ -0,0 +1,17 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/RevisionInValidOrder.yang b/utils/yangutils/src/test/resources/RevisionInValidOrder.yang
new file mode 100644
index 0000000..c60d434
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionInValidOrder.yang
@@ -0,0 +1,9 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+revision 2016-02-03;
+include itut {
+revision-date 2016-02-03;
+}
+}
diff --git a/utils/yangutils/src/test/resources/RevisionInValidSyntax.yang b/utils/yangutils/src/test/resources/RevisionInValidSyntax.yang
new file mode 100644
index 0000000..1795b3e
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionInValidSyntax.yang
@@ -0,0 +1,8 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+contact "Test";
+organization "ONOS";
+revision;
+}
diff --git a/utils/yangutils/src/test/resources/RevisionNoOptionalParameter.yang b/utils/yangutils/src/test/resources/RevisionNoOptionalParameter.yang
new file mode 100644
index 0000000..664204e
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RevisionNoOptionalParameter.yang
@@ -0,0 +1,8 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix test;
+contact "Test";
+organization "ONOS";
+revision 2016-02-03;
+}
diff --git a/utils/yangutils/src/test/resources/SubModuleInvalidName.yang b/utils/yangutils/src/test/resources/SubModuleInvalidName.yang
new file mode 100644
index 0000000..7da9397
--- /dev/null
+++ b/utils/yangutils/src/test/resources/SubModuleInvalidName.yang
@@ -0,0 +1,18 @@
+submodule Test:Test {
+belongs-to ONOS {
+prefix On1;
+}
+yang-version 1;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/SubModuleOrder.yang b/utils/yangutils/src/test/resources/SubModuleOrder.yang
new file mode 100644
index 0000000..9779bbb
--- /dev/null
+++ b/utils/yangutils/src/test/resources/SubModuleOrder.yang
@@ -0,0 +1,18 @@
+submodule Test {
+belongs-to ONOS {
+prefix On1;
+}
+yang-version 1;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/SubModuleValidEntry.yang b/utils/yangutils/src/test/resources/SubModuleValidEntry.yang
new file mode 100644
index 0000000..00ecdca
--- /dev/null
+++ b/utils/yangutils/src/test/resources/SubModuleValidEntry.yang
@@ -0,0 +1,18 @@
+submodule Test {
+yang-version 1;
+belongs-to ONOS {
+prefix On1;
+}
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/SubModuleWithNamespace.yang b/utils/yangutils/src/test/resources/SubModuleWithNamespace.yang
new file mode 100644
index 0000000..d7a38f7
--- /dev/null
+++ b/utils/yangutils/src/test/resources/SubModuleWithNamespace.yang
@@ -0,0 +1,19 @@
+submodule Test {
+belongs-to ONOS {
+prefix On1;
+}
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/SubModuleWithoutBelongsTo.yang b/utils/yangutils/src/test/resources/SubModuleWithoutBelongsTo.yang
new file mode 100644
index 0000000..4a25209
--- /dev/null
+++ b/utils/yangutils/src/test/resources/SubModuleWithoutBelongsTo.yang
@@ -0,0 +1,3 @@
+submodule Test {
+yang-version 1;
+}
diff --git a/utils/yangutils/src/test/resources/SubModuleWithoutVersion.yang b/utils/yangutils/src/test/resources/SubModuleWithoutVersion.yang
new file mode 100644
index 0000000..f44df8b
--- /dev/null
+++ b/utils/yangutils/src/test/resources/SubModuleWithoutVersion.yang
@@ -0,0 +1,17 @@
+submodule Test {
+belongs-to ONOS {
+prefix On1;
+}
+import ietf {
+prefix On2;
+revision-date 2015-02-03;
+}
+include itut {
+revision-date 2016-02-03;
+}
+include sdn {
+revision-date 2014-02-03;
+}
+contact "Test";
+organization "ONOS";
+}
diff --git a/utils/yangutils/src/test/resources/VersionDualEntry.yang b/utils/yangutils/src/test/resources/VersionDualEntry.yang
new file mode 100644
index 0000000..f8eaddd
--- /dev/null
+++ b/utils/yangutils/src/test/resources/VersionDualEntry.yang
@@ -0,0 +1,6 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+yang-version 1;
+}
diff --git a/utils/yangutils/src/test/resources/VersionInvalidSyntax.yang b/utils/yangutils/src/test/resources/VersionInvalidSyntax.yang
new file mode 100644
index 0000000..26cb0b2
--- /dev/null
+++ b/utils/yangutils/src/test/resources/VersionInvalidSyntax.yang
@@ -0,0 +1,5 @@
+module Test {
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+yang-version ;
+}
diff --git a/utils/yangutils/src/test/resources/VersionInvalidValue.yang b/utils/yangutils/src/test/resources/VersionInvalidValue.yang
new file mode 100644
index 0000000..e8e6107
--- /dev/null
+++ b/utils/yangutils/src/test/resources/VersionInvalidValue.yang
@@ -0,0 +1,5 @@
+module Test {
+yang-version 2;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/VersionNotPresent.yang b/utils/yangutils/src/test/resources/VersionNotPresent.yang
new file mode 100644
index 0000000..eed9953
--- /dev/null
+++ b/utils/yangutils/src/test/resources/VersionNotPresent.yang
@@ -0,0 +1,4 @@
+module Test {
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/VersionOrder.yang b/utils/yangutils/src/test/resources/VersionOrder.yang
new file mode 100644
index 0000000..92463e9
--- /dev/null
+++ b/utils/yangutils/src/test/resources/VersionOrder.yang
@@ -0,0 +1,5 @@
+module Test {
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+yang-version 1;
+}
diff --git a/utils/yangutils/src/test/resources/VersionValidEntry.yang b/utils/yangutils/src/test/resources/VersionValidEntry.yang
new file mode 100644
index 0000000..439ded8
--- /dev/null
+++ b/utils/yangutils/src/test/resources/VersionValidEntry.yang
@@ -0,0 +1,5 @@
+module Test {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix On;
+}
diff --git a/utils/yangutils/src/test/resources/YangFileWithSyntaxError.yang b/utils/yangutils/src/test/resources/YangFileWithSyntaxError.yang
new file mode 100644
index 0000000..413a181
--- /dev/null
+++ b/utils/yangutils/src/test/resources/YangFileWithSyntaxError.yang
@@ -0,0 +1,6 @@
+module Antlrtest {
+yang-version 1
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix Ant;
+}
+
diff --git a/utils/yangutils/src/test/resources/YangFileWithoutSyntaxError.yang b/utils/yangutils/src/test/resources/YangFileWithoutSyntaxError.yang
new file mode 100644
index 0000000..4f4839f
--- /dev/null
+++ b/utils/yangutils/src/test/resources/YangFileWithoutSyntaxError.yang
@@ -0,0 +1,6 @@
+module Antlrtest {
+yang-version 1;
+namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
+prefix Ant;
+}
+