Vidyashree Rama
Committed by Gerrit Code Review

[ONOS-3892,3895,3882,3883,3896]Unit test of yang container, list, leaf, leaf-list parser

Change-Id: Iae040d9d354e012584db8adc0aa7ff1ea4c099a0
Showing 115 changed files with 3132 additions and 0 deletions
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeaf;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangDataTypes;
28 +import org.onosproject.yangutils.datamodel.YangStatusType;
29 +import org.onosproject.yangutils.datamodel.YangContainer;
30 +import org.onosproject.yangutils.datamodel.YangList;
31 +import org.onosproject.yangutils.datamodel.YangLeafList;
32 +import org.onosproject.yangutils.parser.exceptions.ParserException;
33 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
34 +
35 +import java.io.IOException;
36 +import java.util.ListIterator;
37 +
38 +import static org.hamcrest.MatcherAssert.assertThat;
39 +import static org.hamcrest.core.Is.is;
40 +
41 +/**
42 + * Test cases for config listener.
43 + */
44 +public class ConfigListenerTest {
45 +
46 + @Rule
47 + public ExpectedException thrown = ExpectedException.none();
48 +
49 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
50 +
51 + /**
52 + * Checks valid config statement.
53 + */
54 + @Test
55 + public void processConfigTrue() throws IOException, ParserException {
56 +
57 + YangNode node = manager.getDataModel("src/test/resources/ConfigTrue.yang");
58 +
59 + // Check whether the data model tree returned is of type module.
60 + assertThat((node instanceof YangModule), is(true));
61 +
62 + // Check whether the node type is set properly to module.
63 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
64 +
65 + // Check whether the module name is set correctly.
66 + YangModule yangNode = (YangModule) node;
67 + assertThat(yangNode.getName(), is("Test"));
68 +
69 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
70 + YangLeaf leafInfo = leafIterator.next();
71 +
72 + // Check whether the Config value is set correctly.
73 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
74 + assertThat(leafInfo.isConfig(), is(true));
75 + }
76 +
77 + /**
78 + * Checks valid config statement.
79 + */
80 + @Test
81 + public void processConfigFalse() throws IOException, ParserException {
82 +
83 + YangNode node = manager.getDataModel("src/test/resources/ConfigFalse.yang");
84 +
85 + // Check whether the data model tree returned is of type module.
86 + assertThat((node instanceof YangModule), is(true));
87 +
88 + // Check whether the node type is set properly to module.
89 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
90 +
91 + // Check whether the module name is set correctly.
92 + YangModule yangNode = (YangModule) node;
93 + assertThat(yangNode.getName(), is("Test"));
94 +
95 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
96 + YangLeaf leafInfo = leafIterator.next();
97 +
98 + // Check whether the Config value is set correctly.
99 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
100 + assertThat(leafInfo.isConfig(), is(false));
101 + }
102 +
103 + /**
104 + * Checks invalid config statement and expects parser exception.
105 + */
106 + @Test
107 + public void processConfigWithoutStatementEnd() throws IOException, ParserException {
108 + thrown.expect(ParserException.class);
109 + thrown.expectMessage("missing ';' at '}'");
110 + YangNode node = manager.getDataModel("src/test/resources/ConfigWithoutStatementEnd.yang");
111 + }
112 +
113 + /**
114 + * Checks invalid config statement and expects parser exception.
115 + */
116 + @Test
117 + public void processConfigInvalidValue() throws IOException, ParserException {
118 + thrown.expect(ParserException.class);
119 + thrown.expectMessage("mismatched input 'invalid' expecting {'false', 'true'}");
120 + YangNode node = manager.getDataModel("src/test/resources/ConfigInvalidValue.yang");
121 + }
122 +
123 + /**
124 + * Checks invalid config statement and expects parser exception.
125 + */
126 + @Test
127 + public void processConfigEmptyValue() throws IOException, ParserException {
128 + thrown.expect(ParserException.class);
129 + thrown.expectMessage("missing {'false', 'true'} at ';'");
130 + YangNode node = manager.getDataModel("src/test/resources/ConfigEmptyValue.yang");
131 + }
132 +
133 + /**
134 + * Checks config statement as sub-statement of module.
135 + */
136 + @Test
137 + public void processModuleSubStatementConfig() throws IOException, ParserException {
138 + thrown.expect(ParserException.class);
139 + thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container'," +
140 + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', " +
141 + "'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
142 + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
143 + YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang");
144 + }
145 +
146 + /**
147 + * Checks config statement as sub-statement of container.
148 + */
149 + @Test
150 + public void processContainerSubStatementConfig() throws IOException, ParserException {
151 +
152 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementConfig.yang");
153 +
154 + // Check whether the data model tree returned is of type module.
155 + assertThat((node instanceof YangModule), is(true));
156 +
157 + // Check whether the node type is set properly to module.
158 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
159 +
160 + // Check whether the module name is set correctly.
161 + YangModule yangNode = (YangModule) node;
162 + assertThat(yangNode.getName(), is("Test"));
163 +
164 + // Check whether the config value is set correctly.
165 + YangContainer container = (YangContainer) yangNode.getChild();
166 + assertThat(container.getName(), is("valid"));
167 + assertThat(container.isConfig(), is(true));
168 +
169 + // Check whether leaf properties as set correctly.
170 + ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
171 + YangLeaf leafInfo = leafIterator.next();
172 +
173 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
174 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
175 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
176 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
177 + assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
178 + assertThat(leafInfo.isMandatory(), is(true));
179 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
180 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
181 + }
182 +
183 + /**
184 + * Checks config statement as sub-statement of list.
185 + */
186 + @Test
187 + public void processListSubStatementConfig() throws IOException, ParserException {
188 +
189 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementConfig.yang");
190 +
191 + assertThat((node instanceof YangModule), is(true));
192 +
193 + // Check whether the node type is set properly to module.
194 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
195 +
196 + // Check whether the module name is set correctly.
197 + YangModule yangNode = (YangModule) node;
198 + assertThat(yangNode.getName(), is("Test"));
199 +
200 + // Check whether the list is child of module and config value is set.
201 + YangList yangList = (YangList) yangNode.getChild();
202 + assertThat(yangList.getName(), is("valid"));
203 + assertThat(yangList.isConfig(), is(true));
204 +
205 + // Check whether leaf properties as set correctly.
206 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
207 + YangLeaf leafInfo = leafIterator.next();
208 +
209 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
210 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
211 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
212 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
213 + assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
214 + assertThat(leafInfo.isMandatory(), is(true));
215 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
216 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
217 + }
218 +
219 + /**
220 + * Checks valid config statement as sub-statement of leaf-list.
221 + */
222 + @Test
223 + public void processLeafListSubStatementConfig() throws IOException, ParserException {
224 +
225 + YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatementConfig.yang");
226 +
227 + // Check whether the data model tree returned is of type module.
228 + assertThat((node instanceof YangModule), is(true));
229 +
230 + // Check whether the node type is set properly to module.
231 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
232 +
233 + // Check whether the module name is set correctly.
234 + YangModule yangNode = (YangModule) node;
235 + assertThat(yangNode.getName(), is("Test"));
236 +
237 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
238 + YangLeafList leafListInfo = leafListIterator.next();
239 +
240 + // Check whether config value is set correctly.
241 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
242 + assertThat(leafListInfo.isConfig(), is(true));
243 + }
244 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeaf;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangDataTypes;
28 +import org.onosproject.yangutils.datamodel.YangStatusType;
29 +import org.onosproject.yangutils.datamodel.YangContainer;
30 +import org.onosproject.yangutils.datamodel.YangList;
31 +import org.onosproject.yangutils.parser.exceptions.ParserException;
32 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
33 +
34 +import java.io.IOException;
35 +import java.util.ListIterator;
36 +
37 +import static org.hamcrest.MatcherAssert.assertThat;
38 +import static org.hamcrest.core.Is.is;
39 +
40 +/**
41 + * Test cases for testing container listener.
42 + */
43 +public class ContainerListenerTest {
44 +
45 + @Rule
46 + public ExpectedException thrown = ExpectedException.none();
47 +
48 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
49 +
50 + /**
51 + * Checks container statement as sub-statement of module.
52 + */
53 + @Test
54 + public void processModuleSubStatementContainer() throws IOException, ParserException {
55 +
56 + YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementContainer.yang");
57 +
58 + assertThat((node instanceof YangModule), is(true));
59 +
60 + // Check whether the node type is set properly to module.
61 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
62 +
63 + // Check whether the module name is set correctly.
64 + YangModule yangNode = (YangModule) node;
65 + assertThat(yangNode.getName(), is("Test"));
66 +
67 + // Check whether the container is child of module
68 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
69 + assertThat(yangContainer.getName(), is("valid"));
70 + }
71 +
72 + /**
73 + * Checks container statement as sub-statement of container.
74 + */
75 + @Test
76 + public void processContainerSubStatementContainer() throws IOException, ParserException {
77 +
78 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementContainer.yang");
79 +
80 + assertThat((node instanceof YangModule), is(true));
81 +
82 + // Check whether the node type is set properly to module.
83 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
84 +
85 + // Check whether the module name is set correctly.
86 + YangModule yangNode = (YangModule) node;
87 + assertThat(yangNode.getName(), is("Test"));
88 +
89 + // Check whether the container is child of module
90 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
91 + assertThat(yangContainer.getName(), is("ospf"));
92 +
93 + // Check whether the container is child of container
94 + YangContainer yangContainer1 = (YangContainer) yangContainer.getChild();
95 + assertThat(yangContainer1.getName(), is("valid"));
96 + }
97 +
98 + /**
99 + * Checks container statement as sub-statement of list.
100 + */
101 + @Test
102 + public void processListSubStatementContainer() throws IOException, ParserException {
103 +
104 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementContainer.yang");
105 +
106 + assertThat((node instanceof YangModule), is(true));
107 +
108 + // Check whether the node type is set properly to module.
109 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
110 +
111 + // Check whether the module name is set correctly.
112 + YangModule yangNode = (YangModule) node;
113 + assertThat(yangNode.getName(), is("Test"));
114 +
115 + // Check whether the list is child of module
116 + YangList yangList1 = (YangList) yangNode.getChild();
117 + assertThat(yangList1.getName(), is("ospf"));
118 +
119 + ListIterator<String> keyList = yangList1.getKeyList().listIterator();
120 + assertThat(keyList.next(), is("process-id"));
121 +
122 + // Check whether the list is child of list
123 + YangContainer yangContainer = (YangContainer) yangList1.getChild();
124 + assertThat(yangContainer.getName(), is("interface"));
125 + }
126 +
127 + /**
128 + * Checks container with all its sub-statements.
129 + */
130 + @Test
131 + public void processContainerSubStatements() throws IOException, ParserException {
132 +
133 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatements.yang");
134 +
135 + assertThat((node instanceof YangModule), is(true));
136 +
137 + // Check whether the node type is set properly to module.
138 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
139 +
140 + // Check whether the module name is set correctly.
141 + YangModule yangNode = (YangModule) node;
142 + assertThat(yangNode.getName(), is("Test"));
143 +
144 + // Check whether the container is child of module
145 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
146 +
147 + // Check whether container properties as set correctly.
148 + assertThat(yangContainer.getName(), is("ospf"));
149 +
150 + assertThat(yangContainer.isConfig(), is(true));
151 + assertThat(yangContainer.getPresence(), is("\"ospf logs\""));
152 + assertThat(yangContainer.getDescription(), is("\"container description\""));
153 + assertThat(yangContainer.getStatus(), is(YangStatusType.CURRENT));
154 + assertThat(yangContainer.getReference(), is("\"container reference\""));
155 +
156 + // Check whether leaf properties as set correctly.
157 + ListIterator<YangLeaf> leafIterator = yangContainer.getListOfLeaf().listIterator();
158 + YangLeaf leafInfo = leafIterator.next();
159 +
160 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
161 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
162 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
163 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
164 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
165 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
166 + }
167 +
168 + /**
169 + * Checks cardinality of sub-statements of container.
170 + */
171 + @Test
172 + public void processContainerSubStatementCardinality() throws IOException, ParserException {
173 + thrown.expect(ParserException.class);
174 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in reference before processing.");
175 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementCardinality.yang");
176 + }
177 +
178 + /**
179 + * Checks container as root node.
180 + */
181 + @Test
182 + public void processContainerRootNode() throws IOException, ParserException {
183 + thrown.expect(ParserException.class);
184 + thrown.expectMessage("no viable alternative at input 'container'");
185 + YangNode node = manager.getDataModel("src/test/resources/ContainerRootNode.yang");
186 + }
187 +
188 + /**
189 + * Checks invalid identifier for container statement.
190 + */
191 + @Test
192 + public void processContainerInvalidIdentifier() throws IOException, ParserException {
193 + thrown.expect(ParserException.class);
194 + thrown.expectMessage("mismatched input '1valid' expecting IDENTIFIER");
195 + YangNode node = manager.getDataModel("src/test/resources/ContainerInvalidIdentifier.yang");
196 + }
197 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangModule;
24 +import org.onosproject.yangutils.datamodel.YangNode;
25 +import org.onosproject.yangutils.datamodel.YangNodeType;
26 +import org.onosproject.yangutils.datamodel.YangList;
27 +import org.onosproject.yangutils.parser.exceptions.ParserException;
28 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
29 +
30 +import java.io.IOException;
31 +import java.util.List;
32 +import java.util.ListIterator;
33 +
34 +import static org.hamcrest.MatcherAssert.assertThat;
35 +import static org.hamcrest.core.Is.is;
36 +
37 +/**
38 + * Test cases for key listener.
39 + */
40 +public class KeyListenerTest {
41 +
42 + @Rule
43 + public ExpectedException thrown = ExpectedException.none();
44 +
45 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
46 +
47 + /**
48 + * Checks key statement as sub-statement of list.
49 + */
50 + @Test
51 + public void processListSubStatementKey() throws IOException, ParserException {
52 +
53 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementKey.yang");
54 +
55 + assertThat((node instanceof YangModule), is(true));
56 +
57 + // Check whether the node type is set properly to module.
58 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
59 +
60 + // Check whether the module name is set correctly.
61 + YangModule yangNode = (YangModule) node;
62 + assertThat(yangNode.getName(), is("Test"));
63 +
64 + // Check whether the list is child of module
65 + YangList yangList = (YangList) yangNode.getChild();
66 + assertThat(yangList.getName(), is("valid"));
67 +
68 + ListIterator<String> keyList = yangList.getKeyList().listIterator();
69 + assertThat(keyList.next(), is("invalid-interval"));
70 + }
71 +
72 + /**
73 + * Check multiple key values.
74 + */
75 + @Test
76 + public void processMultipleKeyValues() throws IOException, ParserException {
77 +
78 + YangNode node = manager.getDataModel("src/test/resources/MultipleKeyValues.yang");
79 +
80 + assertThat((node instanceof YangModule), is(true));
81 +
82 + // Check whether the node type is set properly to module.
83 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
84 +
85 + // Check whether the module name is set correctly.
86 + YangModule yangNode = (YangModule) node;
87 + assertThat(yangNode.getName(), is("Test"));
88 +
89 + // Check whether the list is child of module
90 + YangList yangList = (YangList) yangNode.getChild();
91 + assertThat(yangList.getName(), is("valid"));
92 +
93 + List<String> keyList = yangList.getKeyList();
94 + assertThat(keyList.contains("ospf"), is(true));
95 + assertThat(keyList.contains("isis"), is(true));
96 + }
97 +
98 + /**
99 + * Checks key statement without statement end.
100 + */
101 + @Test
102 + public void processKeyWithoutStatementEnd() throws IOException, ParserException {
103 + thrown.expect(ParserException.class);
104 + thrown.expectMessage("mismatched input 'leaf' expecting {';', '+'}");
105 + YangNode node = manager.getDataModel("src/test/resources/KeyWithoutStatementEnd.yang");
106 + }
107 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeafList;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangDataTypes;
28 +import org.onosproject.yangutils.datamodel.YangStatusType;
29 +import org.onosproject.yangutils.datamodel.YangContainer;
30 +import org.onosproject.yangutils.datamodel.YangList;
31 +import org.onosproject.yangutils.parser.exceptions.ParserException;
32 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
33 +
34 +import java.io.IOException;
35 +import java.util.ListIterator;
36 +
37 +import static org.hamcrest.MatcherAssert.assertThat;
38 +import static org.hamcrest.core.Is.is;
39 +
40 +/**
41 + * Test cases for testing leaf-list listener.
42 + */
43 +public class LeafListListenerTest {
44 +
45 + @Rule
46 + public ExpectedException thrown = ExpectedException.none();
47 +
48 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
49 +
50 + /**
51 + * Checks all the values of leaf-list sub-statements are set
52 + * correctly.
53 + */
54 + @Test
55 + public void processLeafListSubStatements() throws IOException, ParserException {
56 +
57 + YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatements.yang");
58 +
59 + // Check whether the data model tree returned is of type module.
60 + assertThat((node instanceof YangModule), is(true));
61 +
62 + // Check whether the node type is set properly to module.
63 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
64 +
65 + // Check whether the module name is set correctly.
66 + YangModule yangNode = (YangModule) node;
67 + assertThat(yangNode.getName(), is("Test"));
68 +
69 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
70 + YangLeafList leafListInfo = leafListIterator.next();
71 +
72 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
73 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
74 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
75 + assertThat(leafListInfo.getUnits(), is("\"seconds\""));
76 + assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
77 + assertThat(leafListInfo.isConfig(), is(true));
78 + assertThat(leafListInfo.getMaxElelements(), is(3));
79 + assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
80 + assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
81 + }
82 +
83 + /**
84 + * Checks whether exception is thrown when leaf-list identifier
85 + * starts with digit.
86 + */
87 + @Test
88 + public void processLeafListInvalidIdentifier() throws IOException, ParserException {
89 + thrown.expect(ParserException.class);
90 + thrown.expectMessage("mismatched input '1invalid-interval' expecting IDENTIFIER");
91 + YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidIdentifier.yang");
92 + }
93 +
94 + /**
95 + * Checks whether exception is thrown when leaf-list keyword
96 + * is incorrect.
97 + */
98 + @Test
99 + public void processLeafListInvalidStatement() throws IOException, ParserException {
100 + thrown.expect(ParserException.class);
101 + thrown.expectMessage("mismatched input 'leaflist' expecting {'augment', 'choice', 'contact', 'container'," +
102 + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," +
103 + " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
104 + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
105 + YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidStatement.yang");
106 + }
107 +
108 + /**
109 + * Checks whether exception is thrown when leaf-list keyword
110 + * without Left brace as per grammar.
111 + */
112 + @Test
113 + public void processLeafListWithoutLeftBrace() throws IOException, ParserException {
114 + thrown.expect(ParserException.class);
115 + thrown.expectMessage("missing '{' at 'type'");
116 + YangNode node = manager.getDataModel("src/test/resources/LeafListWithoutLeftBrace.yang");
117 + }
118 +
119 + /**
120 + * Checks whether exception is thrown when config statement
121 + * cardinality is not as per grammar.
122 + */
123 + @Test
124 + public void processLeafListConfigInvalidCardinality() throws IOException, ParserException {
125 + thrown.expect(ParserException.class);
126 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in config before processing.");
127 + YangNode node = manager.getDataModel("src/test/resources/LeafListConfigInvalidCardinality.yang");
128 + }
129 +
130 + /**
131 + * Checks whether exception is thrown when units statement
132 + * cardinality is not as per grammar.
133 + */
134 + @Test
135 + public void processLeafListUnitsInvalidCardinality() throws IOException, ParserException {
136 + thrown.expect(ParserException.class);
137 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in units before processing.");
138 + YangNode node = manager.getDataModel("src/test/resources/LeafListUnitsInvalidCardinality.yang");
139 + }
140 +
141 + /**
142 + * Checks leaf-list statement as sub-statement of container.
143 + */
144 + @Test
145 + public void processContainerSubStatementLeafList() throws IOException, ParserException {
146 +
147 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementLeafList.yang");
148 +
149 + // Check whether the data model tree returned is of type module.
150 + assertThat((node instanceof YangModule), is(true));
151 +
152 + // Check whether the node type is set properly to module.
153 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
154 +
155 + // Check whether the module name is set correctly.
156 + YangModule yangNode = (YangModule) node;
157 + assertThat(yangNode.getName(), is("Test"));
158 +
159 + //Check whether the container is child of module.
160 + YangContainer container = (YangContainer) yangNode.getChild();
161 + assertThat(container.getName(), is("valid"));
162 +
163 + // Check whether leaf-list properties as set correctly.
164 + ListIterator<YangLeafList> leafListIterator = container.getListOfLeafList().listIterator();
165 + YangLeafList leafListInfo = leafListIterator.next();
166 +
167 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
168 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
169 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
170 + assertThat(leafListInfo.getUnits(), is("\"seconds\""));
171 + assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
172 + assertThat(leafListInfo.isConfig(), is(true));
173 + assertThat(leafListInfo.getMinElements(), is(1));
174 + assertThat(leafListInfo.getMaxElelements(), is(2147483647));
175 + assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
176 + assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
177 + }
178 +
179 + /**
180 + * Checks leaf-list statement as sub-statement of list.
181 + */
182 + @Test
183 + public void processListSubStatementLeafList() throws IOException, ParserException {
184 +
185 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementLeafList.yang");
186 +
187 + assertThat((node instanceof YangModule), is(true));
188 +
189 + // Check whether the node type is set properly to module.
190 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
191 +
192 + // Check whether the module name is set correctly.
193 + YangModule yangNode = (YangModule) node;
194 + assertThat(yangNode.getName(), is("Test"));
195 +
196 + // Check whether the list is child of module
197 + YangList yangList = (YangList) yangNode.getChild();
198 + assertThat(yangList.getName(), is("valid"));
199 +
200 + // Check whether leaf-list properties as set correctly.
201 + ListIterator<YangLeafList> leafListIterator = yangList.getListOfLeafList().listIterator();
202 + YangLeafList leafListInfo = leafListIterator.next();
203 +
204 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
205 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
206 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
207 + assertThat(leafListInfo.getUnits(), is("\"seconds\""));
208 + assertThat(leafListInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
209 + assertThat(leafListInfo.isConfig(), is(true));
210 +
211 + assertThat(leafListInfo.getStatus(), is(YangStatusType.CURRENT));
212 + assertThat(leafListInfo.getReference(), is("\"RFC 6020\""));
213 + }
214 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeaf;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangDataTypes;
28 +import org.onosproject.yangutils.datamodel.YangStatusType;
29 +import org.onosproject.yangutils.datamodel.YangContainer;
30 +import org.onosproject.yangutils.datamodel.YangList;
31 +import org.onosproject.yangutils.parser.exceptions.ParserException;
32 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
33 +
34 +import java.io.IOException;
35 +import java.util.ListIterator;
36 +
37 +import static org.hamcrest.MatcherAssert.assertThat;
38 +import static org.hamcrest.core.Is.is;
39 +
40 +/**
41 + * Test cases for testing leaf listener.
42 + */
43 +public class LeafListenerTest {
44 +
45 + @Rule
46 + public ExpectedException thrown = ExpectedException.none();
47 +
48 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
49 +
50 + /**
51 + * Checks all the values of leaf sub-statements are set
52 + * correctly.
53 + */
54 + @Test
55 + public void processLeafSubStatements() throws IOException, ParserException {
56 +
57 + YangNode node = manager.getDataModel("src/test/resources/LeafSubStatements.yang");
58 +
59 + // Check whether the data model tree returned is of type module.
60 + assertThat((node instanceof YangModule), is(true));
61 +
62 + // Check whether the node type is set properly to module.
63 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
64 +
65 + // Check whether the module name is set correctly.
66 + YangModule yangNode = (YangModule) node;
67 + assertThat(yangNode.getName(), is("Test"));
68 +
69 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
70 + YangLeaf leafInfo = leafIterator.next();
71 +
72 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
73 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
74 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
75 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
76 + assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
77 + assertThat(leafInfo.isConfig(), is(true));
78 + assertThat(leafInfo.isMandatory(), is(true));
79 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
80 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
81 + }
82 +
83 + /**
84 + * Checks whether exception is thrown when leaf identifier
85 + * starts with digit.
86 + */
87 + @Test
88 + public void processLeafInvalidIdentifier() throws IOException, ParserException {
89 + thrown.expect(ParserException.class);
90 + thrown.expectMessage("mismatched input '1invalid-interval' expecting IDENTIFIER");
91 + YangNode node = manager.getDataModel("src/test/resources/LeafInvalidIdentifier.yang");
92 + }
93 +
94 + /**
95 + * Checks whether exception is thrown when leaf keyword
96 + * is incorrect.
97 + */
98 + @Test
99 + public void processLeafInvalidStatement() throws IOException, ParserException {
100 + thrown.expect(ParserException.class);
101 + thrown.expectMessage("mismatched input 'leafs' expecting {'augment', 'choice', 'contact', 'container'," +
102 + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," +
103 + " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
104 + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
105 + YangNode node = manager.getDataModel("src/test/resources/LeafInvalidStatement.yang");
106 + }
107 +
108 + /**
109 + * Checks whether exception is thrown when leaf keyword
110 + * without Left brace as per grammar.
111 + */
112 + @Test
113 + public void processLeafWithoutLeftBrace() throws IOException, ParserException {
114 + thrown.expect(ParserException.class);
115 + thrown.expectMessage("missing '{' at 'type'");
116 + YangNode node = manager.getDataModel("src/test/resources/LeafWithoutLeftBrace.yang");
117 + }
118 +
119 + /**
120 + * Checks whether exception is thrown when config statement
121 + * cardinality is not as per grammar.
122 + */
123 + @Test
124 + public void processLeafConfigInvalidCardinality() throws IOException, ParserException {
125 + thrown.expect(ParserException.class);
126 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in config before processing.");
127 + YangNode node = manager.getDataModel("src/test/resources/LeafConfigInvalidCardinality.yang");
128 + }
129 +
130 + /**
131 + * Checks whether exception is thrown when mandatory statement
132 + * cardinality is not as per grammar.
133 + */
134 + @Test
135 + public void processLeafMandatoryInvalidCardinality() throws IOException, ParserException {
136 + thrown.expect(ParserException.class);
137 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in mandatory before processing.");
138 + YangNode node = manager.getDataModel("src/test/resources/LeafMandatoryInvalidCardinality.yang");
139 + }
140 +
141 + /**
142 + * Checks leaf statement as sub-statement of container.
143 + */
144 + @Test
145 + public void processContainerSubStatementLeaf() throws IOException, ParserException {
146 +
147 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementLeaf.yang");
148 +
149 + // Check whether the data model tree returned is of type module.
150 + assertThat((node instanceof YangModule), is(true));
151 +
152 + // Check whether the node type is set properly to module.
153 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
154 +
155 + // Check whether the module name is set correctly.
156 + YangModule yangNode = (YangModule) node;
157 + assertThat(yangNode.getName(), is("Test"));
158 +
159 + //Check whether the container is child of module.
160 + YangContainer container = (YangContainer) yangNode.getChild();
161 + assertThat(container.getName(), is("valid"));
162 +
163 + // Check whether leaf properties as set correctly.
164 + ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
165 + YangLeaf leafInfo = leafIterator.next();
166 +
167 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
168 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
169 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
170 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
171 + assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
172 + assertThat(leafInfo.isConfig(), is(true));
173 + assertThat(leafInfo.isMandatory(), is(true));
174 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
175 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
176 + }
177 +
178 + /**
179 + * Checks leaf statement as sub-statement of list.
180 + */
181 + @Test
182 + public void processListSubStatementLeaf() throws IOException, ParserException {
183 +
184 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementLeaf.yang");
185 +
186 + assertThat((node instanceof YangModule), is(true));
187 +
188 + // Check whether the node type is set properly to module.
189 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
190 +
191 + // Check whether the module name is set correctly.
192 + YangModule yangNode = (YangModule) node;
193 + assertThat(yangNode.getName(), is("Test"));
194 +
195 + // Check whether the list is child of module
196 + YangList yangList = (YangList) yangNode.getChild();
197 + assertThat(yangList.getName(), is("valid"));
198 +
199 + // Check whether leaf properties as set correctly.
200 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
201 + YangLeaf leafInfo = leafIterator.next();
202 +
203 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
204 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
205 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
206 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
207 + assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
208 + assertThat(leafInfo.isConfig(), is(true));
209 + assertThat(leafInfo.isMandatory(), is(true));
210 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
211 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
212 + }
213 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeaf;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangDataTypes;
28 +import org.onosproject.yangutils.datamodel.YangStatusType;
29 +import org.onosproject.yangutils.datamodel.YangContainer;
30 +import org.onosproject.yangutils.datamodel.YangList;
31 +import org.onosproject.yangutils.parser.exceptions.ParserException;
32 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
33 +
34 +import java.io.IOException;
35 +import java.util.ListIterator;
36 +
37 +import static org.hamcrest.MatcherAssert.assertThat;
38 +import static org.hamcrest.core.Is.is;
39 +
40 +/**
41 + * Test cases for testing list listener.
42 + */
43 +public class ListListenerTest {
44 +
45 + @Rule
46 + public ExpectedException thrown = ExpectedException.none();
47 +
48 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
49 +
50 + /**
51 + * Checks list statement as sub-statement of module.
52 + */
53 + @Test
54 + public void processModuleSubStatementList() throws IOException, ParserException {
55 +
56 + YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementList.yang");
57 +
58 + assertThat((node instanceof YangModule), is(true));
59 +
60 + // Check whether the node type is set properly to module.
61 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
62 +
63 + // Check whether the module name is set correctly.
64 + YangModule yangNode = (YangModule) node;
65 + assertThat(yangNode.getName(), is("Test"));
66 +
67 + // Check whether the list is child of module
68 + YangList yangList = (YangList) yangNode.getChild();
69 + assertThat(yangList.getName(), is("valid"));
70 +
71 + ListIterator<String> keyList = yangList.getKeyList().listIterator();
72 + assertThat(keyList.next(), is("invalid"));
73 + }
74 +
75 + /**
76 + * Checks list statement as sub-statement of container.
77 + */
78 + @Test
79 + public void processContainerSubStatementList() throws IOException, ParserException {
80 +
81 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementList.yang");
82 +
83 + assertThat((node instanceof YangModule), is(true));
84 +
85 + // Check whether the node type is set properly to module.
86 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
87 +
88 + // Check whether the module name is set correctly.
89 + YangModule yangNode = (YangModule) node;
90 + assertThat(yangNode.getName(), is("Test"));
91 +
92 + // Check whether the container is child of module
93 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
94 + assertThat(yangContainer.getName(), is("ospf"));
95 +
96 + // Check whether the list is child of container
97 + YangList yangList = (YangList) yangContainer.getChild();
98 + assertThat(yangList.getName(), is("valid"));
99 + assertThat(yangList.getKeyList().contains("invalid"), is(true));
100 + }
101 +
102 + /**
103 + * Checks list statement as sub-statement of list.
104 + */
105 + @Test
106 + public void processListSubStatementList() throws IOException, ParserException {
107 +
108 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementList.yang");
109 +
110 + assertThat((node instanceof YangModule), is(true));
111 +
112 + // Check whether the node type is set properly to module.
113 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
114 +
115 + // Check whether the module name is set correctly.
116 + YangModule yangNode = (YangModule) node;
117 + assertThat(yangNode.getName(), is("Test"));
118 +
119 + // Check whether the list is child of module
120 + YangList yangList1 = (YangList) yangNode.getChild();
121 + assertThat(yangList1.getName(), is("ospf"));
122 + assertThat(yangList1.getKeyList().contains("process-id"), is(true));
123 +
124 + // Check whether the list is child of list
125 + YangList yangList = (YangList) yangList1.getChild();
126 + assertThat(yangList.getName(), is("valid"));
127 + assertThat(yangList.getKeyList().contains("invalid"), is(true));
128 + }
129 +
130 + /**
131 + * Checks list with all its sub-statements.
132 + */
133 + @Test
134 + public void processListSubStatements() throws IOException, ParserException {
135 +
136 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatements.yang");
137 +
138 + assertThat((node instanceof YangModule), is(true));
139 +
140 + // Check whether the node type is set properly to module.
141 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
142 +
143 + // Check whether the module name is set correctly.
144 + YangModule yangNode = (YangModule) node;
145 + assertThat(yangNode.getName(), is("Test"));
146 +
147 + // Check whether the list is child of module
148 + YangList yangList = (YangList) yangNode.getChild();
149 +
150 + // Check whether list properties as set correctly.
151 + assertThat(yangList.getName(), is("ospf"));
152 + assertThat(yangList.getKeyList().contains("process-id"), is(true));
153 +
154 + assertThat(yangList.isConfig(), is(true));
155 + assertThat(yangList.getMaxElelements(), is(10));
156 + assertThat(yangList.getMinElements(), is(3));
157 + assertThat(yangList.getDescription(), is("\"list description\""));
158 + assertThat(yangList.getStatus(), is(YangStatusType.CURRENT));
159 + assertThat(yangList.getReference(), is("\"list reference\""));
160 +
161 + // Check whether leaf properties as set correctly.
162 + ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
163 + YangLeaf leafInfo = leafIterator.next();
164 +
165 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
166 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
167 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
168 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
169 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
170 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
171 + }
172 +
173 + /**
174 + * Checks cardinality of sub-statements of list.
175 + */
176 + @Test
177 + public void processListSubStatementsCardinality() throws IOException, ParserException {
178 + thrown.expect(ParserException.class);
179 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in reference before processing.");
180 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementsCardinality.yang");
181 + }
182 +
183 + /**
184 + * Checks list statement without child.
185 + */
186 + @Test
187 + public void processListStatementWithoutChild() throws IOException, ParserException {
188 + thrown.expect(ParserException.class);
189 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in list before processing.");
190 + YangNode node = manager.getDataModel("src/test/resources/ListStatementWithoutChild.yang");
191 + }
192 +
193 + /**
194 + * Checks list as root node.
195 + */
196 + @Test
197 + public void processListAsRootNode() throws IOException, ParserException {
198 + thrown.expect(ParserException.class);
199 + thrown.expectMessage("no viable alternative at input 'list'");
200 + YangNode node = manager.getDataModel("src/test/resources/ListAsRootNode.yang");
201 + }
202 +
203 + /**
204 + * Checks invalid identifier for list statement.
205 + */
206 + @Test
207 + public void processListInvalidIdentifier() throws IOException, ParserException {
208 + thrown.expect(ParserException.class);
209 + thrown.expectMessage("mismatched input '1valid' expecting IDENTIFIER");
210 + YangNode node = manager.getDataModel("src/test/resources/ListInvalidIdentifier.yang");
211 + }
212 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +import org.junit.rules.ExpectedException;
22 +import org.onosproject.yangutils.datamodel.YangNode;
23 +import org.onosproject.yangutils.datamodel.YangNodeType;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangLeaf;
26 +import org.onosproject.yangutils.parser.exceptions.ParserException;
27 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
28 +
29 +import java.io.IOException;
30 +import java.util.ListIterator;
31 +
32 +import static org.hamcrest.MatcherAssert.assertThat;
33 +import static org.hamcrest.core.Is.is;
34 +
35 +/**
36 + * Test case for mandatory listener.
37 + */
38 +public class MandatoryListenerTest {
39 +
40 + @Rule
41 + public ExpectedException thrown = ExpectedException.none();
42 +
43 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
44 +
45 + /**
46 + * Checks valid mandatory with value true statement.
47 + */
48 + @Test
49 + public void processMandatoryTrue() throws IOException, ParserException {
50 +
51 + YangNode node = manager.getDataModel("src/test/resources/MandatoryTrue.yang");
52 +
53 + // Check whether the data model tree returned is of type module.
54 + assertThat((node instanceof YangModule), is(true));
55 +
56 + // Check whether the node type is set properly to module.
57 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
58 +
59 + // Check whether the module name is set correctly.
60 + YangModule yangNode = (YangModule) node;
61 + assertThat(yangNode.getName(), is("Test"));
62 +
63 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
64 + YangLeaf leafInfo = leafIterator.next();
65 +
66 + // Check whether the mandatory value is set correctly.
67 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
68 + assertThat(leafInfo.isMandatory(), is(true));
69 + }
70 +
71 + /**
72 + * Checks valid mandatory with value false statement.
73 + */
74 + @Test
75 + public void processMandatoryFalse() throws IOException, ParserException {
76 +
77 + YangNode node = manager.getDataModel("src/test/resources/MandatoryFalse.yang");
78 +
79 + // Check whether the data model tree returned is of type module.
80 + assertThat((node instanceof YangModule), is(true));
81 +
82 + // Check whether the node type is set properly to module.
83 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
84 +
85 + // Check whether the module name is set correctly.
86 + YangModule yangNode = (YangModule) node;
87 + assertThat(yangNode.getName(), is("Test"));
88 +
89 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
90 + YangLeaf leafInfo = leafIterator.next();
91 +
92 + // Check whether the mandatory value is set correctly.
93 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
94 + assertThat(leafInfo.isMandatory(), is(false));
95 + }
96 +
97 + /**
98 + * Checks default value of mandatory statement.
99 + */
100 + @Test
101 + public void processMandatoryDefaultValue() throws IOException, ParserException {
102 +
103 + YangNode node = manager.getDataModel("src/test/resources/MandatoryDefaultValue.yang");
104 +
105 + // Check whether the data model tree returned is of type module.
106 + assertThat((node instanceof YangModule), is(true));
107 +
108 + // Check whether the node type is set properly to module.
109 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
110 +
111 + // Check whether the module name is set correctly.
112 + YangModule yangNode = (YangModule) node;
113 + assertThat(yangNode.getName(), is("Test"));
114 +
115 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
116 + YangLeaf leafInfo = leafIterator.next();
117 +
118 + // Check whether the mandatory value is set correctly.
119 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
120 + assertThat(leafInfo.isMandatory(), is(false));
121 + }
122 +
123 + /**
124 + * Checks invalid of mandatory statement and expects exception.
125 + */
126 + @Test
127 + public void processMandatoryEmptyStatement() throws IOException, ParserException {
128 + thrown.expect(ParserException.class);
129 + thrown.expectMessage("missing {'false', 'true'} at ';'");
130 + YangNode node = manager.getDataModel("src/test/resources/MandatoryEmptyStatement.yang");
131 + }
132 +
133 + /**
134 + * Checks invalid mandatory statement(without statement end) and expects exception.
135 + */
136 + @Test
137 + public void processMandatoryWithoutStatementEnd() throws IOException, ParserException {
138 + thrown.expect(ParserException.class);
139 + thrown.expectMessage("missing ';' at '}'");
140 + YangNode node = manager.getDataModel("src/test/resources/MandatoryWithoutStatementEnd.yang");
141 + }
142 +
143 + /**
144 + * Checks mandatory statement as sub-statement of module and expects exception.
145 + */
146 + @Test
147 + public void processModuleSubStatementMandatory() throws IOException, ParserException {
148 + thrown.expect(ParserException.class);
149 + thrown.expectMessage("mismatched input 'mandatory' expecting {'augment', 'choice', 'contact', 'container'," +
150 + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," +
151 + " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
152 + " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
153 + YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementMandatory.yang");
154 + }
155 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeafList;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangList;
28 +import org.onosproject.yangutils.parser.exceptions.ParserException;
29 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
30 +
31 +import java.io.IOException;
32 +import java.util.ListIterator;
33 +
34 +import static org.hamcrest.MatcherAssert.assertThat;
35 +import static org.hamcrest.core.Is.is;
36 +
37 +/**
38 + * Test cases for testing max-elements listener.
39 + */
40 +public class MaxElementsListenerTest {
41 +
42 + @Rule
43 + public ExpectedException thrown = ExpectedException.none();
44 +
45 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
46 +
47 + /**
48 + * Checks max-elements as sub-statements of leaf-list.
49 + */
50 + @Test
51 + public void processLeafListSubStatementMaxElements() throws IOException, ParserException {
52 +
53 + YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatementMaxElements.yang");
54 +
55 + // Check whether the data model tree returned is of type module.
56 + assertThat((node instanceof YangModule), is(true));
57 +
58 + // Check whether the node type is set properly to module.
59 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
60 +
61 + // Check whether the module name is set correctly.
62 + YangModule yangNode = (YangModule) node;
63 + assertThat(yangNode.getName(), is("Test"));
64 +
65 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
66 + YangLeafList leafListInfo = leafListIterator.next();
67 +
68 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
69 + assertThat(leafListInfo.getMaxElelements(), is(3));
70 + }
71 +
72 + /**
73 + * Checks max-elements as sub-statements of list.
74 + */
75 + @Test
76 + public void processListSubStatementMaxElements() throws IOException, ParserException {
77 +
78 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementMaxElements.yang");
79 +
80 + assertThat((node instanceof YangModule), is(true));
81 +
82 + // Check whether the node type is set properly to module.
83 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
84 +
85 + // Check whether the module name is set correctly.
86 + YangModule yangNode = (YangModule) node;
87 + assertThat(yangNode.getName(), is("Test"));
88 +
89 + // Check whether the list is child of module
90 + YangList yangList = (YangList) yangNode.getChild();
91 + assertThat(yangList.getName(), is("valid"));
92 + assertThat(yangList.getMaxElelements(), is(3));
93 + }
94 +
95 + /**
96 + * Checks whether exception is thrown when invalid max-elements keyword
97 + * is given as input.
98 + */
99 + @Test
100 + public void processMaxElementsInvalidStatement() throws IOException, ParserException {
101 + thrown.expect(ParserException.class);
102 + thrown.expectMessage("extraneous input 'max-element' expecting {'config', 'description', 'if-feature'," +
103 + " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units', " +
104 + "'when', '}'}");
105 + YangNode node = manager.getDataModel("src/test/resources/MaxElementsInvalidStatement.yang");
106 + }
107 +
108 + /**
109 + * Checks whether exception is thrown when max-elements statement without statement
110 + * end is given as input.
111 + */
112 + @Test
113 + public void processMaxElementsWithoutStatementEnd() throws IOException, ParserException {
114 + thrown.expect(ParserException.class);
115 + thrown.expectMessage("missing ';' at 'description'");
116 + YangNode node = manager.getDataModel("src/test/resources/MaxElementsWithoutStatementEnd.yang");
117 + }
118 +
119 + /**
120 + * Checks whether exception is thrown when max-elements cardinality is not
121 + * as per the grammar.
122 + */
123 + @Test
124 + public void processMaxElementsCardinality() throws IOException, ParserException {
125 + thrown.expect(ParserException.class);
126 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in max-elements before processing.");
127 + YangNode node = manager.getDataModel("src/test/resources/MaxElementsCardinality.yang");
128 + }
129 +
130 + /**
131 + * Checks unbounded value of max-elements statement.
132 + */
133 + @Test
134 + public void processMaxElementsUnbounded() throws IOException, ParserException {
135 +
136 + YangNode node = manager.getDataModel("src/test/resources/MaxElementsUnbounded.yang");
137 +
138 + // Check whether the data model tree returned is of type module.
139 + assertThat((node instanceof YangModule), is(true));
140 +
141 + // Check whether the node type is set properly to module.
142 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
143 +
144 + // Check whether the module name is set correctly.
145 + YangModule yangNode = (YangModule) node;
146 + assertThat(yangNode.getName(), is("Test"));
147 +
148 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
149 + YangLeafList leafListInfo = leafListIterator.next();
150 +
151 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
152 + assertThat(leafListInfo.getMaxElelements(), is(2147483647));
153 + }
154 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeafList;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangList;
28 +import org.onosproject.yangutils.parser.exceptions.ParserException;
29 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
30 +
31 +import java.io.IOException;
32 +import java.util.ListIterator;
33 +
34 +import static org.hamcrest.MatcherAssert.assertThat;
35 +import static org.hamcrest.core.Is.is;
36 +
37 +/**
38 + * Test cases for testing min-elements listener.
39 + */
40 +public class MinElementsListenerTest {
41 +
42 + @Rule
43 + public ExpectedException thrown = ExpectedException.none();
44 +
45 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
46 +
47 + /**
48 + * Checks min-elements as sub-statements of leaf-list.
49 + */
50 + @Test
51 + public void processLeafListSubStatementMinElements() throws IOException, ParserException {
52 +
53 + YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatementMinElements.yang");
54 +
55 + // Check whether the data model tree returned is of type module.
56 + assertThat((node instanceof YangModule), is(true));
57 +
58 + // Check whether the node type is set properly to module.
59 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
60 +
61 + // Check whether the module name is set correctly.
62 + YangModule yangNode = (YangModule) node;
63 + assertThat(yangNode.getName(), is("Test"));
64 +
65 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
66 + YangLeafList leafListInfo = leafListIterator.next();
67 +
68 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
69 + assertThat(leafListInfo.getMinElements(), is(3));
70 + }
71 +
72 + /**
73 + * Checks min-elements as sub-statements of list.
74 + */
75 + @Test
76 + public void processListSubStatementMinElements() throws IOException, ParserException {
77 +
78 + YangNode node = manager.getDataModel("src/test/resources/ListSubStatementMinElements.yang");
79 +
80 + assertThat((node instanceof YangModule), is(true));
81 +
82 + // Check whether the node type is set properly to module.
83 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
84 +
85 + // Check whether the module name is set correctly.
86 + YangModule yangNode = (YangModule) node;
87 + assertThat(yangNode.getName(), is("Test"));
88 +
89 + // Check whether the list is child of module
90 + YangList yangList = (YangList) yangNode.getChild();
91 + assertThat(yangList.getName(), is("valid"));
92 + assertThat(yangList.getMinElements(), is(3));
93 + }
94 +
95 + /**
96 + * Checks whether exception is thrown when invalid min-elements keyword
97 + * is given as input.
98 + */
99 + @Test
100 + public void processMinElementsInvalidKeyword() throws IOException, ParserException {
101 + thrown.expect(ParserException.class);
102 + thrown.expectMessage("extraneous input 'min-element' expecting {'config', 'description', 'if-feature'," +
103 + " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units'," +
104 + " 'when', '}'}");
105 + YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidKeyword.yang");
106 + }
107 +
108 + /**
109 + * Checks whether exception is thrown when invalid min-elements value
110 + * is given as input.
111 + */
112 + @Test
113 + public void processMinElementsInvalidValue() throws IOException, ParserException {
114 + thrown.expect(ParserException.class);
115 + thrown.expectMessage("mismatched input 'asd' expecting INTEGER");
116 + YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidValue.yang");
117 + }
118 +
119 + /**
120 + * Checks whether exception is thrown when min-elements statement without statement
121 + * end is given as input.
122 + */
123 + @Test
124 + public void processMinElementsWithoutStatementEnd() throws IOException, ParserException {
125 + thrown.expect(ParserException.class);
126 + thrown.expectMessage("missing ';' at 'description'");
127 + YangNode node = manager.getDataModel("src/test/resources/MinElementsWithoutStatementEnd.yang");
128 + }
129 +
130 + /**
131 + * Checks whether exception is thrown when min-elements cardinality is not
132 + * as per the grammar.
133 + */
134 + @Test
135 + public void processMinElementsInvalidCardinality() throws IOException, ParserException {
136 + thrown.expect(ParserException.class);
137 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in" +
138 + " min-elements before processing.");
139 + YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidCardinality.yang");
140 + }
141 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangModule;
24 +import org.onosproject.yangutils.datamodel.YangNode;
25 +import org.onosproject.yangutils.datamodel.YangNodeType;
26 +import org.onosproject.yangutils.datamodel.YangContainer;
27 +import org.onosproject.yangutils.parser.exceptions.ParserException;
28 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
29 +
30 +import java.io.IOException;
31 +
32 +import static org.hamcrest.MatcherAssert.assertThat;
33 +import static org.hamcrest.Matchers.is;
34 +import static org.hamcrest.Matchers.nullValue;
35 +
36 +/**
37 + * Test cases for presence listener.
38 + */
39 +public class PresenceListenerTest {
40 +
41 + @Rule
42 + public ExpectedException thrown = ExpectedException.none();
43 +
44 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
45 +
46 + /**
47 + * Checks presence statement as sub-statement of container.
48 + */
49 + @Test
50 + public void processContainerSubStatementPresence() throws IOException, ParserException {
51 +
52 + YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementPresence.yang");
53 +
54 + assertThat((node instanceof YangModule), is(true));
55 +
56 + // Check whether the node type is set properly to module.
57 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
58 +
59 + // Check whether the module name is set correctly.
60 + YangModule yangNode = (YangModule) node;
61 + assertThat(yangNode.getName(), is("Test"));
62 +
63 + // Check whether the list is child of module
64 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
65 + assertThat(yangContainer.getName(), is("valid"));
66 + assertThat(yangContainer.getPresence(), is("\"invalid\""));
67 + }
68 +
69 + /**
70 + * checks default value of presence statement.
71 + */
72 + @Test
73 + public void processPresenceDefaultValue() throws IOException, ParserException {
74 +
75 + YangNode node = manager.getDataModel("src/test/resources/PresenceDefaultValue.yang");
76 +
77 + assertThat((node instanceof YangModule), is(true));
78 +
79 + // Check whether the node type is set properly to module.
80 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
81 +
82 + // Check whether the module name is set correctly.
83 + YangModule yangNode = (YangModule) node;
84 + assertThat(yangNode.getName(), is("Test"));
85 +
86 + // Check whether the list is child of module
87 + YangContainer yangContainer = (YangContainer) yangNode.getChild();
88 + assertThat(yangContainer.getName(), is("valid"));
89 + assertThat(yangContainer.getPresence(), is(nullValue()));
90 + }
91 +
92 + /**
93 + * Checks presence statement without statement end.
94 + */
95 + @Test
96 + public void processPresenceWithoutStatementEnd() throws IOException, ParserException {
97 + thrown.expect(ParserException.class);
98 + thrown.expectMessage("mismatched input 'leaf' expecting {';', '+'}");
99 + YangNode node = manager.getDataModel("src/test/resources/PresenceWithoutStatementEnd.yang");
100 + }
101 +}
...\ No newline at end of file ...\ No newline at end of file
1 +package org.onosproject.yangutils.parser.impl.listeners;
2 +
3 +import org.junit.Test;
4 +import org.onosproject.yangutils.datamodel.YangLeaf;
5 +import org.onosproject.yangutils.datamodel.YangModule;
6 +import org.onosproject.yangutils.datamodel.YangNode;
7 +import org.onosproject.yangutils.datamodel.YangNodeType;
8 +import org.onosproject.yangutils.datamodel.YangDataTypes;
9 +import org.onosproject.yangutils.datamodel.YangLeafList;
10 +import org.onosproject.yangutils.parser.exceptions.ParserException;
11 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
12 +
13 +import java.io.IOException;
14 +import java.util.ListIterator;
15 +
16 +import static org.hamcrest.MatcherAssert.assertThat;
17 +import static org.hamcrest.core.Is.is;
18 +
19 +/**
20 + * Test case for type listener.
21 + */
22 +public class TypeListenerTest {
23 +
24 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
25 +
26 + /**
27 + * Checks derived statement without contraints.
28 + */
29 + @Test
30 + public void processDerivedTypeStatement() throws IOException, ParserException {
31 +
32 + YangNode node = manager.getDataModel("src/test/resources/DerivedTypeStatement.yang");
33 +
34 + // Check whether the data model tree returned is of type module.
35 + assertThat((node instanceof YangModule), is(true));
36 +
37 + // Check whether the node type is set properly to module.
38 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
39 +
40 + // Check whether the module name is set correctly.
41 + YangModule yangNode = (YangModule) node;
42 + assertThat(yangNode.getName(), is("Test"));
43 +
44 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
45 + YangLeaf leafInfo = leafIterator.next();
46 +
47 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
48 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"hello\""));
49 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
50 + }
51 +
52 + /**
53 + * Checks valid yang data type.
54 + */
55 + @Test
56 + public void processIntegerTypeStatement() throws IOException, ParserException {
57 +
58 + YangNode node = manager.getDataModel("src/test/resources/IntegerTypeStatement.yang");
59 +
60 + // Check whether the data model tree returned is of type module.
61 + assertThat((node instanceof YangModule), is(true));
62 +
63 + // Check whether the node type is set properly to module.
64 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
65 +
66 + // Check whether the module name is set correctly.
67 + YangModule yangNode = (YangModule) node;
68 + assertThat(yangNode.getName(), is("Test"));
69 +
70 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
71 + YangLeaf leafInfo = leafIterator.next();
72 +
73 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
74 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
75 + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
76 + }
77 +
78 + /**
79 + * Checks type for leaf-list.
80 + */
81 + @Test
82 + public void processLeafListSubStatementType() throws IOException, ParserException {
83 +
84 + YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatementType.yang");
85 +
86 + // Check whether the data model tree returned is of type module.
87 + assertThat((node instanceof YangModule), is(true));
88 +
89 + // Check whether the node type is set properly to module.
90 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
91 +
92 + // Check whether the module name is set correctly.
93 + YangModule yangNode = (YangModule) node;
94 + assertThat(yangNode.getName(), is("Test"));
95 +
96 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
97 + YangLeafList leafListInfo = leafListIterator.next();
98 +
99 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
100 + assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
101 + assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
102 + }
103 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.junit.Rule;
20 +import org.junit.Test;
21 +
22 +import org.junit.rules.ExpectedException;
23 +import org.onosproject.yangutils.datamodel.YangLeaf;
24 +import org.onosproject.yangutils.datamodel.YangModule;
25 +import org.onosproject.yangutils.datamodel.YangNode;
26 +import org.onosproject.yangutils.datamodel.YangNodeType;
27 +import org.onosproject.yangutils.datamodel.YangStatusType;
28 +import org.onosproject.yangutils.datamodel.YangLeafList;
29 +import org.onosproject.yangutils.parser.exceptions.ParserException;
30 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31 +
32 +import java.io.IOException;
33 +import java.util.ListIterator;
34 +
35 +import static org.hamcrest.MatcherAssert.assertThat;
36 +import static org.hamcrest.core.Is.is;
37 +import static org.hamcrest.Matchers.nullValue;
38 +
39 +/**
40 + * Test cases for units listener.
41 + */
42 +public class UnitsListenerTest {
43 +
44 + @Rule
45 + public ExpectedException thrown = ExpectedException.none();
46 +
47 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
48 +
49 + /**
50 + * Checks valid units statement.
51 + */
52 + @Test
53 + public void processUnitsStatement() throws IOException, ParserException {
54 +
55 + YangNode node = manager.getDataModel("src/test/resources/UnitsStatement.yang");
56 +
57 + // Check whether the data model tree returned is of type module.
58 + assertThat((node instanceof YangModule), is(true));
59 +
60 + // Check whether the node type is set properly to module.
61 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
62 +
63 + // Check whether the module name is set correctly.
64 + YangModule yangNode = (YangModule) node;
65 + assertThat(yangNode.getName(), is("Test"));
66 +
67 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
68 + YangLeaf leafInfo = leafIterator.next();
69 +
70 + // Check whether units value is set correctly.
71 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
72 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
73 + }
74 +
75 + /**
76 + * Checks invalid units statement as sub-statement of module.
77 + */
78 + @Test
79 + public void processModuleSubStatementUnits() throws IOException, ParserException {
80 + thrown.expect(ParserException.class);
81 + thrown.expectMessage("mismatched input 'type' expecting {'augment', 'choice', 'contact', 'container', " +
82 + "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', " +
83 + "'include', 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', " +
84 + "'prefix', 'reference', 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
85 + YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementUnits.yang");
86 + }
87 +
88 + /**
89 + * Checks invalid units statement(without statement end).
90 + */
91 + @Test
92 + public void processUnitsWithoutStatementEnd() throws IOException, ParserException {
93 + thrown.expect(ParserException.class);
94 + thrown.expectMessage("mismatched input '}' expecting {';', '+'}");
95 + YangNode node = manager.getDataModel("src/test/resources/UnitsWithoutStatementEnd.yang");
96 + }
97 +
98 + /**
99 + * Checks order of units statement in leaf.
100 + */
101 + @Test
102 + public void processUnitsStatementOrder() throws IOException, ParserException {
103 +
104 + YangNode node = manager.getDataModel("src/test/resources/UnitsStatementOrder.yang");
105 +
106 + // Check whether the data model tree returned is of type module.
107 + assertThat((node instanceof YangModule), is(true));
108 +
109 + // Check whether the node type is set properly to module.
110 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
111 +
112 + // Check whether the module name is set correctly.
113 + YangModule yangNode = (YangModule) node;
114 + assertThat(yangNode.getName(), is("Test"));
115 +
116 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
117 + YangLeaf leafInfo = leafIterator.next();
118 +
119 + // Check whether leaf properties is set correctly.
120 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
121 + assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
122 + assertThat(leafInfo.getUnits(), is("\"seconds\""));
123 + assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
124 + assertThat(leafInfo.isConfig(), is(true));
125 + assertThat(leafInfo.isMandatory(), is(true));
126 + assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT));
127 + assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
128 + }
129 +
130 + /**
131 + * Checks the default value of unit statement.
132 + */
133 + @Test
134 + public void processUnitsDefaultValue() throws IOException, ParserException {
135 +
136 + YangNode node = manager.getDataModel("src/test/resources/UnitsDefaultValue.yang");
137 +
138 + // Check whether the data model tree returned is of type module.
139 + assertThat((node instanceof YangModule), is(true));
140 +
141 + // Check whether the node type is set properly to module.
142 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
143 +
144 + // Check whether the module name is set correctly.
145 + YangModule yangNode = (YangModule) node;
146 + assertThat(yangNode.getName(), is("Test"));
147 +
148 + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
149 + YangLeaf leafInfo = leafIterator.next();
150 +
151 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
152 + assertThat(leafInfo.getUnits(), is(nullValue()));
153 + }
154 +
155 + /**
156 + * Checks invalid occurance of units statement as sub-statement of leaf.
157 + */
158 + @Test
159 + public void processUnitsStatementCardinality() throws IOException, ParserException {
160 + thrown.expect(ParserException.class);
161 + thrown.expectMessage("Internal parser error detected: Invalid cardinality in units before processing.");
162 + YangNode node = manager.getDataModel("src/test/resources/UnitsStatementCardinality.yang");
163 + }
164 +
165 + /**
166 + * Checks valid units statement as sub-statement of leaf-list.
167 + */
168 + @Test
169 + public void processLeafListSubStatementUnits() throws IOException, ParserException {
170 +
171 + YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatementUnits.yang");
172 +
173 + // Check whether the data model tree returned is of type module.
174 + assertThat((node instanceof YangModule), is(true));
175 +
176 + // Check whether the node type is set properly to module.
177 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
178 +
179 + // Check whether the module name is set correctly.
180 + YangModule yangNode = (YangModule) node;
181 + assertThat(yangNode.getName(), is("Test"));
182 +
183 + ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
184 + YangLeafList leafListInfo = leafListIterator.next();
185 +
186 + // Check whether units value is set correctly.
187 + assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
188 + assertThat(leafListInfo.getUnits(), is("\"seconds\""));
189 + }
190 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + config ;
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config false;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + config invalid;
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + config false
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container 1valid {
6 + reference "RFC 6020";
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +container valid {
2 + reference "RFC 6020";
3 + leaf invalid-interval {
4 + type "uint16";
5 + units "seconds";
6 + status current;
7 + reference "RFC 6020";
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + reference "RFC 6020";
7 + reference "RFC 6020";
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + status current;
12 + reference "RFC 6020";
13 + }
14 + }
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + config true;
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + description "Interval before a route is declared invalid";
11 + mandatory true;
12 + status current;
13 + reference "RFC 6020";
14 + }
15 + }
16 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container ospf {
6 + container valid {
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + }
14 + }
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + description "container description";
7 + config true;
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + description "Interval before a route is declared invalid";
12 + mandatory true;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
18 +
1 +
2 +module Test {
3 + yang-version 1;
4 + namespace http://huawei.com;
5 + prefix Ant;
6 + container valid {
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + description "Interval before a route is declared invalid";
11 + config true;
12 + mandatory true;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + leaf-list invalid-interval {
7 + type "uint16";
8 + units "seconds";
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + min-elements 1;
12 + max-elements unbounded;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container ospf {
6 + list valid {
7 + key "invalid";
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + status current;
12 + reference "RFC 6020";
13 + }
14 + }
15 + }
16 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + presence "invalid";
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + reference "container reference";
7 + config true;
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + description "Interval before a route is declared invalid";
12 + mandatory true;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + config true;
7 + status obsolete;
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + description "Interval before a route is declared invalid";
12 + mandatory true;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container ospf {
6 + presence "ospf logs";
7 + config true;
8 + description "container description";
9 + status current;
10 + reference "container reference";
11 + leaf invalid-interval {
12 + type "uint16";
13 + units "seconds";
14 + status current;
15 + reference "RFC 6020";
16 + }
17 + }
18 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "hello";
7 + }
8 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + description "";
6 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + description "Interval before a " + "route is declared invalid";
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + description "Interval before a " + "route is declared invalid"
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + }
8 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid"
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + config false;
11 + mandatory true;
12 + status current;
13 + reference "RFC 6020";
14 + }
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf 1invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leafs invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + config false;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list 1invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaflist invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + max-elements 3;
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + min-elements 3;
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + }
8 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + max-elements 3;
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + units "minutes";
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + status current;
11 + reference "RFC 6020";
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + mandatory false;
12 + status current;
13 + reference "RFC 6020";
14 + }
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +list valid {
2 + reference "RFC 6020";
3 + leaf invalid-interval {
4 + type "uint16";
5 + units "seconds";
6 + status current;
7 + reference "RFC 6020";
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list 1valid {
6 + key "invalid-interval";
7 + reference "RFC 6020";
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + status current;
12 + reference "RFC 6020";
13 + }
14 + }
15 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + reference "RFC 6020";
7 + }
8 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + config true;
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + description "Interval before a route is declared invalid";
12 + mandatory true;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list ospf {
6 + key "process-id";
7 + container interface {
8 + leaf invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + status current;
12 + reference "RFC 6020";
13 + }
14 + }
15 + }
16 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + description "list description";
8 + config true;
9 + leaf invalid-interval {
10 + type "uint16";
11 + units "seconds";
12 + description "Interval before a route is declared invalid";
13 + mandatory true;
14 + status current;
15 + reference "RFC 6020";
16 + }
17 + }
18 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + }
14 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + description "Interval before a route is declared invalid";
11 + config true;
12 + mandatory true;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +module Test {
3 + yang-version 1;
4 + namespace http://huawei.com;
5 + prefix Ant;
6 + list valid {
7 + key "invalid-interval";
8 + leaf-list invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + description "Interval before a route is declared invalid";
12 + config true;
13 + status current;
14 + reference "RFC 6020";
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list ospf {
6 + key "process-id";
7 + list valid {
8 + key "invalid";
9 + leaf invalid-interval {
10 + type "uint16";
11 + units "seconds";
12 + status current;
13 + reference "RFC 6020";
14 + }
15 + }
16 + }
17 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + max-elements 3;
8 + leaf-list invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + description "Interval before a route is declared invalid";
12 + }
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + min-elements 3;
8 + leaf-list invalid-interval {
9 + type "uint16";
10 + units "seconds";
11 + description "Interval before a route is declared invalid";
12 + }
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + reference "list reference";
8 + config true;
9 + leaf invalid-interval {
10 + type "uint16";
11 + units "seconds";
12 + description "Interval before a route is declared invalid";
13 + mandatory true;
14 + status current;
15 + reference "RFC 6020";
16 + }
17 + }
18 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + status current;
8 + config true;
9 + leaf invalid-interval {
10 + type "uint16";
11 + units "seconds";
12 + description "Interval before a route is declared invalid";
13 + mandatory true;
14 + status current;
15 + reference "RFC 6020";
16 + }
17 + }
18 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list ospf {
6 + key "process-id";
7 + config true;
8 + max-elements 10;
9 + min-elements 3;
10 + description "list description";
11 + status current;
12 + reference "list reference";
13 + leaf invalid-interval {
14 + type "uint16";
15 + units "seconds";
16 + status current;
17 + reference "RFC 6020";
18 + }
19 + }
20 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid-interval";
7 + reference "RFC 6020";
8 + reference "RFC 6020";
9 + leaf invalid-interval {
10 + type "uint16";
11 + units "seconds";
12 + status current;
13 + reference "RFC 6020";
14 + }
15 + }
16 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + }
8 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + mandatory ;
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + mandatory false;
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + description "Interval before a route is declared invalid";
9 + config true;
10 + mandatory true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf invalid-interval {
6 + type "uint16";
7 + mandatory false
8 + }
9 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + max-elements 4;
9 + max-elements 6;
10 + description "Interval before a route is declared invalid";
11 + config true;
12 + status current;
13 + reference "RFC 6020";
14 + }
15 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + max-element 3;
9 + description "Interval before a route is declared invalid;
10 + config true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + max-elements unbounded;
8 + }
9 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + max-elements 3
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + min-elements 4;
9 + min-elements 6;
10 + description "Interval before a route is declared invalid";
11 + config true;
12 + status current;
13 + reference "RFC 6020";
14 + }
15 +}
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + min-element 3;
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + min-elements asd;
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + leaf-list invalid-interval {
6 + type "uint16";
7 + units "seconds";
8 + min-elements 3
9 + description "Interval before a route is declared invalid";
10 + config true;
11 + status current;
12 + reference "RFC 6020";
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + config invalid;
6 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + leaf invalid-interval {
7 + type "uint16";
8 + units "seconds";
9 + status current;
10 + reference "RFC 6020";
11 + }
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + description "Interval before a route is declared invalid";
6 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "invalid";
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + mandatory false;
6 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + reference "RFC 6020";
6 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + status current;
6 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + type "uint16";
6 + units "seconds";
7 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + list valid {
6 + key "ospf isis";
7 + leaf ospf {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + leaf isis {
14 + type "uint16";
15 + units "seconds";
16 + status current;
17 + reference "RFC 6020";
18 + }
19 + }
20 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + leaf ospf {
7 + type "uint16";
8 + units "seconds";
9 + status current;
10 + reference "RFC 6020";
11 + }
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + presence "invalid"
7 + leaf invalid-interval {
8 + type "uint16";
9 + units "seconds";
10 + status current;
11 + reference "RFC 6020";
12 + }
13 + }
14 +}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.