b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 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 | |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 19 | import java.io.File; |
| 20 | import java.io.IOException; |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 21 | import java.lang.reflect.Constructor; |
| 22 | import java.lang.reflect.InvocationTargetException; |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 23 | import java.text.ParseException; |
| 24 | import java.text.SimpleDateFormat; |
| 25 | import java.util.Date; |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 26 | |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 27 | import org.junit.Rule; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 28 | import org.junit.Test; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 29 | import org.junit.rules.ExpectedException; |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangRevision; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 33 | |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 34 | import static org.apache.commons.io.FileUtils.deleteDirectory; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 35 | import static org.hamcrest.core.Is.is; |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 36 | import static org.hamcrest.core.IsNot.not; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 37 | import static org.junit.Assert.assertThat; |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.doesPackageExist; |
| 39 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG; |
| 41 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 42 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 44 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 45 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath; |
| 46 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; |
Vinod Kumar S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 48 | |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 49 | /** |
| 50 | * Unit tests for java identifier syntax. |
| 51 | */ |
| 52 | public final class JavaIdentifierSyntaxTest { |
| 53 | |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 54 | @Rule |
| 55 | public ExpectedException thrown = ExpectedException.none(); |
| 56 | |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 57 | private static final String PARENT_PACKAGE = "test5/test6/test7"; |
| 58 | private static final String CHILD_PACKAGE = "test1:test2:test3"; |
| 59 | private static final String DATE1 = "2000-1-5"; |
| 60 | private static final String DATE2 = "1992-01-25"; |
| 61 | private static final String PARENT_WITH_PERIOD = "test5.test6.test7"; |
| 62 | private static final String CHILD_WITH_PERIOD = "test1.test2.test3"; |
| 63 | private static final String DATE_WITH_REV1 = "rev20000105"; |
| 64 | private static final String DATE_WITH_REV2 = "rev19920125"; |
| 65 | private static final String VERSION_NUMBER = "v1"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 66 | private static final String VALID_PREFIX = "123add-prefix"; |
| 67 | private static final String INVALID_PREFIX = "-*()&^&#$%"; |
| 68 | private static final String INVALID_PREFIX1 = "abc~!@#$%^&*()_+}{:<>?`1234567890-=[]''|,./SS"; |
| 69 | private static final String INVALID_NAME_SPACE_FOR_INVALID_PREFIX = "try:#test3:9case3"; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 70 | private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3"; |
| 71 | private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 72 | private static final String INVALID_NAME_SPACE3 = "CONST:TRY://9test3"; |
| 73 | private static final String VALID_NAME_SPACE1 = "123addprefixbyte.test2.123addprefix9test3"; |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 74 | private static final String VALID_NAME_SPACE2 = "yangautoprefixconst.test2.yangautoprefix9test3"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 75 | private static final String VALID_NAME_SPACE3 = "abc1234567890ssconst.test2.abc1234567890ss9test3"; |
| 76 | private static final String VALID_NAME_SPACE4 = "yangautoprefixconst.yangautoprefixtry.yangautoprefix9test3"; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 77 | private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier"; |
| 78 | private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier"; |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 79 | private static final String WITHOUT_CAMEL_CASE1 = ".-_try-._-.123"; |
| 80 | private static final String WITH_CAMEL_CASE1 = "try123"; |
| 81 | private static final String WITHOUT_CAMEL_CASE2 = "_try"; |
| 82 | private static final String WITH_CAMEL_CASE2 = "yangAutoPrefixTry"; |
| 83 | private static final String WITHOUT_CAMEL_CASE3 = "-1-123g-123ga-a"; |
| 84 | private static final String WITH_CAMEL_CASE3 = "yangAutoPrefix1123G123Gaa"; |
| 85 | private static final String WITHOUT_CAMEL_CASE4 = "a-b-c-d-e-f-g-h"; |
| 86 | private static final String WITH_CAMEL_CASE4 = "aBcDeFgh"; |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 87 | private static final String WITHOUT_CAMEL_CASE5 = "TestName"; |
| 88 | private static final String WITH_CAMEL_CASE5 = "testName"; |
| 89 | private static final String WITHOUT_CAMEL_CASE6 = "TEST-NAME"; |
| 90 | private static final String WITH_CAMEL_CASE6 = "testName"; |
| 91 | private static final String WITHOUT_CAMEL_CASE7 = "TESTNAME"; |
| 92 | private static final String WITH_CAMEL_CASE7 = "testname"; |
| 93 | private static final String WITHOUT_CAMEL_CASE8 = "TE-ST-NA-ME"; |
| 94 | private static final String WITH_CAMEL_CASE8 = "teStNaMe"; |
| 95 | private static final String WITHOUT_CAMEL_CASE9 = "TEST3NAME"; |
| 96 | private static final String WITH_CAMEL_CASE9 = "test3Name"; |
| 97 | private static final String WITHOUT_CAMEL_CASE10 = "TEST3"; |
| 98 | private static final String WITH_CAMEL_CASE10 = "test3"; |
| 99 | private static final String WITHOUT_CAMEL_CASE11 = "TEST3nAMe"; |
| 100 | private static final String WITH_CAMEL_CASE11 = "test3Name"; |
| 101 | private static final String WITHOUT_CAMEL_CASE12 = "TEST3name"; |
| 102 | private static final String WITH_CAMEL_CASE12 = "test3Name"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 103 | private static final String WITHOUT_CAMEL_CASE13 = "t-RY"; |
| 104 | private static final String WITH_CAMEL_CASE13 = "tRy"; |
| 105 | private static final String WITHOUT_CAMEL_CASE14 = "TRY"; |
| 106 | private static final String WITH_CAMEL_CASE14 = "yangAutoPrefixTry"; |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 107 | private static final String WITHOUT_CAPITAL = "test_this"; |
| 108 | private static final String WITH_CAPITAL = "Test_this"; |
| 109 | private static final String WITH_SMALL = "test_this"; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 110 | private static final String WITH_CAMEL_CASE_WITH_PREFIX = "123addPrefixTry"; |
| 111 | private static final String WITH_CAMEL_CASE_WITH_PREFIX1 = "abc1234567890Ss1123G123Gaa"; |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 112 | private static final String DATE_FORMAT = "yyyy-MM-dd"; |
| 113 | private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 114 | private static YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 115 | private static final String BASE_DIR_PKG = "target.UnitTestCase."; |
| 116 | private static final String DIR_PATH = "exist1.exist2.exist3"; |
| 117 | private static final String PKG_INFO = "package-info.java"; |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 118 | |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 119 | /** |
| 120 | * Unit test for private constructor. |
| 121 | * |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 122 | * @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 S | 9f26ae5 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 129 | * @throws InvocationTargetException when an exception occurs by the method |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 130 | * or constructor. |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 131 | */ |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 132 | @Test |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 133 | public void callPrivateConstructors() |
| 134 | throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
| 135 | InstantiationException, IllegalAccessException, InvocationTargetException { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 136 | |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 137 | Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class}; |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 138 | for (Class<?> clazz : classesToConstruct) { |
| 139 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 140 | constructor.setAccessible(true); |
Bharat saraswal | 780eca3 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 141 | assertThat(null, not(constructor.newInstance())); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 146 | * Unit test for root package generation with revision complexity. |
| 147 | */ |
| 148 | @Test |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 149 | public void getRootPackageTest() |
| 150 | throws ParseException { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 151 | conflictResolver.setPrefixForIdentifier(null); |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 152 | String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, getYangRevision(DATE1), conflictResolver); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 153 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 154 | + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true)); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /** |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 158 | * Unit test for root package generation with invalid prefix. |
| 159 | */ |
| 160 | @Test |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 161 | public void getRootPackageWithInvalidPrefix() |
| 162 | throws TranslatorException, ParseException { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 163 | thrown.expect(TranslatorException.class); |
| 164 | thrown.expectMessage("The given prefix in pom.xml is invalid."); |
| 165 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX); |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 166 | String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE_FOR_INVALID_PREFIX, getYangRevision(DATE1), |
| 167 | conflictResolver); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 171 | * Unit test for root package generation with special characters presence. |
| 172 | */ |
| 173 | @Test |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 174 | public void getRootPackageWithSpecialCharactersTest() |
| 175 | throws ParseException { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 176 | conflictResolver.setPrefixForIdentifier(VALID_PREFIX); |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 177 | String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, getYangRevision(DATE1), conflictResolver); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 178 | assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 179 | + PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 180 | conflictResolver.setPrefixForIdentifier(null); |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 181 | String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, getYangRevision(DATE1), conflictResolver); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 182 | assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 183 | + PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true)); |
| 184 | String rootPackage2 = getRootPackage((byte) 1, INVALID_NAME_SPACE3, getYangRevision(DATE1), conflictResolver); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 185 | assertThat(rootPackage2.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 186 | + PERIOD + VALID_NAME_SPACE4 + PERIOD + DATE_WITH_REV1), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 187 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1); |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 188 | String rootPackage3 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, getYangRevision(DATE1), conflictResolver); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 189 | assertThat(rootPackage3.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 190 | + PERIOD + VALID_NAME_SPACE3 + PERIOD + DATE_WITH_REV1), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 191 | |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Unit test for root package generation without complexity in revision. |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 196 | */ |
| 197 | @Test |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 198 | public void getRootPackageWithRevTest() |
| 199 | throws ParseException { |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 200 | Date date = simpleDateFormat.parse(DATE2); |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 201 | String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, getYangRevision(DATE2), null); |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 202 | assertThat(rootPkgWithRev.equals( |
| 203 | DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2), |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 204 | is(true)); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Unit test for capitalizing the incoming string. |
| 209 | */ |
| 210 | @Test |
| 211 | public void getCapitalCaseTest() { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 212 | String capitalCase = getCapitalCase(WITHOUT_CAPITAL); |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 213 | assertThat(capitalCase.equals(WITH_CAPITAL), is(true)); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Unit test for getting the camel case for the received string. |
| 218 | */ |
| 219 | @Test |
| 220 | public void getCamelCaseTest() { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 221 | conflictResolver.setPrefixForIdentifier(null); |
| 222 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE, conflictResolver); |
b.janani | e6d43af | 2016-03-04 12:29:05 +0530 | [diff] [blame] | 223 | assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 224 | String camelCase1 = getCamelCase(WITHOUT_CAMEL_CASE1, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 225 | assertThat(camelCase1.equals(WITH_CAMEL_CASE1), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 226 | String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 227 | assertThat(camelCase2.equals(WITH_CAMEL_CASE2), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 228 | String camelCase3 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 229 | assertThat(camelCase3.equals(WITH_CAMEL_CASE3), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 230 | String camelCase4 = getCamelCase(WITHOUT_CAMEL_CASE4, conflictResolver); |
janani b | 1c6acc4 | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 231 | assertThat(camelCase4.equals(WITH_CAMEL_CASE4), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 232 | String camelCase5 = getCamelCase(WITHOUT_CAMEL_CASE5, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 233 | assertThat(camelCase5.equals(WITH_CAMEL_CASE5), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 234 | String camelCase6 = getCamelCase(WITHOUT_CAMEL_CASE6, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 235 | assertThat(camelCase6.equals(WITH_CAMEL_CASE6), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 236 | String camelCase7 = getCamelCase(WITHOUT_CAMEL_CASE7, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 237 | assertThat(camelCase7.equals(WITH_CAMEL_CASE7), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 238 | String camelCase8 = getCamelCase(WITHOUT_CAMEL_CASE8, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 239 | assertThat(camelCase8.equals(WITH_CAMEL_CASE8), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 240 | String camelCase9 = getCamelCase(WITHOUT_CAMEL_CASE9, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 241 | assertThat(camelCase9.equals(WITH_CAMEL_CASE9), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 242 | String camelCase10 = getCamelCase(WITHOUT_CAMEL_CASE10, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 243 | assertThat(camelCase10.equals(WITH_CAMEL_CASE10), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 244 | String camelCase11 = getCamelCase(WITHOUT_CAMEL_CASE11, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 245 | assertThat(camelCase11.equals(WITH_CAMEL_CASE11), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 246 | String camelCase12 = getCamelCase(WITHOUT_CAMEL_CASE12, conflictResolver); |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 247 | assertThat(camelCase12.equals(WITH_CAMEL_CASE12), is(true)); |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 248 | String camelCase13 = getCamelCase(WITHOUT_CAMEL_CASE13, conflictResolver); |
| 249 | assertThat(camelCase13.equals(WITH_CAMEL_CASE13), is(true)); |
| 250 | String camelCase14 = getCamelCase(WITHOUT_CAMEL_CASE14, conflictResolver); |
| 251 | assertThat(camelCase14.equals(WITH_CAMEL_CASE14), is(true)); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Unit test for getting the camel case along with the prefix provided. |
| 256 | */ |
| 257 | @Test |
| 258 | public void getCamelCaseWithPrefixTest() { |
| 259 | |
| 260 | conflictResolver.setPrefixForIdentifier(VALID_PREFIX); |
| 261 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE2, conflictResolver); |
| 262 | assertThat(camelCase.equals(WITH_CAMEL_CASE_WITH_PREFIX), is(true)); |
| 263 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX1); |
| 264 | String camelCase2 = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver); |
| 265 | assertThat(camelCase2.equals(WITH_CAMEL_CASE_WITH_PREFIX1), is(true)); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Unit test for getting the camel case along with the invalid prefix provided. |
| 270 | */ |
| 271 | @Test |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 272 | public void getCamelCaseWithInvalidPrefixTest() |
| 273 | throws TranslatorException { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 274 | |
| 275 | thrown.expect(TranslatorException.class); |
| 276 | thrown.expectMessage("The given prefix in pom.xml is invalid."); |
| 277 | conflictResolver.setPrefixForIdentifier(INVALID_PREFIX); |
| 278 | String camelCase = getCamelCase(WITHOUT_CAMEL_CASE3, conflictResolver); |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 279 | } |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * Unit test for getting the camel case for the received string. |
| 283 | */ |
| 284 | @Test |
| 285 | public void getSmallCaseTest() { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 286 | String smallCase = getSmallCase(WITHOUT_CAPITAL); |
| 287 | assertThat(smallCase.equals(WITH_SMALL), is(true)); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Unit test for getting the camel case for the received string. |
| 292 | */ |
| 293 | @Test |
| 294 | public void getPackageFromPathTest() { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 295 | String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE); |
| 296 | assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true)); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Unit test for getting the camel case for the received string. |
| 301 | */ |
| 302 | @Test |
| 303 | public void getPathFromPackageTest() { |
Bharat saraswal | d532a4c | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 304 | String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD); |
| 305 | assertThat(path.equals(PARENT_PACKAGE), is(true)); |
| 306 | } |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 307 | |
| 308 | |
| 309 | /** |
| 310 | * This test case checks whether the package is existing. |
| 311 | * |
| 312 | * @throws IOException when failed to create a test file |
| 313 | */ |
| 314 | @Test |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 315 | public void packageExistTest() |
| 316 | throws IOException { |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 317 | |
| 318 | String strPath = BASE_DIR_PKG + DIR_PATH; |
| 319 | File createDir = new File(strPath.replace(PERIOD, SLASH)); |
| 320 | createDir.mkdirs(); |
| 321 | File createFile = new File(createDir + SLASH + PKG_INFO); |
| 322 | createFile.createNewFile(); |
| 323 | assertThat(true, is(doesPackageExist(strPath))); |
| 324 | createDir.delete(); |
| 325 | deleteDirectory(createDir); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 326 | deleteDirectory(new File(BASE_DIR_PKG.replace(PERIOD, SLASH))); |
Gaurav Agrawal | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 327 | } |
Bharat saraswal | 1edde62 | 2016-09-06 10:18:04 +0530 | [diff] [blame] | 328 | |
| 329 | private YangRevision getYangRevision(String date) { |
| 330 | YangRevision revision = new YangRevision(); |
| 331 | try { |
| 332 | revision.setRevDate(simpleDateFormat.parse(date)); |
| 333 | } catch (ParseException e) { |
| 334 | e.printStackTrace(); |
| 335 | } |
| 336 | return revision; |
| 337 | } |
b.janani | 0d4517a | 2016-02-25 12:25:55 +0530 | [diff] [blame] | 338 | } |