Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | |
Gaurav Agrawal | c5f6327 | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.plugin.manager; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 18 | |
| 19 | import java.io.IOException; |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 21 | import org.apache.maven.plugin.MojoExecutionException; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 22 | import org.junit.Test; |
| 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 25 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
Shankara-Huawei | bdf24bb | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 28 | |
| 29 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 30 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Unit tests for union translator. |
| 34 | */ |
| 35 | public final class UnionTranslatorTest { |
| 36 | |
| 37 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 38 | |
| 39 | /** |
| 40 | * Checks union translation should not result in any exception. |
| 41 | */ |
| 42 | @Test |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 43 | public void processUnionTranslator() |
| 44 | throws IOException, ParserException { |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 45 | |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 46 | YangNode node = manager.getDataModel("src/test/resources/UnionTranslator.yang"); |
| 47 | |
| 48 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
VinodKumarS-Huawei | cb3a1f5 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 49 | yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/"); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 50 | |
Bharat saraswal | 33dfa01 | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 51 | generateJavaCode(node, yangPluginConfig); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 52 | |
Bharat saraswal | 991f688 | 2016-06-17 12:16:25 +0530 | [diff] [blame] | 53 | deleteDirectory("target/UnionTestGenFile/"); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 54 | } |
| 55 | |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 56 | /** |
| 57 | * Unit test case to test conflicting types. |
| 58 | * |
| 59 | * @throws IOException when fails to do IO operations |
| 60 | * @throws MojoExecutionException when fails to do mojo operations |
| 61 | */ |
| 62 | @Test |
| 63 | public void processUnionIntUintConflictingTypes() throws IOException, MojoExecutionException { |
| 64 | String searchDir = "src/test/resources/unionTranslator/intuint"; |
| 65 | YangUtilManager utilManager = new YangUtilManager(); |
| 66 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 67 | utilManager.parseYangFileInfoSet(); |
| 68 | utilManager.createYangNodeSet(); |
| 69 | utilManager.resolveDependenciesUsingLinker(); |
| 70 | |
| 71 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 72 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 73 | |
| 74 | utilManager.translateToJava(yangPluginConfig); |
| 75 | deleteDirectory("target/unionTranslator/"); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Unit test case to test conflicting types. |
| 80 | * |
| 81 | * @throws IOException when fails to do IO operations |
| 82 | * @throws MojoExecutionException when fails to do mojo operations |
| 83 | */ |
| 84 | @Test |
| 85 | public void processUnionUintIntConflictingTypes() throws IOException, MojoExecutionException { |
| 86 | String searchDir = "src/test/resources/unionTranslator/uintint"; |
| 87 | YangUtilManager utilManager = new YangUtilManager(); |
| 88 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 89 | utilManager.parseYangFileInfoSet(); |
| 90 | utilManager.createYangNodeSet(); |
| 91 | utilManager.resolveDependenciesUsingLinker(); |
| 92 | |
| 93 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 94 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 95 | |
| 96 | utilManager.translateToJava(yangPluginConfig); |
| 97 | deleteDirectory("target/unionTranslator/"); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Unit test case to test conflicting types. |
| 102 | * |
| 103 | * @throws IOException when fails to do IO operations |
| 104 | * @throws MojoExecutionException when fails to do mojo operations |
| 105 | */ |
| 106 | @Test |
| 107 | public void processUnionLongUlongConflictingTypes() throws IOException, MojoExecutionException { |
| 108 | String searchDir = "src/test/resources/unionTranslator/longulong"; |
| 109 | YangUtilManager utilManager = new YangUtilManager(); |
| 110 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 111 | utilManager.parseYangFileInfoSet(); |
| 112 | utilManager.createYangNodeSet(); |
| 113 | utilManager.resolveDependenciesUsingLinker(); |
| 114 | |
| 115 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 116 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 117 | |
| 118 | utilManager.translateToJava(yangPluginConfig); |
| 119 | deleteDirectory("target/unionTranslator/"); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Unit test case to test conflicting types. |
| 124 | * |
| 125 | * @throws IOException when fails to do IO operations |
| 126 | * @throws MojoExecutionException when fails to do mojo operations |
| 127 | */ |
| 128 | @Test |
| 129 | public void processUnionUlongLongConflictingTypes() throws IOException, MojoExecutionException { |
| 130 | String searchDir = "src/test/resources/unionTranslator/ulonglong"; |
| 131 | YangUtilManager utilManager = new YangUtilManager(); |
| 132 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 133 | utilManager.parseYangFileInfoSet(); |
| 134 | utilManager.createYangNodeSet(); |
| 135 | utilManager.resolveDependenciesUsingLinker(); |
| 136 | |
| 137 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 138 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 139 | |
| 140 | utilManager.translateToJava(yangPluginConfig); |
| 141 | deleteDirectory("target/unionTranslator/"); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Unit test case to test conflicting types. |
| 146 | * |
| 147 | * @throws IOException when fails to do IO operations |
| 148 | * @throws MojoExecutionException when fails to do mojo operations |
| 149 | */ |
| 150 | @Test |
| 151 | public void processUnionIntUintUlongLongConflictingTypes() throws IOException, MojoExecutionException { |
| 152 | String searchDir = "src/test/resources/unionTranslator/intuintulonglong"; |
| 153 | YangUtilManager utilManager = new YangUtilManager(); |
| 154 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 155 | utilManager.parseYangFileInfoSet(); |
| 156 | utilManager.createYangNodeSet(); |
| 157 | utilManager.resolveDependenciesUsingLinker(); |
| 158 | |
| 159 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 160 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 161 | |
| 162 | utilManager.translateToJava(yangPluginConfig); |
| 163 | deleteDirectory("target/unionTranslator/"); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Unit test case to test conflicting types. |
| 168 | * |
| 169 | * @throws IOException when fails to do IO operations |
| 170 | * @throws MojoExecutionException when fails to do mojo operations |
| 171 | */ |
| 172 | @Test |
| 173 | public void processUnionIntUintUlongLongStringConflictingTypes() throws IOException, |
| 174 | MojoExecutionException { |
| 175 | String searchDir = "src/test/resources/unionTranslator/intuintulonglongstring"; |
| 176 | YangUtilManager utilManager = new YangUtilManager(); |
| 177 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 178 | utilManager.parseYangFileInfoSet(); |
| 179 | utilManager.createYangNodeSet(); |
| 180 | utilManager.resolveDependenciesUsingLinker(); |
| 181 | |
| 182 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 183 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 184 | |
| 185 | utilManager.translateToJava(yangPluginConfig); |
| 186 | deleteDirectory("target/unionTranslator/"); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Unit test case to test conflicting types. |
| 191 | * |
| 192 | * @throws IOException when fails to do IO operations |
| 193 | * @throws MojoExecutionException when fails to do mojo operations |
| 194 | */ |
| 195 | @Test |
| 196 | public void processUnionIntUintStringConflictingTypes() throws IOException, |
| 197 | MojoExecutionException { |
| 198 | String searchDir = "src/test/resources/unionTranslator/intuintstring"; |
| 199 | YangUtilManager utilManager = new YangUtilManager(); |
| 200 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 201 | utilManager.parseYangFileInfoSet(); |
| 202 | utilManager.createYangNodeSet(); |
| 203 | utilManager.resolveDependenciesUsingLinker(); |
| 204 | |
| 205 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 206 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
Bharat saraswal | e707f03 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 207 | |
| 208 | utilManager.translateToJava(yangPluginConfig); |
| 209 | deleteDirectory("target/unionTranslator/"); |
| 210 | } |
| 211 | |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 212 | // TODO enhance the test cases, after having a framework of translator test. |
| 213 | } |