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 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);
43 static void verifyCorrectLog(Verifier v) throws VerificationException {
44 v.verifyErrorFreeLog();
45 v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from");
46 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
47 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
51 public void testNoGenerators() throws VerificationException {
52 Verifier v = setUp("NoGenerators/", false);
53 v.verifyErrorFreeLog();
54 v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
58 public void testUnknownGenerator() throws VerificationException {
59 Verifier v = setUp("UnknownGenerator/", true);
60 v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
61 v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
62 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
63 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
64 v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}");
68 public void testNoYangFiles() throws VerificationException {
69 Verifier v = setUp("NoYangFiles/", false);
70 v.verifyTextInLog("[WARNING] yang-to-sources: No yang file found in ");
71 v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from []");
72 v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
73 v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
76 static void assertVerificationException(VerificationException e,
78 assertThat(e.getMessage(), containsString(string));
81 static Verifier setUp(String project, boolean ignoreF)
82 throws VerificationException {
83 Verifier verifier = new Verifier(new File("src/test/resources/"
84 + project).getAbsolutePath());
86 verifier.addCliOption("-fn");
87 verifier.executeGoal("generate-resources");