[ONOS-5539] Process sub tree defect fix
Change-Id: I6e06a8ca430a86cc538543b161bbbc56dc9cade6
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
index c4a2341..531a285 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
@@ -57,7 +57,7 @@
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
compileCode(COMP);
- //deleteDirectory(DIR);
+ deleteDirectory(DIR);
}
/**
@@ -113,8 +113,6 @@
@Test
public void processChoiceAugmentInterTranslator() throws IOException,
ParserException, MojoExecutionException {
- //FIXME: for augment having node with child nodes.
- /*
deleteDirectory(DIR);
String searchDir = "src/test/resources/choiceAugment";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
@@ -127,7 +125,6 @@
utilManager.translateToJava(yangPluginConfig);
compileCode(COMP);
deleteDirectory(DIR);
- */
}
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
index 662b7e5..367bf82 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
@@ -16,11 +16,13 @@
package org.onosproject.yangutils.plugin.manager;
+import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import java.io.File;
import java.io.IOException;
@@ -33,7 +35,10 @@
* Unit tests for choice-case translator.
*/
public final class ChoiceCaseTranslatorTest {
-
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private static final String DIR = "target/ChoiceCaseTestGenFile/";
+ private static final String COMP = System.getProperty("user.dir") + File
+ .separator + DIR;
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
@@ -54,5 +59,26 @@
compileCode(dir1);
deleteDirectory(dir);
}
- // TODO enhance the test cases, after having a framework of translator test.
+
+ /**
+ * Checks augment translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processChoiceAllTranslator() throws IOException,
+ ParserException, MojoExecutionException {
+ deleteDirectory(DIR);
+ String searchDir = "src/test/resources/choiceTranslator";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+ compileCode(COMP);
+ deleteDirectory(DIR);
+ }
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/GroupingTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/GroupingTranslatorTest.java
new file mode 100644
index 0000000..a590cc0
--- /dev/null
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/GroupingTranslatorTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.plugin.manager;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.onosproject.yangutils.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Unit test case for grouping translator.
+ */
+public class GroupingTranslatorTest {
+
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private static final String DIR = "target/groupingTranslator/";
+ private static final String COMP = System.getProperty("user.dir") + File
+ .separator + DIR;
+
+ /**
+ * Checks grouping translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processTranslator() throws IOException, ParserException, MojoExecutionException {
+
+ deleteDirectory(DIR);
+ String searchDir = "src/test/resources/grouping";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+ compileCode(COMP);
+ deleteDirectory(DIR);
+ }
+
+}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
index 4e9cdcb..adeb42f 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
@@ -57,6 +57,6 @@
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
compileCode(COMP);
- //deleteDirectory(DIR);
+ deleteDirectory(DIR);
}
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
index 6ec65b9..e80bf0b 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
@@ -49,6 +49,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
+import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
@@ -78,7 +79,7 @@
@Test
public void processSingleJarLinking()
throws IOException, MojoExecutionException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
+ utilManager.createYangFileInfoSet(getYangFiles(YANG_FILES_DIR));
Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
int size1 = info.size();
utilManager.parseYangFileInfoSet();
@@ -104,7 +105,7 @@
@Test
public void processMultipleJarLinking()
throws IOException, MojoExecutionException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
+ utilManager.createYangFileInfoSet(getYangFiles(YANG_FILES_DIR));
Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
int size1 = info.size();
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
new file mode 100644
index 0000000..501e2bc
--- /dev/null
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ProcessSubTreeCodeGenTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.plugin.manager;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.onosproject.yangutils.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Unit test case for process sub tree code generation test.
+ */
+public class ProcessSubTreeCodeGenTest {
+
+ private final YangUtilManager utilManager = new YangUtilManager();
+ private static final String DIR = "target/pstf/";
+ private static final String COMP = System.getProperty("user.dir") + File
+ .separator + DIR;
+
+ /**
+ * Checks pst translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processTranslator() throws IOException, ParserException, MojoExecutionException {
+
+ deleteDirectory(DIR);
+ String searchDir = "src/test/resources/pstcodegen";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(DIR);
+ utilManager.translateToJava(yangPluginConfig);
+ compileCode(COMP);
+ //deleteDirectory(DIR);
+ }
+
+}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index a6fdf76..6a31ba0 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -203,7 +203,7 @@
String method = getConstructor(testAttr, GENERATE_SERVICE_AND_MANAGER
);
assertThat(true, is(method.contains(
- THIS + PERIOD + ATTRIBUTE_NAME + SPACE + EQUAL + SPACE +
+ ATTRIBUTE_NAME + SPACE + EQUAL + SPACE +
BUILDER_LOWER_CASE + OBJECT + PERIOD +
GET_METHOD_PREFIX + CLASS_NAME + OPEN_PARENTHESIS +
CLOSE_PARENTHESIS + SEMI_COLON)));
diff --git a/plugin/maven/src/test/resources/choiceAugment/all.yang b/plugin/maven/src/test/resources/choiceAugment/all.yang
deleted file mode 100644
index 4c08537..0000000
--- a/plugin/maven/src/test/resources/choiceAugment/all.yang
+++ /dev/null
@@ -1,128 +0,0 @@
-module ietf-inet {
-
- namespace "yang:all";
- prefix "inet";
- yang-version 1;
-
- choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
-
-
- container c {
- choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
- }
-
- list l {
- config false;
-choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
- }
-
-
- grouping g {
- choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
- }
-
- notification n {
- choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
- }
- rpc r {
- input {
- choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
- }
- output {
- choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
- }
- }
-
- augment /name {
- choice name {
- case a {
- leaf udp {
- type empty;
- }
- }
- case b {
- leaf tcp {
- type empty;
- }
- }
- }
- }
-
-}
\ No newline at end of file
diff --git a/plugin/maven/src/test/resources/choiceTranslator/all.yang b/plugin/maven/src/test/resources/choiceTranslator/all.yang
new file mode 100644
index 0000000..be2fd07
--- /dev/null
+++ b/plugin/maven/src/test/resources/choiceTranslator/all.yang
@@ -0,0 +1,157 @@
+module all {
+
+ namespace "yang:all";
+ prefix "all";
+ yang-version 1;
+
+ choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ }
+ case b {
+ leaf tcp {
+ type empty;
+ }
+ }
+ }
+
+
+ container c {
+ choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ }
+ case b {
+ leaf tcp {
+ type empty;
+ }
+ }
+ }
+ }
+
+ list l {
+ config false;
+choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ }
+ case b {
+ leaf tcp {
+ type empty;
+ }
+ }
+ }
+ }
+
+
+ grouping g {
+ choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ }
+ case b {
+ leaf tcp {
+ type empty;
+ }
+ }
+ }
+ }
+ rpc r {
+ input {
+ choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ }
+ case b {
+ leaf tcp {
+ type empty;
+ }
+ }
+ }
+ }
+ output {
+ choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ }
+ case b {
+ leaf tcp {
+ type empty;
+ }
+ }
+ }
+ }
+ }
+
+ augment /name {
+ choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ container cont1 {
+ container cont2 {
+ choice name {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ container cont1 {
+ container cont2 {
+ leaf udp1 {
+ type empty;
+ }
+ }
+ leaf udp2 {
+ type empty;
+ }
+ }
+ }
+ case b {
+ leaf tcp3 {
+ type empty;
+ }
+ }
+ }
+ leaf udp4 {
+ type empty;
+ }
+ }
+ leaf udp5 {
+ type empty;
+ }
+ }
+ }
+ case b {
+ leaf tcp2 {
+ type empty;
+ }
+ }
+ }
+ choice name1 {
+ case a {
+ leaf udp {
+ type empty;
+ }
+ }
+ case b {
+ leaf tcp {
+ type empty;
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/plugin/maven/src/test/resources/grouping/grouping.yang b/plugin/maven/src/test/resources/grouping/grouping.yang
new file mode 100644
index 0000000..518150f
--- /dev/null
+++ b/plugin/maven/src/test/resources/grouping/grouping.yang
@@ -0,0 +1,58 @@
+module grouping {
+
+ namespace "yang:grouping";
+ prefix "grouping";
+ yang-version 1;
+ revision 2016-10-08;
+
+ grouping link-details {
+ leaf link-id {
+ type union {
+ type int32;
+ type uint16;
+ type enumeration {
+ enum one;
+ enum two;
+ enum five {
+ value 5;
+ }
+ enum six-square {
+ value 36;
+ }
+ }
+ }
+ }
+ typedef group {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit Mb-only {
+ position 2;
+ }
+ }
+ }
+ container link {
+ leaf port {
+ type int32;
+ }
+
+ leaf-list port-id {
+ type string;
+ }
+ list areas {
+ key "name1";
+ leaf name1 {
+ type string;
+ }
+ }
+ }
+ }
+
+ container cont2 {
+ uses link-details;
+ }
+}
diff --git a/plugin/maven/src/test/resources/pstcodegen/test.yang b/plugin/maven/src/test/resources/pstcodegen/test.yang
new file mode 100644
index 0000000..93e1476
--- /dev/null
+++ b/plugin/maven/src/test/resources/pstcodegen/test.yang
@@ -0,0 +1,83 @@
+module test {
+ namespace "test:test";
+ prefix test;
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ leaf-list leaf-list1 {
+ type int32;
+ }
+ list list1 {
+ key "name";
+ leaf name {
+ type string;
+ }
+ }
+ container cont2 {
+ leaf leaf2 {
+ type int32;
+ }
+ }
+ }
+ leaf leaf2 {
+ type int32;
+ }
+ leaf-list leaf-list2 {
+ type int32;
+ }
+ list list2 {
+ key "name";
+ leaf name {
+ type string;
+ }
+ }
+ choice choice1 {
+ case case1 {
+ leaf leaf3 {
+ type int32;
+ }
+ leaf-list leaf-list3 {
+ type int32;
+ }
+ list list3 {
+ key "name";
+ leaf name {
+ type string;
+ }
+ }
+ }
+ }
+ grouping group1 {
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ leaf-list leaf-list1 {
+ type int32;
+ }
+ list list1 {
+ key "name";
+ leaf name {
+ type string;
+ }
+ }
+ container cont2 {
+ leaf leaf2 {
+ type int32;
+ }
+ }
+ }
+ }
+ rpc rpc1 {
+ input {
+ uses group1;
+ }
+ }
+ augment /cont1/list1 {
+ leaf leaf2 {
+ type int64;
+ }
+ }
+}
\ No newline at end of file