2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.yang2sources.plugin.it;
10 import static org.junit.Assert.*;
11 import static org.junit.matchers.JUnitMatchers.*;
15 import org.apache.maven.it.VerificationException;
16 import org.apache.maven.it.Verifier;
17 import org.junit.Test;
19 public class YangToSourcesPluginTest {
21 // TODO Test yang files in transitive dependencies
24 public void testYangRootNotExist() {
26 setUp("YangRootNotExist/", false);
27 } catch (VerificationException e) {
28 assertVerificationException(e,
29 "[ERROR] yang-to-sources: Unable to parse yang files from ");
30 assertVerificationException(
32 "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from ");
36 fail("Verification exception should have been thrown");
40 public void testCorrect() throws VerificationException {
41 Verifier v = setUp("Correct/", false);
46 public void testAdditionalConfiguration() throws VerificationException {
47 Verifier v = setUp("AdditionalConfig/", false);
48 v.verifyTextInLog("[INFO] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}");
49 v.verifyTextInLog("[INFO] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}");
53 public void testMissingYangInDep() throws VerificationException {
55 setUp("MissingYangInDep/", false);
56 } catch (VerificationException e) {
57 assertVerificationException(
59 "org.opendaylight.controller.yang.parser.util.YangValidationException: Not existing module imported:unknownDep:2013-02-27 by:private:2013-02-27");
63 fail("Verification exception should have been thrown");
66 static void verifyCorrectLog(Verifier v) throws VerificationException {
67 v.verifyErrorFreeLog();
68 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from");
69 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
70 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
74 public void testNoGenerators() throws VerificationException {
75 Verifier v = setUp("NoGenerators/", false);
76 v.verifyErrorFreeLog();
77 v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
81 public void testUnknownGenerator() throws VerificationException {
82 Verifier v = setUp("UnknownGenerator/", true);
83 v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
84 v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
85 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
86 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
87 v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}");
91 public void testNoYangFiles() throws VerificationException {
92 Verifier v = setUp("NoYangFiles/", false);
93 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from []");
94 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
95 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
98 static void assertVerificationException(VerificationException e,
100 assertThat(e.getMessage(), containsString(string));
103 static Verifier setUp(String project, boolean ignoreF)
104 throws VerificationException {
105 Verifier verifier = new Verifier(new File("src/test/resources/"
106 + project).getAbsolutePath());
108 verifier.addCliOption("-fn");
109 verifier.executeGoal("generate-sources");
114 public void testNoOutputDir() throws VerificationException {
115 Verifier v = YangToSourcesPluginTest.setUp("NoOutputDir/", false);
120 public void testFindResourceOnCp() throws VerificationException {
121 Verifier v1 = new Verifier(
122 new File("src/test/resources/GenerateTest1/").getAbsolutePath());
123 v1.executeGoal("clean");
124 v1.executeGoal("package");
125 v1.assertFilePresent("target/classes/META-INF/yang/testfile1.yang");
126 v1.assertFilePresent("target/classes/META-INF/yang/testfile2.yang");
127 v1.assertFilePresent("target/classes/META-INF/yang/testfile3.yang");
129 Verifier v2 = YangToSourcesPluginTest.setUp("GenerateTest2/", false);
130 v2.executeGoal("clean");
131 v2.executeGoal("package");
132 v2.assertFilePresent("target/classes/META-INF/yang/private.yang");
133 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile1.yang");
134 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile2.yang");
135 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile3.yang");