Bharat saraswal
Committed by Gerrit Code Review

YANG augment's generated file name resolver implementation and UT fixes.

Change-Id: Ib960a15398a3b9f529f9ad28402d5bac539fb525
...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,6 +18,7 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.util.List; 19 import java.util.List;
20 20
21 +import org.onosproject.yangutils.datamodel.CollisionDetector;
21 import org.onosproject.yangutils.datamodel.YangAugment; 22 import org.onosproject.yangutils.datamodel.YangAugment;
22 import org.onosproject.yangutils.datamodel.YangModule; 23 import org.onosproject.yangutils.datamodel.YangModule;
23 import org.onosproject.yangutils.datamodel.YangNode; 24 import org.onosproject.yangutils.datamodel.YangNode;
...@@ -32,6 +33,9 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener; ...@@ -32,6 +33,9 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
32 33
33 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; 34 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
34 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangAugmentNode; 35 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangAugmentNode;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
38 +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; 39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
36 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 40 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 41 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
...@@ -45,7 +49,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.get ...@@ -45,7 +49,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.get
45 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 49 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
46 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; 50 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
47 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; 51 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
48 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
49 import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA; 52 import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA;
50 import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; 53 import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
51 import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA; 54 import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA;
...@@ -81,8 +84,6 @@ import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA; ...@@ -81,8 +84,6 @@ import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA;
81 */ 84 */
82 public final class AugmentListener { 85 public final class AugmentListener {
83 86
84 - private static final String AUGMENTED = "Augmented";
85 -
86 /** 87 /**
87 * Creates a new augment listener. 88 * Creates a new augment listener.
88 */ 89 */
...@@ -116,11 +117,11 @@ public final class AugmentListener { ...@@ -116,11 +117,11 @@ public final class AugmentListener {
116 117
117 Parsable curData = listener.getParsedDataStack().peek(); 118 Parsable curData = listener.getParsedDataStack().peek();
118 if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) { 119 if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) {
119 -
120 YangNode curNode = (YangNode) curData; 120 YangNode curNode = (YangNode) curData;
121 YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION); 121 YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION);
122 yangAugment.setTargetNode(targetNodes); 122 yangAugment.setTargetNode(targetNodes);
123 - yangAugment.setName(getValidNameForAugment(targetNodes)); 123 + yangAugment.setName(detectCollisionForTargetNode(curData, targetNodes, line, charPositionInLine, listener));
124 +
124 try { 125 try {
125 curNode.addChild(yangAugment); 126 curNode.addChild(yangAugment);
126 } catch (DataModelException e) { 127 } catch (DataModelException e) {
...@@ -161,7 +162,6 @@ public final class AugmentListener { ...@@ -161,7 +162,6 @@ public final class AugmentListener {
161 * @param ctx context object of the grammar rule 162 * @param ctx context object of the grammar rule
162 */ 163 */
163 private static void validateSubStatementsCardinality(GeneratedYangParser.AugmentStatementContext ctx) { 164 private static void validateSubStatementsCardinality(GeneratedYangParser.AugmentStatementContext ctx) {
164 -
165 validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, AUGMENT_DATA, ctx.augment().getText()); 165 validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, AUGMENT_DATA, ctx.augment().getText());
166 validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, AUGMENT_DATA, ctx.augment().getText()); 166 validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, AUGMENT_DATA, ctx.augment().getText());
167 validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText()); 167 validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText());
...@@ -171,21 +171,52 @@ public final class AugmentListener { ...@@ -171,21 +171,52 @@ public final class AugmentListener {
171 } 171 }
172 172
173 /** 173 /**
174 - * Returns a name identifier for augment. 174 + * Detects collision for java file generation of augment node when
175 + * it is updating the same target node in same parent multiple times.
176 + * Returns name for generated java file of augment node
175 * 177 *
176 - * @param targetNode list of target nodes 178 + * @param curData parsable data
177 - * @return name identifier 179 + * @param targetNodes list of target nodes
180 + * @param line line in YANG file
181 + * @param charPositionInLine char position in YANG file
182 + * @param listener tree walk listener
183 + * @return name for generated java file for augment node
178 */ 184 */
179 - private static String getValidNameForAugment(List<YangNodeIdentifier> targetNodes) { 185 + private static String detectCollisionForTargetNode(Parsable curData, List<YangNodeIdentifier> targetNodes, int line,
180 - String name = ""; 186 + int charPositionInLine, TreeWalkListener listener) {
187 +
188 + String curPrefix = null;
189 + if (curData instanceof YangModule) {
190 + curPrefix = ((YangModule) curData).getPrefix();
191 + } else if (curData instanceof YangSubModule) {
192 + curPrefix = ((YangSubModule) curData).getPrefix();
193 + }
181 YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1); 194 YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
195 + boolean isPrefix = isPrefixPresent(nodeId, curPrefix);
196 + String xpath = createValidNameForAugment(nodeId, isPrefix);
182 197
183 - if (nodeId.getPrefix() != null) { 198 + if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
184 - name = AUGMENTED + getCaptialCase(nodeId.getPrefix()) + getCaptialCase(nodeId.getName()); 199 + try {
185 - } else { 200 + ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(xpath,
186 - //TODO: name = name + ((HasAugmentation)getParentNode()).getAugmentPrefix(nodeId); 201 + AUGMENT_DATA);
202 + } catch (DataModelException e) {
203 + return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix);
204 + }
187 } 205 }
188 - return name; 206 +
207 + clearOccurrenceCount();
208 + return xpath;
209 + }
210 +
211 + /**
212 + * Returns true if a prefix is present and it is not equals to parents prefix.
213 + *
214 + * @param nodeId YANG node identifier
215 + * @param parentsPrefix parent's prefix
216 + * @return true if a prefix is present and it is not equals to parents prefix
217 + */
218 + private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) {
219 + return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix;
189 } 220 }
190 221
191 /** 222 /**
......
1 +/*
2 + * Copyright 2016-present 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.parserutils;
18 +
19 +import java.util.ArrayList;
20 +import java.util.List;
21 +
22 +import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
23 +
24 +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
25 +
26 +/**
27 + * Represents a utility which provides valid name for generated java file for augment node.
28 + */
29 +public final class AugmentJavaFileNameGenUtil {
30 +
31 + /**
32 + * Prefix to be added to generated java file for augment node.
33 + */
34 + private static final String AUGMENTED = "Augmented";
35 +
36 + /**
37 + * The number of time augment has updated the same target node in same module/submodule.
38 + */
39 + private static int occurrenceCount = 1;
40 +
41 + /**
42 + * List of names for generated augment java file.
43 + */
44 + private static List<String> augmentJavaFileNameList = new ArrayList<>();
45 +
46 + private static final int ONE = 1;
47 + private static final int TWO = 2;
48 + private static final int ZERO = 0;
49 +
50 + /**
51 + * Creates an instance of augment java file name generator utility.
52 + */
53 + private AugmentJavaFileNameGenUtil() {
54 + }
55 +
56 + /**
57 + * Sets the augment java file name list.
58 + *
59 + * @param nameList name list
60 + */
61 + private static void setAugmentJavaFileNameList(List<String> nameList) {
62 + augmentJavaFileNameList = nameList;
63 + }
64 +
65 + /**
66 + * Returns augment java file name list.
67 + *
68 + * @return augment java file name list
69 + */
70 + public static List<String> getAugmentJavaFileNameList() {
71 + return augmentJavaFileNameList;
72 + }
73 +
74 + /**
75 + * Sets occurrence count.
76 + *
77 + * @param occurrence occurrence count
78 + */
79 + private static void setOccurrenceCount(int occurrence) {
80 + occurrenceCount = occurrence;
81 + }
82 +
83 + /**
84 + * Returns occurrence count.
85 + *
86 + * @return occurrence count
87 + */
88 + private static int getOccurrenceCount() {
89 + return occurrenceCount;
90 + }
91 +
92 + /**
93 + * Creates a name identifier for augment.
94 + *
95 + * @param nodeId node identifier
96 + * @param isPrefix if prefix is present or it is not equals to parent's prefix
97 + * @return valid name for augment
98 + */
99 + public static String createValidNameForAugment(YangNodeIdentifier nodeId, boolean isPrefix) {
100 + getAugmentJavaFileNameList().add(createName(nodeId, isPrefix));
101 + setAugmentJavaFileNameList(getAugmentJavaFileNameList());
102 + return getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - 1);
103 + }
104 +
105 + /**
106 + * Creates name for the current augment file.
107 + *
108 + * @param nodeId node identifier
109 + * @param isPrefix if prefix is present or it is not equals to parent's prefix
110 + */
111 + private static String createName(YangNodeIdentifier nodeId, boolean isPrefix) {
112 + if (isPrefix) {
113 + return AUGMENTED + getCaptialCase(nodeId.getPrefix()) + getCaptialCase(nodeId.getName());
114 + } else {
115 + return AUGMENTED + getCaptialCase(nodeId.getName());
116 + }
117 + }
118 +
119 + /**
120 + * Updates occurrence count of augment.
121 + */
122 + public static void updateOccurenceCount() {
123 + int count = getOccurrenceCount();
124 + count++;
125 + setOccurrenceCount(count);
126 + }
127 +
128 + /**
129 + * Updates the list of name when augment has occurred multiple times to update the same target node
130 + * and returns a valid name for augment node's generated java file.
131 + *
132 + * @param nodeId YANG node identifier
133 + * @param isPrefix true if a prefix is present and it is not equals to parents prefix
134 + * @return valid name for augment node
135 + */
136 + public static String updateNameWhenHasMultipleOuccrrence(YangNodeIdentifier nodeId, boolean isPrefix) {
137 + String name = "";
138 + updateOccurenceCount();
139 +
140 + if (getOccurrenceCount() == TWO) {
141 + String previousAugmentsName = getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - ONE);
142 + getAugmentJavaFileNameList().remove(ZERO);
143 + getAugmentJavaFileNameList().add(previousAugmentsName + ONE);
144 + //TODO: update when already contains the name.
145 + name = createName(nodeId, isPrefix) + TWO;
146 + } else {
147 + name = createName(nodeId, isPrefix) + getOccurrenceCount();
148 + }
149 + getAugmentJavaFileNameList().add(name);
150 + return name;
151 + }
152 +
153 + /**
154 + * Resets occurrence count to one.
155 + */
156 + public static void clearOccurrenceCount() {
157 + setOccurrenceCount(ONE);
158 + }
159 +
160 +}
...@@ -52,7 +52,9 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory; ...@@ -52,7 +52,9 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
52 52
53 /** 53 /**
54 * Represents ONOS YANG utility maven plugin. 54 * Represents ONOS YANG utility maven plugin.
55 - * Goal of plugin is yang2java Execution phase in generate-sources requiresDependencyResolution at compile time. 55 + * Goal of plugin is yang2java.
56 + * Execution phase is generate-sources.
57 + * requiresDependencyResolution at compile time.
56 */ 58 */
57 @Mojo(name = "yang2java", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE, 59 @Mojo(name = "yang2java", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE,
58 requiresProject = true) 60 requiresProject = true)
......
1 +/*
2 + * Copyright 2016-present 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.parseutils;
18 +
19 +import org.junit.Test;
20 +import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
21 +
22 +import static org.hamcrest.core.Is.is;
23 +import static org.junit.Assert.assertThat;
24 +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
25 +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
26 +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.getAugmentJavaFileNameList;
27 +import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
28 +
29 +/**
30 + * Unit test case for augment java file name generator utility.
31 + */
32 +public class AugmentJavaFileNameGenUtilTest {
33 +
34 + private static final String TEST1 = "test1Node";
35 + private static final String PARENT_PREFIX = "if";
36 + private static final String NODE_PREFIX = "rf";
37 +
38 + private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX = "AugmentedTest1Node";
39 + private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1 = "AugmentedTest1Node1";
40 + private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2 = "AugmentedTest1Node2";
41 + private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3 = "AugmentedTest1Node3";
42 +
43 + private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX = "AugmentedRfTest1Node";
44 + private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI1 = "AugmentedRfTest1Node1";
45 + private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2 = "AugmentedRfTest1Node2";
46 + private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3 = "AugmentedRfTest1Node3";
47 +
48 + private static String testString = "";
49 +
50 + /**
51 + * Unit test case when parent's prefix is present and one occurrence of augment node to update same target node.
52 + */
53 + @Test
54 + public void testForAugmentNameWhenOneOuccrrenceWithParentPrefix() {
55 + clearData();
56 + testString = createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
57 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
58 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX)));
59 + }
60 +
61 + /**
62 + * Unit test case when no prefix and one occurrence of augment node to update same target node.
63 + */
64 + @Test
65 + public void testForAugmentNameWhenOneOuccrrenceWithNoPrefix() {
66 + clearData();
67 + testString = createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
68 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
69 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX)));
70 + }
71 +
72 + /**
73 + * Unit test case when different prefix then parent is present and
74 + * one occurrence of augment node to update same target node.
75 + */
76 + @Test
77 + public void testForAugmentNameWhenOneOuccrrenceWithDiffPrefix() {
78 + clearData();
79 + testString = createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
80 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
81 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX)));
82 + }
83 +
84 + /**
85 + * Unit test case when parent's prefix is present and two occurrence of augment node to update
86 + * same target node is present.
87 + */
88 + @Test
89 + public void testForAugmentNameWhenTwoOuccrrenceWithParentPrefix() {
90 + clearData();
91 +
92 + createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
93 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
94 + testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
95 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
96 +
97 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
98 + }
99 +
100 + /**
101 + * Unit test case when no prefix and two occurrence of augment node to update
102 + * same target node is present.
103 + */
104 + @Test
105 + public void testForAugmentNameWhenTwoOuccrrenceWithNoPrefix() {
106 + clearData();
107 +
108 + createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
109 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
110 + testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
111 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
112 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
113 + }
114 +
115 + /**
116 + * Unit test case when different prefix then parent is present and
117 + * two occurrence of augment node to update same target node is present.
118 + */
119 + @Test
120 + public void testForAugmentNameWhenTwoOuccrrenceWithDiffPrefix() {
121 + clearData();
122 +
123 + createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
124 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
125 + testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
126 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
127 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2)));
128 + }
129 +
130 + /**
131 + * Unit test case when parent prefix and three occurrence of augment node to update
132 + * same target node is present.
133 + */
134 + @Test
135 + public void testForAugmentNameWhenThreeOuccrrenceWithParentPrefix() {
136 + clearData();
137 +
138 + createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
139 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
140 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
141 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
142 +
143 + testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
144 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
145 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
146 + }
147 +
148 + /**
149 + * Unit test case when no prefix and three occurrence of augment node to update
150 + * same target node is present.
151 + */
152 + @Test
153 + public void testForAugmentNameWhenThreeOuccrrenceNoPrefix() {
154 + clearData();
155 +
156 + createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
157 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
158 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
159 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
160 +
161 + testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
162 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
163 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
164 + }
165 +
166 + /**
167 + * Unit test case when different prefix and three occurrence of augment node to update
168 + * same target node is present.
169 + */
170 + @Test
171 + public void testForAugmentNameWhenThreeOuccrrenceWithDiffPrefix() {
172 + clearData();
173 +
174 + createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
175 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
176 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
177 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
178 +
179 + testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
180 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
181 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3)));
182 + }
183 +
184 + /**
185 + * Unit test case for when three occurrence is there and parent prefix is present,
186 + * all the names need to be updated in list.
187 + */
188 + @Test
189 + public void testForPreviousNamesGotUpdatedWhenParentPrefix() {
190 + clearData();
191 +
192 + createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
193 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
194 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
195 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
196 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
197 + isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
198 +
199 + testString = getAugmentJavaFileNameList().get(0);
200 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1)));
201 +
202 + testString = getAugmentJavaFileNameList().get(1);
203 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
204 +
205 + testString = getAugmentJavaFileNameList().get(2);
206 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
207 + }
208 +
209 + /**
210 + * Unit test case for when three occurrence is there and no prefix is present,
211 + * all the names need to be updated in list.
212 + */
213 + @Test
214 + public void testForPreviousNamesGotUpdatedWhenNoPrefix() {
215 + clearData();
216 +
217 + createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
218 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
219 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
220 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
221 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
222 + isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
223 +
224 + testString = getAugmentJavaFileNameList().get(0);
225 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1)));
226 +
227 + testString = getAugmentJavaFileNameList().get(1);
228 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
229 +
230 + testString = getAugmentJavaFileNameList().get(2);
231 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
232 + }
233 +
234 + /**
235 + * Unit test case for when three occurrence is there and different prefix is present,
236 + * all the names need to be updated in list.
237 + */
238 + @Test
239 + public void testForPreviousNamesGotUpdatedWhenDifferentPrefix() {
240 + clearData();
241 +
242 + createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
243 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
244 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
245 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
246 + updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
247 + isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
248 +
249 + testString = getAugmentJavaFileNameList().get(0);
250 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI1)));
251 +
252 + testString = getAugmentJavaFileNameList().get(1);
253 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2)));
254 +
255 + testString = getAugmentJavaFileNameList().get(2);
256 + assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3)));
257 + }
258 +
259 + /**
260 + * Returns stub node identifier when parent prefix is used.
261 + *
262 + * @param name name of node
263 + * @param prefix prefix of node
264 + * @return node identifier for node
265 + */
266 + private YangNodeIdentifier getStubNodeIdetifierWithParentPrefix() {
267 + YangNodeIdentifier nodeId = new YangNodeIdentifier();
268 + nodeId.setName(TEST1);
269 + nodeId.setPrefix(PARENT_PREFIX);
270 + return nodeId;
271 + }
272 +
273 + /**
274 + * Returns stub node identifier when no prefix is used.
275 + *
276 + * @param name name of node
277 + * @param prefix prefix of node
278 + * @return node identifier for node
279 + */
280 + private YangNodeIdentifier getStubNodeIdetifierWithNoPrefix() {
281 + YangNodeIdentifier nodeId = new YangNodeIdentifier();
282 + nodeId.setName(TEST1);
283 + nodeId.setPrefix(null);
284 + return nodeId;
285 + }
286 +
287 + /**
288 + * Returns stub node identifier when different prefix is used.
289 + *
290 + * @param name name of node
291 + * @param prefix prefix of node
292 + * @return node identifier for node
293 + */
294 + private YangNodeIdentifier getStubNodeIdetifierWithDiffPrefix() {
295 + YangNodeIdentifier nodeId = new YangNodeIdentifier();
296 + nodeId.setName(TEST1);
297 + nodeId.setPrefix(NODE_PREFIX);
298 + return nodeId;
299 + }
300 +
301 + /**
302 + * Returns true if a prefix is present and it is not equals to parents prefix.
303 + *
304 + * @param nodeId YANG node identifier
305 + * @param parentsPrefix parent's prefix
306 + * @return true if a prefix is present and it is not equals to parents prefix
307 + */
308 + private static boolean isPrefixPresent(YangNodeIdentifier nodeId) {
309 + return nodeId.getPrefix() != null && nodeId.getPrefix() != PARENT_PREFIX;
310 + }
311 +
312 + /**
313 + * Clears list of names and occurrence count after each test case.
314 + */
315 + private void clearData() {
316 + getAugmentJavaFileNameList().clear();
317 + clearOccurrenceCount();
318 + }
319 +
320 +}
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.parser.parseutils; 17 +package org.onosproject.yangutils.parser.impl.parseutils;
18 18
19 import org.junit.Test; 19 import org.junit.Test;
20 20
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.parser.parseutils; 17 +package org.onosproject.yangutils.parser.impl.parseutils;
18 18
19 import org.junit.Rule; 19 import org.junit.Rule;
20 import org.junit.Test; 20 import org.junit.Test;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.yangutils.parser.parseutils; 17 +package org.onosproject.yangutils.parser.impl.parseutils;
18 18
19 import org.antlr.v4.runtime.ANTLRFileStream; 19 import org.antlr.v4.runtime.ANTLRFileStream;
20 import org.antlr.v4.runtime.ANTLRInputStream; 20 import org.antlr.v4.runtime.ANTLRInputStream;
......