YANG augment's generated file name resolver implementation and UT fixes.
Change-Id: Ib960a15398a3b9f529f9ad28402d5bac539fb525
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
index 39e0a04..57eea99 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
@@ -18,6 +18,7 @@
import java.util.List;
+import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
@@ -32,6 +33,9 @@
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangAugmentNode;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
@@ -45,7 +49,6 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA;
@@ -81,8 +84,6 @@
*/
public final class AugmentListener {
- private static final String AUGMENTED = "Augmented";
-
/**
* Creates a new augment listener.
*/
@@ -116,11 +117,11 @@
Parsable curData = listener.getParsedDataStack().peek();
if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) {
-
YangNode curNode = (YangNode) curData;
YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION);
yangAugment.setTargetNode(targetNodes);
- yangAugment.setName(getValidNameForAugment(targetNodes));
+ yangAugment.setName(detectCollisionForTargetNode(curData, targetNodes, line, charPositionInLine, listener));
+
try {
curNode.addChild(yangAugment);
} catch (DataModelException e) {
@@ -161,7 +162,6 @@
* @param ctx context object of the grammar rule
*/
private static void validateSubStatementsCardinality(GeneratedYangParser.AugmentStatementContext ctx) {
-
validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, AUGMENT_DATA, ctx.augment().getText());
validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, AUGMENT_DATA, ctx.augment().getText());
validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText());
@@ -171,21 +171,52 @@
}
/**
- * Returns a name identifier for augment.
+ * Detects collision for java file generation of augment node when
+ * it is updating the same target node in same parent multiple times.
+ * Returns name for generated java file of augment node
*
- * @param targetNode list of target nodes
- * @return name identifier
+ * @param curData parsable data
+ * @param targetNodes list of target nodes
+ * @param line line in YANG file
+ * @param charPositionInLine char position in YANG file
+ * @param listener tree walk listener
+ * @return name for generated java file for augment node
*/
- private static String getValidNameForAugment(List<YangNodeIdentifier> targetNodes) {
- String name = "";
- YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
+ private static String detectCollisionForTargetNode(Parsable curData, List<YangNodeIdentifier> targetNodes, int line,
+ int charPositionInLine, TreeWalkListener listener) {
- if (nodeId.getPrefix() != null) {
- name = AUGMENTED + getCaptialCase(nodeId.getPrefix()) + getCaptialCase(nodeId.getName());
- } else {
- //TODO: name = name + ((HasAugmentation)getParentNode()).getAugmentPrefix(nodeId);
+ String curPrefix = null;
+ if (curData instanceof YangModule) {
+ curPrefix = ((YangModule) curData).getPrefix();
+ } else if (curData instanceof YangSubModule) {
+ curPrefix = ((YangSubModule) curData).getPrefix();
}
- return name;
+ YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
+ boolean isPrefix = isPrefixPresent(nodeId, curPrefix);
+ String xpath = createValidNameForAugment(nodeId, isPrefix);
+
+ if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
+ try {
+ ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(xpath,
+ AUGMENT_DATA);
+ } catch (DataModelException e) {
+ return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix);
+ }
+ }
+
+ clearOccurrenceCount();
+ return xpath;
+ }
+
+ /**
+ * Returns true if a prefix is present and it is not equals to parents prefix.
+ *
+ * @param nodeId YANG node identifier
+ * @param parentsPrefix parent's prefix
+ * @return true if a prefix is present and it is not equals to parents prefix
+ */
+ private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) {
+ return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix;
}
/**
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentJavaFileNameGenUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentJavaFileNameGenUtil.java
new file mode 100644
index 0000000..113138f
--- /dev/null
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentJavaFileNameGenUtil.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parserutils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
+
+/**
+ * Represents a utility which provides valid name for generated java file for augment node.
+ */
+public final class AugmentJavaFileNameGenUtil {
+
+ /**
+ * Prefix to be added to generated java file for augment node.
+ */
+ private static final String AUGMENTED = "Augmented";
+
+ /**
+ * The number of time augment has updated the same target node in same module/submodule.
+ */
+ private static int occurrenceCount = 1;
+
+ /**
+ * List of names for generated augment java file.
+ */
+ private static List<String> augmentJavaFileNameList = new ArrayList<>();
+
+ private static final int ONE = 1;
+ private static final int TWO = 2;
+ private static final int ZERO = 0;
+
+ /**
+ * Creates an instance of augment java file name generator utility.
+ */
+ private AugmentJavaFileNameGenUtil() {
+ }
+
+ /**
+ * Sets the augment java file name list.
+ *
+ * @param nameList name list
+ */
+ private static void setAugmentJavaFileNameList(List<String> nameList) {
+ augmentJavaFileNameList = nameList;
+ }
+
+ /**
+ * Returns augment java file name list.
+ *
+ * @return augment java file name list
+ */
+ public static List<String> getAugmentJavaFileNameList() {
+ return augmentJavaFileNameList;
+ }
+
+ /**
+ * Sets occurrence count.
+ *
+ * @param occurrence occurrence count
+ */
+ private static void setOccurrenceCount(int occurrence) {
+ occurrenceCount = occurrence;
+ }
+
+ /**
+ * Returns occurrence count.
+ *
+ * @return occurrence count
+ */
+ private static int getOccurrenceCount() {
+ return occurrenceCount;
+ }
+
+ /**
+ * Creates a name identifier for augment.
+ *
+ * @param nodeId node identifier
+ * @param isPrefix if prefix is present or it is not equals to parent's prefix
+ * @return valid name for augment
+ */
+ public static String createValidNameForAugment(YangNodeIdentifier nodeId, boolean isPrefix) {
+ getAugmentJavaFileNameList().add(createName(nodeId, isPrefix));
+ setAugmentJavaFileNameList(getAugmentJavaFileNameList());
+ return getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - 1);
+ }
+
+ /**
+ * Creates name for the current augment file.
+ *
+ * @param nodeId node identifier
+ * @param isPrefix if prefix is present or it is not equals to parent's prefix
+ */
+ private static String createName(YangNodeIdentifier nodeId, boolean isPrefix) {
+ if (isPrefix) {
+ return AUGMENTED + getCaptialCase(nodeId.getPrefix()) + getCaptialCase(nodeId.getName());
+ } else {
+ return AUGMENTED + getCaptialCase(nodeId.getName());
+ }
+ }
+
+ /**
+ * Updates occurrence count of augment.
+ */
+ public static void updateOccurenceCount() {
+ int count = getOccurrenceCount();
+ count++;
+ setOccurrenceCount(count);
+ }
+
+ /**
+ * Updates the list of name when augment has occurred multiple times to update the same target node
+ * and returns a valid name for augment node's generated java file.
+ *
+ * @param nodeId YANG node identifier
+ * @param isPrefix true if a prefix is present and it is not equals to parents prefix
+ * @return valid name for augment node
+ */
+ public static String updateNameWhenHasMultipleOuccrrence(YangNodeIdentifier nodeId, boolean isPrefix) {
+ String name = "";
+ updateOccurenceCount();
+
+ if (getOccurrenceCount() == TWO) {
+ String previousAugmentsName = getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - ONE);
+ getAugmentJavaFileNameList().remove(ZERO);
+ getAugmentJavaFileNameList().add(previousAugmentsName + ONE);
+ //TODO: update when already contains the name.
+ name = createName(nodeId, isPrefix) + TWO;
+ } else {
+ name = createName(nodeId, isPrefix) + getOccurrenceCount();
+ }
+ getAugmentJavaFileNameList().add(name);
+ return name;
+ }
+
+ /**
+ * Resets occurrence count to one.
+ */
+ public static void clearOccurrenceCount() {
+ setOccurrenceCount(ONE);
+ }
+
+}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index b88d5df..86203c6 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -52,7 +52,9 @@
/**
* Represents ONOS YANG utility maven plugin.
- * Goal of plugin is yang2java Execution phase in generate-sources requiresDependencyResolution at compile time.
+ * Goal of plugin is yang2java.
+ * Execution phase is generate-sources.
+ * requiresDependencyResolution at compile time.
*/
@Mojo(name = "yang2java", defaultPhase = GENERATE_SOURCES, requiresDependencyResolution = COMPILE,
requiresProject = true)
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentJavaFileNameGenUtilTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentJavaFileNameGenUtilTest.java
new file mode 100644
index 0000000..ac3658c
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentJavaFileNameGenUtilTest.java
@@ -0,0 +1,320 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parseutils;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.getAugmentJavaFileNameList;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
+
+/**
+ * Unit test case for augment java file name generator utility.
+ */
+public class AugmentJavaFileNameGenUtilTest {
+
+ private static final String TEST1 = "test1Node";
+ private static final String PARENT_PREFIX = "if";
+ private static final String NODE_PREFIX = "rf";
+
+ private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX = "AugmentedTest1Node";
+ private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1 = "AugmentedTest1Node1";
+ private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2 = "AugmentedTest1Node2";
+ private static final String TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3 = "AugmentedTest1Node3";
+
+ private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX = "AugmentedRfTest1Node";
+ private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI1 = "AugmentedRfTest1Node1";
+ private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2 = "AugmentedRfTest1Node2";
+ private static final String TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3 = "AugmentedRfTest1Node3";
+
+ private static String testString = "";
+
+ /**
+ * Unit test case when parent's prefix is present and one occurrence of augment node to update same target node.
+ */
+ @Test
+ public void testForAugmentNameWhenOneOuccrrenceWithParentPrefix() {
+ clearData();
+ testString = createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX)));
+ }
+
+ /**
+ * Unit test case when no prefix and one occurrence of augment node to update same target node.
+ */
+ @Test
+ public void testForAugmentNameWhenOneOuccrrenceWithNoPrefix() {
+ clearData();
+ testString = createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX)));
+ }
+
+ /**
+ * Unit test case when different prefix then parent is present and
+ * one occurrence of augment node to update same target node.
+ */
+ @Test
+ public void testForAugmentNameWhenOneOuccrrenceWithDiffPrefix() {
+ clearData();
+ testString = createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX)));
+ }
+
+ /**
+ * Unit test case when parent's prefix is present and two occurrence of augment node to update
+ * same target node is present.
+ */
+ @Test
+ public void testForAugmentNameWhenTwoOuccrrenceWithParentPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+ testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+ }
+
+ /**
+ * Unit test case when no prefix and two occurrence of augment node to update
+ * same target node is present.
+ */
+ @Test
+ public void testForAugmentNameWhenTwoOuccrrenceWithNoPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+ testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+ }
+
+ /**
+ * Unit test case when different prefix then parent is present and
+ * two occurrence of augment node to update same target node is present.
+ */
+ @Test
+ public void testForAugmentNameWhenTwoOuccrrenceWithDiffPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+ testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2)));
+ }
+
+ /**
+ * Unit test case when parent prefix and three occurrence of augment node to update
+ * same target node is present.
+ */
+ @Test
+ public void testForAugmentNameWhenThreeOuccrrenceWithParentPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+
+ testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+ }
+
+ /**
+ * Unit test case when no prefix and three occurrence of augment node to update
+ * same target node is present.
+ */
+ @Test
+ public void testForAugmentNameWhenThreeOuccrrenceNoPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+
+ testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+ }
+
+ /**
+ * Unit test case when different prefix and three occurrence of augment node to update
+ * same target node is present.
+ */
+ @Test
+ public void testForAugmentNameWhenThreeOuccrrenceWithDiffPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+
+ testString = updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3)));
+ }
+
+ /**
+ * Unit test case for when three occurrence is there and parent prefix is present,
+ * all the names need to be updated in list.
+ */
+ @Test
+ public void testForPreviousNamesGotUpdatedWhenParentPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithParentPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithParentPrefix()));
+
+ testString = getAugmentJavaFileNameList().get(0);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1)));
+
+ testString = getAugmentJavaFileNameList().get(1);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+
+ testString = getAugmentJavaFileNameList().get(2);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+ }
+
+ /**
+ * Unit test case for when three occurrence is there and no prefix is present,
+ * all the names need to be updated in list.
+ */
+ @Test
+ public void testForPreviousNamesGotUpdatedWhenNoPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithNoPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithNoPrefix()));
+
+ testString = getAugmentJavaFileNameList().get(0);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI1)));
+
+ testString = getAugmentJavaFileNameList().get(1);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI2)));
+
+ testString = getAugmentJavaFileNameList().get(2);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITHOUT_PREFIX_MULTI3)));
+ }
+
+ /**
+ * Unit test case for when three occurrence is there and different prefix is present,
+ * all the names need to be updated in list.
+ */
+ @Test
+ public void testForPreviousNamesGotUpdatedWhenDifferentPrefix() {
+ clearData();
+
+ createValidNameForAugment(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+ updateNameWhenHasMultipleOuccrrence(getStubNodeIdetifierWithDiffPrefix(),
+ isPrefixPresent(getStubNodeIdetifierWithDiffPrefix()));
+
+ testString = getAugmentJavaFileNameList().get(0);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI1)));
+
+ testString = getAugmentJavaFileNameList().get(1);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI2)));
+
+ testString = getAugmentJavaFileNameList().get(2);
+ assertThat(true, is(testString.equals(TEST1_AUGMENTED_NAME_WITH_PREFIX_MULTI3)));
+ }
+
+ /**
+ * Returns stub node identifier when parent prefix is used.
+ *
+ * @param name name of node
+ * @param prefix prefix of node
+ * @return node identifier for node
+ */
+ private YangNodeIdentifier getStubNodeIdetifierWithParentPrefix() {
+ YangNodeIdentifier nodeId = new YangNodeIdentifier();
+ nodeId.setName(TEST1);
+ nodeId.setPrefix(PARENT_PREFIX);
+ return nodeId;
+ }
+
+ /**
+ * Returns stub node identifier when no prefix is used.
+ *
+ * @param name name of node
+ * @param prefix prefix of node
+ * @return node identifier for node
+ */
+ private YangNodeIdentifier getStubNodeIdetifierWithNoPrefix() {
+ YangNodeIdentifier nodeId = new YangNodeIdentifier();
+ nodeId.setName(TEST1);
+ nodeId.setPrefix(null);
+ return nodeId;
+ }
+
+ /**
+ * Returns stub node identifier when different prefix is used.
+ *
+ * @param name name of node
+ * @param prefix prefix of node
+ * @return node identifier for node
+ */
+ private YangNodeIdentifier getStubNodeIdetifierWithDiffPrefix() {
+ YangNodeIdentifier nodeId = new YangNodeIdentifier();
+ nodeId.setName(TEST1);
+ nodeId.setPrefix(NODE_PREFIX);
+ return nodeId;
+ }
+
+ /**
+ * Returns true if a prefix is present and it is not equals to parents prefix.
+ *
+ * @param nodeId YANG node identifier
+ * @param parentsPrefix parent's prefix
+ * @return true if a prefix is present and it is not equals to parents prefix
+ */
+ private static boolean isPrefixPresent(YangNodeIdentifier nodeId) {
+ return nodeId.getPrefix() != null && nodeId.getPrefix() != PARENT_PREFIX;
+ }
+
+ /**
+ * Clears list of names and occurrence count after each test case.
+ */
+ private void clearData() {
+ getAugmentJavaFileNameList().clear();
+ clearOccurrenceCount();
+ }
+
+}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerErrorMessageConstructionTest.java
similarity index 98%
rename from utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java
rename to utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerErrorMessageConstructionTest.java
index d10e009..79c46f4 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerErrorMessageConstructionTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerErrorMessageConstructionTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.parser.parseutils;
+package org.onosproject.yangutils.parser.impl.parseutils;
import org.junit.Test;
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerValidationTest.java
similarity index 98%
rename from utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java
rename to utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerValidationTest.java
index f4e284e..9cab4dc 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ListenerValidationTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ListenerValidationTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.parser.parseutils;
+package org.onosproject.yangutils.parser.impl.parseutils;
import org.junit.Rule;
import org.junit.Test;
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ParseTreeErrorListenerTest.java
similarity index 98%
rename from utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java
rename to utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ParseTreeErrorListenerTest.java
index dd09247..4489e77 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/parseutils/ParseTreeErrorListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/ParseTreeErrorListenerTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.parser.parseutils;
+package org.onosproject.yangutils.parser.impl.parseutils;
import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.ANTLRInputStream;