X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fmaven-yang-plugin-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang2sources%2Fplugin%2Fit%2FYangToSourcesPluginTest.java;fp=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fmaven-yang-plugin-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang2sources%2Fplugin%2Fit%2FYangToSourcesPluginTest.java;h=1d8f5708530c631aaf3314995f499aad2df1f92d;hb=78718ca2980d6289703f239abb6b7928ea08c8e4;hp=0000000000000000000000000000000000000000;hpb=8e7e1c62838a9bf7057590e08226220044326e86;p=controller.git diff --git a/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTest.java b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTest.java new file mode 100644 index 0000000000..1d8f570853 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/java/org/opendaylight/controller/yang2sources/plugin/it/YangToSourcesPluginTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang2sources.plugin.it; + +import static org.junit.Assert.*; +import static org.junit.matchers.JUnitMatchers.*; + +import java.io.File; + +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.junit.Test; + +public class YangToSourcesPluginTest { + + @Test + public void testYangRootNotExist() { + try { + setUp("YangRootNotExist/", false); + } catch (VerificationException e) { + assertVerificationException(e, + "[ERROR] yang-to-sources: Unable to parse yang files from unknown"); + assertVerificationException( + e, + "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from unknown"); + return; + } + + fail("Verification exception should have been thrown"); + } + + @Test + public void testCorrect() throws VerificationException { + Verifier v = setUp("Correct/", false); + verifyCorrectLog(v); + } + + static void verifyCorrectLog(Verifier v) throws VerificationException { + v.verifyErrorFreeLog(); + v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from"); + v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl"); + v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null"); + } + + @Test + public void testNoGenerators() throws VerificationException { + Verifier v = setUp("NoGenerators/", false); + v.verifyErrorFreeLog(); + v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided"); + } + + @Test + public void testUnknownGenerator() throws VerificationException { + Verifier v = setUp("UnknownGenerator/", true); + v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator"); + v.verifyTextInLog("java.lang.ClassNotFoundException: unknown"); + v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl"); + v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null"); + v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}"); + } + + @Test + public void testNoYangFiles() throws VerificationException { + Verifier v = setUp("NoYangFiles/", false); + v.verifyTextInLog("[WARNING] yang-to-sources: No yang file found in "); + v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from []"); + v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl"); + v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null"); + } + + static void assertVerificationException(VerificationException e, + String string) { + assertThat(e.getMessage(), containsString(string)); + } + + static Verifier setUp(String project, boolean ignoreF) + throws VerificationException { + Verifier verifier = new Verifier(new File("src/test/resources/" + + project).getAbsolutePath()); + if (ignoreF) + verifier.addCliOption("-fn"); + verifier.executeGoal("generate-resources"); + return verifier; + } + +}