1 22 package org.objectweb.petals.tools.packageplugin; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.lang.reflect.Method ; 27 import java.util.ArrayList ; 28 import java.util.List ; 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 43 public class PackageAssemblyMojoTest extends TestCase { 44 45 private String 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 , 54 NoSuchMethodException , IOException { 55 PackageAssemblyMojo assemblyMojo = EasyMock.createMock( 56 PackageAssemblyMojo.class, new Method [] { 57 PackageAssemblyMojo.class.getDeclaredMethod("prepare", 58 new Class [] {}), 59 PackageAssemblyMojo.class.getDeclaredMethod( 60 "copyRessources", new Class [] {}), 61 PackageAssemblyMojo.class.getDeclaredMethod("copyLib", 62 new Class [] {}), 63 PackageAssemblyMojo.class.getDeclaredMethod( 64 "copyMonitoringRessources", new Class [] {}), 65 PackageAssemblyMojo.class.getDeclaredMethod( 66 "makeMonitoringServerJar", new Class [] {}), 67 PackageAssemblyMojo.class.getDeclaredMethod( 68 "makeServerJar", new Class [] {})}); 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 { 83 PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo(); 84 85 File as = new File (baseDir + "target" + File.separator 86 + "test-assembly"); 87 assemblyMojo.petalsAssemblyDirectory = as; 88 89 assemblyMojo.prepare(); 90 91 assertTrue(new File (as + File.separator + "ant").exists()); 92 assertTrue(new File (as + File.separator + "bin").exists()); 93 assertTrue(new File (as + File.separator + "components").exists()); 94 assertTrue(new File (as + File.separator + "conf").exists()); 95 assertTrue(new File (as + File.separator + "demos").exists()); 96 assertTrue(new File (as + File.separator + "lib").exists()); 97 assertTrue(new File (as + File.separator + "logs").exists()); 98 assertTrue(new File (as + File.separator + "schema").exists()); 99 assertTrue(new File (as + File.separator + "install").exists()); 100 assertTrue(new File (as + File.separator + "installed").exists()); 101 assertTrue(new File (as + File.separator + "uninstalled").exists()); 102 } 103 104 public void testCopyRessources() throws IOException { 105 PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo(); 106 107 String assemblyDir = baseDir.replace("tools", "platform"); 108 assemblyDir = assemblyDir.replace("package-plugin", "assembly"); 109 110 assemblyMojo.baseDir = new File (assemblyDir); 111 File as = new File (baseDir + "target" + File.separator 112 + "test-assembly"); 113 assemblyMojo.petalsAssemblyDirectory = as; 114 115 assemblyMojo.copyRessources(); 116 117 assertTrue(new File (as + File.separator + "bin" + File.separator 118 + "startup.bat").exists()); 119 assertTrue(new File (as + File.separator + "conf" + File.separator 120 + "julia.cfg").exists()); 121 assertTrue(new File (as + File.separator + "schema" + File.separator 122 + "jbi.xsd").exists()); 123 } 124 125 public void testCopyLib() throws IOException { 126 PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo(); 127 128 assemblyMojo.baseDir = new File (baseDir.replace("tools" 129 + File.separator + "package-plugin", "platform" 130 + File.separator + "assembly")); 131 File as = new File (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 <Dependency> deps = new ArrayList <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 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 (as + File.separator + "lib" + File.separator 161 + "jbi-1.0.jar").exists()); 162 } 163 164 public void testMakeServerJar() throws IOException { 165 PackageAssemblyMojo assemblyMojo = new PackageAssemblyMojo(); 166 167 assemblyMojo.baseDir = new File (baseDir.replace("tools" 168 + File.separator + "package-plugin", "platform" 169 + File.separator + "assembly")); 170 File as = new File (baseDir + "target" + File.separator 171 + "test-assembly"); 172 assemblyMojo.petalsAssemblyDirectory = as; 173 174 assemblyMojo.makeServerJar(); 175 176 assertTrue(new File (as + File.separator + "bin" + File.separator 177 + "server.jar").exists()); 178 } 179 180 } 181 | Popular Tags |