KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > project > ant > AntArtifactQueryTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.project.ant;
21
22 import java.io.File JavaDoc;
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.spi.project.support.ant.AntBasedTestUtil;
28 import org.netbeans.spi.project.support.ant.AntProjectHelper;
29 import org.netbeans.spi.project.support.ant.EditableProperties;
30 import org.netbeans.spi.project.support.ant.ProjectGenerator;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33 import org.openide.util.Lookup;
34
35 /* XXX tests needed:
36  * - testFindArtifactFromNonexistentFile
37  * like testFindArtifactFromFile but file does not yet exist on disk
38  * - testFindArtifactByTarget
39  * - testFindArtifactsByType
40  */

41
42 /**
43  * Test functionality of AntArtifactQuery, StandardAntArtifactQueryImpl, etc.
44  * @author Jesse Glick
45  */

46 public class AntArtifactQueryTest extends NbTestCase {
47     
48     public AntArtifactQueryTest(String JavaDoc 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 JavaDoc {
59         super.setUp();
60         TestUtil.setLookup(new Object JavaDoc[] {
61             AntBasedTestUtil.testAntBasedProjectType(),
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         AntProjectHelper sisterh = ProjectGenerator.createProject(sisterprojdir, "test");
70         EditableProperties props = sisterh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
71         props.setProperty("build.jar", "dist/proj2.jar");
72         props.setProperty("build.javadoc", "build/javadoc");
73         sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
74         dummyprojdir = scratch.createFolder("dummy");
75         dummyprojdir.createFolder("testproject");
76     }
77
78     protected void tearDown() throws Exception JavaDoc {
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 JavaDoc {
88         FileObject proj2JarFO = FileUtil.createData(sisterprojdir, "dist/proj2.jar");
89         File JavaDoc proj2Jar = FileUtil.toFile(proj2JarFO);
90         assertNotNull("have dist/proj2.jar on disk", proj2Jar);
91         AntArtifact art = AntArtifactQuery.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 JavaDoc(FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation());
99     }
100     
101     public void testFindArtifactsByType() throws Exception JavaDoc {
102         Project p = pm.findProject(projdir);
103         assertNotNull("have a project in " + projdir, p);
104         AntArtifact[] arts = AntArtifactQuery.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 = AntArtifactQuery.findArtifactsByType(p, "jar");
111         assertEquals("no JAR artifacts", 0, arts.length);
112     }
113     
114 }
115
Popular Tags