Committed by
Gerrit Code Review
UT test cases fixes in YANG translator.
Change-Id: I8408280c663dda016956b76db27285f466f24fad
Showing
6 changed files
with
229 additions
and
69 deletions
| ... | @@ -63,6 +63,21 @@ public final class JavaAttributeInfo { | ... | @@ -63,6 +63,21 @@ public final class JavaAttributeInfo { |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /** | 65 | /** |
| 66 | + * Construct object of java attribute info. | ||
| 67 | + * | ||
| 68 | + * @param attrType YANG type | ||
| 69 | + * @param name attribute name | ||
| 70 | + * @param isListAttr is list attribute | ||
| 71 | + * @param isQualifiedName is qualified name | ||
| 72 | + */ | ||
| 73 | + public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) { | ||
| 74 | + this.attrType = attrType; | ||
| 75 | + this.name = name; | ||
| 76 | + this.isListAttr = isListAttr; | ||
| 77 | + this.isQualifiedName = isQualifiedName; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 66 | * Get the data type info of attribute. | 81 | * Get the data type info of attribute. |
| 67 | * | 82 | * |
| 68 | * @return the data type info of attribute | 83 | * @return the data type info of attribute | ... | ... |
| ... | @@ -176,21 +176,10 @@ public final class YangIoUtils { | ... | @@ -176,21 +176,10 @@ public final class YangIoUtils { |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | /** | 178 | /** |
| 179 | - * Returns backspaced string. | ||
| 180 | - * | ||
| 181 | - * @param charString char string | ||
| 182 | - * @return backspace string | ||
| 183 | - */ | ||
| 184 | - public static String deleteLastChar(String charString) { | ||
| 185 | - | ||
| 186 | - return charString.substring(0, charString.length() - 1); | ||
| 187 | - } | ||
| 188 | - | ||
| 189 | - /** | ||
| 190 | * Get the directory path of the package in canonical form. | 179 | * Get the directory path of the package in canonical form. |
| 191 | * | 180 | * |
| 192 | * @param baseCodeGenPath base path where the generated files needs to be | 181 | * @param baseCodeGenPath base path where the generated files needs to be |
| 193 | - * put. | 182 | + * put |
| 194 | * @param pathOfJavaPkg java package of the file being generated | 183 | * @param pathOfJavaPkg java package of the file being generated |
| 195 | * @return absolute path of the package in canonical form | 184 | * @return absolute path of the package in canonical form |
| 196 | */ | 185 | */ |
| ... | @@ -211,7 +200,7 @@ public final class YangIoUtils { | ... | @@ -211,7 +200,7 @@ public final class YangIoUtils { |
| 211 | * Get the absolute path of the package in canonical form. | 200 | * Get the absolute path of the package in canonical form. |
| 212 | * | 201 | * |
| 213 | * @param baseCodeGenPath base path where the generated files needs to be | 202 | * @param baseCodeGenPath base path where the generated files needs to be |
| 214 | - * put. | 203 | + * put |
| 215 | * @param pathOfJavaPkg java package of the file being generated | 204 | * @param pathOfJavaPkg java package of the file being generated |
| 216 | * @return absolute path of the package in canonical form | 205 | * @return absolute path of the package in canonical form |
| 217 | */ | 206 | */ | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.yangutils.translator.tojava.utils; | ||
| 18 | + | ||
| 19 | +import java.lang.reflect.Constructor; | ||
| 20 | +import java.lang.reflect.InvocationTargetException; | ||
| 21 | + | ||
| 22 | +import org.junit.Test; | ||
| 23 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
| 24 | +import org.onosproject.yangutils.datamodel.YangType; | ||
| 25 | + | ||
| 26 | +import static org.hamcrest.core.Is.is; | ||
| 27 | +import static org.junit.Assert.assertNotNull; | ||
| 28 | +import static org.junit.Assert.assertThat; | ||
| 29 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; | ||
| 30 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; | ||
| 31 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; | ||
| 32 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8; | ||
| 33 | +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaDataType; | ||
| 34 | +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass; | ||
| 35 | +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage; | ||
| 36 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * Unit test case for attribute java data type. | ||
| 40 | + */ | ||
| 41 | +public class AttributesJavaDataTypeTest { | ||
| 42 | + | ||
| 43 | + private static final YangDataTypes TYPE1 = STRING; | ||
| 44 | + private static final YangDataTypes TYPE2 = INT32; | ||
| 45 | + private static final YangDataTypes TYPE3 = BOOLEAN; | ||
| 46 | + private static final YangDataTypes TYPE4 = UINT8; | ||
| 47 | + private static final String CLASS_INFO1 = "String"; | ||
| 48 | + private static final String CLASS_INFO2 = "int"; | ||
| 49 | + private static final String CLASS_INFO3 = "boolean"; | ||
| 50 | + private static final String CLASS_INFO4 = "short"; | ||
| 51 | + private static final String CLASS_INFO5 = "Integer"; | ||
| 52 | + private static String test = ""; | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Unit test for private constructor. | ||
| 56 | + * | ||
| 57 | + * @throws SecurityException if any security violation is observed | ||
| 58 | + * @throws NoSuchMethodException if when the method is not found | ||
| 59 | + * @throws IllegalArgumentException if there is illegal argument found | ||
| 60 | + * @throws InstantiationException if instantiation is provoked for the private constructor | ||
| 61 | + * @throws IllegalAccessException if instance is provoked or a method is provoked | ||
| 62 | + * @throws InvocationTargetException when an exception occurs by the method or constructor | ||
| 63 | + */ | ||
| 64 | + @Test | ||
| 65 | + public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException, | ||
| 66 | + InstantiationException, IllegalAccessException, InvocationTargetException { | ||
| 67 | + | ||
| 68 | + Class<?>[] classesToConstruct = {AttributesJavaDataType.class }; | ||
| 69 | + for (Class<?> clazz : classesToConstruct) { | ||
| 70 | + Constructor<?> constructor = clazz.getDeclaredConstructor(); | ||
| 71 | + constructor.setAccessible(true); | ||
| 72 | + assertNotNull(constructor.newInstance()); | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Unit test for java class info method test. | ||
| 78 | + */ | ||
| 79 | + @Test | ||
| 80 | + public void testgetJavaClassInfo() { | ||
| 81 | + | ||
| 82 | + test = getJavaImportClass(getStubYangType(TYPE1), false); | ||
| 83 | + assertThat(true, is(test.equals(CLASS_INFO1))); | ||
| 84 | + | ||
| 85 | + test = getJavaImportClass(getStubYangType(TYPE2), true); | ||
| 86 | + assertThat(true, is(test.equals(CLASS_INFO5))); | ||
| 87 | + | ||
| 88 | + test = getJavaImportClass(getStubYangType(TYPE3), false); | ||
| 89 | + assertThat(null, is(test)); | ||
| 90 | + | ||
| 91 | + test = getJavaImportClass(getStubYangType(TYPE4), false); | ||
| 92 | + assertThat(null, is(test)); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * Unit test for java data type method. | ||
| 97 | + */ | ||
| 98 | + @Test | ||
| 99 | + public void testgetJavaDataType() { | ||
| 100 | + | ||
| 101 | + test = getJavaDataType(getStubYangType(TYPE1)); | ||
| 102 | + assertThat(true, is(test.equals(CLASS_INFO1))); | ||
| 103 | + | ||
| 104 | + test = getJavaDataType(getStubYangType(TYPE2)); | ||
| 105 | + assertThat(true, is(test.equals(CLASS_INFO2))); | ||
| 106 | + | ||
| 107 | + test = getJavaDataType(getStubYangType(TYPE3)); | ||
| 108 | + assertThat(true, is(test.equals(CLASS_INFO3))); | ||
| 109 | + | ||
| 110 | + test = getJavaDataType(getStubYangType(TYPE4)); | ||
| 111 | + assertThat(true, is(test.equals(CLASS_INFO4))); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Unit test for java package info method. | ||
| 116 | + */ | ||
| 117 | + @Test | ||
| 118 | + public void testgetJavaPkgInfo() { | ||
| 119 | + | ||
| 120 | + test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1); | ||
| 121 | + assertThat(true, is(test.equals(JAVA_LANG))); | ||
| 122 | + | ||
| 123 | + test = getJavaImportPackage(getStubYangType(TYPE2), true, CLASS_INFO5); | ||
| 124 | + assertThat(true, is(test.equals(JAVA_LANG))); | ||
| 125 | + | ||
| 126 | + test = getJavaImportPackage(getStubYangType(TYPE3), false, CLASS_INFO3); | ||
| 127 | + assertThat(null, is(test)); | ||
| 128 | + | ||
| 129 | + test = getJavaImportPackage(getStubYangType(TYPE4), false, CLASS_INFO4); | ||
| 130 | + assertThat(null, is(test)); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * Returns stub YANG type for test. | ||
| 135 | + * | ||
| 136 | + * @param dataTypes YANG data types | ||
| 137 | + * @return YANG type | ||
| 138 | + */ | ||
| 139 | + private YangType<?> getStubYangType(YangDataTypes dataTypes) { | ||
| 140 | + | ||
| 141 | + YangType<?> type = new YangType(); | ||
| 142 | + type.setDataType(dataTypes); | ||
| 143 | + return type; | ||
| 144 | + } | ||
| 145 | +} |
| ... | @@ -30,24 +30,19 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -30,24 +30,19 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
| 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 32 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; |
| 33 | -import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ||
| 34 | -import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | ||
| 35 | -import static org.onosproject.yangutils.utils.UtilConstants.FINAL; | ||
| 36 | -import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | ||
| 37 | -import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; | ||
| 38 | -import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; | ||
| 39 | -import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ||
| 40 | -import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ||
| 41 | -import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 42 | -import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | ||
| 43 | -import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ||
| 44 | 33 | ||
| 45 | /** | 34 | /** |
| 46 | * Unit tests for class definition generator for generated files. | 35 | * Unit tests for class definition generator for generated files. |
| 47 | */ | 36 | */ |
| 48 | public final class ClassDefinitionGeneratorTest { | 37 | public final class ClassDefinitionGeneratorTest { |
| 49 | 38 | ||
| 50 | - private static final String CLASS_NAME = "testclass"; | 39 | + private static final String CLASS_NAME = "TestClass"; |
| 40 | + private static final String INTERFACE_CLASS_DEF = "public interface TestClass {\n"; | ||
| 41 | + private static final String BULDER_INTERFACE_CLASS_DEF = "interface TestClassBuilder {\n\n"; | ||
| 42 | + private static final String BUILDER_CLASS_DEF = "public class TestClassBuilder implements " | ||
| 43 | + + "TestClass.TestClassBuilder {\n"; | ||
| 44 | + private static final String IMPL_CLASS_DEF = "public final class TestClassImpl implements TestClass {\n"; | ||
| 45 | + private static final String TYPE_DEF_CLASS_DEF = "public final class TestClass {\n"; | ||
| 51 | 46 | ||
| 52 | /** | 47 | /** |
| 53 | * Unit test for private constructor. | 48 | * Unit test for private constructor. |
| ... | @@ -78,9 +73,7 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -78,9 +73,7 @@ public final class ClassDefinitionGeneratorTest { |
| 78 | public void generateBuilderClassDefinitionTest() { | 73 | public void generateBuilderClassDefinitionTest() { |
| 79 | 74 | ||
| 80 | String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME); | 75 | String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME); |
| 81 | - assertThat(true, is(builderClassDefinition.equals( | 76 | + assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF))); |
| 82 | - PUBLIC + SPACE + CLASS + SPACE + CLASS_NAME + BUILDER + SPACE + IMPLEMENTS + SPACE + CLASS_NAME + PERIOD | ||
| 83 | - + CLASS_NAME + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); | ||
| 84 | } | 77 | } |
| 85 | 78 | ||
| 86 | /** | 79 | /** |
| ... | @@ -90,8 +83,7 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -90,8 +83,7 @@ public final class ClassDefinitionGeneratorTest { |
| 90 | public void generateBuilderInterfaceDefinitionTest() { | 83 | public void generateBuilderInterfaceDefinitionTest() { |
| 91 | 84 | ||
| 92 | String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME); | 85 | String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME); |
| 93 | - assertThat(true, is(builderInterfaceDefinition | 86 | + assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF))); |
| 94 | - .equals(INTERFACE + SPACE + CLASS_NAME + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE))); | ||
| 95 | } | 87 | } |
| 96 | 88 | ||
| 97 | /** | 89 | /** |
| ... | @@ -101,9 +93,7 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -101,9 +93,7 @@ public final class ClassDefinitionGeneratorTest { |
| 101 | public void generateImplDefinitionTest() { | 93 | public void generateImplDefinitionTest() { |
| 102 | 94 | ||
| 103 | String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME); | 95 | String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME); |
| 104 | - assertThat(true, is(implDefinition.equals( | 96 | + assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF))); |
| 105 | - PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + CLASS_NAME + IMPL + SPACE + IMPLEMENTS + SPACE | ||
| 106 | - + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); | ||
| 107 | } | 97 | } |
| 108 | 98 | ||
| 109 | /** | 99 | /** |
| ... | @@ -113,8 +103,7 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -113,8 +103,7 @@ public final class ClassDefinitionGeneratorTest { |
| 113 | public void generateinterfaceDefinitionTest() { | 103 | public void generateinterfaceDefinitionTest() { |
| 114 | 104 | ||
| 115 | String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME); | 105 | String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME); |
| 116 | - assertThat(true, is(interfaceDefinition | 106 | + assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF))); |
| 117 | - .equals(PUBLIC + SPACE + INTERFACE + SPACE + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); | ||
| 118 | } | 107 | } |
| 119 | 108 | ||
| 120 | /** | 109 | /** |
| ... | @@ -124,7 +113,6 @@ public final class ClassDefinitionGeneratorTest { | ... | @@ -124,7 +113,6 @@ public final class ClassDefinitionGeneratorTest { |
| 124 | public void generateTypeDefTest() { | 113 | public void generateTypeDefTest() { |
| 125 | 114 | ||
| 126 | String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME); | 115 | String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME); |
| 127 | - assertThat(true, is(typeDef.equals( | 116 | + assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF))); |
| 128 | - PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE))); | ||
| 129 | } | 117 | } |
| 130 | } | 118 | } | ... | ... |
This diff is collapsed. Click to expand it.
| 1 | + | ||
| 1 | /* | 2 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory | 3 | * Copyright 2016 Open Networking Laboratory |
| 3 | * | 4 | * |
| ... | @@ -16,70 +17,78 @@ | ... | @@ -16,70 +17,78 @@ |
| 16 | 17 | ||
| 17 | package org.onosproject.yangutils.utils.io.impl; | 18 | package org.onosproject.yangutils.utils.io.impl; |
| 18 | 19 | ||
| 19 | -import org.junit.Test; | ||
| 20 | -import org.junit.Rule; | ||
| 21 | -import org.junit.rules.ExpectedException; | ||
| 22 | -import org.onosproject.yangutils.utils.UtilConstants; | ||
| 23 | - | ||
| 24 | import java.io.File; | 20 | import java.io.File; |
| 25 | import java.io.IOException; | 21 | import java.io.IOException; |
| 22 | +import java.lang.reflect.Constructor; | ||
| 23 | +import java.lang.reflect.InvocationTargetException; | ||
| 26 | 24 | ||
| 27 | import org.apache.maven.project.MavenProject; | 25 | import org.apache.maven.project.MavenProject; |
| 26 | +import org.junit.Rule; | ||
| 27 | +import org.junit.Test; | ||
| 28 | +import org.junit.rules.ExpectedException; | ||
| 29 | +import org.onosproject.yangutils.utils.UtilConstants; | ||
| 28 | import org.sonatype.plexus.build.incremental.BuildContext; | 30 | import org.sonatype.plexus.build.incremental.BuildContext; |
| 29 | import org.sonatype.plexus.build.incremental.DefaultBuildContext; | 31 | import org.sonatype.plexus.build.incremental.DefaultBuildContext; |
| 30 | 32 | ||
| 31 | -import org.slf4j.Logger; | ||
| 32 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 33 | -import static org.junit.Assert.assertThat; | ||
| 34 | -import static org.junit.Assert.assertNotNull; | ||
| 35 | import static org.hamcrest.core.Is.is; | 33 | import static org.hamcrest.core.Is.is; |
| 36 | -import java.lang.reflect.Constructor; | 34 | +import static org.junit.Assert.assertNotNull; |
| 37 | -import java.lang.reflect.InvocationTargetException; | 35 | +import static org.junit.Assert.assertThat; |
| 36 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; | ||
| 37 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource; | ||
| 38 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; | ||
| 39 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories; | ||
| 40 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | ||
| 38 | 41 | ||
| 39 | /** | 42 | /** |
| 40 | * Unit tests for YANG io utils. | 43 | * Unit tests for YANG io utils. |
| 41 | */ | 44 | */ |
| 42 | public final class YangIoUtilsTest { | 45 | public final class YangIoUtilsTest { |
| 43 | 46 | ||
| 44 | - public static String baseDir = "target/UnitTestCase"; | 47 | + private static final String BASE_DIR = "target/UnitTestCase"; |
| 45 | - | 48 | + private static final String CREATE_PATH = BASE_DIR + File.separator + "dir1/dir2/dir3/dir4/"; |
| 46 | - public static String createPath = baseDir + File.separator + "dir1/dir2/dir3/dir4/"; | 49 | + private static final String CHECK_STRING = "one, two, three, four, five, six"; |
| 47 | - | 50 | + private static final String TRIM_STRING = "one, two, three, four, five, "; |
| 48 | - private final Logger log = getLogger(getClass()); | ||
| 49 | 51 | ||
| 52 | + /** | ||
| 53 | + * Expected exceptions. | ||
| 54 | + */ | ||
| 50 | @Rule | 55 | @Rule |
| 51 | public ExpectedException thrown = ExpectedException.none(); | 56 | public ExpectedException thrown = ExpectedException.none(); |
| 52 | 57 | ||
| 53 | /** | 58 | /** |
| 54 | * This test case checks whether the package-info file is created. | 59 | * This test case checks whether the package-info file is created. |
| 60 | + * | ||
| 61 | + * @throws IOException when fails to do IO operations for test case | ||
| 55 | */ | 62 | */ |
| 56 | @Test | 63 | @Test |
| 57 | public void addPackageInfoTest() throws IOException { | 64 | public void addPackageInfoTest() throws IOException { |
| 58 | 65 | ||
| 59 | - File dirPath = new File(createPath); | 66 | + File dirPath = new File(CREATE_PATH); |
| 60 | dirPath.mkdirs(); | 67 | dirPath.mkdirs(); |
| 61 | - CopyrightHeader.parseCopyrightHeader(); | 68 | + addPackageInfo(dirPath, "check1", CREATE_PATH); |
| 62 | - YangIoUtils.addPackageInfo(dirPath, "check1", createPath); | ||
| 63 | File filePath = new File(dirPath + File.separator + "package-info.java"); | 69 | File filePath = new File(dirPath + File.separator + "package-info.java"); |
| 64 | assertThat(filePath.isFile(), is(true)); | 70 | assertThat(filePath.isFile(), is(true)); |
| 65 | } | 71 | } |
| 66 | 72 | ||
| 67 | /** | 73 | /** |
| 68 | * This test case checks with an additional info in the path. | 74 | * This test case checks with an additional info in the path. |
| 75 | + * | ||
| 76 | + * @throws IOException when fails to do IO operations for test case | ||
| 69 | */ | 77 | */ |
| 70 | @Test | 78 | @Test |
| 71 | public void addPackageInfoWithPathTest() throws IOException { | 79 | public void addPackageInfoWithPathTest() throws IOException { |
| 72 | 80 | ||
| 73 | - File dirPath = new File(createPath); | 81 | + File dirPath = new File(CREATE_PATH); |
| 74 | dirPath.mkdirs(); | 82 | dirPath.mkdirs(); |
| 75 | - CopyrightHeader.parseCopyrightHeader(); | 83 | + addPackageInfo(dirPath, "check1", "src/main/yangmodel/" + CREATE_PATH); |
| 76 | - YangIoUtils.addPackageInfo(dirPath, "check1", "src/main/yangmodel/" + createPath); | ||
| 77 | File filePath = new File(dirPath + File.separator + "package-info.java"); | 84 | File filePath = new File(dirPath + File.separator + "package-info.java"); |
| 78 | assertThat(filePath.isFile(), is(true)); | 85 | assertThat(filePath.isFile(), is(true)); |
| 79 | } | 86 | } |
| 80 | 87 | ||
| 81 | /** | 88 | /** |
| 82 | * This test case checks whether the package-info file is created when invalid path is given. | 89 | * This test case checks whether the package-info file is created when invalid path is given. |
| 90 | + * | ||
| 91 | + * @throws IOException when fails to do IO operations for test case | ||
| 83 | */ | 92 | */ |
| 84 | @Test | 93 | @Test |
| 85 | public void addPackageInfoWithEmptyPathTest() throws IOException { | 94 | public void addPackageInfoWithEmptyPathTest() throws IOException { |
| ... | @@ -87,7 +96,7 @@ public final class YangIoUtilsTest { | ... | @@ -87,7 +96,7 @@ public final class YangIoUtilsTest { |
| 87 | File dirPath = new File("invalid/check"); | 96 | File dirPath = new File("invalid/check"); |
| 88 | thrown.expect(IOException.class); | 97 | thrown.expect(IOException.class); |
| 89 | thrown.expectMessage("Exception occured while creating package info file."); | 98 | thrown.expectMessage("Exception occured while creating package info file."); |
| 90 | - YangIoUtils.addPackageInfo(dirPath, "check1", createPath); | 99 | + addPackageInfo(dirPath, "check1", CREATE_PATH); |
| 91 | File filePath1 = new File(dirPath + File.separator + "package-info.java"); | 100 | File filePath1 = new File(dirPath + File.separator + "package-info.java"); |
| 92 | assertThat(filePath1.isFile(), is(false)); | 101 | assertThat(filePath1.isFile(), is(false)); |
| 93 | } | 102 | } |
| ... | @@ -116,26 +125,30 @@ public final class YangIoUtilsTest { | ... | @@ -116,26 +125,30 @@ public final class YangIoUtilsTest { |
| 116 | 125 | ||
| 117 | /** | 126 | /** |
| 118 | * This test case checks if the directory is cleaned. | 127 | * This test case checks if the directory is cleaned. |
| 128 | + * | ||
| 129 | + * @throws IOException when fails to do IO operations for test case | ||
| 119 | */ | 130 | */ |
| 120 | @Test | 131 | @Test |
| 121 | public void cleanGeneratedDirTest() throws IOException { | 132 | public void cleanGeneratedDirTest() throws IOException { |
| 122 | 133 | ||
| 123 | - File baseDirPath = new File(baseDir); | 134 | + File baseDirPath = new File(BASE_DIR); |
| 124 | - File createNewDir = new File(baseDir + File.separator + UtilConstants.YANG_GEN_DIR); | 135 | + File createNewDir = new File(BASE_DIR + File.separator + UtilConstants.YANG_GEN_DIR); |
| 125 | createNewDir.mkdirs(); | 136 | createNewDir.mkdirs(); |
| 126 | File createFile = new File(createNewDir + File.separator + "check1.java"); | 137 | File createFile = new File(createNewDir + File.separator + "check1.java"); |
| 127 | createFile.createNewFile(); | 138 | createFile.createNewFile(); |
| 128 | - YangIoUtils.clean(baseDirPath.getAbsolutePath()); | 139 | + clean(baseDirPath.getAbsolutePath()); |
| 129 | } | 140 | } |
| 130 | 141 | ||
| 131 | /** | 142 | /** |
| 132 | * This test case checks the cleaning method when an invalid path is provided. | 143 | * This test case checks the cleaning method when an invalid path is provided. |
| 144 | + * | ||
| 145 | + * @throws IOException when fails to do IO operations for test case | ||
| 133 | */ | 146 | */ |
| 134 | @Test | 147 | @Test |
| 135 | public void cleanWithInvalidDirTest() throws IOException { | 148 | public void cleanWithInvalidDirTest() throws IOException { |
| 136 | 149 | ||
| 137 | - File baseDirPath = new File(baseDir + "invalid"); | 150 | + File baseDirPath = new File(BASE_DIR + "invalid"); |
| 138 | - YangIoUtils.clean(baseDirPath.getAbsolutePath()); | 151 | + clean(baseDirPath.getAbsolutePath()); |
| 139 | } | 152 | } |
| 140 | 153 | ||
| 141 | /** | 154 | /** |
| ... | @@ -144,20 +157,30 @@ public final class YangIoUtilsTest { | ... | @@ -144,20 +157,30 @@ public final class YangIoUtilsTest { |
| 144 | @Test | 157 | @Test |
| 145 | public void createDirectoryTest() { | 158 | public void createDirectoryTest() { |
| 146 | 159 | ||
| 147 | - File dirPath = YangIoUtils.createDirectories(createPath); | 160 | + File dirPath = createDirectories(CREATE_PATH); |
| 148 | assertThat(dirPath.isDirectory(), is(true)); | 161 | assertThat(dirPath.isDirectory(), is(true)); |
| 149 | } | 162 | } |
| 150 | 163 | ||
| 151 | /** | 164 | /** |
| 152 | - * This testcase checks whether the source is getting added. | 165 | + * This test case checks whether the source is getting added. |
| 153 | */ | 166 | */ |
| 154 | @Test | 167 | @Test |
| 155 | public void testForAddSource() { | 168 | public void testForAddSource() { |
| 156 | 169 | ||
| 157 | MavenProject project = new MavenProject(); | 170 | MavenProject project = new MavenProject(); |
| 158 | BuildContext context = new DefaultBuildContext(); | 171 | BuildContext context = new DefaultBuildContext(); |
| 159 | - File sourceDir = new File(baseDir + File.separator + "yang"); | 172 | + File sourceDir = new File(BASE_DIR + File.separator + "yang"); |
| 160 | sourceDir.mkdirs(); | 173 | sourceDir.mkdirs(); |
| 161 | - YangIoUtils.addToSource(sourceDir.toString(), project, context); | 174 | + addToSource(sourceDir.toString(), project, context); |
| 175 | + } | ||
| 176 | + | ||
| 177 | + /* | ||
| 178 | + * Unit test case for trim at last method. | ||
| 179 | + */ | ||
| 180 | + @Test | ||
| 181 | + public void testForTrimAtLast() { | ||
| 182 | + | ||
| 183 | + String test = trimAtLast(CHECK_STRING, "six"); | ||
| 184 | + assertThat(test.contains(TRIM_STRING), is(true)); | ||
| 162 | } | 185 | } |
| 163 | } | 186 | } | ... | ... |
-
Please register or login to post a comment