Gaurav Agrawal | 97a5e1c | 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 | de75bea | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.plugin.manager; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 18 | |
| 19 | import java.io.IOException; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 21 | import org.apache.maven.plugin.MojoExecutionException; |
Gaurav Agrawal | 97a5e1c | 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 | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 28 | |
| 29 | import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 30 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; |
Gaurav Agrawal | 97a5e1c | 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 | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 43 | public void processUnionTranslator() |
| 44 | throws IOException, ParserException { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 45 | |
Gaurav Agrawal | 97a5e1c | 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 | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 49 | yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/"); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 50 | yangPluginConfig.setManagerCodeGenDir("target/UnionTestGenFile/"); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 51 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 52 | generateJavaCode(node, yangPluginConfig); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 53 | |
Bharat saraswal | 9c16a2e | 2016-06-17 12:16:25 +0530 | [diff] [blame] | 54 | deleteDirectory("target/UnionTestGenFile/"); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 55 | } |
| 56 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 57 | /** |
| 58 | * Unit test case to test conflicting types. |
| 59 | * |
| 60 | * @throws IOException when fails to do IO operations |
| 61 | * @throws MojoExecutionException when fails to do mojo operations |
| 62 | */ |
| 63 | @Test |
| 64 | public void processUnionIntUintConflictingTypes() throws IOException, MojoExecutionException { |
| 65 | String searchDir = "src/test/resources/unionTranslator/intuint"; |
| 66 | YangUtilManager utilManager = new YangUtilManager(); |
| 67 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 68 | utilManager.parseYangFileInfoSet(); |
| 69 | utilManager.createYangNodeSet(); |
| 70 | utilManager.resolveDependenciesUsingLinker(); |
| 71 | |
| 72 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 73 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
| 74 | yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); |
| 75 | |
| 76 | utilManager.translateToJava(yangPluginConfig); |
| 77 | deleteDirectory("target/unionTranslator/"); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Unit test case to test conflicting types. |
| 82 | * |
| 83 | * @throws IOException when fails to do IO operations |
| 84 | * @throws MojoExecutionException when fails to do mojo operations |
| 85 | */ |
| 86 | @Test |
| 87 | public void processUnionUintIntConflictingTypes() throws IOException, MojoExecutionException { |
| 88 | String searchDir = "src/test/resources/unionTranslator/uintint"; |
| 89 | YangUtilManager utilManager = new YangUtilManager(); |
| 90 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 91 | utilManager.parseYangFileInfoSet(); |
| 92 | utilManager.createYangNodeSet(); |
| 93 | utilManager.resolveDependenciesUsingLinker(); |
| 94 | |
| 95 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 96 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
| 97 | yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); |
| 98 | |
| 99 | utilManager.translateToJava(yangPluginConfig); |
| 100 | deleteDirectory("target/unionTranslator/"); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Unit test case to test conflicting types. |
| 105 | * |
| 106 | * @throws IOException when fails to do IO operations |
| 107 | * @throws MojoExecutionException when fails to do mojo operations |
| 108 | */ |
| 109 | @Test |
| 110 | public void processUnionLongUlongConflictingTypes() throws IOException, MojoExecutionException { |
| 111 | String searchDir = "src/test/resources/unionTranslator/longulong"; |
| 112 | YangUtilManager utilManager = new YangUtilManager(); |
| 113 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 114 | utilManager.parseYangFileInfoSet(); |
| 115 | utilManager.createYangNodeSet(); |
| 116 | utilManager.resolveDependenciesUsingLinker(); |
| 117 | |
| 118 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 119 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
| 120 | yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); |
| 121 | |
| 122 | utilManager.translateToJava(yangPluginConfig); |
| 123 | deleteDirectory("target/unionTranslator/"); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Unit test case to test conflicting types. |
| 128 | * |
| 129 | * @throws IOException when fails to do IO operations |
| 130 | * @throws MojoExecutionException when fails to do mojo operations |
| 131 | */ |
| 132 | @Test |
| 133 | public void processUnionUlongLongConflictingTypes() throws IOException, MojoExecutionException { |
| 134 | String searchDir = "src/test/resources/unionTranslator/ulonglong"; |
| 135 | YangUtilManager utilManager = new YangUtilManager(); |
| 136 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 137 | utilManager.parseYangFileInfoSet(); |
| 138 | utilManager.createYangNodeSet(); |
| 139 | utilManager.resolveDependenciesUsingLinker(); |
| 140 | |
| 141 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 142 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
| 143 | yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); |
| 144 | |
| 145 | utilManager.translateToJava(yangPluginConfig); |
| 146 | deleteDirectory("target/unionTranslator/"); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Unit test case to test conflicting types. |
| 151 | * |
| 152 | * @throws IOException when fails to do IO operations |
| 153 | * @throws MojoExecutionException when fails to do mojo operations |
| 154 | */ |
| 155 | @Test |
| 156 | public void processUnionIntUintUlongLongConflictingTypes() throws IOException, MojoExecutionException { |
| 157 | String searchDir = "src/test/resources/unionTranslator/intuintulonglong"; |
| 158 | YangUtilManager utilManager = new YangUtilManager(); |
| 159 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 160 | utilManager.parseYangFileInfoSet(); |
| 161 | utilManager.createYangNodeSet(); |
| 162 | utilManager.resolveDependenciesUsingLinker(); |
| 163 | |
| 164 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 165 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
| 166 | yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); |
| 167 | |
| 168 | utilManager.translateToJava(yangPluginConfig); |
| 169 | deleteDirectory("target/unionTranslator/"); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Unit test case to test conflicting types. |
| 174 | * |
| 175 | * @throws IOException when fails to do IO operations |
| 176 | * @throws MojoExecutionException when fails to do mojo operations |
| 177 | */ |
| 178 | @Test |
| 179 | public void processUnionIntUintUlongLongStringConflictingTypes() throws IOException, |
| 180 | MojoExecutionException { |
| 181 | String searchDir = "src/test/resources/unionTranslator/intuintulonglongstring"; |
| 182 | YangUtilManager utilManager = new YangUtilManager(); |
| 183 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 184 | utilManager.parseYangFileInfoSet(); |
| 185 | utilManager.createYangNodeSet(); |
| 186 | utilManager.resolveDependenciesUsingLinker(); |
| 187 | |
| 188 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 189 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
| 190 | yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); |
| 191 | |
| 192 | utilManager.translateToJava(yangPluginConfig); |
| 193 | deleteDirectory("target/unionTranslator/"); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Unit test case to test conflicting types. |
| 198 | * |
| 199 | * @throws IOException when fails to do IO operations |
| 200 | * @throws MojoExecutionException when fails to do mojo operations |
| 201 | */ |
| 202 | @Test |
| 203 | public void processUnionIntUintStringConflictingTypes() throws IOException, |
| 204 | MojoExecutionException { |
| 205 | String searchDir = "src/test/resources/unionTranslator/intuintstring"; |
| 206 | YangUtilManager utilManager = new YangUtilManager(); |
| 207 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 208 | utilManager.parseYangFileInfoSet(); |
| 209 | utilManager.createYangNodeSet(); |
| 210 | utilManager.resolveDependenciesUsingLinker(); |
| 211 | |
| 212 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 213 | yangPluginConfig.setCodeGenDir("target/unionTranslator/"); |
| 214 | yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/"); |
| 215 | |
| 216 | utilManager.translateToJava(yangPluginConfig); |
| 217 | deleteDirectory("target/unionTranslator/"); |
| 218 | } |
| 219 | |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 220 | // TODO enhance the test cases, after having a framework of translator test. |
| 221 | } |