View Javadoc
1   /*
2     Copyright (C) 2020 - 2022 Alexander Kapitman
3   
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15  */
16  
17  package ru.akman.maven.plugins.jpackage;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  import static org.junit.Assert.fail;
24  
25  import java.io.File;
26  import java.io.IOException;
27  import java.util.Arrays;
28  import java.util.List;
29  import org.apache.maven.execution.MavenSession;
30  import org.apache.maven.plugin.MojoExecution;
31  import org.apache.maven.plugin.testing.MojoRule;
32  import org.apache.maven.project.MavenProject;
33  import org.apache.maven.shared.model.fileset.FileSet;
34  import org.apache.maven.toolchain.ToolchainManager;
35  import org.codehaus.plexus.PlexusContainer;
36  import org.junit.Rule;
37  import org.junit.Test;
38  import ru.akman.maven.plugins.TestUtils;
39  
40  /**
41   * JPackageMojo Test Class.
42   */
43  public class JPackageMojoTest {
44  
45    /**
46     * Relative path to the base directory of tested project.
47     */
48    private static final String PROJECT_DIR = "target/test-classes/project/";
49  
50    /**
51     * Executed goal.
52     */
53    private static final String MOJO_EXECUTION = "jpackage";
54  
55    /**
56     * Plexus DI container.
57     */
58    private PlexusContainer container;
59  
60    /**
61     * Toolchain manager.
62     */
63    private ToolchainManager toolchainManager;
64  
65    /**
66     * Maven project.
67     */
68    private MavenProject project;
69  
70    /**
71     * Maven session.
72     */
73    private MavenSession session;
74  
75    /**
76     * Mojo execution.
77     */
78    private MojoExecution execution;
79  
80    /**
81     * JPackage Mojo.
82     */
83    private JPackageMojo mojo;
84  
85    /**
86     * AbstractMojoTestCase wrapper.
87     * All protected methods of the TestCase are exhibited as public in the rule.
88     */
89    @Rule
90    public MojoRule rule = new MojoRule() {
91  
92      @Override
93      protected void before() throws Throwable {
94        // Plexus container
95        container = getContainer();
96        assertNotNull("Has access to the plexus container", container);
97        // Toolchain manager
98        toolchainManager = (ToolchainManager) container.lookup(
99            ToolchainManager.class.getName());
100       assertNotNull("Can get the toolchain manager", toolchainManager);
101       // Project directory
102       final File pom = new File(PROJECT_DIR);
103       assertNotNull("Project directory path is valid", pom);
104       assertTrue("Project directory exists", pom.exists());
105       // Maven project
106       project = readMavenProject(pom);
107       assertNotNull("Can read the project", project);
108       // Maven session
109       session = newMavenSession(project);
110       assertNotNull("Can create new session", session);
111       // Mojo execution
112       execution = newMojoExecution(MOJO_EXECUTION);
113       assertNotNull("Can create new execution", execution);
114       // Mojo
115       mojo = (JPackageMojo) lookupConfiguredMojo(session, execution);
116       assertNotNull("Can lookup configured mojo", mojo);
117     }
118 
119     @Override
120     protected void after() {
121       // skip
122     }
123 
124   };
125 
126   /**
127    * Parameter 'toolhome' exists and has a value.
128    *
129    * @throws Exception if any errors occurred
130    */
131   @Test
132   public void testMojoHasToolHome() throws Exception {
133     final File toolhome =
134         (File) rule.getVariableValueFromObject(mojo, "toolhome");
135     assertEquals("toolhome",
136         TestUtils.getCanonicalPath(toolhome),
137         TestUtils.getCanonicalPath(new File(project.getBasedir(),
138             "path/to/jpackage/home"))
139     );
140   }
141 
142   /**
143    * Parameter 'dest' exists and has a value.
144    *
145    * @throws Exception if any errors occurred
146    */
147   @Test
148   public void testMojoHasDest() throws Exception {
149     final File dest =
150         (File) rule.getVariableValueFromObject(mojo, "dest");
151     assertEquals("dest",
152         TestUtils.getCanonicalPath(dest),
153         TestUtils.getCanonicalPath(new File(project.getBuild().getDirectory(),
154             "jpackage"))
155     );
156   }
157 
158   /**
159    * Parameter 'temp' exists and has a value.
160    *
161    * @throws Exception if any errors occurred
162    */
163   @Test
164   public void testMojoHasTemp() throws Exception {
165     final File temp =
166         (File) rule.getVariableValueFromObject(mojo, "temp");
167     assertEquals("temp",
168         TestUtils.getCanonicalPath(temp),
169         TestUtils.getCanonicalPath(new File(project.getBuild().getDirectory(),
170             "jpackage/temp"))
171     );
172   }
173 
174   /**
175    * Parameter 'type' exists and has a value.
176    *
177    * @throws Exception if any errors occurred
178    */
179   @Test
180   public void testMojoHasType() throws Exception {
181     final PackageType type =
182         (PackageType) rule.getVariableValueFromObject(mojo, "type");
183     assertEquals("type",
184         type,
185         PackageType.IMAGE
186     );
187   }
188 
189   /**
190    * Parameter 'verbose' exists and has a value.
191    *
192    * @throws Exception if any errors occurred
193    */
194   @Test
195   public void testMojoHasVerbose() throws Exception {
196     final boolean verbose =
197         (boolean) rule.getVariableValueFromObject(mojo, "verbose");
198     assertTrue("verbose",
199         verbose);
200   }
201 
202   /**
203    * Parameter 'appversion' exists and has a value.
204    *
205    * @throws Exception if any errors occurred
206    */
207   @Test
208   public void testMojoHasAppVersion() throws Exception {
209     final String appversion =
210         (String) rule.getVariableValueFromObject(mojo, "appversion");
211     assertEquals("appversion",
212         appversion,
213         "1.0"
214     );
215   }
216 
217   /**
218    * Parameter 'copyright' exists and has a value.
219    *
220    * @throws Exception if any errors occurred
221    */
222   @Test
223   public void testMojoHasCopyright() throws Exception {
224     final String copyright =
225         (String) rule.getVariableValueFromObject(mojo, "copyright");
226     assertEquals("copyright",
227         copyright,
228         "Copyright (C) 2020 Alexander Kapitman"
229     );
230   }
231 
232   /**
233    * Parameter 'description' exists and has a value.
234    *
235    * @throws Exception if any errors occurred
236    */
237   @Test
238   public void testMojoHasDescription() throws Exception {
239     final String description =
240         (String) rule.getVariableValueFromObject(mojo, "description");
241     assertEquals("description",
242         description,
243         "JPackage Maven Plugin Unit Tests"
244     );
245   }
246 
247   /**
248    * Parameter 'name' exists and has a value.
249    *
250    * @throws Exception if any errors occurred
251    */
252   @Test
253   public void testMojoHasName() throws Exception {
254     final String name =
255         (String) rule.getVariableValueFromObject(mojo, "name");
256     assertEquals("name",
257         name,
258         "appimage"
259     );
260   }
261 
262   /**
263    * Parameter 'vendor' exists and has a value.
264    *
265    * @throws Exception if any errors occurred
266    */
267   @Test
268   public void testMojoHasVendor() throws Exception {
269     final String vendor =
270         (String) rule.getVariableValueFromObject(mojo, "vendor");
271     assertEquals("vendor",
272         vendor,
273         "Akman"
274     );
275   }
276 
277   /**
278    * Parameter 'icon' exists and has a value.
279    *
280    * @throws Exception if any errors occurred
281    */
282   @Test
283   public void testMojoHasIcon() throws Exception {
284     final File icon =
285         (File) rule.getVariableValueFromObject(mojo, "icon");
286     assertEquals("icon",
287         TestUtils.getCanonicalPath(icon),
288         TestUtils.getCanonicalPath(new File(project.getBasedir(),
289             "config/jpackage/icon.ico"))
290     );
291   }
292 
293   /**
294    * Parameter 'input' exists and has a value.
295    *
296    * @throws Exception if any errors occurred
297    */
298   @Test
299   public void testMojoHasInput() throws Exception {
300     final File input =
301         (File) rule.getVariableValueFromObject(mojo, "input");
302     assertEquals("input",
303         TestUtils.getCanonicalPath(input),
304         TestUtils.getCanonicalPath(new File(project.getBuild().getDirectory(),
305             "jlink/libs"))
306     );
307   }
308 
309   /**
310    * Parameter 'runtimeimage' exists and has a value.
311    *
312    * @throws Exception if any errors occurred
313    */
314   @Test
315   public void testMojoHasRuntimeImage() throws Exception {
316     final File runtimeimage =
317         (File) rule.getVariableValueFromObject(mojo, "runtimeimage");
318     assertEquals("runtimeimage",
319         TestUtils.getCanonicalPath(runtimeimage),
320         TestUtils.getCanonicalPath(new File(project.getBuild().getDirectory(),
321             "jlink/image"))
322     );
323   }
324 
325   /**
326    * Parameter 'modulepath' exists.
327    *
328    * @throws Exception if any errors occurred
329    */
330   @Test
331   public void testMojoHasModulePath() throws Exception {
332     final ModulePath modulepath =
333         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
334     assertNotNull("modulepath",
335         modulepath);
336   }
337 
338   /**
339    * Parameter 'modulepath/pathelements' exists and has a value.
340    *
341    * @throws Exception if any errors occurred
342    */
343   @Test
344   public void testMojoHasPathElements() throws Exception {
345     final ModulePath modulepath =
346         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
347     final List<File> pathelements = modulepath.getPathElements();
348     assertEquals("modulepath/pathelements",
349         TestUtils.buildPathFromFiles(pathelements),
350         TestUtils.buildPathFromNames(PROJECT_DIR, Arrays.asList(
351             "mod.jar",
352             "mod.jmod",
353             "mods/exploded/mod"
354         ))
355     );
356   }
357 
358   /**
359    * Parameter 'modulepath/filesets' exists and has a value.
360    *
361    * @throws Exception if any errors occurred
362    */
363   @Test
364   public void testMojoHasFilesets() throws Exception {
365     final ModulePath modulepath =
366         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
367     final List<FileSet> filesets = modulepath.getFileSets();
368     assertEquals("modulepath/filesets",
369         filesets.size(), 1);
370   }
371 
372   /**
373    * Parameter 'modulepath/filesets/fileset/isfollowsymlinks' exists
374    * and has a value.
375    *
376    * @throws Exception if any errors occurred
377    */
378   @Test
379   public void testMojoHasFilesetFollowSymlinks() throws Exception {
380     final ModulePath modulepath =
381         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
382     final List<FileSet> filesets = modulepath.getFileSets();
383     final FileSet fileset = filesets.get(0);
384     assertFalse("modulepath/filesets/fileset/isfollowsymlinks",
385         fileset.isFollowSymlinks());
386   }
387 
388   /**
389    * Parameter 'modulepath/filesets/fileset/includes' exists and has a value.
390    *
391    * @throws Exception if any errors occurred
392    */
393   @Test
394   public void testMojoHasFilesetIncludes() throws Exception {
395     final ModulePath modulepath =
396         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
397     final List<FileSet> filesets = modulepath.getFileSets();
398     final FileSet fileset = filesets.get(0);
399     assertEquals("modulepath/filesets/fileset/includes",
400         TestUtils.buildStringFromNames(fileset.getIncludes()),
401         TestUtils.buildStringFromNames(Arrays.asList("**/*"))
402     );
403   }
404 
405   /**
406    * Parameter 'modulepath/filesets/fileset/excludes' exists and has a value.
407    *
408    * @throws Exception if any errors occurred
409    */
410   @Test
411   public void testMojoHasFilesetExcludes() throws Exception {
412     final ModulePath modulepath =
413         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
414     final List<FileSet> filesets = modulepath.getFileSets();
415     final FileSet fileset = filesets.get(0);
416     assertEquals("modulepath/filesets/fileset/excludes",
417         TestUtils.buildStringFromNames(fileset.getExcludes()),
418         TestUtils.buildStringFromNames(Arrays.asList(
419             "**/*Empty.jar",
420             "jlink.opts",
421             "jlink-opts"
422         ))
423     );
424   }
425 
426   /**
427    * Parameter 'modulepath/filesets/fileset/directory' exists and has a value.
428    *
429    * @throws Exception if any errors occurred
430    */
431   @Test
432   public void testMojoHasFilesetDirectory() throws Exception {
433     final ModulePath modulepath =
434         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
435     final List<FileSet> filesets = modulepath.getFileSets();
436     final FileSet fileset = filesets.get(0);
437     try {
438       PluginUtils.normalizeFileSetBaseDir(project.getBasedir(), fileset);
439     } catch (IOException ex) {
440       fail("Error: Unable to resolve fileset base directory: ["
441           + project.getBasedir() + "]."
442           + System.lineSeparator()
443           + ex.toString()
444       );
445     }
446     assertEquals("modulepath/filesets/fileset/directory",
447         TestUtils.getCanonicalPath(new File(fileset.getDirectory())),
448         TestUtils.getCanonicalPath(new File(project.getBuild().getDirectory()))
449     );
450   }
451 
452   /**
453    * Parameter 'modulepath/dirsets' exists and has a value.
454    *
455    * @throws Exception if any errors occurred
456    */
457   @Test
458   public void testMojoHasDirsets() throws Exception {
459     final ModulePath modulepath =
460         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
461     final List<FileSet> dirsets = modulepath.getDirSets();
462     assertEquals("modulepath/dirsets",
463         dirsets.size(), 1);
464   }
465 
466   /**
467    * Parameter 'modulepath/dirsets/dirset/isfollowsymlinks' exists
468    * and has a value.
469    *
470    * @throws Exception if any errors occurred
471    */
472   @Test
473   public void testMojoHasDirsetFollowSymlinks() throws Exception {
474     final ModulePath modulepath =
475         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
476     final List<FileSet> dirsets = modulepath.getDirSets();
477     final FileSet dirset = dirsets.get(0);
478     assertTrue("modulepath/dirsets/dirset/isfollowsymlinks",
479         dirset.isFollowSymlinks());
480   }
481 
482   /**
483    * Parameter 'modulepath/dirsets/dirset/includes' exists and has a value.
484    *
485    * @throws Exception if any errors occurred
486    */
487   @Test
488   public void testMojoHasDirsetIncludes() throws Exception {
489     final ModulePath modulepath =
490         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
491     final List<FileSet> dirsets = modulepath.getDirSets();
492     final FileSet dirset = dirsets.get(0);
493     assertEquals("modulepath/dirsets/dirset/includes",
494         TestUtils.buildStringFromNames(dirset.getIncludes()),
495         TestUtils.buildStringFromNames(Arrays.asList("**/*"))
496     );
497   }
498 
499   /**
500    * Parameter 'modulepath/dirsets/dirset/excludes' exists and has a value.
501    *
502    * @throws Exception if any errors occurred
503    */
504   @Test
505   public void testMojoHasDirsetExcludes() throws Exception {
506     final ModulePath modulepath =
507         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
508     final List<FileSet> dirsets = modulepath.getDirSets();
509     final FileSet dirset = dirsets.get(0);
510     assertEquals("modulepath/dirsets/dirset/excludes",
511         TestUtils.buildStringFromNames(dirset.getExcludes()),
512         TestUtils.buildStringFromNames(Arrays.asList("**/*Test"))
513     );
514   }
515 
516   /**
517    * Parameter 'modulepath/dirsets/dirset/directory' exists and has a value.
518    *
519    * @throws Exception if any errors occurred
520    */
521   @Test
522   public void testMojoHasDirsetDirectory() throws Exception {
523     final ModulePath modulepath =
524         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
525     final List<FileSet> dirsets = modulepath.getDirSets();
526     final FileSet dirset = dirsets.get(0);
527     try {
528       PluginUtils.normalizeFileSetBaseDir(project.getBasedir(), dirset);
529     } catch (IOException ex) {
530       fail("Error: Unable to resolve fileset base directory: ["
531           + project.getBasedir() + "]."
532           + System.lineSeparator()
533           + ex.toString()
534       );
535     }
536     assertEquals("modulepath/dirsets/dirset/directory",
537         TestUtils.getCanonicalPath(new File(dirset.getDirectory())),
538         TestUtils.getCanonicalPath(new File(project.getBuild().getDirectory()))
539     );
540   }
541 
542   /**
543    * Parameter 'modulepath/dependencysets' exists and has a value.
544    *
545    * @throws Exception if any errors occurred
546    */
547   @Test
548   public void testMojoHasDependencysets() throws Exception {
549     final ModulePath modulepath =
550         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
551     final List<DependencySet> dependencysets = modulepath.getDependencySets();
552     assertEquals("modulepath/dependencysets",
553         dependencysets.size(), 1);
554   }
555 
556   /**
557    * Parameter 'modulepath/dependencysets/dependencyset/outputincluded' exists
558    * and has a value.
559    *
560    * @throws Exception if any errors occurred
561    */
562   @Test
563   public void testMojoHasDependencysetOutputIncluded() throws Exception {
564     final ModulePath modulepath =
565         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
566     final List<DependencySet> dependencysets = modulepath.getDependencySets();
567     final DependencySet depset = dependencysets.get(0);
568     assertFalse("modulepath/dependencysets/dependencyset/outputincluded",
569         depset.isOutputIncluded());
570   }
571 
572   /**
573    * Parameter 'modulepath/dependencysets/dependencyset/automaticexcluded'
574    * exists and has a value.
575    *
576    * @throws Exception if any errors occurred
577    */
578   @Test
579   public void testMojoHasDependencysetAutomaticExcluded() throws Exception {
580     final ModulePath modulepath =
581         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
582     final List<DependencySet> dependencysets = modulepath.getDependencySets();
583     final DependencySet depset = dependencysets.get(0);
584     assertFalse("modulepath/dependencysets/dependencyset/automaticexcluded",
585         depset.isAutomaticExcluded());
586   }
587 
588   /**
589    * Parameter 'modulepath/dependencysets/dependencyset/includes' exists and
590    * has a value.
591    *
592    * @throws Exception if any errors occurred
593    */
594   @Test
595   public void testMojoHasDependencysetIncludes() throws Exception {
596     final ModulePath modulepath =
597         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
598     final List<DependencySet> dependencysets = modulepath.getDependencySets();
599     final DependencySet depset = dependencysets.get(0);
600     assertEquals("modulepath/dependencysets/dependencyset/includes",
601         TestUtils.buildStringFromNames(depset.getIncludes()),
602         TestUtils.buildStringFromNames(Arrays.asList(
603             "glob:**/*.jar",
604             "regex:foo-(bar|baz)-.*?\\.jar"
605         ))
606     );
607   }
608 
609   /**
610    * Parameter 'modulepath/dependencysets/dependencyset/excludes' exists and
611    * has a value.
612    *
613    * @throws Exception if any errors occurred
614    */
615   @Test
616   public void testMojoHasDependencysetExcludes() throws Exception {
617     final ModulePath modulepath =
618         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
619     final List<DependencySet> dependencysets = modulepath.getDependencySets();
620     final DependencySet depset = dependencysets.get(0);
621     assertEquals("modulepath/dependencysets/dependencyset/excludes",
622         TestUtils.buildStringFromNames(depset.getExcludes()),
623         TestUtils.buildStringFromNames(Arrays.asList("glob:**/javafx.*Empty"))
624     );
625   }
626 
627   /**
628    * Parameter 'modulepath/dependencysets/dependencyset/includenames' exists
629    * and has a value.
630    *
631    * @throws Exception if any errors occurred
632    */
633   @Test
634   public void testMojoHasDependencysetIncludeNames() throws Exception {
635     final ModulePath modulepath =
636         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
637     final List<DependencySet> dependencysets = modulepath.getDependencySets();
638     final DependencySet depset = dependencysets.get(0);
639     assertEquals("modulepath/dependencysets/dependencyset/includenames",
640         TestUtils.buildStringFromNames(depset.getIncludeNames()),
641         TestUtils.buildStringFromNames(Arrays.asList(".*"))
642     );
643   }
644 
645   /**
646    * Parameter 'modulepath/dependencysets/dependencyset/excludenames' exists
647    * and has a value.
648    *
649    * @throws Exception if any errors occurred
650    */
651   @Test
652   public void testMojoHasDependencysetExcludeNames() throws Exception {
653     final ModulePath modulepath =
654         (ModulePath) rule.getVariableValueFromObject(mojo, "modulepath");
655     final List<DependencySet> dependencysets = modulepath.getDependencySets();
656     final DependencySet depset = dependencysets.get(0);
657     assertEquals("modulepath/dependencysets/dependencyset/excludenames",
658         TestUtils.buildStringFromNames(depset.getExcludeNames()),
659         TestUtils.buildStringFromNames(Arrays.asList("javafx\\..+Empty"))
660     );
661   }
662 
663   /**
664    * Parameter 'addmodules' exists and has a value.
665    *
666    * @throws Exception if any errors occurred
667    */
668   @Test
669   @SuppressWarnings("unchecked") // unchecked cast
670   public void testMojoHasAddModules() throws Exception {
671     final List<String> addmodules =
672         (List<String>) rule.getVariableValueFromObject(mojo, "addmodules");
673     assertEquals("addmodules",
674         TestUtils.buildStringFromNames(addmodules),
675         TestUtils.buildStringFromNames(Arrays.asList(
676             "java.base", "org.example.rootmodule"))
677     );
678   }
679 
680   /**
681    * Parameter 'bindservices' exists and has a value.
682    *
683    * @throws Exception if any errors occurred
684    */
685   @Test
686   public void testMojoHasBindServices() throws Exception {
687     final boolean bindservices =
688         (boolean) rule.getVariableValueFromObject(mojo, "bindservices");
689     assertTrue("bindservices",
690         bindservices);
691   }
692 
693   /**
694    * Parameter 'module' exists and has a value.
695    *
696    * @throws Exception if any errors occurred
697    */
698   @Test
699   public void testMojoHasModule() throws Exception {
700     final String module =
701         (String) rule.getVariableValueFromObject(mojo, "module");
702     assertEquals("module",
703         module,
704         "mainModuleName/mainClassName"
705     );
706   }
707 
708   /**
709    * Parameter 'mainjar' exists and has a value.
710    *
711    * @throws Exception if any errors occurred
712    */
713   @Test
714   public void testMojoHasMainJar() throws Exception {
715     final String mainjar =
716         (String) rule.getVariableValueFromObject(mojo, "mainjar");
717     assertEquals("mainjar",
718         mainjar,
719         "mainJar.jar"
720     );
721   }
722 
723   /**
724    * Parameter 'mainclass' exists and has a value.
725    *
726    * @throws Exception if any errors occurred
727    */
728   @Test
729   public void testMojoHasMainClass() throws Exception {
730     final String mainclass =
731         (String) rule.getVariableValueFromObject(mojo, "mainclass");
732     assertEquals("mainclass",
733         mainclass,
734         "mainClassName"
735     );
736   }
737 
738   /**
739    * Parameter 'arguments' exists and has a value.
740    *
741    * @throws Exception if any errors occurred
742    */
743   @Test
744   public void testMojoHasArguments() throws Exception {
745     final String arguments =
746         (String) rule.getVariableValueFromObject(mojo, "arguments");
747     assertEquals("arguments",
748         arguments,
749         "--gui"
750     );
751   }
752 
753   /**
754    * Parameter 'javaoptions' exists and has a value.
755    *
756    * @throws Exception if any errors occurred
757    */
758   @Test
759   public void testMojoHasJavaOptions() throws Exception {
760     final String javaoptions =
761         (String) rule.getVariableValueFromObject(mojo, "javaoptions");
762     assertEquals("javaoptions",
763         javaoptions,
764         "-Dfile.encoding=UTF-8 -Xms256m -Xmx512m"
765     );
766   }
767 
768   /**
769    * Parameter 'addlaunchers' exists and has a value.
770    *
771    * @throws Exception if any errors occurred
772    */
773   @Test
774   @SuppressWarnings("unchecked") // unchecked cast
775   public void testMojoHasAddLaunchers() throws Exception {
776     final List<Launcher> addlaunchers =
777         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
778     assertNotNull("addlaunchers",
779         addlaunchers);
780   }
781 
782   /**
783    * Parameter 'addlaunchers/addlauncher' exists and has a value.
784    *
785    * @throws Exception if any errors occurred
786    */
787   @Test
788   @SuppressWarnings("unchecked") // unchecked cast
789   public void testMojoHasAddLaunchersAddLauncher() throws Exception {
790     final List<Launcher> addlaunchers =
791         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
792     assertNotNull("addlaunchers/addlauncher",
793         addlaunchers.get(0));
794   }
795 
796   /**
797    * Parameter 'addlaunchers/addlauncher/name' exists and has a value.
798    *
799    * @throws Exception if any errors occurred
800    */
801   @Test
802   @SuppressWarnings("unchecked") // unchecked cast
803   public void testMojoHasAddLaunchersAddLauncherName() throws Exception {
804     final List<Launcher> addlaunchers =
805         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
806     assertEquals("addlaunchers/addlauncher/name",
807         addlaunchers.get(0).getName(),
808         "launcher1"
809     );
810   }
811 
812   /**
813    * Parameter 'addlaunchers/addlauncher/file' exists and has a value.
814    *
815    * @throws Exception if any errors occurred
816    */
817   @Test
818   @SuppressWarnings("unchecked") // unchecked cast
819   public void testMojoHasAddLaunchersAddLauncherFile() throws Exception {
820     final List<Launcher> addlaunchers =
821         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
822     assertEquals("addlaunchers/addlauncher/file",
823         TestUtils.getCanonicalPath(addlaunchers.get(0).getFile()),
824         TestUtils.getCanonicalPath(new File(project.getBasedir(),
825             "config/jpackage/launcher1.properties"))
826     );
827   }
828 
829   /**
830    * Parameter 'addlaunchers/addlauncher/module' exists and has a value.
831    *
832    * @throws Exception if any errors occurred
833    */
834   @Test
835   @SuppressWarnings("unchecked") // unchecked cast
836   public void testMojoHasAddLaunchersAddLauncherModule() throws Exception {
837     final List<Launcher> addlaunchers =
838         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
839     assertEquals("addlaunchers/addlauncher/module",
840         addlaunchers.get(0).getModule(),
841         "mainModule1Name/mainClass1Name"
842     );
843   }
844 
845   /**
846    * Parameter 'addlaunchers/addlauncher/mainjar' exists and has a value.
847    *
848    * @throws Exception if any errors occurred
849    */
850   @Test
851   @SuppressWarnings("unchecked") // unchecked cast
852   public void testMojoHasAddLaunchersAddLauncherMainJar() throws Exception {
853     final List<Launcher> addlaunchers =
854         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
855     assertEquals("addlaunchers/addlauncher/mainjar",
856         addlaunchers.get(0).getMainJar(),
857         "mainJar1.jar"
858     );
859   }
860 
861   /**
862    * Parameter 'addlaunchers/addlauncher/mainclass' exists and has a value.
863    *
864    * @throws Exception if any errors occurred
865    */
866   @Test
867   @SuppressWarnings("unchecked") // unchecked cast
868   public void testMojoHasAddLaunchersAddLauncherMainClass() throws Exception {
869     final List<Launcher> addlaunchers =
870         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
871     assertEquals("addlaunchers/addlauncher/mainclass",
872         addlaunchers.get(0).getMainClass(),
873         "mainClass1Name"
874     );
875   }
876 
877   /**
878    * Parameter 'addlaunchers/addlauncher/arguments' exists and has a value.
879    *
880    * @throws Exception if any errors occurred
881    */
882   @Test
883   @SuppressWarnings("unchecked") // unchecked cast
884   public void testMojoHasAddLaunchersAddLauncherArguments() throws Exception {
885     final List<Launcher> addlaunchers =
886         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
887     assertEquals("addlaunchers/addlauncher/arguments",
888         addlaunchers.get(0).getArguments(),
889         "--arg11 --arg12"
890     );
891   }
892 
893   /**
894    * Parameter 'addlaunchers/addlauncher/javaoptions' exists and has a value.
895    *
896    * @throws Exception if any errors occurred
897    */
898   @Test
899   @SuppressWarnings("unchecked") // unchecked cast
900   public void testMojoHasAddLaunchersAddLauncherJavaOptions() throws Exception {
901     final List<Launcher> addlaunchers =
902         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
903     assertEquals("addlaunchers/addlauncher/javaoptions",
904         addlaunchers.get(0).getJavaOptions(),
905         "-Xms128m -Xmx1024m"
906     );
907   }
908 
909   /**
910    * Parameter 'addlaunchers/addlauncher/appversion' exists and has a value.
911    *
912    * @throws Exception if any errors occurred
913    */
914   @Test
915   @SuppressWarnings("unchecked") // unchecked cast
916   public void testMojoHasAddLaunchersAddLauncherAppVersion() throws Exception {
917     final List<Launcher> addlaunchers =
918         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
919     assertEquals("addlaunchers/addlauncher/appversion",
920         addlaunchers.get(0).getAppVersion(),
921         "1.0.1"
922     );
923   }
924 
925   /**
926    * Parameter 'addlaunchers/addlauncher/icon' exists and has a value.
927    *
928    * @throws Exception if any errors occurred
929    */
930   @Test
931   @SuppressWarnings("unchecked") // unchecked cast
932   public void testMojoHasAddLaunchersAddLauncherIcon() throws Exception {
933     final List<Launcher> addlaunchers =
934         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
935     assertEquals("addlaunchers/addlauncher/icon",
936         TestUtils.getCanonicalPath(addlaunchers.get(0).getIcon()),
937         TestUtils.getCanonicalPath(new File(project.getBasedir(),
938             "config/jpackage/launcher1.ico"))
939     );
940   }
941 
942   /**
943    * Parameter 'addlaunchers/addlauncher/winconsole' exists and has a value.
944    *
945    * @throws Exception if any errors occurred
946    */
947   @Test
948   @SuppressWarnings("unchecked") // unchecked cast
949   public void testMojoHasAddLaunchersAddLauncherWinConsole() throws Exception {
950     final List<Launcher> addlaunchers =
951         (List<Launcher>) rule.getVariableValueFromObject(mojo, "addlaunchers");
952     assertTrue("addlaunchers/addlauncher/winconsole",
953         addlaunchers.get(0).isWinConsole());
954   }
955 
956   /**
957    * Parameter 'winconsole' exists and has a value.
958    *
959    * @throws Exception if any errors occurred
960    */
961   @Test
962   public void testMojoHasWinConsole() throws Exception {
963     final boolean winconsole =
964         (boolean) rule.getVariableValueFromObject(mojo, "winconsole");
965     assertFalse("winconsole",
966         winconsole);
967   }
968 
969   /**
970    * Parameter 'appimage' exists and has a value.
971    *
972    * @throws Exception if any errors occurred
973    */
974   @Test
975   public void testMojoHasAppImage() throws Exception {
976     final File appimage =
977         (File) rule.getVariableValueFromObject(mojo, "appimage");
978     assertEquals("appimage",
979         TestUtils.getCanonicalPath(appimage),
980         TestUtils.getCanonicalPath(new File(project.getBuild().getDirectory(),
981             "jpackage/appimage"))
982     );
983   }
984 
985   /**
986    * Parameter 'fileassociations' exists and has a value.
987    *
988    * @throws Exception if any errors occurred
989    */
990   @Test
991   @SuppressWarnings("unchecked") // unchecked cast
992   public void testMojoHasFileAssociations() throws Exception {
993     final List<File> fileassociations =
994         (List<File>) rule.getVariableValueFromObject(mojo, "fileassociations");
995     assertEquals("fileassociations",
996         TestUtils.buildPathFromFiles(fileassociations),
997         TestUtils.buildPathFromNames(PROJECT_DIR, Arrays.asList(
998             "config/jpackage/associations1.properties",
999             "config/jpackage/associations2.properties"
1000         ))
1001     );
1002   }
1003 
1004   /**
1005    * Parameter 'installdir' exists and has a value.
1006    *
1007    * @throws Exception if any errors occurred
1008    */
1009   @Test
1010   public void testMojoHasInstallDir() throws Exception {
1011     final String installdir =
1012         (String) rule.getVariableValueFromObject(mojo, "installdir");
1013     assertEquals("installdir",
1014         installdir,
1015         "Akman/My Application"
1016     );
1017   }
1018 
1019   /**
1020    * Parameter 'licensefile' exists and has a value.
1021    *
1022    * @throws Exception if any errors occurred
1023    */
1024   @Test
1025   public void testMojoHasLicenseFile() throws Exception {
1026     final File licensefile =
1027         (File) rule.getVariableValueFromObject(mojo, "licensefile");
1028     assertEquals("licensefile",
1029         TestUtils.getCanonicalPath(licensefile),
1030         TestUtils.getCanonicalPath(new File(project.getBasedir(),
1031             "config/jpackage/LICENSE"))
1032     );
1033   }
1034 
1035   /**
1036    * Parameter 'resourcedir' exists and has a value.
1037    *
1038    * @throws Exception if any errors occurred
1039    */
1040   @Test
1041   public void testMojoHasResourceDir() throws Exception {
1042     final File resourcedir =
1043         (File) rule.getVariableValueFromObject(mojo, "resourcedir");
1044     assertEquals("resourcedir",
1045         TestUtils.getCanonicalPath(resourcedir),
1046         TestUtils.getCanonicalPath(new File(project.getBasedir(),
1047             "config/jpackage/resources"))
1048     );
1049   }
1050 
1051   /**
1052    * Parameter 'windirchooser' exists and has a value.
1053    *
1054    * @throws Exception if any errors occurred
1055    */
1056   @Test
1057   public void testMojoHasWinDirChooser() throws Exception {
1058     final boolean windirchooser =
1059         (boolean) rule.getVariableValueFromObject(mojo, "windirchooser");
1060     assertTrue("windirchooser",
1061         windirchooser);
1062   }
1063 
1064   /**
1065    * Parameter 'winmenu' exists and has a value.
1066    *
1067    * @throws Exception if any errors occurred
1068    */
1069   @Test
1070   public void testMojoHasWinMenu() throws Exception {
1071     final boolean winmenu =
1072         (boolean) rule.getVariableValueFromObject(mojo, "winmenu");
1073     assertTrue("winmenu",
1074         winmenu);
1075   }
1076 
1077   /**
1078    * Parameter 'winmenugroup' exists and has a value.
1079    *
1080    * @throws Exception if any errors occurred
1081    */
1082   @Test
1083   public void testMojoHasWinMenuGroup() throws Exception {
1084     final String winmenugroup =
1085         (String) rule.getVariableValueFromObject(mojo, "winmenugroup");
1086     assertEquals("winmenugroup",
1087         winmenugroup,
1088         "JPackage"
1089     );
1090   }
1091 
1092   /**
1093    * Parameter 'winperuserinstall' exists and has a value.
1094    *
1095    * @throws Exception if any errors occurred
1096    */
1097   @Test
1098   public void testMojoHasWinPerUserInstall() throws Exception {
1099     final boolean winperuserinstall =
1100         (boolean) rule.getVariableValueFromObject(mojo, "winperuserinstall");
1101     assertTrue("winperuserinstall",
1102         winperuserinstall);
1103   }
1104 
1105   /**
1106    * Parameter 'winshortcut' exists and has a value.
1107    *
1108    * @throws Exception if any errors occurred
1109    */
1110   @Test
1111   public void testMojoHasWinShortcut() throws Exception {
1112     final boolean winshortcut =
1113         (boolean) rule.getVariableValueFromObject(mojo, "winshortcut");
1114     assertTrue("winshortcut",
1115         winshortcut);
1116   }
1117 
1118   /**
1119    * Parameter 'winupgradeuuid' exists and has a value.
1120    *
1121    * @throws Exception if any errors occurred
1122    */
1123   @Test
1124   public void testMojoHasWinUpgradeUuid() throws Exception {
1125     final String winupgradeuuid =
1126         (String) rule.getVariableValueFromObject(mojo, "winupgradeuuid");
1127     assertEquals("winupgradeuuid",
1128         winupgradeuuid,
1129         "8CF81762-0B19-46A6-875E-1F839A1700D0"
1130     );
1131   }
1132 
1133   /**
1134    * Parameter 'macpackageidentifier' exists and has a value.
1135    *
1136    * @throws Exception if any errors occurred
1137    */
1138   @Test
1139   public void testMojoHasMacPackageIdentifier() throws Exception {
1140     final String macpackageidentifier =
1141         (String) rule.getVariableValueFromObject(mojo, "macpackageidentifier");
1142     assertEquals("macpackageidentifier",
1143         macpackageidentifier,
1144         "macPackageIdentifier"
1145     );
1146   }
1147 
1148   /**
1149    * Parameter 'macpackagename' exists and has a value.
1150    *
1151    * @throws Exception if any errors occurred
1152    */
1153   @Test
1154   public void testMojoHasMacPackageName() throws Exception {
1155     final String macpackagename =
1156         (String) rule.getVariableValueFromObject(mojo, "macpackagename");
1157     assertEquals("macpackagename",
1158         macpackagename,
1159         "macPackageName"
1160     );
1161   }
1162 
1163   /**
1164    * Parameter 'macpackagesigningprefix' exists and has a value.
1165    *
1166    * @throws Exception if any errors occurred
1167    */
1168   @Test
1169   public void testMojoHasMacPackageSigningPrefix() throws Exception {
1170     final String macpackagesigningprefix =
1171         (String) rule.getVariableValueFromObject(mojo, "macpackagesigningprefix");
1172     assertEquals("macpackagesigningprefix",
1173         macpackagesigningprefix,
1174         "macPackageSigningPrefix"
1175     );
1176   }
1177 
1178   /**
1179    * Parameter 'macsign' exists and has a value.
1180    *
1181    * @throws Exception if any errors occurred
1182    */
1183   @Test
1184   public void testMojoHasMacSign() throws Exception {
1185     final boolean macsign =
1186         (boolean) rule.getVariableValueFromObject(mojo, "macsign");
1187     assertFalse("macsign",
1188         macsign);
1189   }
1190 
1191   /**
1192    * Parameter 'macsigningkeychain' exists and has a value.
1193    *
1194    * @throws Exception if any errors occurred
1195    */
1196   @Test
1197   public void testMojoHasMacSigningKeyChain() throws Exception {
1198     final File macsigningkeychain =
1199         (File) rule.getVariableValueFromObject(mojo, "macsigningkeychain");
1200     assertEquals("macsigningkeychain",
1201         TestUtils.getCanonicalPath(macsigningkeychain),
1202         TestUtils.getCanonicalPath(new File(project.getBasedir(),
1203             "macSigningKeyChain"))
1204     );
1205   }
1206 
1207   /**
1208    * Parameter 'macsigningkeyusername' exists and has a value.
1209    *
1210    * @throws Exception if any errors occurred
1211    */
1212   @Test
1213   public void testMojoHasMacSigningKeyUserName() throws Exception {
1214     final String macsigningkeyusername =
1215         (String) rule.getVariableValueFromObject(mojo, "macsigningkeyusername");
1216     assertEquals("macsigningkeyusername",
1217         macsigningkeyusername,
1218         "macSigningKeyUserName"
1219     );
1220   }
1221 
1222   /**
1223    * Parameter 'linuxpackagename' exists and has a value.
1224    *
1225    * @throws Exception if any errors occurred
1226    */
1227   @Test
1228   public void testMojoHasLinuxPackageName() throws Exception {
1229     final String linuxpackagename =
1230         (String) rule.getVariableValueFromObject(mojo, "linuxpackagename");
1231     assertEquals("linuxpackagename",
1232         linuxpackagename,
1233         "linuxPackageName"
1234     );
1235   }
1236 
1237   /**
1238    * Parameter 'linuxdebmaintainer' exists and has a value.
1239    *
1240    * @throws Exception if any errors occurred
1241    */
1242   @Test
1243   public void testMojoHasLinuxDebMaintainer() throws Exception {
1244     final String linuxdebmaintainer =
1245         (String) rule.getVariableValueFromObject(mojo, "linuxdebmaintainer");
1246     assertEquals("linuxdebmaintainer",
1247         linuxdebmaintainer,
1248         "linuxDebMaintainer"
1249     );
1250   }
1251 
1252   /**
1253    * Parameter 'linuxmenugroup' exists and has a value.
1254    *
1255    * @throws Exception if any errors occurred
1256    */
1257   @Test
1258   public void testMojoHasLinuxMenuGroup() throws Exception {
1259     final String linuxmenugroup =
1260         (String) rule.getVariableValueFromObject(mojo, "linuxmenugroup");
1261     assertEquals("linuxmenugroup",
1262         linuxmenugroup,
1263         "linuxMenuGroup"
1264     );
1265   }
1266 
1267   /**
1268    * Parameter 'linuxpackagedeps' exists and has a value.
1269    *
1270    * @throws Exception if any errors occurred
1271    */
1272   @Test
1273   public void testMojoHasLinuxPackageDeps() throws Exception {
1274     final boolean linuxpackagedeps =
1275         (boolean) rule.getVariableValueFromObject(mojo, "linuxpackagedeps");
1276     assertFalse("linuxpackagedeps",
1277         linuxpackagedeps);
1278   }
1279 
1280   /**
1281    * Parameter 'linuxrpmlicensetype' exists and has a value.
1282    *
1283    * @throws Exception if any errors occurred
1284    */
1285   @Test
1286   public void testMojoHasLinuxRpmLicenseType() throws Exception {
1287     final String linuxrpmlicensetype =
1288         (String) rule.getVariableValueFromObject(mojo, "linuxrpmlicensetype");
1289     assertEquals("linuxrpmlicensetype",
1290         linuxrpmlicensetype,
1291         "MIT"
1292     );
1293   }
1294 
1295   /**
1296    * Parameter 'linuxapprelease' exists and has a value.
1297    *
1298    * @throws Exception if any errors occurred
1299    */
1300   @Test
1301   public void testMojoHasLinuxAppRelease() throws Exception {
1302     final String linuxapprelease =
1303         (String) rule.getVariableValueFromObject(mojo, "linuxapprelease");
1304     assertEquals("linuxapprelease",
1305         linuxapprelease,
1306         "linuxAppRelease"
1307     );
1308   }
1309 
1310   /**
1311    * Parameter 'linuxappcategory' exists and has a value.
1312    *
1313    * @throws Exception if any errors occurred
1314    */
1315   @Test
1316   public void testMojoHasLinuxAppCategory() throws Exception {
1317     final String linuxappcategory =
1318         (String) rule.getVariableValueFromObject(mojo, "linuxappcategory");
1319     assertEquals("linuxappcategory",
1320         linuxappcategory,
1321         "linuxAppCategory"
1322     );
1323   }
1324 
1325   /**
1326    * Parameter 'linuxshortcut' exists and has a value.
1327    *
1328    * @throws Exception if any errors occurred
1329    */
1330   @Test
1331   public void testMojoHasLinuxShortcut() throws Exception {
1332     final boolean linuxshortcut =
1333         (boolean) rule.getVariableValueFromObject(mojo, "linuxshortcut");
1334     assertTrue("linuxshortcut",
1335         linuxshortcut);
1336   }
1337 
1338 }