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;
15 import org.apache.maven.it.VerificationException;
16 import org.apache.maven.it.Verifier;
17 import org.junit.Test;
19 public class YangToSourcesPluginTest {
22 public void testYangRootNotExist() {
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(
30 "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from unknown");
34 fail("Verification exception should have been thrown");
38 public void testCorrect() throws VerificationException {
39 Verifier v = setUp("Correct/", false);
44 static void verifyCorrectLog(Verifier v) throws VerificationException {
45 v.verifyErrorFreeLog();
46 v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from");
47 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
48 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
49 v.verifyTextInLog("[INFO] yang-to-sources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
50 v.verifyTextInLog("[INFO] yang-to-sources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
54 public void testNoGenerators() throws VerificationException {
55 Verifier v = setUp("NoGenerators/", false);
56 v.verifyErrorFreeLog();
57 v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
61 public void testUnknownGenerator() throws VerificationException {
62 Verifier v = setUp("UnknownGenerator/", true);
63 v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
64 v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
65 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
66 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
67 v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}");
71 public void testNoYangFiles() throws VerificationException {
72 Verifier v = setUp("NoYangFiles/", false);
73 v.verifyTextInLog("[WARNING] yang-to-sources: No yang file found in ");
74 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
75 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
78 static void assertVerificationException(VerificationException e,
80 assertThat(e.getMessage(), containsString(string));
83 static Verifier setUp(String project, boolean ignoreF)
84 throws VerificationException {
85 Verifier verifier = new Verifier(new File("src/test/resources/"
86 + project).getAbsolutePath());
88 verifier.addCliOption("-fn");
89 verifier.executeGoal("generate-sources");
94 public void testNoGeneratorsResources() throws VerificationException {
95 Verifier v = YangToSourcesPluginTest.setUp("NoGenerators_resources/",
97 v.verifyErrorFreeLog();
98 v.verifyTextInLog("[WARNING] yang-to-sources: No resource provider classes provided");
102 public void testUnknownGeneratorResources() throws VerificationException {
103 Verifier v = YangToSourcesPluginTest.setUp(
104 "UnknownGenerator_resources/", true);
105 v.verifyTextInLog("[ERROR] yang-to-sources: Unable to provide resources with unknown resource provider");
106 v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
107 v.verifyTextInLog("[INFO] yang-to-sources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
108 v.verifyTextInLog("[INFO] yang-to-sources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
109 v.verifyTextInLog("[ERROR] yang-to-sources: One or more code resource provider failed, including failed list(resourceProviderClass=exception) {unknown=java.lang.ClassNotFoundException}");
113 public void testNoOutputDir() throws VerificationException {
114 Verifier v = YangToSourcesPluginTest.setUp("NoOutputDir/",
120 public void testFindResourceOnCp() throws VerificationException {
121 Verifier v1 = new Verifier(new File("src/test/resources/GenerateTest1/").getAbsolutePath());
122 v1.executeGoal("package");
123 v1.assertFilePresent("target/external-resources/testfile1.yang");
124 v1.assertFilePresent("target/external-resources/testfile2.yang");
125 v1.assertFilePresent("target/external-resources/testfile3.yang");
127 Verifier v2 = YangToSourcesPluginTest.setUp("GenerateTest2/",
129 v2.executeGoal("package");