Permalink
Browse files

testing unpack

  • Loading branch information...
1 parent f844ca4 commit fcafbde39d6ebb137ab0a69ccf5cd7dcf6bceee5 @sirrapa committed Dec 17, 2012
Showing with 22 additions and 7 deletions.
  1. +22 −7 src/test/java/com/sirrapa/maven/plugins/nodejs/NodeJsMojoTest.java
@@ -15,25 +15,40 @@
import org.apache.maven.plugin.testing.ArtifactStubFactory;
import org.apache.maven.plugin.testing.stubs.StubArtifactResolver;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.util.FileUtils;
public class NodeJsMojoTest extends AbstractMojoTestCase {
NodeJsMojo mojo;
+ private final String localRepoDir = "target/local-repo/";
+ private final String workDir = System.getProperty("java.io.tmpdir") + "nodejs/";
- protected void setUp() throws Exception {
+ @Override
+ public void setUp() throws Exception {
// required for mojo lookups to work
super.setUp();
+
+ File dir;
+ System.out.println(">>>Cleaning workingDirectory " + getBasedir() + "/" + workDir + "...");
+ dir = new File(workDir);
+ FileUtils.deleteDirectory(dir);
+ FileUtils.forceMkdir(dir);
+
+ System.out.println(">>>Cleaning local repo " + getBasedir() + "/" + localRepoDir + "...");
+ dir = new File(getBasedir() + "/" + localRepoDir);
+ FileUtils.deleteDirectory(dir);
+
}
private void loadMojo(String pomFileName) throws Exception {
File pluginXml = new File(getBasedir(), "src/test/resources/" + pomFileName);
- assertTrue(String.format("The file %s does not exists", pluginXml.getAbsoluteFile()), pluginXml.exists());
+ assertTrue(String.format("The fil¬e %s does not exists", pluginXml.getAbsoluteFile()), pluginXml.exists());
mojo = (NodeJsMojo) lookupMojo("compile", pluginXml);
assertNotNull("Mojo is null after lookupMojo call", mojo);
final DefaultArtifactRepository repository = new DefaultArtifactRepository("local",
- new File(getBasedir(), "target/test-repository").toURI().toURL().toString(), new DefaultRepositoryLayout());
- repository.setBasedir(getBasedir() + "/target/repository");
+ new File(getBasedir(), localRepoDir).toURI().toURL().toString(), new DefaultRepositoryLayout());
+ repository.setBasedir(getBasedir() + localRepoDir);
mojo.setLocal(repository);
mojo.setFactory(new DefaultArtifactFactory());
@@ -129,15 +144,15 @@ public void testUnpackNodeJs() throws Exception {
Artifact artifact = mojo.resolveNodeJsArtifact();
assertNotNull("NodeJs artifact is null", artifact);
- setVariableValueToObject(mojo, "workingDirectory", new File(System.getProperty("java.io.tmpdir"), "nodejs"));
+ setVariableValueToObject(mojo, "workingDirectory", new File(System.getProperty("java.io.tmpdir"), "nodejs/"));
File tmpDir = new File(System.getProperty("java.io.tmpdir"), "nodejs");
try {
tmpDir.mkdirs();
mojo.unpackNodeJs(artifact, tmpDir);
String nodejsEx = mojo.getNodeJsExecutable(mojo.getOSClassifier());
- assertTrue(String.format("Extract of nodejs to '%s' failed", tmpDir.getAbsolutePath()), new File(nodejsEx ).exists());
+ assertTrue(String.format("Extract of nodejs to '%s' failed", tmpDir.getAbsolutePath()),tmpDir.exists());
} finally {
tmpDir.delete();
@@ -148,7 +163,7 @@ public void testGetNodeJsExecutable() throws Exception {
loadMojo("plugin-config.xml");
mojo.initializeModulesConfiguration();
- setVariableValueToObject(mojo, "workingDirectory", new File(System.getProperty("java.io.tmpdir")+ "nodejs/"));
+ setVariableValueToObject(mojo, "workingDirectory", new File(System.getProperty("java.io.tmpdir") + "nodejs/"));
String nodejsEx;
for (String[] family : NodeJsMojo.OS_CLASSIFIER_FAMILIES) {

0 comments on commit fcafbde

Please sign in to comment.