blob: 3c972926b6e9013c0a921d49b2d919c29d5d164e [file] [log] [blame]
Bharat saraswale707f032016-07-14 23:33:55 +05301/*
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
17package org.onosproject.yangutils.plugin.manager;
18
19import java.io.IOException;
20
21import org.apache.maven.plugin.MojoExecutionException;
22import org.junit.Test;
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053023import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
Bharat saraswale707f032016-07-14 23:33:55 +053024import org.onosproject.yangutils.parser.exceptions.ParserException;
25import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
Bharat saraswale707f032016-07-14 23:33:55 +053026
27import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
28
29/**
30 * Unit test case for typedef translator.
31 */
32public class TypeDefTranslatorTest {
33
34 private final YangUtilManager utilManager = new YangUtilManager();
35
36 /**
37 * Checks typedef translation should not result in any exception.
38 *
39 * @throws MojoExecutionException
40 */
41 @Test
42 public void processTypeDefTranslator() throws IOException, ParserException, MojoExecutionException {
43
Bharat saraswal6a5911f2016-08-02 18:43:16 +053044 String searchDir = "src/test/resources/typedefTranslator/without";
Bharat saraswale707f032016-07-14 23:33:55 +053045 utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
46 utilManager.parseYangFileInfoSet();
47 utilManager.createYangNodeSet();
48 utilManager.resolveDependenciesUsingLinker();
49
50 YangPluginConfig yangPluginConfig = new YangPluginConfig();
51 yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
Bharat saraswale707f032016-07-14 23:33:55 +053052 utilManager.translateToJava(yangPluginConfig);
53
54 deleteDirectory("target/typedefTranslator/");
55 }
56
Bharat saraswal6a5911f2016-08-02 18:43:16 +053057 /**
58 * Checks typedef translation should not result in any exception.
59 *
60 * @throws MojoExecutionException
61 */
62 @Test
63 public void processTypeDefWithRestrictionsTranslator() throws IOException, ParserException, MojoExecutionException {
64
Bharat saraswal6a5911f2016-08-02 18:43:16 +053065 String searchDir = "src/test/resources/typedefTranslator/with";
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/typedefTranslator/");
Bharat saraswal6a5911f2016-08-02 18:43:16 +053073 utilManager.translateToJava(yangPluginConfig);
74
75 deleteDirectory("target/typedefTranslator/");
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053076
Bharat saraswal6a5911f2016-08-02 18:43:16 +053077 }
Bharat saraswal2d90b0c2016-08-04 02:00:03 +053078
Bharat saraswale707f032016-07-14 23:33:55 +053079}