KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > packageplugin > PackageAssemblyMojoTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: PackageAssemblyMojoTest.java 1:09:38 PM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.tools.packageplugin;
23
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.maven.artifact.repository.ArtifactRepository;
31 import org.apache.maven.model.Dependency;
32 import org.apache.maven.plugin.MojoExecutionException;
33 import org.apache.maven.project.MavenProject;
34 import org.easymock.classextension.EasyMock;
35
36 import junit.framework.TestCase;
37
38 /**
39  * Tests of PackageAssemblyMojo
40  *
41  * @author ddesjardins - eBMWebsourcing
42  */

43 public class PackageAssemblyMojoTest extends TestCase {
44
45     private String JavaDoc baseDir;
46
47     public void setUp() {
48         baseDir = this.getClass().getResource(".").toString();
49         baseDir = baseDir.substring(0, baseDir.indexOf("target"));
50         baseDir = baseDir.substring(baseDir.indexOf(":") + 1);
51     }
52
53     public void testExecute() throws MojoExecutionException, SecurityException JavaDoc,
54         NoSuchMethodException JavaDoc, IOException JavaDoc {
55         PackageAssemblyMojo assemblyMojo = EasyMock.createMock(
56                 PackageAssemblyMojo.class, new Method JavaDoc[] {
57                     PackageAssemblyMojo.class.getDeclaredMethod("prepare",
58                             new Class JavaDoc[] {}),
59                     PackageAssemblyMojo.class.getDeclaredMethod(
60                             "copyRessources", new Class JavaDoc[] {}),
61                     PackageAssemblyMojo.class.getDeclaredMethod("copyLib",
62                             new Class JavaDoc[] {}),
63                     PackageAssemblyMojo.class.getDeclaredMethod(
64                             "copyMonitoringRessources", new Class JavaDoc[] {}),
65                     PackageAssemblyMojo.class.getDeclaredMethod(
66                             "makeMonitoringServerJar", new Class JavaDoc[] {}),
67                     PackageAssemblyMojo.class.getDeclaredMethod(
68                             "makeServerJar", new Class JavaDoc[] {})});
69
70         assemblyMojo.prepare();
71         assemblyMojo.copyRessources();
72         assemblyMojo.copyLib();
73         assemblyMojo.makeServerJar();
74         
75         EasyMock.replay(assemblyMojo);
76
77         assemblyMojo.execute();
78
79         EasyMock.verify(assemblyMojo);
80     }
81
82     public void testPrepare() throws IOException JavaDoc {
83         PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo();
84
85         File JavaDoc as = new File JavaDoc(baseDir + "target" + File.separator
86                 + "test-assembly");
87         assemblyMojo.petalsAssemblyDirectory = as;
88
89         assemblyMojo.prepare();
90
91         assertTrue(new File JavaDoc(as + File.separator + "ant").exists());
92         assertTrue(new File JavaDoc(as + File.separator + "bin").exists());
93         assertTrue(new File JavaDoc(as + File.separator + "components").exists());
94         assertTrue(new File JavaDoc(as + File.separator + "conf").exists());
95         assertTrue(new File JavaDoc(as + File.separator + "demos").exists());
96         assertTrue(new File JavaDoc(as + File.separator + "lib").exists());
97         assertTrue(new File JavaDoc(as + File.separator + "logs").exists());
98         assertTrue(new File JavaDoc(as + File.separator + "schema").exists());
99         assertTrue(new File JavaDoc(as + File.separator + "install").exists());
100         assertTrue(new File JavaDoc(as + File.separator + "installed").exists());
101         assertTrue(new File JavaDoc(as + File.separator + "uninstalled").exists());
102     }
103
104     public void testCopyRessources() throws IOException JavaDoc {
105         PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo();
106
107         String JavaDoc assemblyDir = baseDir.replace("tools", "platform");
108         assemblyDir = assemblyDir.replace("package-plugin", "assembly");
109
110         assemblyMojo.baseDir = new File JavaDoc(assemblyDir);
111         File JavaDoc as = new File JavaDoc(baseDir + "target" + File.separator
112                 + "test-assembly");
113         assemblyMojo.petalsAssemblyDirectory = as;
114
115         assemblyMojo.copyRessources();
116
117         assertTrue(new File JavaDoc(as + File.separator + "bin" + File.separator
118                 + "startup.bat").exists());
119         assertTrue(new File JavaDoc(as + File.separator + "conf" + File.separator
120                 + "julia.cfg").exists());
121         assertTrue(new File JavaDoc(as + File.separator + "schema" + File.separator
122                 + "jbi.xsd").exists());
123     }
124
125     public void testCopyLib() throws IOException JavaDoc {
126         PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo();
127
128         assemblyMojo.baseDir = new File JavaDoc(baseDir.replace("tools"
129                 + File.separator + "package-plugin", "platform"
130                 + File.separator + "assembly"));
131         File JavaDoc as = new File JavaDoc(baseDir + "target" + File.separator
132                 + "test-assembly");
133         assemblyMojo.petalsAssemblyDirectory = as;
134
135         MavenProject project = EasyMock.createMock(MavenProject.class);
136         ArtifactRepository artifactRepository = EasyMock
137                 .createMock(ArtifactRepository.class);
138
139         List JavaDoc<Dependency> deps = new ArrayList JavaDoc<Dependency>();
140         Dependency dependency = new Dependency();
141         dependency.setArtifactId("jbi");
142         dependency.setGroupId("javax.jbi");
143         dependency.setVersion("1.0");
144         dependency.setScope(null);
145         deps.add(dependency);
146
147         EasyMock.expect(project.getDependencies()).andReturn(deps).anyTimes();
148
149         String JavaDoc bd = System.getProperty("user.home");
150         EasyMock.expect(artifactRepository.getBasedir()).andReturn(
151                 bd + File.separator + ".m2" + File.separator + "repository");
152
153         EasyMock.replay(project);
154         EasyMock.replay(artifactRepository);
155
156         assemblyMojo.project = project;
157         assemblyMojo.localRepository = artifactRepository;
158         assemblyMojo.copyLib();
159
160         assertTrue(new File JavaDoc(as + File.separator + "lib" + File.separator
161                 + "jbi-1.0.jar").exists());
162     }
163
164     public void testMakeServerJar() throws IOException JavaDoc {
165         PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo();
166
167         assemblyMojo.baseDir = new File JavaDoc(baseDir.replace("tools"
168                 + File.separator + "package-plugin", "platform"
169                 + File.separator + "assembly"));
170         File JavaDoc as = new File JavaDoc(baseDir + "target" + File.separator
171                 + "test-assembly");
172         assemblyMojo.petalsAssemblyDirectory = as;
173
174         assemblyMojo.makeServerJar();
175
176         assertTrue(new File JavaDoc(as + File.separator + "bin" + File.separator
177                 + "server.jar").exists());
178     }
179
180 }
181
Popular Tags