KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

109     public void testBuildJNLP() throws Exception JavaDoc {
110         int ret = runAntTargetsOnFeedreader(new String JavaDoc[] {"build-jnlp"});
111         assertEquals("build-jnlp ant target should return zero - build successful", 0 , ret);
112     }
113     
114     /**
115      * Invokes build-zip target on feedreader
116      */

117     public void testBuildZip() throws Exception JavaDoc {
118         int ret = runAntTargetsOnFeedreader(new String JavaDoc[] {"build-zip"});
119         assertEquals("build-zipant target should return zero - build successful", 0 , ret);
120     }
121     
122     /**
123      * Invokes build target on feedreader
124      */

125     public void testBuild() throws Exception JavaDoc {
126         int ret = runAntTargetsOnFeedreader(new String JavaDoc[] {"build"});
127         assertEquals("build ant target should return zero - build successful", 0 , ret);
128     }
129     
130     /**
131      * Invokes nbms target on feedreader
132      */

133     public void testBuildNBMs() throws Exception JavaDoc {
134         int ret = runAntTargetsOnFeedreader(new String JavaDoc[] {"nbms"});
135         assertEquals("build ant target should return zero - build successful", 0 , ret);
136     }
137     
138     /**
139      * Invokes clean target on feedreader
140      */

141     public void testClean() throws Exception JavaDoc {
142         int ret = runAntTargetsOnFeedreader(new String JavaDoc[] {"clean"});
143         assertEquals("clean ant target should return zero - build successful", 0 , ret);
144     }
145     
146 }
147
148
Popular Tags