1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is the maven-har-plugin.
15 *
16 * The Initial Developer of the Original Code is
17 * the Vermont Department of Taxes.
18 * Portions created by the Initial Developer are Copyright (C) 2007
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Tom Cort <tom.cort@state.vt.us>
23 *
24 * ***** END LICENSE BLOCK ***** */
25
26 package net.sf.mavenhar;
27
28 import org.apache.maven.cli.ConsoleDownloadMonitor;
29 import org.apache.maven.embedder.MavenEmbedder;
30 import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
31 import org.apache.maven.embedder.PlexusLoggerAdapter;
32 import org.apache.maven.monitor.event.EventMonitor;
33 import org.apache.maven.monitor.event.DefaultEventMonitor;
34 import org.apache.maven.project.MavenProject;
35 import junit.framework.TestCase;
36
37 import java.io.File;
38 import java.io.FileInputStream;
39 import java.io.FileNotFoundException;
40 import java.io.FileOutputStream;
41 import java.io.IOException;
42
43 import java.nio.channels.FileChannel;
44
45 import java.util.Collections;
46 import java.util.List;
47
48 public class HarMojoTest extends TestCase {
49
50 /**
51 * Temporary repo to use while we do some testing.
52 */
53 File repo = new File("target/test-classes/unit/dummy-repo");
54
55 /**
56 * Copy a file from src to dest.
57 *
58 * @param src location of file to copy.
59 * @param dest location of copied file.
60 * @throws FileNotFoundException when a file doesn't exist.
61 * @throws IOException when FileChannel fails.
62 */
63 public void copy(File src, File dest) throws FileNotFoundException, IOException {
64
65 FileInputStream srcStream = new FileInputStream(src);
66 FileOutputStream destStream = new FileOutputStream(dest);
67
68 FileChannel srcChannel = srcStream.getChannel();
69 FileChannel destChannel = destStream.getChannel();
70
71 srcChannel.transferTo(0, srcChannel.size(), destChannel);
72
73 destChannel.close();
74 srcChannel.close();
75
76 destStream.close();
77 srcStream.close();
78 }
79
80 public void testMavenHarPluginJarExists() throws Exception {
81 /*
82 // Configure MavenEmbedder
83 MavenEmbedder embedder = new MavenEmbedder();
84 embedder.setClassLoader(Thread.currentThread().getContextClassLoader());
85 embedder.setLogger(new MavenEmbedderConsoleLogger());
86 embedder.setOffline(true);
87
88 // Configure Dummy Repository
89 embedder.setLocalRepositoryDirectory(repo);
90 embedder.setOffline(true);
91
92 // Init
93 embedder.start();
94
95 File mavenHarPluginJar = new File("target/maven-har-plugin-1.0-SNAPSHOT.jar");
96 embedder.getLogger().info("mavenHarPluginJar exists? => " + mavenHarPluginJar.exists());
97 assertTrue(mavenHarPluginJar.exists());
98
99 // Cleanup
100 embedder.stop();
101 */
102 }
103
104 /**
105 * Functional Testing. This method builds a har.
106 *
107 * @throws Exception
108 */
109 public void testGenerateSimpleHarPackage() throws Exception {
110
111 /*
112 // Configure MavenEmbedder
113 MavenEmbedder embedder = new MavenEmbedder();
114 embedder.setClassLoader(Thread.currentThread().getContextClassLoader());
115 embedder.setLogger(new MavenEmbedderConsoleLogger());
116 embedder.setOffline(true);
117
118 // Configure Dummy Repository
119 embedder.setLocalRepositoryDirectory(repo);
120 embedder.setOffline(true);
121
122 // Init
123 embedder.start();
124
125 // Configure Project
126 File baseDir = new File("target/test-classes/unit/basic-har-package");
127 File pom = new File(baseDir, "plugin-config.xml");
128 MavenProject project = embedder.readProjectWithDependencies(pom);
129
130 // Configure Event Monitor
131 EventMonitor eventMonitor = new DefaultEventMonitor(new PlexusLoggerAdapter(new MavenEmbedderConsoleLogger()));
132
133 // Configure goals
134 List<String> goals = Collections.singletonList("net.sf.maven-har:maven-har-plugin:1.0-SNAPSHOT:har");
135
136 // Execute
137 embedder.execute(project, goals, eventMonitor, new ConsoleDownloadMonitor(), null, baseDir);
138
139 // Assertions here!
140
141 // Cleanup
142 embedder.stop();
143 */
144 boolean blah = false;
145 assertFalse(blah);
146 }
147 }