yang choice case translator + whitebox fix
Change-Id: I96f1855bc71a002335946150b51e911ae6ac2fb2
diff --git a/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java b/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
index 52fb4ff..956867d 100644
--- a/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
+++ b/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
@@ -53,7 +53,7 @@
YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang");
// Check whether the data model tree returned is of type module.
- assertThat((node instanceof YangModule), is(true));
+ assertThat(node instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
@@ -72,7 +72,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -111,7 +111,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -151,7 +151,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild().getNextSibling()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -191,7 +191,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -228,21 +228,21 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -280,21 +280,21 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
}
@@ -331,21 +331,21 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -383,7 +383,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
@@ -392,7 +392,7 @@
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java b/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
index e8cfa92..44d0c67 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
@@ -27,22 +27,22 @@
*/
public final class CustomExceptionMatcher extends TypeSafeMatcher<ParserException> {
+ private int actualLine;
+ private final int expectedLine;
+ private int actualCharPosition;
+ private final int expectedCharPosition;
+
/**
* Customized exception matcher to match error location.
*
* @param line error line
* @param charPosition error character position
- * @return
+ * @return customized exception matcher to match error location
*/
public static CustomExceptionMatcher errorLocation(int line, int charPosition) {
return new CustomExceptionMatcher(line, charPosition);
}
- private int actualLine;
- private final int expectedLine;
- private int actualCharPosition;
- private final int expectedCharPosition;
-
private CustomExceptionMatcher(int expectedLine, int expectedCharPosition) {
this.expectedLine = expectedLine;
this.expectedCharPosition = expectedCharPosition;
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
index 79c8488..bb59e65 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
@@ -54,9 +54,6 @@
assertThat(yangNode.getName(), is("Test"));
YangAugment yangAugment = (YangAugment) yangNode.getChild();
- if (yangAugment.getTargetNode().isEmpty()) {
- System.out.println("list is empty");
- }
ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator();
YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next();
assertThat(yangNodeIdentifier.getPrefix(), is("if"));
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
new file mode 100644
index 0000000..9f67ed0
--- /dev/null
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.translator.tojava.utils;
+
+import java.io.IOException;
+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 static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
+
+/**
+ * Unit tests for choice-case translator.
+ */
+public final class ChoiceCaseTranslatorTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks choice-case translation should not result in any exception.
+ */
+ @Test
+ public void processChoiceCaseTranslator() throws IOException, ParserException {
+
+ String userDir = System.getProperty("user.dir");
+ YangNode node = manager.getDataModel("src/test/resources/ChoiceCaseTranslator.yang");
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
+
+ generateJavaCode(node, yangPluginConfig);
+
+ clean(userDir + "/target/ChoiceCaseTestGenFile/");
+ }
+ // TODO enhance the test cases, after having a framework of translator test.
+}
\ No newline at end of file
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
index 97302d8..8359ef3 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
@@ -28,21 +28,18 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.slf4j.Logger;
import static org.apache.commons.io.FileUtils.contentEquals;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Unit Tests for the CopyrightHeader contents.
*/
public final class CopyrightHeaderTest {
- private final Logger log = getLogger(getClass());
private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR)
+ "-present Open Networking Laboratory\n";
@Rule
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
index 0057b56..d3137b3 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
@@ -26,14 +26,12 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.slf4j.Logger;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getJavaFiles;
import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles;
-import static org.slf4j.LoggerFactory.getLogger;
import static java.io.File.separator;
@@ -42,8 +40,6 @@
*/
public final class YangFileScannerTest {
- private final Logger log = getLogger(getClass());
-
@Rule
public ExpectedException thrown = ExpectedException.none();
diff --git a/src/test/resources/ChoiceCaseTranslator.yang b/src/test/resources/ChoiceCaseTranslator.yang
new file mode 100644
index 0000000..e8127ea
--- /dev/null
+++ b/src/test/resources/ChoiceCaseTranslator.yang
@@ -0,0 +1,22 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container food {
+ choice snack {
+ case sports-arena {
+ leaf pretzel {
+ type string;
+ }
+ leaf beer {
+ type string;
+ }
+ }
+ case late-night {
+ leaf chocolate {
+ type string;
+ }
+ }
+ }
+ }
+}