KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > project > support > ant > SimpleAntArtifactTest


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.spi.project.support.ant;
21
22 import java.io.File JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.Collections JavaDoc;
26 import org.netbeans.api.project.ProjectManager;
27 import org.netbeans.api.project.TestUtil;
28 import org.netbeans.api.project.ant.AntArtifact;
29 import org.netbeans.junit.NbTestCase;
30 import org.openide.filesystems.FileObject;
31 import org.openide.filesystems.FileUtil;
32 import org.openide.util.Lookup;
33
34 /**
35  * Test functionality of SimpleAntArtifact.
36  * @author Jesse Glick
37  */

38 public class SimpleAntArtifactTest extends NbTestCase {
39     
40     public SimpleAntArtifactTest(String JavaDoc name) {
41         super(name);
42     }
43     
44     private FileObject scratch;
45     private FileObject sisterprojdir;
46     private ProjectManager pm;
47     private AntProjectHelper sisterh;
48     
49     protected void setUp() throws Exception JavaDoc {
50         super.setUp();
51         scratch = TestUtil.makeScratchDir(this);
52         TestUtil.setLookup(new Object JavaDoc[] {
53             AntBasedTestUtil.testAntBasedProjectType(),
54         });
55         pm = ProjectManager.getDefault();
56         sisterprojdir = FileUtil.createFolder(scratch, "proj2");
57         sisterh = ProjectGenerator.createProject(sisterprojdir, "test");
58         EditableProperties props = sisterh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
59         props.setProperty("build.jar", "build/proj2.jar");
60         props.setProperty("build.jar.absolute", getWorkDir().getAbsolutePath()+"/build/proj3.jar");
61         sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
62     }
63     
64     protected void tearDown() throws Exception JavaDoc {
65         scratch = null;
66         sisterprojdir = null;
67         sisterh = null;
68         pm = null;
69         TestUtil.setLookup(Lookup.EMPTY);
70         super.tearDown();
71     }
72     
73     /**
74      * Check that {@link SimpleAntArtifact} works as documented.
75      */

76     public void testSimpleAntArtifact() throws Exception JavaDoc {
77         AntArtifact art = sisterh.createSimpleAntArtifact("jar", "build.jar", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
78         assertEquals("correct type", "jar", art.getType());
79         assertEquals("correct target name", "dojar", art.getTargetName());
80         assertEquals("correct clean target name", "clean", art.getCleanTargetName());
81         assertEquals("correct artifact location", URI.create("build/proj2.jar"), art.getArtifactLocations()[0]);
82         assertEquals("no artifact file yet", 0, art.getArtifactFiles().length);
83         FileObject artfile = FileUtil.createData(sisterprojdir, "build/proj2.jar");
84         assertEquals("now have an artifact file", Collections.singletonList(artfile), Arrays.asList(art.getArtifactFiles()));
85         assertEquals("correct script location", new File JavaDoc(FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation());
86         assertEquals("no script file yet", null, art.getScriptFile());
87         FileObject scriptfile = FileUtil.createData(sisterprojdir, "build.xml");
88         assertEquals("now have a script file", scriptfile, art.getScriptFile());
89         assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject());
90         
91         art = sisterh.createSimpleAntArtifact("jar", "build.jar.absolute", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
92         assertEquals("correct artifact location", (new File JavaDoc(getWorkDir().getAbsolutePath()+"/build/proj3.jar")).toURI(), art.getArtifactLocations()[0]);
93     }
94     
95 }
96
Popular Tags