KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.apisupport.project;
20
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import junit.framework.*;
24 import org.apache.tools.ant.module.api.support.ActionUtils;
25 import org.netbeans.junit.*;
26 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
27 import org.openide.DialogDescriptor;
28 import org.openide.filesystems.FileObject;
29
30 /**
31  * Test building and cleaning tests
32  * @author pzajac
33  */

34 public class TestBuildCleanTest extends TestBase {
35     
36     public TestBuildCleanTest(java.lang.String JavaDoc testName) {
37         super(testName);
38     }
39     static {
40         // #65461: do not try to load ModuleInfo instances from ant module
41
System.setProperty("org.netbeans.core.startup.ModuleSystem.CULPRIT", "true");
42         LayerTestBase.Lkp.setLookup(new Object JavaDoc[0]);
43         DialogDisplayerImpl.returnFromNotify(DialogDescriptor.NO_OPTION);
44     }
45     
46     protected void setUp() throws Exception JavaDoc {
47         clearWorkDir();
48         super.setUp();
49         InstalledFileLocatorImpl.registerDestDir(destDirF);
50     }
51
52     protected void tearDown() throws Exception JavaDoc {
53         // restore jars
54
super.tearDown();
55     }
56
57 // public void testNBCVSProject() throws Exception {
58
// FileObject fsbuild = nbCVSRoot().getFileObject("openide/fs/build.xml");
59
// FileObject msfsbuild = nbCVSRoot().getFileObject("openide/masterfs/build.xml");
60
// FileObject loadersBuild = nbCVSRoot().getFileObject("openide/loaders/build.xml");
61
// try {
62
// // Check unit tests
63
// //
64
// runTask(fsbuild,"test-build");
65
// checkTest("org-openide-filesystems",CLUSTER_PLATFORM,"unit",true);
66
// // masterfs tests depends on fs tests
67
// runTask(msfsbuild,"test-build");
68
// checkTest("org-netbeans-modules-masterfs",CLUSTER_PLATFORM,"unit",true);
69
//
70
// deleteTests("org-openide-filesystems",CLUSTER_PLATFORM,"unit");
71
//// checkTest("org-openide-filesystems",CLUSTER_PLATFORM,"unit",false);
72
// runTask(fsbuild,"test-build");
73
// checkTest("org-openide-filesystems",CLUSTER_PLATFORM,"unit",true);
74
//
75
// // check qa-functional tests
76
// runTask(loadersBuild,"test-build-qa-functional");
77
// checkTest("org-openide-loaders",CLUSTER_PLATFORM,"qa-functional",true);
78
//// deleteTests("org-openide-loaders",CLUSTER_PLATFORM,"qa-functional");
79
//// checkTest("org-openide-loaders",CLUSTER_PLATFORM,"qa-functional",false);
80
// } finally {
81
// String pathfs = "nbbuild/build/testdist/unit/" + CLUSTER_PLATFORM + "/org-openide-fs/tests.jar";
82
// String pathjava = "nbbuild/build/testdist/unit/" + CLUSTER_IDE + "/org-netbeans-modules-java-project/tests.jar";
83
//
84
// if (!(new File(nbCVSRootFile(),pathfs).exists())) {
85
// runTask(fsbuild,"test-build");
86
// }
87
// if (!(new File(nbCVSRootFile(),pathjava).exists())) {
88
// runTask(loadersBuild,"test-build-qa-functional");
89
// }
90
// }
91
// }
92

93     public void testExternalProject() throws Exception JavaDoc {
94         FileObject module1build = resolveEEP("/suite4/module1/build.xml");
95         FileObject module2build = resolveEEP("/suite4/module2/build.xml");
96         runTask(module1build,"test-build");
97         checkTestExternal("module1",true);
98         runTask(module2build,"test-build");
99         checkTestExternal("module2",true);
100         runTask(module1build,"clean");
101         checkTestExternal("module1",false);
102     }
103     
104     private void checkTest(String JavaDoc cnb, String JavaDoc cluster, String JavaDoc testtype, boolean exist) {
105         String JavaDoc path = "nbbuild/build/testdist/" + testtype + "/" + cluster + "/" + cnb + "/tests.jar";
106         FileObject testsFo = nbCVSRoot().getFileObject(path);
107         if (exist) {
108             assertTrue("test.jar for " + path + " doesn't exist.", testsFo != null && testsFo.isValid());
109         } else {
110             assertTrue("test.jar for " + path + " exists.", testsFo == null || !testsFo.isValid());
111         }
112     }
113
114     private void deleteTests(String JavaDoc cnb,String JavaDoc cluster,String JavaDoc testtype) throws IOException JavaDoc {
115         String JavaDoc path = "nbbuild/build/testdist/" + testtype + "/" + cluster + "/" + cnb + "/tests.jar";
116         FileObject testsFo = nbCVSRoot().getFileObject(path);
117         if (testsFo.isValid()) {
118   // testsFo.delete();
119
}
120     }
121     private void runTask(FileObject fo, String JavaDoc target) throws IOException JavaDoc {
122         ActionUtils.runTarget(fo,new String JavaDoc[]{target},null).waitFinished();
123     }
124
125     private void checkTestExternal(String JavaDoc cnd, boolean exist) {
126         String JavaDoc path = "/suite4/build/testdist/unit/cluster/" + cnd + "/tests.jar";
127         File JavaDoc tests = resolveEEPFile(path);
128         if (exist) {
129             assertTrue("test.jar for " + path + " doesn't exist.",tests.exists());
130         } else {
131             assertTrue("test.jar for " + path + " exists.", !tests.exists());
132         }
133     }
134 }
135
Popular Tags