View Javadoc
1   /*
2    * #%L
3    * JAXX :: Maven plugin
4    * %%
5    * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  
23  package org.nuiton.jaxx.plugin;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.maven.plugin.MojoExecutionException;
28  
29  
30  import org.apache.maven.plugin.logging.SystemStreamLog;
31  import org.junit.Test;
32  import static org.junit.Assert.*;
33  
34  public class Evolution74Test extends JaxxBaseTest {
35  
36      /** Logger. */
37      private static final Log log = LogFactory.getLog(Evolution74Test.class);
38  
39      @Test
40      public void ok() throws Exception {
41          GenerateMojo mojo = getMojo();
42          mojo.execute();
43          assertNumberJaxxFiles(6);
44  
45          checkPattern(mojo, "JComboBox", true, "org/nuiton/jaxx/plugin/evolution74Test/ok/swingcombo.java");
46          checkPattern(mojo, "JComboBox", false, "org/nuiton/jaxx/plugin/evolution74Test/ok/jaxxcombo.java");
47          checkPattern(mojo, "JAXXComboBox", false, "org/nuiton/jaxx/plugin/evolution74Test/ok/swingcombo.java");
48          checkPattern(mojo, "JAXXComboBox", true, "org/nuiton/jaxx/plugin/evolution74Test/ok/jaxxcombo.java");
49  
50          checkPattern(mojo, "JList", true, "org/nuiton/jaxx/plugin/evolution74Test/ok/swinglist.java");
51          checkPattern(mojo, "JList", false, "org/nuiton/jaxx/plugin/evolution74Test/ok/jaxxlist.java");
52          checkPattern(mojo, "JAXXList", false, "org/nuiton/jaxx/plugin/evolution74Test/ok/swinglist.java");
53          checkPattern(mojo, "JAXXList", true, "org/nuiton/jaxx/plugin/evolution74Test/ok/jaxxlist.java");
54  
55          checkPattern(mojo, "JTree", true, "org/nuiton/jaxx/plugin/evolution74Test/ok/swingtree.java");
56          checkPattern(mojo, "JTree", false, "org/nuiton/jaxx/plugin/evolution74Test/ok/jaxxtree.java");
57          checkPattern(mojo, "JAXXTree", false, "org/nuiton/jaxx/plugin/evolution74Test/ok/swingtree.java");
58          checkPattern(mojo, "JAXXTree", true, "org/nuiton/jaxx/plugin/evolution74Test/ok/jaxxtree.java");
59      }
60  
61      @SuppressWarnings({"unchecked"})
62      @Test
63      public void error() throws Exception {
64          GenerateMojo mojo = getMojo();
65          // init mojo to get alls files to treate
66          mojo.init();
67  
68          assertNumberJaxxFiles(3);
69  
70          mojo.setLog(new SystemStreamLog() {
71  
72              @Override
73              public boolean isErrorEnabled() {
74                  return false;
75              }
76  
77              @Override
78              public void error(Throwable error) {
79                  //do nothing
80              }
81  
82              @Override
83              public void error(CharSequence content) {
84                  //do nothing
85              }
86  
87              @Override
88              public void error(CharSequence content, Throwable error) {
89                  //do nothing
90              }
91          });
92  
93          // execute mjo on each jaxx file to produce the error
94          for (String file : mojo.files) {
95              log.info("test bad file " + file);
96              mojo.files = new String[]{file};
97              try {
98                  mojo.doAction();
99                  // should never pass
100                 fail();
101             } catch (MojoExecutionException e) {
102                 // ok jaxx compiler failed
103                 assertTrue(true);
104                 assertError(mojo.getEngine(), file, 1);
105             }
106         }
107     }
108 }