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 YangToSourcesPluginTestIT {
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("[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}");
49 v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}");
50 v.verifyTextInLog("../files marked as resources: META-INF/yang");
51 v.verifyTextInLog("target/generated-resources marked as resources for generator: org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
55 public void testMissingYangInDep() throws VerificationException {
57 setUp("MissingYangInDep/", false);
58 } catch (VerificationException e) {
59 assertVerificationException(
61 "org.opendaylight.controller.yang.parser.util.YangValidationException: Not existing module imported:unknownDep:2013-02-27 by:private:2013-02-27");
65 fail("Verification exception should have been thrown");
68 static void verifyCorrectLog(Verifier v) throws VerificationException {
69 v.verifyErrorFreeLog();
70 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from");
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");
76 public void testNoGenerators() throws VerificationException {
77 Verifier v = setUp("NoGenerators/", false);
78 v.verifyErrorFreeLog();
79 v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
83 public void testUnknownGenerator() throws VerificationException {
84 Verifier v = setUp("UnknownGenerator/", true);
85 v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
86 v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
87 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
88 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
89 v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}");
93 public void testNoYangFiles() throws VerificationException {
94 Verifier v = setUp("NoYangFiles/", false);
95 v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from []");
96 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
97 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
100 static void assertVerificationException(VerificationException e,
102 assertThat(e.getMessage(), containsString(string));
105 static Verifier setUp(String project, boolean ignoreF)
106 throws VerificationException {
107 Verifier verifier = new Verifier(new File("src/test/resources/"
108 + project).getAbsolutePath());
110 verifier.addCliOption("-fn");
111 verifier.setMavenDebug(true);
112 verifier.executeGoal("generate-sources");
117 public void testNoOutputDir() throws VerificationException {
118 Verifier v = YangToSourcesPluginTestIT.setUp("NoOutputDir/", false);
123 public void testFindResourceOnCp() throws VerificationException {
124 Verifier v1 = new Verifier(
125 new File("src/test/resources/GenerateTest1/").getAbsolutePath());
126 v1.executeGoal("clean");
127 v1.executeGoal("package");
128 v1.assertFilePresent("target/classes/META-INF/yang/testfile1.yang");
129 v1.assertFilePresent("target/classes/META-INF/yang/testfile2.yang");
130 v1.assertFilePresent("target/classes/META-INF/yang/testfile3.yang");
132 Verifier v2 = YangToSourcesPluginTestIT.setUp("GenerateTest2/", false);
133 v2.executeGoal("clean");
134 v2.executeGoal("package");
135 v2.assertFilePresent("target/classes/META-INF/yang/private.yang");
136 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile1.yang");
137 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile2.yang");
138 v2.assertFileNotPresent("target/classes/META-INF/yang/testfile3.yang");