blob: bfde08d6268ad323a72084b412ed4865df3b0e4b [file] [log] [blame]
b.janani8b8ebdc2016-02-25 12:25:55 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
b.janani8b8ebdc2016-02-25 12:25:55 +05303 *
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
17package org.onosproject.yangutils.translator.tojava.utils;
18
Gaurav Agrawalc5f63272016-06-16 13:09:53 +053019import java.io.File;
20import java.io.IOException;
b.janani8b8ebdc2016-02-25 12:25:55 +053021import java.lang.reflect.Constructor;
22import java.lang.reflect.InvocationTargetException;
Vidyashree Ramadeac28b2016-06-20 15:12:43 +053023import java.text.ParseException;
24import java.text.SimpleDateFormat;
25import java.util.Date;
janani bdd1314f2016-05-19 17:39:50 +053026import org.junit.Rule;
Vinod Kumar S38046502016-03-23 15:30:27 +053027import org.junit.Test;
janani bdd1314f2016-05-19 17:39:50 +053028import org.junit.rules.ExpectedException;
29import org.onosproject.yangutils.translator.exception.TranslatorException;
Gaurav Agrawal8a5af142016-06-15 13:58:01 +053030import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
Bharat saraswal2f11f652016-03-25 18:19:46 +053031
Gaurav Agrawalc5f63272016-06-16 13:09:53 +053032import static org.apache.commons.io.FileUtils.deleteDirectory;
Bharat saraswal2f11f652016-03-25 18:19:46 +053033import static org.hamcrest.core.Is.is;
Bharat saraswal6ef0b762016-04-05 12:45:45 +053034import static org.hamcrest.core.IsNot.not;
Bharat saraswal2f11f652016-03-25 18:19:46 +053035import static org.junit.Assert.assertThat;
Gaurav Agrawalc5f63272016-06-16 13:09:53 +053036import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.doesPackageExist;
37import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
38import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
39import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
40import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
Gaurav Agrawal8a5af142016-06-15 13:58:01 +053041import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
42import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
43import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
44import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
Gaurav Agrawal8a5af142016-06-15 13:58:01 +053045import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
Vinod Kumar S38046502016-03-23 15:30:27 +053046
b.janani8b8ebdc2016-02-25 12:25:55 +053047/**
48 * Unit tests for java identifier syntax.
49 */
50public final class JavaIdentifierSyntaxTest {
51
janani bdd1314f2016-05-19 17:39:50 +053052 @Rule
53 public ExpectedException thrown = ExpectedException.none();
54
Bharat saraswal2f11f652016-03-25 18:19:46 +053055 private static final String PARENT_PACKAGE = "test5/test6/test7";
56 private static final String CHILD_PACKAGE = "test1:test2:test3";
57 private static final String DATE1 = "2000-1-5";
58 private static final String DATE2 = "1992-01-25";
59 private static final String PARENT_WITH_PERIOD = "test5.test6.test7";
60 private static final String CHILD_WITH_PERIOD = "test1.test2.test3";
61 private static final String DATE_WITH_REV1 = "rev20000105";
62 private static final String DATE_WITH_REV2 = "rev19920125";
63 private static final String VERSION_NUMBER = "v1";
janani bdd1314f2016-05-19 17:39:50 +053064 private static final String VALID_PREFIX = "123add-prefix";
65 private static final String INVALID_PREFIX = "-*()&^&#$%";
66 private static final String INVALID_PREFIX1 = "abc~!@#$%^&*()_+}{:<>?`1234567890-=[]''|,./SS";
67 private static final String INVALID_NAME_SPACE_FOR_INVALID_PREFIX = "try:#test3:9case3";
Bharat saraswal2f11f652016-03-25 18:19:46 +053068 private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
69 private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
janani bdd1314f2016-05-19 17:39:50 +053070 private static final String INVALID_NAME_SPACE3 = "CONST:TRY://9test3";
71 private static final String VALID_NAME_SPACE1 = "123addprefixbyte.test2.123addprefix9test3";
janani bde4ffab2016-04-15 16:18:30 +053072 private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3";
janani bdd1314f2016-05-19 17:39:50 +053073 private static final String VALID_NAME_SPACE3 = "abc1234567890ssconst.test2.abc1234567890ss9test3";
74 private static final String VALID_NAME_SPACE4 = "yangautoprefixconst.yangautoprefixtry.yangautoprefix9test3";
Bharat saraswal2f11f652016-03-25 18:19:46 +053075 private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier";
76 private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier";
janani bde4ffab2016-04-15 16:18:30 +053077 private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123";
78 private static final String WITH_CAMEL_CASE1 = "try123";
79 private static final String WITHOUT_CAMEL_CASE2 = "_try";
80 private static final String WITH_CAMEL_CASE2 = "yangAutoPrefixTry";
81 private static final String WITHOUT_CAMEL_CASE3 = "-1-123g-123ga-a";
82 private static final String WITH_CAMEL_CASE3 = "yangAutoPrefix1123G123Gaa";
83 private static final String WITHOUT_CAMEL_CASE4 = "a-b-c-d-e-f-g-h";
84 private static final String WITH_CAMEL_CASE4 = "aBcDeFgh";
janani b4a6711a2016-05-17 13:12:22 +053085 private static final String WITHOUT_CAMEL_CASE5 = "TestName";
86 private static final String WITH_CAMEL_CASE5 = "testName";
87 private static final String WITHOUT_CAMEL_CASE6 = "TEST-NAME";
88 private static final String WITH_CAMEL_CASE6 = "testName";
89 private static final String WITHOUT_CAMEL_CASE7 = "TESTNAME";
90 private static final String WITH_CAMEL_CASE7 = "testname";
91 private static final String WITHOUT_CAMEL_CASE8 = "TE-ST-NA-ME";
92 private static final String WITH_CAMEL_CASE8 = "teStNaMe";
93 private static final String WITHOUT_CAMEL_CASE9 = "TEST3NAME";
94 private static final String WITH_CAMEL_CASE9 = "test3Name";
95 private static final String WITHOUT_CAMEL_CASE10 = "TEST3";
96 private static final String WITH_CAMEL_CASE10 = "test3";
97 private static final String WITHOUT_CAMEL_CASE11 = "TEST3nAMe";
98 private static final String WITH_CAMEL_CASE11 = "test3Name";
99 private static final String WITHOUT_CAMEL_CASE12 = "TEST3name";
100 private static final String WITH_CAMEL_CASE12 = "test3Name";
janani bdd1314f2016-05-19 17:39:50 +0530101 private static final String WITHOUT_CAMEL_CASE13 = "t-RY";
102 private static final String WITH_CAMEL_CASE13 = "tRy";
103 private static final String WITHOUT_CAMEL_CASE14 = "TRY";
104 private static final String WITH_CAMEL_CASE14 = "yangAutoPrefixTry";
Bharat saraswal2f11f652016-03-25 18:19:46 +0530105 private static final String WITHOUT_CAPITAL = "test_this";
106 private static final String WITH_CAPITAL = "Test_this";
107 private static final String WITH_SMALL = "test_this";
janani bdd1314f2016-05-19 17:39:50 +0530108 private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry";
109 private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa";
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530110 private static final String DATE_FORMAT = "yyyy-MM-dd";
111 private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT);
janani bdd1314f2016-05-19 17:39:50 +0530112 private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
Gaurav Agrawalc5f63272016-06-16 13:09:53 +0530113 private static final String BASE_DIR_PKG = "target.UnitTestCase.";
114 private static final String DIR_PATH = "exist1.exist2.exist3";
115 private static final String PKG_INFO = "package-info.java";
116 private static final String BASE_PKG = "target/UnitTestCase";
117 private static final String TEST_DATA_1 = "This is to append a text to the file first1\n";
b.janani1fef2732016-03-04 12:29:05 +0530118
b.janani8b8ebdc2016-02-25 12:25:55 +0530119 /**
120 * Unit test for private constructor.
121 *
Gaurav Agrawalc5f63272016-06-16 13:09:53 +0530122 * @throws SecurityException if any security violation is observed.
123 * @throws NoSuchMethodException if when the method is not found.
124 * @throws IllegalArgumentException if there is illegal argument found.
125 * @throws InstantiationException if instantiation is provoked for the
126 * private constructor.
127 * @throws IllegalAccessException if instance is provoked or a method is
128 * provoked.
Vinod Kumar S38046502016-03-23 15:30:27 +0530129 * @throws InvocationTargetException when an exception occurs by the method
Gaurav Agrawalc5f63272016-06-16 13:09:53 +0530130 * or constructor.
b.janani8b8ebdc2016-02-25 12:25:55 +0530131 */
b.janani1fef2732016-03-04 12:29:05 +0530132 @Test
b.janani8b8ebdc2016-02-25 12:25:55 +0530133 public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
Vinod Kumar S38046502016-03-23 15:30:27 +0530134 InstantiationException, IllegalAccessException, InvocationTargetException {
Bharat saraswal2f11f652016-03-25 18:19:46 +0530135
Gaurav Agrawalc5f63272016-06-16 13:09:53 +0530136 Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class};
b.janani8b8ebdc2016-02-25 12:25:55 +0530137 for (Class<?> clazz : classesToConstruct) {
138 Constructor<?> constructor = clazz.getDeclaredConstructor();
139 constructor.setAccessible(true);
Bharat saraswal6ef0b762016-04-05 12:45:45 +0530140 assertThat(null, not(constructor.newInstance()));
b.janani8b8ebdc2016-02-25 12:25:55 +0530141 }
142 }
143
144 /**
b.janani8b8ebdc2016-02-25 12:25:55 +0530145 * Unit test for root package generation with revision complexity.
146 */
147 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530148 public void getRootPackageTest() throws ParseException {
janani bdd1314f2016-05-19 17:39:50 +0530149 conflictResolver.setPrefixForIdentifier(null);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530150 Date date = simpleDateFormat.parse(DATE1);
151 String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, date, conflictResolver);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530152 assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
153 + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
b.janani8b8ebdc2016-02-25 12:25:55 +0530154 }
155
156 /**
janani bdd1314f2016-05-19 17:39:50 +0530157 * Unit test for root package generation with invalid prefix.
158 */
159 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530160 public void getRootPackageWithInvalidPrefix() throws TranslatorException, ParseException {
janani bdd1314f2016-05-19 17:39:50 +0530161 thrown.expect(TranslatorException.class);
162 thrown.expectMessage("The given prefix in pom.xml is invalid.");
163 conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530164 Date date = simpleDateFormat.parse(DATE1);
165 String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, date,
166 conflictResolver);
janani bdd1314f2016-05-19 17:39:50 +0530167 }
168
169 /**
b.janani1fef2732016-03-04 12:29:05 +0530170 * Unit test for root package generation with special characters presence.
171 */
172 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530173 public void getRootPackageWithSpecialCharactersTest() throws ParseException {
janani bdd1314f2016-05-19 17:39:50 +0530174 conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530175 Date date = simpleDateFormat.parse(DATE1);
176 String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, date, conflictResolver);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530177 assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
178 + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530179 conflictResolver.setPrefixForIdentifier(null);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530180 String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530181 assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
182 + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true));
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530183 String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, date, conflictResolver);
janani bdd1314f2016-05-19 17:39:50 +0530184 assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
185 + PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true));
186 conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530187 String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, date, conflictResolver);
janani bdd1314f2016-05-19 17:39:50 +0530188 assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
189 + PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true));
190
b.janani1fef2732016-03-04 12:29:05 +0530191 }
192
193 /**
194 * Unit test for root package generation without complexity in revision.
b.janani8b8ebdc2016-02-25 12:25:55 +0530195 */
196 @Test
Vidyashree Ramadeac28b2016-06-20 15:12:43 +0530197 public void getRootPackageWithRevTest() throws ParseException {
198 Date date = simpleDateFormat.parse(DATE2);
199 String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, date, null);
Bharat saraswal2f11f652016-03-25 18:19:46 +0530200 assertThat(rootPkgWithRev.equals(
201 DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
b.janani1fef2732016-03-04 12:29:05 +0530202 is(true));
b.janani8b8ebdc2016-02-25 12:25:55 +0530203 }
204
205 /**
206 * Unit test for capitalizing the incoming string.
207 */
208 @Test
209 public void getCapitalCaseTest() {
janani b4a6711a2016-05-17 13:12:22 +0530210 String capitalCase = getCapitalCase(WITHOUT_CAPITAL);
b.janani1fef2732016-03-04 12:29:05 +0530211 assertThat(capitalCase.equals(WITH_CAPITAL), is(true));
b.janani8b8ebdc2016-02-25 12:25:55 +0530212 }
213
214 /**
215 * Unit test for getting the camel case for the received string.
216 */
217 @Test
218 public void getCamelCaseTest() {
janani bdd1314f2016-05-19 17:39:50 +0530219 conflictResolver.setPrefixForIdentifier(null);
220 String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, conflictResolver);
b.janani1fef2732016-03-04 12:29:05 +0530221 assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530222 String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, conflictResolver);
janani bde4ffab2016-04-15 16:18:30 +0530223 assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530224 String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver);
janani bde4ffab2016-04-15 16:18:30 +0530225 assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530226 String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
janani bde4ffab2016-04-15 16:18:30 +0530227 assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530228 String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, conflictResolver);
janani bde4ffab2016-04-15 16:18:30 +0530229 assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530230 String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530231 assertThat(camelCase5.equals(WITH_CAMEL_CASE5), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530232 String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530233 assertThat(camelCase6.equals(WITH_CAMEL_CASE6), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530234 String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530235 assertThat(camelCase7.equals(WITH_CAMEL_CASE7), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530236 String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530237 assertThat(camelCase8.equals(WITH_CAMEL_CASE8), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530238 String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530239 assertThat(camelCase9.equals(WITH_CAMEL_CASE9), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530240 String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530241 assertThat(camelCase10.equals(WITH_CAMEL_CASE10), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530242 String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530243 assertThat(camelCase11.equals(WITH_CAMEL_CASE11), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530244 String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, conflictResolver);
janani b4a6711a2016-05-17 13:12:22 +0530245 assertThat(camelCase12.equals(WITH_CAMEL_CASE12), is(true));
janani bdd1314f2016-05-19 17:39:50 +0530246 String camelCase13 = getCamelCase(WITHOUT_CAMEL_CASE13, conflictResolver);
247 assertThat(camelCase13.equals(WITH_CAMEL_CASE13), is(true));
248 String camelCase14 = getCamelCase(WITHOUT_CAMEL_CASE14, conflictResolver);
249 assertThat(camelCase14.equals(WITH_CAMEL_CASE14), is(true));
250 }
251
252 /**
253 * Unit test for getting the camel case along with the prefix provided.
254 */
255 @Test
256 public void getCamelCaseWithPrefixTest() {
257
258 conflictResolver.setPrefixForIdentifier(VALID_PREFIX);
259 String camelCase = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver);
260 assertThat(camelCase.equals(WITH_CAMEL_CASE_WITH_PREFIX), is(true));
261 conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1);
262 String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
263 assertThat(camelCase2.equals(WITH_CAMEL_CASE_WITH_PREFIX1), is(true));
264 }
265
266 /**
267 * Unit test for getting the camel case along with the invalid prefix provided.
268 */
269 @Test
270 public void getCamelCaseWithInvalidPrefixTest() throws TranslatorException {
271
272 thrown.expect(TranslatorException.class);
273 thrown.expectMessage("The given prefix in pom.xml is invalid.");
274 conflictResolver.setPrefixForIdentifier(INVALID_PREFIX);
275 String camelCase = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver);
b.janani8b8ebdc2016-02-25 12:25:55 +0530276 }
Bharat saraswal2f11f652016-03-25 18:19:46 +0530277
278 /**
279 * Unit test for getting the camel case for the received string.
280 */
281 @Test
282 public void getSmallCaseTest() {
Bharat saraswal2f11f652016-03-25 18:19:46 +0530283 String smallCase = getSmallCase(WITHOUT_CAPITAL);
284 assertThat(smallCase.equals(WITH_SMALL), is(true));
285 }
286
287 /**
288 * Unit test for getting the camel case for the received string.
289 */
290 @Test
291 public void getPackageFromPathTest() {
Bharat saraswal2f11f652016-03-25 18:19:46 +0530292 String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE);
293 assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true));
294 }
295
296 /**
297 * Unit test for getting the camel case for the received string.
298 */
299 @Test
300 public void getPathFromPackageTest() {
Bharat saraswal2f11f652016-03-25 18:19:46 +0530301 String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD);
302 assertThat(path.equals(PARENT_PACKAGE), is(true));
303 }
Gaurav Agrawalc5f63272016-06-16 13:09:53 +0530304
305
306 /**
307 * This test case checks whether the package is existing.
308 *
309 * @throws IOException when failed to create a test file
310 */
311 @Test
312 public void packageExistTest() throws IOException {
313
314 String strPath = BASE_DIR_PKG + DIR_PATH;
315 File createDir = new File(strPath.replace(PERIOD, SLASH));
316 createDir.mkdirs();
317 File createFile = new File(createDir + SLASH + PKG_INFO);
318 createFile.createNewFile();
319 assertThat(true, is(doesPackageExist(strPath)));
320 createDir.delete();
321 deleteDirectory(createDir);
322 }
b.janani8b8ebdc2016-02-25 12:25:55 +0530323}