blob: 817fb4e1da158871a7e97a6978341cc615493746 [file] [log] [blame]
Bharat saraswalb1170bd2016-07-14 13:26:18 +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.File;
20import java.io.IOException;
21
22import org.apache.maven.plugin.MojoExecutionException;
23import org.junit.Test;
24import org.onosproject.yangutils.parser.exceptions.ParserException;
25import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
26import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
27
28import static org.hamcrest.core.Is.is;
29import static org.junit.Assert.assertThat;
30import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
31
32/**
33 * Unit test case to test code generation for root nodes.
34 */
35public class ManagerCodeGeneratorTest {
36
37 private final YangUtilManager utilManager = new YangUtilManager();
38
39 /**
40 * Checks manager translation should not result in any exception.
41 *
42 * @throws MojoExecutionException
43 */
44 @Test
45 public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
46
47 String searchDir = "src/test/resources/manager";
48 utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
49 utilManager.parseYangFileInfoSet();
50 utilManager.createYangNodeSet();
51 utilManager.resolveDependenciesUsingLinker();
52
53 YangPluginConfig yangPluginConfig = new YangPluginConfig();
54 yangPluginConfig.setCodeGenDir("target/manager/");
55 yangPluginConfig.setManagerCodeGenDir("target/manager/");
56
57 utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
58 String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
59 String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
60 String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
61 File manager = new File(file1);
62 assertThat(false, is(manager.exists()));
63
64 File manager2 = new File(file2);
65 assertThat(false, is(manager2.exists()));
66
67 File manager3 = new File(file3);
68 assertThat(true, is(manager3.exists()));
69
70 deleteDirectory("target/manager/");
71 }
72
73 /**
74 * Checks manager translation in different package should not result in any exception.
75 *
76 * @throws MojoExecutionException
77 */
78 @Test
79 public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
80 MojoExecutionException {
81
82 String searchDir = "src/test/resources/manager";
83 utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
84 utilManager.parseYangFileInfoSet();
85 utilManager.createYangNodeSet();
86 utilManager.resolveDependenciesUsingLinker();
87
88 YangPluginConfig yangPluginConfig = new YangPluginConfig();
89 yangPluginConfig.setCodeGenDir("target/manager/");
90 yangPluginConfig.setManagerCodeGenDir("target/manager1/");
91
92 utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
93 String file3 = "target/manager1/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
94
95 File manager3 = new File(file3);
96 assertThat(true, is(manager3.exists()));
97
98 deleteDirectory("target/manager/");
99 deleteDirectory("target/manager1/");
100 }
101}