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.yangtools.yang2sources.plugin.it;
10 import static org.junit.Assert.*;
11 import static org.junit.matchers.JUnitMatchers.containsString;
16 import org.apache.maven.it.VerificationException;
17 import org.apache.maven.it.Verifier;
18 import org.junit.Test;
20 public class YangToSourcesPluginTestIT {
22 // TODO Test yang files in transitive dependencies
25 public void testYangRootNotExist() {
27 setUp("YangRootNotExist/", false);
28 } catch (VerificationException e) {
29 assertVerificationException(e,
30 "[ERROR] yang-to-sources: Unable to parse yang files from ");
31 assertVerificationException(
33 "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from ");
37 fail("Verification exception should have been thrown");
41 public void testCorrect() throws VerificationException {
42 Verifier v = setUp("Correct/", false);
47 public void testAdditionalConfiguration() throws VerificationException {
48 Verifier v = setUp("AdditionalConfig/", false);
49 v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}");
50 v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}");
51 v.verifyTextInLog(File.separator
52 + "files marked as resources: META-INF/yang");
53 v.verifyTextInLog("target"
55 + "generated-resources marked as resources for generator: org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl");
59 public void testMissingYangInDep() throws VerificationException {
61 setUp("MissingYangInDep/", false);
62 } catch (VerificationException e) {
63 assertVerificationException(
65 "org.opendaylight.yangtools.yang.parser.util.YangValidationException: Not existing module imported:unknownDep:2013-02-27 by:private:2013-02-27");
69 fail("Verification exception should have been thrown");
72 static void verifyCorrectLog(Verifier v) throws VerificationException {
73 v.verifyErrorFreeLog();
74 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from");
75 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl");
76 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: null");
80 public void testNoGenerators() throws VerificationException {
81 Verifier v = setUp("NoGenerators/", false);
82 v.verifyErrorFreeLog();
83 v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
87 public void testUnknownGenerator() throws VerificationException {
88 Verifier v = setUp("UnknownGenerator/", true);
89 v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
90 v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
91 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl");
92 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: null");
93 v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}");
97 public void testNoYangFiles() throws VerificationException {
98 Verifier v = setUp("NoYangFiles/", false);
99 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from []");
100 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl");
101 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: null");
104 static void assertVerificationException(VerificationException e,
106 assertThat(e.getMessage(), containsString(string));
109 static Verifier setUp(String project, boolean ignoreF)
110 throws VerificationException {
111 final URL path = YangToSourcesPluginTestIT.class.getResource("/"
112 + project + "pom.xml");
113 File parent = new File(path.getPath());
114 Verifier verifier = new Verifier(parent.getParent());
116 verifier.addCliOption("-fn");
117 verifier.setMavenDebug(true);
118 verifier.executeGoal("generate-sources");
123 public void testNoOutputDir() throws VerificationException {
124 Verifier v = YangToSourcesPluginTestIT.setUp("NoOutputDir/", false);
129 public void testFindResourceOnCp() throws VerificationException {
130 Verifier v1 = new Verifier(new File(getClass().getResource(
131 "/GenerateTest1/pom.xml").getPath()).getParent());
132 v1.executeGoal("clean");
133 v1.executeGoal("package");
134 v1.assertFilePresent("target/classes/META-INF/yang/testfile1.yang");
135 v1.assertFilePresent("target/classes/META-INF/yang/testfile2.yang");
136 v1.assertFilePresent("target/classes/META-INF/yang/testfile3.yang");
138 Verifier v2 = YangToSourcesPluginTestIT.setUp("GenerateTest2/", false);
139 v2.executeGoal("clean");
140 v2.executeGoal("package");
141 v2.assertFilePresent("target/classes/META-INF/yang/private.yang");
142 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile1.yang");
143 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile2.yang");
144 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile3.yang");