Added generation of Transfer Objects from Type Definitions.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / maven-yang-plugin-it / src / test / java / org / opendaylight / controller / yang2sources / plugin / it / YangToSourcesPluginTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.yang2sources.plugin.it;
9
10 import static org.junit.Assert.*;
11 import static org.junit.matchers.JUnitMatchers.*;
12
13 import java.io.File;
14
15 import org.apache.maven.it.VerificationException;
16 import org.apache.maven.it.Verifier;
17 import org.junit.Test;
18
19 public class YangToSourcesPluginTest {
20
21     @Test
22     public void testYangRootNotExist() {
23         try {
24             setUp("YangRootNotExist/", false);
25         } catch (VerificationException e) {
26             assertVerificationException(e,
27                     "[ERROR] yang-to-sources: Unable to parse yang files from unknown");
28             assertVerificationException(
29                     e,
30                     "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from unknown");
31             return;
32         }
33
34         fail("Verification exception should have been thrown");
35     }
36
37     @Test
38     public void testCorrect() throws VerificationException {
39         Verifier v = setUp("Correct/", false);
40         verifyCorrectLog(v);
41     }
42
43     static void verifyCorrectLog(Verifier v) throws VerificationException {
44         v.verifyErrorFreeLog();
45         v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from");
46         v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
47         v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
48     }
49
50     @Test
51     public void testNoGenerators() throws VerificationException {
52         Verifier v = setUp("NoGenerators/", false);
53         v.verifyErrorFreeLog();
54         v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
55     }
56
57     @Test
58     public void testUnknownGenerator() throws VerificationException {
59         Verifier v = setUp("UnknownGenerator/", true);
60         v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
61         v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
62         v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
63         v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
64         v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}");
65     }
66
67     @Test
68     public void testNoYangFiles() throws VerificationException {
69         Verifier v = setUp("NoYangFiles/", false);
70         v.verifyTextInLog("[WARNING] yang-to-sources: No yang file found in ");
71         v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
72         v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
73     }
74
75     static void assertVerificationException(VerificationException e,
76             String string) {
77         assertThat(e.getMessage(), containsString(string));
78     }
79
80     static Verifier setUp(String project, boolean ignoreF)
81             throws VerificationException {
82         Verifier verifier = new Verifier(new File("src/test/resources/"
83                 + project).getAbsolutePath());
84         if (ignoreF)
85             verifier.addCliOption("-fn");
86         verifier.executeGoal("generate-resources");
87         return verifier;
88     }
89
90 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.