[ONOS-4711] Removed cyclic dependencies
because of JUNIT testcases
Change-Id: I0402d224cbb0d0d541a1f47333a4e5de5cf240b0
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataTypeTest.java
similarity index 96%
rename from plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
rename to plugin/src/test/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataTypeTest.java
index 35cc4bc..5a603c5 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataTypeTest.java
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.translator.tojava.utils;
+package org.onosproject.yangutils.translator.tojava.javamodel;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
@@ -26,9 +25,6 @@
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
-import org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.hamcrest.core.Is.is;
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
deleted file mode 100644
index 993d38c..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
-
-/**
- * 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);
-
- deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
- }
- // TODO enhance the test cases, after having a framework of translator test.
-}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
deleted file mode 100644
index 742d310..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
-
-/**
- * Unit test case for enum translator.
- */
-public final class EnumTranslatorTest {
-
- private final YangUtilsParserManager manager = new YangUtilsParserManager();
-
- /**
- * Checks enum translation should not result in any exception.
- */
- @Test
- public void processEnumTranslator()
- throws IOException, ParserException {
-
- String userDir = System.getProperty("user.dir");
- YangNode node = manager.getDataModel("src/test/resources/EnumTranslator.yang");
-
- YangPluginConfig yangPluginConfig = new YangPluginConfig();
- yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
-
- generateJavaCode(node, yangPluginConfig);
-
- deleteDirectory(userDir + "/target/EnumTestGenFile/");
- }
- // TODO enhance the test cases, after having a framework of translator test.
-}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index b844b27..24f4904 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -16,26 +16,30 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
+import static org.apache.commons.io.FileUtils.deleteDirectory;
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.translator.tojava.utils.JavaIdentifierSyntax.doesPackageExist;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
/**
* Unit tests for java identifier syntax.
@@ -101,25 +105,30 @@
private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry";
private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa";
private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
+ private static final String BASE_DIR_PKG = "target.UnitTestCase.";
+ private static final String DIR_PATH = "exist1.exist2.exist3";
+ private static final String PKG_INFO = "package-info.java";
+ private static final String BASE_PKG = "target/UnitTestCase";
+ private static final String TEST_DATA_1 = "This is to append a text to the file first1\n";
/**
* Unit test for private constructor.
*
- * @throws SecurityException if any security violation is observed.
- * @throws NoSuchMethodException if when the method is not found.
- * @throws IllegalArgumentException if there is illegal argument found.
- * @throws InstantiationException if instantiation is provoked for the
- * private constructor.
- * @throws IllegalAccessException if instance is provoked or a method is
- * provoked.
+ * @throws SecurityException if any security violation is observed.
+ * @throws NoSuchMethodException if when the method is not found.
+ * @throws IllegalArgumentException if there is illegal argument found.
+ * @throws InstantiationException if instantiation is provoked for the
+ * private constructor.
+ * @throws IllegalAccessException if instance is provoked or a method is
+ * provoked.
* @throws InvocationTargetException when an exception occurs by the method
- * or constructor.
+ * or constructor.
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
- Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class };
+ Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
@@ -282,4 +291,23 @@
String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD);
assertThat(path.equals(PARENT_PACKAGE), is(true));
}
+
+
+ /**
+ * This test case checks whether the package is existing.
+ *
+ * @throws IOException when failed to create a test file
+ */
+ @Test
+ public void packageExistTest() throws IOException {
+
+ String strPath = BASE_DIR_PKG + DIR_PATH;
+ File createDir = new File(strPath.replace(PERIOD, SLASH));
+ createDir.mkdirs();
+ File createFile = new File(createDir + SLASH + PKG_INFO);
+ createFile.createNewFile();
+ assertThat(true, is(doesPackageExist(strPath)));
+ createDir.delete();
+ deleteDirectory(createDir);
+ }
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
deleted file mode 100644
index e45b1d8..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
-
-/**
- * Unit tests for union translator.
- */
-public final class NotificationTranslatorTest {
-
- private final YangUtilsParserManager manager = new YangUtilsParserManager();
-
- /**
- * Checks union translation should not result in any exception.
- */
- @Test
- public void processUnionTranslator()
- throws IOException, ParserException {
-
- String userDir = System.getProperty("user.dir");
- YangNode node = manager.getDataModel("src/test/resources/NotificationTest.yang");
-
- YangPluginConfig yangPluginConfig = new YangPluginConfig();
- yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
-
- generateJavaCode(node, yangPluginConfig);
-
- deleteDirectory(userDir + "/target/NotificationTest/");
- }
-
- // TODO enhance the test cases, after having a framework of translator test.
-}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
deleted file mode 100644
index 04ef477..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
-
-/**
- * Unit tests for rpc translator.
- */
-public final class RpcTranslatorTest {
-
- private final YangUtilsParserManager manager = new YangUtilsParserManager();
-
- /**
- * Checks rpc translation should not result in any exception.
- */
- @Test
- public void processRpcTranslator()
- throws IOException, ParserException {
-
- String userDir = System.getProperty("user.dir");
- YangNode node = manager.getDataModel("src/test/resources/RpcTranslator.yang");
-
- YangPluginConfig yangPluginConfig = new YangPluginConfig();
- yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
-
- generateJavaCode(node, yangPluginConfig);
-
- deleteDirectory(userDir + "/target/RpcTestGenFile/");
- }
- // TODO enhance the test cases, after having a framework of translator test.
-}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
deleted file mode 100644
index 0441c87..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
-
-/**
- * Unit tests for union translator.
- */
-public final class UnionTranslatorTest {
-
- private final YangUtilsParserManager manager = new YangUtilsParserManager();
-
- /**
- * Checks union translation should not result in any exception.
- */
- @Test
- public void processUnionTranslator()
- throws IOException, ParserException {
-
- String userDir = System.getProperty("user.dir");
- YangNode node = manager.getDataModel("src/test/resources/UnionTranslator.yang");
-
- YangPluginConfig yangPluginConfig = new YangPluginConfig();
- yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
-
- generateJavaCode(node, yangPluginConfig);
-
- deleteDirectory(userDir + "/target/UnionTestGenFile/");
- }
-
- // TODO enhance the test cases, after having a framework of translator test.
-}