rama-huawei
Committed by Patrick Liu

[ONOS-4798] Error Message implementation for YANG utils

Change-Id: Idb13e851258754773f8f447ace69a9393c7c1b3d
Showing 30 changed files with 1002 additions and 226 deletions
/*
* Copyright 2016-present 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.datamodel;
/**
* Represents data model node to maintain YANG app error message information.
*/
public interface YangAppErrorHolder {
/**
* Sets the application's error information.
*
* @param yangAppErrorInfo the application's error information
*/
void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo);
/**
* Returns application's error information.
*
* @return application's error information
*/
YangAppErrorInfo getAppErrorInfo();
}
/*Copyright 2016.year 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
/*
* Copyright 2016-present 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.
*/
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.datamodel;
import java.io.Serializable;
/**
* Abstraction of error message and application info processing.
* Represents data model to maintain yang app error information.
*/
public interface YangAppErrorInfo {
public class YangAppErrorInfo implements Serializable {
private static final long serialVersionUID = 807201693L;
/**
* Application's error message, to be used for data error.
*/
private String errorMessage;
/**
* Error tag, to be filled in data validation error response.
*/
private String errorTag;
/**
* Application's error tag, to be filled in data validation error response.
*/
private String errorAppTag;
/**
* Application's error path, to be filled in data validation error response.
*/
private String errorAppPath;
/**
* Application's error info, to be filled in data validation error response.
*/
private String errorAppInfo;
/**
* Creates a YANG app error info object.
*/
@SuppressWarnings("unused")
public YangAppErrorInfo() {
}
/**
* Returns application's error message, to be used for data error.
*
* @return Application's error message, to be used for data error
*/
public String getGetErrorMessage() {
return errorMessage;
}
/**
* Sets Application's error message, to be used for data error.
*
* @param errMsg Application's error message, to be used for data error
*/
public void setErrorMessage(String errMsg) {
errorMessage = errMsg;
}
/**
* Returns error tag, to be used for data error.
*
* @return error tag, to be used for data error
*/
public String getGetErrorTag() {
return errorTag;
}
/**
* Sets error tag, to be used for data error.
*
* @param errTag error tag, to be used for data error
*/
public void setErrorTag(String errTag) {
errorTag = errTag;
}
/**
* Returns application's error tag, to be used for data error.
*
* @return application's error tag, to be used for data error
*/
public String getGetErrorAppTag() {
return errorAppTag;
}
/**
* Sets application's error tag, to be used for data error.
*
* @param errTag application's error tag, to be used for data error
*/
public void setErrorAppTag(String errTag) {
errorAppTag = errTag;
}
/**
* Returns the application's error message for data error.
* Returns application's error path, to be used for data error.
*
* @return application's error message for data error.
* @return application's error path, to be used for data error
*/
String getGetErrorMessage();
public String getGetErrorAppPath() {
return errorAppPath;
}
/**
* Sets the application's error message for data error.
* Sets application's error path, to be used for data error.
*
* @param errorMessage application's error message for data error.
* @param errPath application's error path, to be used for data error
*/
void setErrorMessage(String errorMessage);
public void setErrorAppPath(String errPath) {
errorAppPath = errPath;
}
/**
* Returns the application's error tag for data error.
* Returns application's error info, to be used for data error.
*
* @return application's error tag for data error.
* @return application's error info, to be used for data error
*/
String getGetErrorAppTag();
public String getGetErrorAppInfo() {
return errorAppInfo;
}
/**
* Sets the application's error tag for data error.
* Sets application's error info, to be used for data error.
*
* @param errorMessage application's error tag for data error.
* @param errInfo application's error info, to be used for data error
*/
void setErrorAppTag(String errorMessage);
public void setErrorAppInfo(String errInfo) {
errorAppInfo = errInfo;
}
}
......
......@@ -23,6 +23,9 @@ import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.ERROR_PATH_MISSING_CHOICE;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.MISSING_CHOICE_ERROR_APP_TAG;
/*-
* Reference RFC 6020.
......@@ -65,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE
*/
public class YangChoice extends YangNode
implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentableNode,
YangWhenHolder, YangIfFeatureHolder {
YangWhenHolder, YangIfFeatureHolder, YangAppErrorHolder {
private static final long serialVersionUID = 806201604L;
......@@ -160,10 +163,19 @@ public class YangChoice extends YangNode
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* YANG application error information.
*/
private YangAppErrorInfo yangAppErrorInfo;
/**
* Create a choice node.
*/
public YangChoice() {
super(YangNodeType.CHOICE_NODE);
yangAppErrorInfo = new YangAppErrorInfo();
yangAppErrorInfo.setErrorTag(DATA_MISSING_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(MISSING_CHOICE_ERROR_APP_TAG);
yangAppErrorInfo.setErrorAppPath(ERROR_PATH_MISSING_CHOICE);
}
/**
......@@ -435,4 +447,15 @@ public class YangChoice extends YangNode
public List<YangAugmentedInfo> getAugmentedInfoList() {
return yangAugmentedInfo;
}
@Override
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
@Override
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
}
......
......@@ -87,7 +87,7 @@ public class YangLeafList
*
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private int maxElelements = Integer.MAX_VALUE;
private YangMaxElement maxElement;
/**
* Reference:RFC 6020.
......@@ -107,7 +107,7 @@ public class YangLeafList
*
* o Otherwise, it is enforced if the ancestor node exists.
*/
private int minElements = 0;
private YangMinElement minElements;
/**
* The textual reference to this leaf-list.
......@@ -153,6 +153,8 @@ public class YangLeafList
* Creates a YANG leaf-list.
*/
public YangLeafList() {
setMinElements(new YangMinElement());
setMaxElements(new YangMaxElement());
}
/**
......@@ -232,38 +234,38 @@ public class YangLeafList
}
/**
* Returns the max elements no.
* Returns the maximum elements number.
*
* @return the max elements no
* @return the maximum elements number
*/
public int getMaxElelements() {
return maxElelements;
public YangMaxElement getMaxElements() {
return maxElement;
}
/**
* Sets the max elements no.
* Sets the maximum elements number.
*
* @param maxElelements max elements no
* @param maxElement maximum elements number
*/
public void setMaxElelements(int maxElelements) {
this.maxElelements = maxElelements;
public void setMaxElements(YangMaxElement maxElement) {
this.maxElement = maxElement;
}
/**
* Returns the min elements no.
* Returns the minimum elements number.
*
* @return the min elements no
* @return the minimum elements number
*/
public int getMinElements() {
public YangMinElement getMinElements() {
return minElements;
}
/**
* Sets the min elements no.
* Sets the minimum elements number.
*
* @param minElements the min elements no
* @param minElements the minimum elements number
*/
public void setMinElements(int minElements) {
public void setMinElements(YangMinElement minElements) {
this.minElements = minElements;
}
......
......@@ -29,6 +29,9 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.ERROR_PATH_LEAFREF_LEAF;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.INSTANCE_REQUIRED_ERROR_APP_TAG;
/*
* Reference:RFC 6020.
......@@ -44,7 +47,7 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVE
* @param <T> YANG leafref info
*/
public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder,
YangXPathResolver {
YangXPathResolver, YangAppErrorHolder {
private static final long serialVersionUID = 286201644L;
......@@ -97,6 +100,21 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI
private List<YangIfFeature> ifFeatureList;
/**
* YANG application error information.
*/
private YangAppErrorInfo yangAppErrorInfo;
/**
* Creates a YANG leaf ref.
*/
public YangLeafRef() {
yangAppErrorInfo = new YangAppErrorInfo();
yangAppErrorInfo.setErrorTag(DATA_MISSING_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(INSTANCE_REQUIRED_ERROR_APP_TAG);
yangAppErrorInfo.setErrorAppPath(ERROR_PATH_LEAFREF_LEAF);
}
/**
* Returns the status of the require instance in leafref.
*
* @return status of the require instance
......@@ -266,6 +284,16 @@ public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangI
}
@Override
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
@Override
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
@Override
public void resolve() throws DataModelException {
if (getReferredLeafOrLeafList() == null) {
......
......@@ -33,7 +33,7 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
/**
* Represents the restriction for length data type.
*/
public class YangLengthRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable {
public class YangLengthRestriction implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
/*-
* Reference RFC 6020.
......@@ -84,19 +84,14 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr
private String reference;
/**
* Application's error message, to be used for data error.
* Textual description.
*/
private String errorMessage;
private String description;
/**
* Application's error tag, to be filled in data validation error response.
* YANG application error information.
*/
private String errorAppTag;
/**
* Textual description.
*/
private String description;
private YangAppErrorInfo yangAppErrorInfo;
/**
* Creates a YANG length restriction object.
......@@ -164,59 +159,38 @@ public class YangLengthRestriction implements YangDesc, YangReference, YangAppEr
}
/**
* Returns application's error message, to be used for data error.
*
* @return Application's error message, to be used for data error
*/
@Override
public String getGetErrorMessage() {
return errorMessage;
public YangConstructType getYangConstructType() {
return YangConstructType.PATTERN_DATA;
}
/**
* Sets Application's error message, to be used for data error.
*
* @param errMsg Application's error message, to be used for data error
*/
@Override
public void setErrorMessage(String errMsg) {
errorMessage = errMsg;
public void validateDataOnEntry() throws DataModelException {
// TODO: implement the method.
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO: implement the method.
}
/**
* Returns application's error tag, to be used for data error.
* Sets the application's error information.
*
* @return application's error tag, to be used for data error
* @param yangAppErrorInfo the application's error information
*/
@Override
public String getGetErrorAppTag() {
return errorAppTag;
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
/**
* Sets application's error tag, to be used for data error.
* Returns application's error information.
*
* @param errTag application's error tag, to be used for data error.
* @return application's error information
*/
@Override
public void setErrorAppTag(String errTag) {
errorAppTag = errTag;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.PATTERN_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO: implement the method.
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO: implement the method.
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
}
......
......@@ -140,7 +140,7 @@ public class YangList
*
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private int maxElements = Integer.MAX_VALUE;
private YangMaxElement maxElements;
/**
* Reference RFC 6020.
......@@ -160,7 +160,7 @@ public class YangList
*
* o Otherwise, it is enforced if the ancestor node exists.
*/
private int minElements = 0;
private YangMinElement minElements;
/**
* reference.
......@@ -381,7 +381,7 @@ public class YangList
*
* @return the max elements
*/
public int getMaxElements() {
public YangMaxElement getMaxElements() {
return maxElements;
}
......@@ -390,8 +390,8 @@ public class YangList
*
* @param max the max elements
*/
public void setMaxElements(int max) {
maxElements = max;
public void setMaxElements(YangMaxElement max) {
this.maxElements = max;
}
/**
......@@ -399,7 +399,7 @@ public class YangList
*
* @return the minimum elements
*/
public int getMinElements() {
public YangMinElement getMinElements() {
return minElements;
}
......@@ -408,7 +408,7 @@ public class YangList
*
* @param minElements the minimum elements
*/
public void setMinElements(int minElements) {
public void setMinElements(YangMinElement minElements) {
this.minElements = minElements;
}
......
/*
* Copyright 2016-present 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.datamodel;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.TOO_MANY_ELEMENTS_ERROR_APP_TAG;
import java.io.Serializable;
/**
* Represents max element data represented in YANG.
*/
public class YangMaxElement implements YangAppErrorHolder, Serializable {
private static final long serialVersionUID = 807201694L;
/**
* YANG application error information.
*/
private YangAppErrorInfo yangAppErrorInfo;
/**
* Reference:RFC 6020.
*
* The "max-elements" statement, which is optional, takes as an argument a
* positive integer or the string "unbounded", which puts a constraint on
* valid list entries. A valid leaf-list or list always has at most
* max-elements entries.
*
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private int maxElement = Integer.MAX_VALUE;
/**
* Creates a YANG maximum element.
*/
public YangMaxElement() {
YangAppErrorInfo yangAppErrorInfo = new YangAppErrorInfo();
yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(TOO_MANY_ELEMENTS_ERROR_APP_TAG);
}
/**
* Returns the maximum element value.
*
* @return the maximum element value
*/
public int getMaxElement() {
return maxElement;
}
/**
* Sets the maximum element value.
*
* @param maxElement the maximum element value
*/
public void setMaxElement(int maxElement) {
this.maxElement = maxElement;
}
@Override
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
@Override
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.datamodel;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.TOO_FEW_ELEMENTS_ERROR_APP_TAG;
import java.io.Serializable;
/**
* Represents minimum element data represented in YANG.
*/
public class YangMinElement implements YangAppErrorHolder, Serializable {
private static final long serialVersionUID = 807201695L;
/**
* YANG application error information.
*/
private YangAppErrorInfo yangAppErrorInfo;
/**
* Reference:RFC 6020.
*
* The "min-elements" statement, which is optional, takes as an argument a
* non-negative integer that puts a constraint on valid list entries. A
* valid leaf-list or list MUST have at least min-elements entries.
*
* If no "min-elements" statement is present, it defaults to zero.
*
* The behavior of the constraint depends on the type of the leaf-list's or
* list's closest ancestor node in the schema tree that is not a non-
* presence container:
*
* If this ancestor is a case node, the constraint is enforced if any
* other node from the case exists.
*
* Otherwise, it is enforced if the ancestor node exists.
*/
private int minElement = 0;
/**
* Creates a YANG minimum element.
*/
public YangMinElement() {
YangAppErrorInfo yangAppErrorInfo = new YangAppErrorInfo();
yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(TOO_FEW_ELEMENTS_ERROR_APP_TAG);
}
/**
* Returns the minimum element value.
*
* @return the minimum element value
*/
public int getMinElement() {
return minElement;
}
/**
* Sets the minimum element value.
*
* @param minElement the minimum element value
*/
public void setMinElement(int minElement) {
this.minElement = minElement;
}
@Override
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
@Override
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
}
......@@ -20,6 +20,8 @@ import java.io.Serializable;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.MUST_VIOLATION_ERROR_APP_TAG;
/*-
* The "must" statement, which is optional, takes as an argument a string that
......@@ -48,7 +50,7 @@ import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents information defined in YANG must.
*/
public class YangMust implements YangDesc, YangReference, Parsable, Serializable {
public class YangMust implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
private static final long serialVersionUID = 806201646L;
......@@ -68,9 +70,17 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable
private String reference;
/**
* YANG application error information.
*/
private YangAppErrorInfo yangAppErrorInfo;
/**
* Creates a YANG must restriction.
*/
public YangMust() {
yangAppErrorInfo = new YangAppErrorInfo();
yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(MUST_VIOLATION_ERROR_APP_TAG);
}
/**
......@@ -160,4 +170,14 @@ public class YangMust implements YangDesc, YangReference, Parsable, Serializable
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
@Override
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
}
......
......@@ -52,7 +52,7 @@ import java.util.List;
* Represents pattern restriction information. The regular expression restriction on string
* data type.
*/
public class YangPatternRestriction implements Serializable {
public class YangPatternRestriction implements Serializable, YangAppErrorHolder {
private static final long serialVersionUID = 806201649L;
......@@ -62,6 +62,11 @@ public class YangPatternRestriction implements Serializable {
private List<String> patternList;
/**
* YANG application error information.
*/
private YangAppErrorInfo yangAppErrorInfo;
/**
* Creates a YANG pattern restriction object.
*/
public YangPatternRestriction() {
......@@ -94,4 +99,14 @@ public class YangPatternRestriction implements Serializable {
public void addPattern(String newPattern) {
getPatternList().add(newPattern);
}
@Override
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
@Override
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
}
......
......@@ -59,7 +59,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* @param <T> range type (data type)
*/
public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable {
implements YangDesc, YangReference, Parsable, Serializable, YangAppErrorHolder {
private static final long serialVersionUID = 8062016051L;
......@@ -75,19 +75,14 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
private String reference;
/**
* Application's error message, to be used for data error.
*/
private String errorMessage;
/**
* Application's error tag, to be filled in data validation error response.
* Textual description.
*/
private String errorAppTag;
private String description;
/**
* Textual description.
* YANG application error information.
*/
private String description;
private YangAppErrorInfo yangAppErrorInfo;
/**
* Creates YANG range restriction object.
......@@ -278,47 +273,6 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
}
/**
* Returns application's error message, to be used for data error.
*
* @return Application's error message, to be used for data error
*/
@Override
public String getGetErrorMessage() {
return errorMessage;
}
/**
* Sets Application's error message, to be used for data error.
*
* @param errMsg Application's error message, to be used for data error
*/
@Override
public void setErrorMessage(String errMsg) {
errorMessage = errMsg;
}
/**
* Returns application's error tag, to be used for data error.
*
* @return application's error tag, to be used for data error
*/
@Override
public String getGetErrorAppTag() {
return errorAppTag;
}
/**
* Sets application's error tag, to be used for data error.
*
* @param errTag application's error tag, to be used for data error.
*/
@Override
public void setErrorAppTag(String errTag) {
errorAppTag = errTag;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.RANGE_DATA;
......@@ -333,4 +287,14 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
public void validateDataOnExit() throws DataModelException {
// TODO: implement the method.
}
@Override
public void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo) {
this.yangAppErrorInfo = yangAppErrorInfo;
}
@Override
public YangAppErrorInfo getAppErrorInfo() {
return yangAppErrorInfo;
}
}
......
......@@ -33,7 +33,7 @@ import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
/**
* Represents the restriction for string data type.
*/
public class YangStringRestriction implements YangDesc, YangReference, YangAppErrorInfo, Parsable, Serializable {
public class YangStringRestriction implements YangDesc, YangReference, Parsable, Serializable {
/*-
* Reference RFC 6020.
......@@ -89,16 +89,6 @@ public class YangStringRestriction implements YangDesc, YangReference, YangAppEr
private String reference;
/**
* Application's error message, to be used for data error.
*/
private String errorMessage;
/**
* Application's error tag, to be filled in data validation error response.
*/
private String errorAppTag;
/**
* Textual description.
*/
private String description;
......@@ -198,47 +188,6 @@ public class YangStringRestriction implements YangDesc, YangReference, YangAppEr
}
/**
* Returns application's error message, to be used for data error.
*
* @return Application's error message, to be used for data error
*/
@Override
public String getGetErrorMessage() {
return errorMessage;
}
/**
* Sets Application's error message, to be used for data error.
*
* @param errMsg Application's error message, to be used for data error
*/
@Override
public void setErrorMessage(String errMsg) {
errorMessage = errMsg;
}
/**
* Returns application's error tag, to be used for data error.
*
* @return application's error tag, to be used for data error
*/
@Override
public String getGetErrorAppTag() {
return errorAppTag;
}
/**
* Sets application's error tag, to be used for data error.
*
* @param errTag application's error tag, to be used for data error.
*/
@Override
public void setErrorAppTag(String errTag) {
errorAppTag = errTag;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.PATTERN_DATA;
......
/*
* Copyright 2016-present 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.datamodel.utils;
/**
* Represents default YANG error message types.
*/
public final class YangErrMsgConstants {
/**
* Static attribute for operation failed error tag.
*/
public static final String OPERATION_FAILED_ERROR_TAG = "operation-failed";
/**
* Static attribute for data missing error tag.
*/
public static final String DATA_MISSING_ERROR_TAG = "data-missing";
/**
* Static attribute for bad attribute error tag.
*/
public static final String BAD_ATTRIBUTE_ERROR_TAG = "bad-attribute";
/**
* Static attribute for data not unique error app tag.
*/
public static final String DATA_NOT_UNIQUE_ERROR_APP_TAG = "data-not-unique";
/**
* Static attribute for too many elements error app tag.
*/
public static final String TOO_MANY_ELEMENTS_ERROR_APP_TAG = "too-many-elements";
/**
* Static attribute for too few elements error app tag.
*/
public static final String TOO_FEW_ELEMENTS_ERROR_APP_TAG = "too-few-elements";
/**
* Static attribute for must violation error app tag.
*/
public static final String MUST_VIOLATION_ERROR_APP_TAG = "must-violation";
/**
* Static attribute for instance required error app tag.
*/
public static final String INSTANCE_REQUIRED_ERROR_APP_TAG = "instance-required";
/**
* Static attribute for missing choice error app tag.
*/
public static final String MISSING_CHOICE_ERROR_APP_TAG = "missing-choice";
/**
* Static attribute for missing instance error app tag.
*/
public static final String MISSING_INSTANCE_ERROR_APP_TAG = "missing-instance";
/**
* TODO: Static attribute for error path to the instance-identifier leaf.
*/
public static final String ERROR_PATH_INSTANCE_IDENTIFIER_LEAF = "Path to the instance-identifier leaf.";
/**
* Static attribute for error path to the missing choice.
*/
public static final String ERROR_PATH_MISSING_CHOICE = "Path to the element with the missing choice.";
/**
* Static attribute for error path to the leafref leaf.
*/
public static final String ERROR_PATH_LEAFREF_LEAF = "Path to the leafref leaf.";
/**
* Creates an instance of yang error message constants.
*/
private YangErrMsgConstants() {
}
}
......@@ -88,7 +88,8 @@ import org.onosproject.yangutils.parser.impl.listeners.UsesListener;
import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener;
import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct;
import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
......@@ -845,7 +846,7 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.ERROR_MESSAGE_DATA, ctx, CURRENTLY_UNSUPPORTED);
ErrorMessageListener.processErrorMessageEntry(this, ctx);
}
@Override
......@@ -855,7 +856,7 @@ public class TreeWalkListener implements GeneratedYangListener {
@Override
public void enterErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) {
handleUnsupportedYangConstruct(YangConstructType.ERROR_APP_TAG_DATA, ctx, CURRENTLY_UNSUPPORTED);
ErrorAppTagListener.processErrorAppTagMessageEntry(this, ctx);
}
@Override
......
/*
* Copyright 2016-present 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.onosproject.yangutils.datamodel.YangAppErrorHolder;
import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ERROR_APP_TAG_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC 6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC 6020
*
* error-app-tag-stmt = error-app-tag-keyword sep string stmtend
*
* ANTLR grammar rule
* errorAppTagStatement : ERROR_APP_TAG_KEYWORD string STMTEND;
*/
/**
* Represents listener based call back function corresponding to the
* error app tag defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class ErrorAppTagListener {
/**
* Creates a new error app tag listener.
*/
private ErrorAppTagListener() {
}
/**
* Performs validations and updates the data model tree. It is called when parser
* receives an input matching the grammar rule error app tag.
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processErrorAppTagMessageEntry(TreeWalkListener listener,
GeneratedYangParser.ErrorAppTagStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_APP_TAG_DATA, ctx.string().getText(), ENTRY);
String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
if (tmpNode instanceof YangAppErrorHolder) {
YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
yangAppErrorInfo.setErrorAppTag(errorMessage);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_APP_TAG_DATA,
ctx.string().getText(), ENTRY));
}
}
}
/*
* Copyright 2016-present 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.onosproject.yangutils.datamodel.YangAppErrorHolder;
import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ERROR_MESSAGE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
* ABNF grammar as per RFC6020
*
* error-message-stmt = error-message-keyword sep string stmtend
*
* ANTLR grammar rule
* errorMessageStatement : ERROR_MESSAGE_KEYWORD string STMTEND;
*/
/**
* Represents listener based call back function corresponding to the
* app error message defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class ErrorMessageListener {
/**
* Creates a new must listener.
*/
private ErrorMessageListener() {
}
/**
* Performs validations and updates the data model tree. It is called when parser
* receives an input matching the grammar rule (app error message).
*
* @param listener listener's object
* @param ctx context object of the grammar rule
*/
public static void processErrorMessageEntry(TreeWalkListener listener,
GeneratedYangParser.ErrorMessageStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_MESSAGE_DATA, ctx.string().getText(), ENTRY);
String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
if (tmpNode instanceof YangAppErrorHolder) {
YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
yangAppErrorInfo.setErrorMessage(errorMessage);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_MESSAGE_DATA,
ctx.string().getText(), ENTRY));
}
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangMaxElement;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
......@@ -81,11 +82,15 @@ public final class MaxElementsListener {
switch (tmpData.getYangConstructType()) {
case LEAF_LIST_DATA:
YangLeafList leafList = (YangLeafList) tmpData;
leafList.setMaxElelements(maxElementsValue);
YangMaxElement maxLeafListElement = new YangMaxElement();
maxLeafListElement.setMaxElement(maxElementsValue);
leafList.setMaxElements(maxLeafListElement);
break;
case LIST_DATA:
YangList yangList = (YangList) tmpData;
yangList.setMaxElements(maxElementsValue);
YangMaxElement maxListElement = new YangMaxElement();
maxListElement.setMaxElement(maxElementsValue);
yangList.setMaxElements(maxListElement);
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY));
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangMinElement;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
......@@ -78,11 +79,15 @@ public final class MinElementsListener {
switch (tmpData.getYangConstructType()) {
case LEAF_LIST_DATA:
YangLeafList leafList = (YangLeafList) tmpData;
leafList.setMinElements(minElementValue);
YangMinElement minLeafListElement = new YangMinElement();
minLeafListElement.setMinElement(minElementValue);
leafList.setMinElements(minLeafListElement);
break;
case LIST_DATA:
YangList yangList = (YangList) tmpData;
yangList.setMinElements(minElementValue);
YangMinElement minElement = new YangMinElement();
minElement.setMinElement(minElementValue);
yangList.setMinElements(minElement);
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MIN_ELEMENT_DATA,
......
/*
* Copyright 2016-present 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.YangMust;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.List;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* Test-cases for testing error app tag message listener functionality.
*/
public class ErrorAppTagListenerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks if error app tag message is default updated in the data model.
*/
@Test
public void processContainerSubStatementErrorDefaultAppTag() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorDefaultAppTag.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("ErrorAppTag"));
YangContainer yangContainer = (YangContainer) yangNode.getChild();
assertThat(yangContainer.getName(), is("interface"));
String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
List<YangMust> mustConstraintList = yangContainer.getListOfMust();
assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("must-violation"));
assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
}
/**
* Checks if error app tag message listener updates the data model.
*/
@Test
public void processContainerSubStatementErrorAppTag() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorAppTag.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("ErrorAppTag"));
YangContainer yangContainer = (YangContainer) yangNode.getChild();
assertThat(yangContainer.getName(), is("interface"));
String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
List<YangMust> mustConstraintList = yangContainer.getListOfMust();
assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
assertThat(yangAppErrorInfo.getGetErrorAppTag(), is("An ethernet MTU must be 1500"));
assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
}
}
\ No newline at end of file
/*
* Copyright 2016-present 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.YangMust;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.List;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* Test-cases for testing error message listener functionality.
*/
public class ErrorMessageListnerTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks if error message listener updates the data model.
*/
@Test
public void processContainerSubStatementErrorMessage() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementErrorMessage.yang");
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("ErrorMessage"));
YangContainer yangContainer = (YangContainer) yangNode.getChild();
assertThat(yangContainer.getName(), is("interface"));
String expectedConstraint = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
List<YangMust> mustConstraintList = yangContainer.getListOfMust();
assertThat(mustConstraintList.iterator().next().getConstraint(), is(expectedConstraint));
YangAppErrorInfo yangAppErrorInfo = mustConstraintList.iterator().next().getAppErrorInfo();
assertThat(yangAppErrorInfo.getGetErrorMessage(), is("An ethernet MTU must be 1500"));
assertThat(yangAppErrorInfo.getGetErrorTag(), is("operation-failed"));
}
}
......@@ -72,8 +72,8 @@ public class InputListenerTest {
assertThat(yangList.getName(), is("ospf"));
assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
assertThat(yangList.isConfig(), is(true));
assertThat(yangList.getMaxElements(), is(10));
assertThat(yangList.getMinElements(), is(3));
assertThat(yangList.getMaxElements().getMaxElement(), is(10));
assertThat(yangList.getMinElements().getMinElement(), is(3));
leafIterator = yangList.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("invalid-interval"));
......
......@@ -72,7 +72,7 @@ public class LeafListListenerTest {
assertThat(leafListInfo.getUnits(), is("\"seconds\""));
assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
assertThat(leafListInfo.isConfig(), is(true));
assertThat(leafListInfo.getMaxElelements(), is(3));
assertThat(leafListInfo.getMaxElements().getMaxElement(), is(3));
assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
}
......@@ -162,8 +162,8 @@ public class LeafListListenerTest {
assertThat(leafListInfo.getUnits(), is("\"seconds\""));
assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
assertThat(leafListInfo.isConfig(), is(true));
assertThat(leafListInfo.getMinElements(), is(1));
assertThat(leafListInfo.getMaxElelements(), is(2147483647));
assertThat(leafListInfo.getMinElements().getMinElement(), is(1));
assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
}
......
......@@ -151,8 +151,8 @@ public class ListListenerTest {
assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
assertThat(yangList.isConfig(), is(true));
assertThat(yangList.getMaxElements(), is(10));
assertThat(yangList.getMinElements(), is(3));
assertThat(yangList.getMaxElements().getMaxElement(), is(10));
assertThat(yangList.getMinElements().getMinElement(), is(3));
assertThat(yangList.getDescription(), is("\"list description\""));
assertThat(yangList.getStatus(), is(YangStatusType.CURRENT));
assertThat(yangList.getReference(), is("\"list reference\""));
......
......@@ -65,7 +65,7 @@ public class MaxElementsListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getName(), is("invalid-interval"));
assertThat(leafListInfo.getMaxElelements(), is(3));
assertThat(leafListInfo.getMaxElements().getMaxElement(), is(3));
}
/**
......@@ -88,7 +88,7 @@ public class MaxElementsListenerTest {
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("valid"));
assertThat(yangList.getMaxElements(), is(3));
assertThat(yangList.getMaxElements().getMaxElement(), is(3));
}
/**
......@@ -136,7 +136,7 @@ public class MaxElementsListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getName(), is("invalid-interval"));
assertThat(leafListInfo.getMaxElelements(), is(2147483647));
assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
}
/**
......@@ -161,7 +161,7 @@ public class MaxElementsListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getName(), is("invalid-interval"));
assertThat(leafListInfo.getMaxElelements(), is(2147483647));
assertThat(leafListInfo.getMaxElements().getMaxElement(), is(2147483647));
}
/**
......
......@@ -65,7 +65,7 @@ public class MinElementsListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getName(), is("invalid-interval"));
assertThat(leafListInfo.getMinElements(), is(3));
assertThat(leafListInfo.getMinElements().getMinElement(), is(3));
}
/**
......@@ -88,7 +88,7 @@ public class MinElementsListenerTest {
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("valid"));
assertThat(yangList.getMinElements(), is(3));
assertThat(yangList.getMinElements().getMinElement(), is(3));
}
/**
......@@ -158,6 +158,6 @@ public class MinElementsListenerTest {
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getName(), is("invalid-interval"));
assertThat(leafListInfo.getMinElements(), is(0));
assertThat(leafListInfo.getMinElements().getMinElement(), is(0));
}
}
......
......@@ -71,8 +71,8 @@ public class OutputListenerTest {
assertThat(yangList.getName(), is("ospf"));
assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
assertThat(yangList.isConfig(), is(true));
assertThat(yangList.getMaxElements(), is(10));
assertThat(yangList.getMinElements(), is(3));
assertThat(yangList.getMaxElements().getMaxElement(), is(10));
assertThat(yangList.getMinElements().getMinElement(), is(3));
leafIterator = yangList.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("invalid-interval"));
......
module ErrorAppTag {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container interface {
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
}
leaf ifMTU {
type uint32;
}
must "ifType != 'ethernet' or " +
"(ifType = 'ethernet' and ifMTU = 1500)" {
description "An ethernet MTU must be 1500";
error-app-tag "An ethernet MTU must be 1500";
}
must "ifType != 'atm' or " +
"(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
description "An atm MTU must be 64 .. 17966";
}
}
}
module ErrorAppTag {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container interface {
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
}
leaf ifMTU {
type uint32;
}
must "ifType != 'ethernet' or " +
"(ifType = 'ethernet' and ifMTU = 1500)" {
description "An ethernet MTU must be 1500";
}
must "ifType != 'atm' or " +
"(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
description "An atm MTU must be 64 .. 17966";
}
}
}
module ErrorMessage {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container interface {
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
}
leaf ifMTU {
type uint32;
}
must "ifType != 'ethernet' or " +
"(ifType = 'ethernet' and ifMTU = 1500)" {
description "An ethernet MTU must be 1500";
error-message "An ethernet MTU must be 1500";
}
must "ifType != 'atm' or " +
"(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
description "An atm MTU must be 64 .. 17966";
}
}
}