1 22 package org.objectweb.petals.tools.jbiplugin; 23 24 import java.io.File ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import junit.framework.TestCase; 29 30 import org.apache.maven.model.Dependency; 31 import org.apache.maven.plugin.MojoExecutionException; 32 import org.apache.maven.project.MavenProject; 33 import org.objectweb.petals.tools.jbiplugin.mock.ArtifactMock; 34 import org.objectweb.petals.tools.jbiplugin.mock.ArtifactRepositoryMock; 35 36 41 public class JBIPluginMojoTest extends TestCase { 42 43 public void testExecute() throws MojoExecutionException { 44 String baseDir = this.getClass().getResource(".").toString(); 45 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 46 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 47 JBIPluginMojo plugin = new JBIPluginMojo(); 48 plugin.jbiDirectory = new File (baseDir + "src" + File.separator 49 + "test-data" + File.separator + "conf"); 50 51 ArtifactRepositoryMock artifactRepositoryMock = new ArtifactRepositoryMock(); 52 artifactRepositoryMock.setBaseDir(baseDir + "src" + File.separator 53 + "test-data" + File.separator + "repository"); 54 plugin.localRepository = artifactRepositoryMock; 55 56 MavenProject project = new MavenProject(); 57 project.setArtifact(new ArtifactMock()); 58 List <Dependency> dependencies = new ArrayList <Dependency>(); 59 Dependency dependency = new Dependency(); 60 dependency.setArtifactId("test"); 61 dependency.setGroupId("test"); 62 dependency.setVersion("1.0"); 63 dependencies.add(dependency); 64 65 project.setDependencies(dependencies); 66 plugin.toExcludes = ""; 67 plugin.project = project; 68 plugin.outputDirectory = new File (baseDir + "target"); 69 plugin.jbiName = "test"; 70 71 plugin.componentJar = new File (baseDir + "src" + File.separator 72 + "test-data" + File.separator + "component.jar"); 73 74 plugin.execute(); 75 } 76 77 public void testExecuteWithSubDep() throws MojoExecutionException { 78 String baseDir = new File (".").getAbsolutePath(); 79 baseDir = baseDir.substring(0, baseDir.length() - 1); 80 if (!baseDir.endsWith("jbi-plugin" + File.separator)) { 81 baseDir += "tools" + File.separator + "jbi-plugin" + File.separator; 82 } 83 JBIPluginMojo plugin = new JBIPluginMojo(); 84 plugin.jbiDirectory = new File (baseDir + "src" + File.separator 85 + "test-data" + File.separator + "conf"); 86 87 ArtifactRepositoryMock artifactRepositoryMock = new ArtifactRepositoryMock(); 88 artifactRepositoryMock.setBaseDir(baseDir + "src" + File.separator 89 + "test-data" + File.separator + "repository"); 90 plugin.localRepository = artifactRepositoryMock; 91 92 MavenProject project = new MavenProject(); 93 project.setArtifact(new ArtifactMock()); 94 List <Dependency> dependencies = new ArrayList <Dependency>(); 95 Dependency dependency = new Dependency(); 96 dependency.setArtifactId("test"); 97 dependency.setGroupId("test"); 98 dependency.setVersion("1.0"); 99 dependencies.add(dependency); 100 101 project.setDependencies(dependencies); 102 plugin.project = project; 103 plugin.toExcludes = ""; 104 plugin.outputDirectory = new File (baseDir + "target"); 105 plugin.jbiName = "test"; 106 107 plugin.componentJar = new File (baseDir + "src" + File.separator 108 + "test-data" + File.separator + "component.jar"); 109 plugin.includeSubDependencies = true; 110 111 plugin.execute(); 112 } 113 114 public void testExecuteUpdateJBI() throws MojoExecutionException { 115 String baseDir = new File (".").getAbsolutePath(); 116 baseDir = baseDir.substring(0, baseDir.length() - 1); 117 if (!baseDir.endsWith("jbi-plugin" + File.separator)) { 118 baseDir += "tools" + File.separator + "jbi-plugin" + File.separator; 119 } 120 JBIPluginMojo plugin = new JBIPluginMojo(); 121 plugin.jbiDirectory = new File (baseDir + "src" + File.separator 122 + "test-data" + File.separator + "conf"); 123 124 ArtifactRepositoryMock artifactRepositoryMock = new ArtifactRepositoryMock(); 125 artifactRepositoryMock.setBaseDir(baseDir + "src" + File.separator 126 + "test-data" + File.separator + "repository"); 127 plugin.localRepository = artifactRepositoryMock; 128 129 MavenProject project = new MavenProject(); 130 project.setArtifact(new ArtifactMock()); 131 List <Dependency> dependencies = new ArrayList <Dependency>(); 132 Dependency dependency = new Dependency(); 133 dependency.setArtifactId("test"); 134 dependency.setGroupId("test"); 135 dependency.setVersion("1.0"); 136 dependencies.add(dependency); 137 138 project.setDependencies(dependencies); 139 plugin.project = project; 140 plugin.toExcludes = ""; 141 plugin.updateJBIXml = true; 142 plugin.outputDirectory = new File (baseDir + "target"); 143 plugin.jbiName = "test"; 144 145 plugin.componentJar = new File (baseDir + "src" + File.separator 146 + "test-data" + File.separator + "component.jar"); 147 plugin.includeSubDependencies = true; 148 149 plugin.execute(); 150 } 151 152 } 153 | Popular Tags |