1 19 20 package org.netbeans.modules.ruby.api.project.rake; 21 22 import java.io.File ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.api.project.TestUtil; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.modules.ruby.spi.project.support.rake.RakeBasedTestUtil; 28 import org.netbeans.modules.ruby.spi.project.support.rake.RakeProjectHelper; 29 import org.netbeans.modules.ruby.spi.project.support.rake.EditableProperties; 30 import org.netbeans.modules.ruby.spi.project.support.rake.ProjectGenerator; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.Lookup; 34 35 41 42 46 public class RakeArtifactQueryTest extends NbTestCase { 47 48 public RakeArtifactQueryTest(String name) { 49 super(name); 50 } 51 52 private FileObject scratch; 53 private FileObject projdir; 54 private FileObject sisterprojdir; 55 private FileObject dummyprojdir; 56 private ProjectManager pm; 57 58 protected void setUp() throws Exception { 59 super.setUp(); 60 TestUtil.setLookup(new Object [] { 61 RakeBasedTestUtil.testRakeBasedProjectType(), 62 TestUtil.testProjectFactory(), 63 }); 64 scratch = TestUtil.makeScratchDir(this); 65 projdir = scratch.createFolder("proj"); 66 ProjectGenerator.createProject(projdir, "test"); 67 pm = ProjectManager.getDefault(); 68 sisterprojdir = FileUtil.createFolder(scratch, "proj2"); 69 RakeProjectHelper sisterh = ProjectGenerator.createProject(sisterprojdir, "test"); 70 EditableProperties props = sisterh.getProperties(RakeProjectHelper.PROJECT_PROPERTIES_PATH); 71 props.setProperty("build.jar", "dist/proj2.jar"); 72 props.setProperty("build.javadoc", "build/javadoc"); 73 sisterh.putProperties(RakeProjectHelper.PROJECT_PROPERTIES_PATH, props); 74 dummyprojdir = scratch.createFolder("dummy"); 75 dummyprojdir.createFolder("testproject"); 76 } 77 78 protected void tearDown() throws Exception { 79 scratch = null; 80 projdir = null; 81 sisterprojdir = null; 82 pm = null; 83 TestUtil.setLookup(Lookup.EMPTY); 84 super.tearDown(); 85 } 86 87 public void testFindArtifactFromFile() throws Exception { 88 FileObject proj2JarFO = FileUtil.createData(sisterprojdir, "dist/proj2.jar"); 89 File proj2Jar = FileUtil.toFile(proj2JarFO); 90 assertNotNull("have dist/proj2.jar on disk", proj2Jar); 91 RakeArtifact art = RakeArtifactQuery.findArtifactFromFile(proj2Jar); 92 assertNotNull("found an artifact matching " + proj2Jar, art); 93 assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject()); 94 assertEquals("correct artifact file", proj2JarFO, art.getArtifactFiles()[0]); 95 assertEquals("correct target name", "dojar", art.getTargetName()); 96 assertEquals("correct clean target name", "clean", art.getCleanTargetName()); 97 assertEquals("correct type", "jar", art.getType()); 98 assertEquals("correct script location", new File (FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation()); 99 } 100 101 public void testFindArtifactsByType() throws Exception { 102 Project p = pm.findProject(projdir); 103 assertNotNull("have a project in " + projdir, p); 104 RakeArtifact[] arts = RakeArtifactQuery.findArtifactsByType(p, "jar"); 105 assertEquals("one JAR artifact", 1, arts.length); 106 assertEquals("correct project", p, arts[0].getProject()); 107 assertEquals("correct target name", "dojar", arts[0].getTargetName()); 108 p = pm.findProject(dummyprojdir); 109 assertNotNull("have a dummy project in " + dummyprojdir, p); 110 arts = RakeArtifactQuery.findArtifactsByType(p, "jar"); 111 assertEquals("no JAR artifacts", 0, arts.length); 112 } 113 114 } 115 | Popular Tags |