KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > BuildPaintapplicationTest


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.modules.apisupport.project;
21
22 import java.io.File JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import org.apache.tools.ant.module.api.support.ActionUtils;
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
27 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
28 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
29 import org.openide.DialogDescriptor;
30 import org.openide.execution.ExecutorTask;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33
34 /**
35  * Tests Paintapp sample.
36  * Invokes various Ant targets over Paintapp sample.
37  *
38  * @author Tomas Musil
39  */

40 public class BuildPaintapplicationTest extends TestBase {
41     
42     private File JavaDoc paintFolder = null;
43     
44     static {
45         // #65461: do not try to load ModuleInfo instances from ant module
46
System.setProperty("org.netbeans.core.startup.ModuleSystem.CULPRIT", "true");
47         LayerTestBase.Lkp.setLookup(new Object JavaDoc[0]);
48         DialogDisplayerImpl.returnFromNotify(DialogDescriptor.NO_OPTION);
49     }
50     
51     public BuildPaintapplicationTest(String JavaDoc testName) {
52         super(testName);
53     }
54     
55     protected void setUp() throws Exception JavaDoc {
56         clearWorkDir();
57         noDataDir = true;
58         super.setUp();
59         InstalledFileLocatorImpl.registerDestDir(destDirF);
60         TestAntLogger.getDefault().setEnabled(true);
61     }
62     
63     protected void tearDown() throws Exception JavaDoc {
64         TestAntLogger.getDefault().setEnabled(false);
65     }
66     
67     /**
68      * Extracts paintapp to workdir, then platform properties are copied and ant task(s) is called. Build status is returned
69      */

70     public int runAntTargetsOnPaintapp(String JavaDoc[] targets) throws Exception JavaDoc{
71         InputStream JavaDoc is = getClass().getClassLoader().getResourceAsStream("org/netbeans/modules/apisupport/paintapp/PaintAppProject.zip");
72         assertNotNull(is);
73         paintFolder = new File JavaDoc(getWorkDir(),"paintapp");
74         paintFolder.mkdir();
75         FileObject fo = FileUtil.toFileObject(paintFolder);
76         assertNotNull(fo);
77         
78         
79         try {
80             FileUtil.extractJar(fo,is);
81         } finally {
82             is.close();
83         }
84         
85         File JavaDoc buildProps = new File JavaDoc(getWorkDir(), "build.properties");
86         File JavaDoc privateFolder = new File JavaDoc(new File JavaDoc(paintFolder, "nbproject"),"private");
87         privateFolder.mkdir();
88         
89         FileObject platfPrivateProps = FileUtil.copyFile(FileUtil.toFileObject(buildProps), FileUtil.toFileObject(privateFolder), "platform-private");
90         assertNotNull(platfPrivateProps);
91         SuiteProject PaintappSuite = (SuiteProject) ProjectManager.getDefault().findProject(fo);
92         assertNotNull(PaintappSuite);
93         FileObject buildScript = PaintappSuite.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
94         assertNotNull(buildScript);
95         assertTrue(buildScript.isValid());
96         
97         System.out.println("------------- BUILD OUTPUT --------------");
98         ExecutorTask et = ActionUtils.runTarget(buildScript, targets, null);
99         et.waitFinished();
100         System.out.println("-----------------------------------------");
101         
102         return et.result();
103     }
104     
105     /**
106      * Invokes build-jnlp target on paintapp
107      */

108     public void testBuildJNLP() throws Exception JavaDoc {
109         int ret = runAntTargetsOnPaintapp(new String JavaDoc[] {"build-jnlp"});
110         assertEquals("build-jnlp ant target should return zero - build successful", 0 , ret);
111         File JavaDoc dist = new File JavaDoc(paintFolder,"dist");
112         File JavaDoc warFile = new File JavaDoc(dist,"paintit.war");
113         assertTrue("paintit.war file should be in dist folder", warFile.exists());
114         
115     }
116     
117     /**
118      * Invokes build-zip target on paintapp
119      */

120     public void testBuildZip() throws Exception JavaDoc {
121         int ret = runAntTargetsOnPaintapp(new String JavaDoc[] {"build-zip"});
122         assertEquals("build-zipant target should return zero - build successful", 0 , ret);
123         File JavaDoc dist = new File JavaDoc(paintFolder,"dist");
124         File JavaDoc zipFile = new File JavaDoc(dist,"paintit.zip");
125         assertTrue("paintit.zip file should be in dist folder", zipFile.exists());
126     }
127     
128     /**
129      * Invokes build target on paintapp
130      */

131     public void testBuild() throws Exception JavaDoc {
132         int ret = runAntTargetsOnPaintapp(new String JavaDoc[] {"build"});
133         assertEquals("build ant target should return zero - build successful", 0 , ret);
134         File JavaDoc buildFolder = new File JavaDoc(paintFolder,"build");
135         assertTrue("build folder should exist", buildFolder.exists() && buildFolder.isDirectory());
136         String JavaDoc[] children = buildFolder.list();
137         assertTrue("build folder is not empty", children.length>0);
138         
139     }
140     
141     /**
142      * Invokes nbms target on paintapp
143      */

144     public void testBuildNBMs() throws Exception JavaDoc {
145         int ret = runAntTargetsOnPaintapp(new String JavaDoc[] {"nbms"});
146         assertEquals("build ant target should return zero - build successful", 0 , ret);
147         File JavaDoc buildFolder = new File JavaDoc(paintFolder,"build");
148         File JavaDoc updatesFolder = new File JavaDoc(buildFolder,"updates");
149         assertTrue("build/update folder exists", updatesFolder.exists() && updatesFolder.isDirectory());
150         File JavaDoc paintNbm = new File JavaDoc(updatesFolder, "org-netbeans-paint.nbm");
151         File JavaDoc colorchooserNbm = new File JavaDoc(updatesFolder, "org-netbeans-swing-colorchooser.nbm");
152         assertTrue("Both nbms(paint+colorchooser) are in build/updates folder", paintNbm.exists() && colorchooserNbm.exists());
153     }
154     
155     /**
156      * Invokes clean target on paintapp
157      */

158     public void testClean() throws Exception JavaDoc {
159         int ret = runAntTargetsOnPaintapp(new String JavaDoc[] {"clean"});
160         assertEquals("clean ant target should return zero - build successful", 0 , ret);
161         File JavaDoc buildFolder = new File JavaDoc(paintFolder,"build");
162         File JavaDoc distFolder = new File JavaDoc(paintFolder,"dist");
163         assertTrue("build and dist folders are deleted", !distFolder.exists() && !buildFolder.exists());
164     }
165     
166 }
167
168
Popular Tags