Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-3880, 3881] Yang Listener for Module and Sub-Module

Change-Id: Iee75c3e04af9b66ebc38acb3396aa4c54af5a268
Showing 99 changed files with 3290 additions and 192 deletions
......@@ -130,7 +130,186 @@ public enum ParsableDataType {
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
......
......@@ -19,13 +19,12 @@ package org.onosproject.yangutils.parser.exceptions;
/**
* 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 @@ public class ParserException extends Exception {
}
/**
* 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 @@ public class ParserException extends Exception {
}
/**
* 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
......
......@@ -69,16 +69,12 @@ public class YangUtilsParserManager implements YangUtilsParser {
// 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,15 +89,14 @@ public class YangUtilsParserManager implements YangUtilsParser {
* Walk parse tree, provide call backs to methods in listener and
* build data model tree.
*/
try {
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());
} 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.
......
......@@ -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 @@ public final class BaseFileListener {
* @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 @@ public final class BaseFileListener {
* @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
......
......@@ -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 final class BelongsToListener {
*/
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 final class BelongsToListener {
*/
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
......
......@@ -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 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
* [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 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
* | 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 @@ public final class ContactListener {
* @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
......
......@@ -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 @@ public final class ImportListener {
* @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 @@ public final class ImportListener {
* @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
......
......@@ -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 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
* 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 @@ public final class IncludeListener {
* @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 @@ public final class IncludeListener {
* @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
......
......@@ -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 @@ public final class ModuleListener {
* @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 @@ public final class ModuleListener {
* @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
......
......@@ -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 final class NamespaceListener {
*/
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
......
......@@ -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 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
* [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 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
* | 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 final class OrganizationListener {
*/
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
......
......@@ -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 @@ public final class PrefixListener {
* @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
......
......@@ -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 final class RevisionDateListener {
*/
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
......
......@@ -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,28 +69,94 @@ public final class RevisionListener {
private RevisionListener() {
}
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);
}
/**
* It is called when parser receives an input matching the grammar
* rule (revision), perform validations and update the data model
* tree.
* It is called when parser exits from grammar rule (revision), it 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 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));
}
}
/**
* It is called when parser exits from grammar rule (revision), it perform
* validations and update the data model tree.
* Validate revision.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
* @return validation result
*/
public static void processRevisionExit(TreeWalkListener listener, GeneratedYangParser.RevisionStatementContext
ctx) {
// TODO method implementation
private static boolean validateRevision(TreeWalkListener listener,
GeneratedYangParser.RevisionStatementContext ctx) {
// TODO to be implemented
return true;
}
}
\ No newline at end of file
......
......@@ -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 final class SubModuleListener {
*/
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 final class SubModuleListener {
*/
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
......
......@@ -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 final class VersionListener {
*/
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
......
......@@ -21,12 +21,18 @@ package org.onosproject.yangutils.parser.impl.parserutils;
*/
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 @@ public class ListenerError {
}
/**
* 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 class ListenerError {
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
......
/*
* 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
/*
* 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
/*
* 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
......@@ -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;
public static void checkStackIsNotEmpty(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);
}
}
// If stack is empty it indicates error condition
if (listener.getParsedDataStack().empty()) {
listener.getErrorInformation().setErrorFlag(true);
listener.getErrorInformation().setErrorMsg("Parsable stack empty at" + errNode + "entry");
return true;
/**
* 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);
}
return false;
}
}
\ No newline at end of file
......
......@@ -29,37 +29,13 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
*/
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
......
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
......@@ -16,74 +16,80 @@
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 {
@Rule
public ExpectedException thrown = ExpectedException.none();
/**
* This test case checks in case error pre-exists, listener validate
* function returns true.
* Checks for exception in case parsable stack is empty while validating for
* not empty scenario.
*/
@Test
public void listenerValidationErrorExists() {
public void validateStackIsNotEmptyForEmptyStack() {
String expectedError = ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_HOLDER, ParsableDataType.YANGBASE_DATA, "",
ListenerErrorLocation.EXIT);
// Create an test error.
ListenerError testError = new ListenerError();
testError.setErrorFlag(true);
testError.setErrorMsg("Test Error");
// 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();
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));
ListenerValidation.checkStackIsNotEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
}
/**
* This test case checks in case parsable stack is empty, listener validate
* function returns true.
* Checks if there is no exception in case parsable stack is not empty while validating
* for not empty scenario.
*/
@Test
public void listenerValidationEmptyStack() {
public void validateStackIsNotEmptyForNonEmptyStack() {
// Create test walker and assign test error to it.
TreeWalkListener testWalker = new TreeWalkListener();
boolean errorFlag = ListenerValidation.preValidation(testWalker, "ErrorTest");
// Create a temporary node of parsable.
YangRevision tmpNode = new YangRevision();
testWalker.getParsedDataStack().push(tmpNode);
/**
* 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 for exception in case parsable stack is not empty while validating
* for empty scenario.
*/
@Test
public void listenerValidationNoErrorNotExists() {
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();
......@@ -92,12 +98,21 @@ public class ListenerValidationTest {
YangRevision tmpNode = new YangRevision();
testWalker.getParsedDataStack().push(tmpNode);
boolean errorFlag = ListenerValidation.preValidation(testWalker, "ErrorTest");
ListenerValidation.checkStackIsEmpty(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.
* Checks if there is no exception in case parsable stack is empty while validating
* for empty scenario.
*/
assertThat(errorFlag, is(false));
@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
......
......@@ -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 @@ public class ParseTreeErrorListenerTest {
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 {
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();
public void checkValidYangFileForNoSyntaxError() throws IOException {
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 @@ public class ParseTreeErrorListenerTest {
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.
* Checks that exception is generated for YANG file with invalid syntax.
*/
assertThat(parseTreeErrorListener.isExceptionFlag(), is(true));
assertThat(parserException.getLineNumber(), is(3));
assertThat(parserException.getCharPositionInLine(), is(0));
@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
......
submodule Test {
yang-version 1;
belongs-to ONOS {
prefix On1;
prefix On2;
}
}
submodule Test {
yang-version 1;
belongs-to ONOS {
prefix On1;
}
}
submodule Test {
yang-version 1;
belongs-to ONOS {
}
}
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";
}
module Test {
yang-version 1;
contact "Test";
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
organization "IETF SPRING Working Group";
}
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>";
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
organization "IETF SPRING Working Group";
contact;
}
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";
}
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";
}
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";
}
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";
}
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";
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
import ietf {
prefix On2;
}
contact "Test";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
}
module Test:Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
}
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;
}
module Test {
yang-version 1;
namespace "urn:ietf:params:xml:ns:yang:ietf-ospf";
prefix On;
}
module Test {
yang-version 1;
prefix On;
}
module Test {
yang-version 1;
namespace "urn:ietf:params:xml:ns:"
+ "yang:ietf-segment-routing";
prefix On;
}
module Test {
yang-version 1;
namespace "urn:ietf:params:xml :ns:yang:ietf-ospf";
prefix On;
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
}
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";
}
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";
}
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 ;
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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";
}
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;
}
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix test;
contact "Test";
organization "ONOS";
revision;
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix test;
contact "Test";
organization "ONOS";
revision 2016-02-03;
}
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";
}
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";
}
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";
}
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";
}
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";
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
yang-version 1;
}
module Test {
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
yang-version ;
}
module Test {
yang-version 2;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
}
module Test {
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
}
module Test {
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
yang-version 1;
}
module Test {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix On;
}
module Antlrtest {
yang-version 1
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix Ant;
}
module Antlrtest {
yang-version 1;
namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
prefix Ant;
}