Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-4711] Removed cyclic dependencies

because of JUNIT testcases

Change-Id: I0402d224cbb0d0d541a1f47333a4e5de5cf240b0
Showing 14 changed files with 78 additions and 102 deletions
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.linker;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Iterator;
......@@ -33,8 +33,6 @@ import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.plugin.manager.YangUtilManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
......@@ -52,7 +50,6 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirector
*/
public class InterFileLinkingTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
private final YangUtilManager utilManager = new YangUtilManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.linker;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.ListIterator;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.linker;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.List;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.linker;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.math.BigInteger;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
......
package org.onosproject.yangutils.plugin.manager;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
/**
* Created by root1 on 16/6/16.
*/
public class YangPluginUtilsTest {
private static final String BASE_DIR = "target/UnitTestCase";
/**
* This test case checks whether the source is getting added.
*/
@Test
public void testForAddSource() throws IOException {
MavenProject project = new MavenProject();
BuildContext context = new DefaultBuildContext();
File sourceDir = new File(BASE_DIR + File.separator + "yang");
sourceDir.mkdirs();
addToCompilationRoot(sourceDir.toString(), project, context);
FileUtils.deleteDirectory(sourceDir);
}
}
......@@ -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.YangNode;
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;
......
......@@ -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,6 +105,11 @@ public final class JavaIdentifierSyntaxTest {
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.
......@@ -119,7 +128,7 @@ public final class JavaIdentifierSyntaxTest {
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 @@ public final class JavaIdentifierSyntaxTest {
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);
}
}
......
......@@ -20,21 +20,13 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
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.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.doesPackageExist;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
......@@ -42,15 +34,12 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileH
*/
public final class FileSystemUtilTest {
private static final String BASE_DIR_PKG = "target.UnitTestCase.";
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";
private static final String TEST_DATA_2 = "This is next second line\n";
private static final String TEST_DATA_3 = "This is next third line in the file";
private static final String TEST_FILE = "testFile";
private static final String SOURCE_TEST_FILE = "sourceTestFile";
private static final String DIR_PATH = "exist1.exist2.exist3";
private static final String PKG_INFO = "package-info.java";
/**
* A private constructor is tested.
......@@ -67,7 +56,7 @@ public final class FileSystemUtilTest {
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {FileSystemUtil.class };
Class<?>[] classesToConstruct = {FileSystemUtil.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -96,52 +85,4 @@ public final class FileSystemUtilTest {
updateFileHandle(createFile, null, true);
deleteDirectory(dir);
}
/**
* 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)));
createPackage(getStubNode());
createDir.delete();
deleteDirectory(createDir);
}
/**
* Returns stub YANG node.
*
* @return stub node
*/
private YangNode getStubNode() {
YangJavaModule module = new YangJavaModule();
module.setName(TEST_DATA_1);
JavaFileInfo javafileInfo = new JavaFileInfo();
javafileInfo.setJavaName(TEST_DATA_1);
javafileInfo.setBaseCodeGenPath("");
javafileInfo.setPackageFilePath(BASE_PKG);
javafileInfo.setPluginConfig(getStubPluginConfig());
module.setJavaFileInfo(javafileInfo);
return module;
}
/**
* Returns stub pluginConfig.
*
* @return stub pluginConfig
*/
private YangPluginConfig getStubPluginConfig() {
YangPluginConfig pluginConfig = new YangPluginConfig();
pluginConfig.setConflictResolver(null);
return pluginConfig;
}
}
......
......@@ -20,23 +20,18 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.utils.UtilConstants;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
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.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
......@@ -189,20 +184,6 @@ public final class YangIoUtilsTest {
}
/**
* This test case checks whether the source is getting added.
*/
@Test
public void testForAddSource() throws IOException {
MavenProject project = new MavenProject();
BuildContext context = new DefaultBuildContext();
File sourceDir = new File(BASE_DIR + File.separator + "yang");
sourceDir.mkdirs();
addToCompilationRoot(sourceDir.toString(), project, context);
FileUtils.deleteDirectory(sourceDir);
}
/**
* Unit test case for trim at last method.
*/
@Test
......