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.containsString;
16 import org.apache.maven.it.VerificationException;
17 import org.apache.maven.it.Verifier;
18 import org.junit.Ignore;
19 import org.junit.Test;
22 public class YangToSourcesPluginTestIT {
24 // TODO Test yang files in transitive dependencies
27 public void testYangRootNotExist() {
29 setUp("YangRootNotExist/", false);
30 } catch (VerificationException e) {
31 assertVerificationException(e,
32 "[ERROR] yang-to-sources: Unable to parse yang files from ");
33 assertVerificationException(
35 "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from ");
39 fail("Verification exception should have been thrown");
43 public void testCorrect() throws VerificationException {
44 Verifier v = setUp("Correct/", false);
49 public void testAdditionalConfiguration() throws VerificationException {
50 Verifier v = setUp("AdditionalConfig/", false);
51 v.verifyTextInLog("[DEBUG] 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}");
52 v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}");
53 v.verifyTextInLog(File.separator
54 + "files marked as resources: META-INF/yang");
55 v.verifyTextInLog("target"
57 + "generated-resources marked as resources for generator: org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
61 public void testMissingYangInDep() throws VerificationException {
63 setUp("MissingYangInDep/", false);
64 } catch (VerificationException e) {
65 assertVerificationException(
67 "org.opendaylight.controller.yang.parser.util.YangValidationException: Not existing module imported:unknownDep:2013-02-27 by:private:2013-02-27");
71 fail("Verification exception should have been thrown");
74 static void verifyCorrectLog(Verifier v) throws VerificationException {
75 v.verifyErrorFreeLog();
76 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from");
77 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
78 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
82 public void testNoGenerators() throws VerificationException {
83 Verifier v = setUp("NoGenerators/", false);
84 v.verifyErrorFreeLog();
85 v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
89 public void testUnknownGenerator() throws VerificationException {
90 Verifier v = setUp("UnknownGenerator/", true);
91 v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
92 v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
93 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
94 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
95 v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}");
99 public void testNoYangFiles() throws VerificationException {
100 Verifier v = setUp("NoYangFiles/", false);
101 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from []");
102 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
103 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
106 static void assertVerificationException(VerificationException e,
108 assertThat(e.getMessage(), containsString(string));
111 static Verifier setUp(String project, boolean ignoreF)
112 throws VerificationException {
113 final URL path = YangToSourcesPluginTestIT.class.getResource("/"
114 + project + "pom.xml");
115 File parent = new File(path.getPath());
116 Verifier verifier = new Verifier(parent.getParent());
118 verifier.addCliOption("-fn");
119 verifier.setMavenDebug(true);
120 verifier.executeGoal("generate-sources");
125 public void testNoOutputDir() throws VerificationException {
126 Verifier v = YangToSourcesPluginTestIT.setUp("NoOutputDir/", false);
131 public void testFindResourceOnCp() throws VerificationException {
132 Verifier v1 = new Verifier(new File(getClass().getResource(
133 "/GenerateTest1/pom.xml").getPath()).getParent());
134 v1.executeGoal("clean");
135 v1.executeGoal("package");
136 v1.assertFilePresent("target/classes/META-INF/yang/testfile1.yang");
137 v1.assertFilePresent("target/classes/META-INF/yang/testfile2.yang");
138 v1.assertFilePresent("target/classes/META-INF/yang/testfile3.yang");
140 Verifier v2 = YangToSourcesPluginTestIT.setUp("GenerateTest2/", false);
141 v2.executeGoal("clean");
142 v2.executeGoal("package");
143 v2.assertFilePresent("target/classes/META-INF/yang/private.yang");
144 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile1.yang");
145 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile2.yang");
146 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile3.yang");