KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > SuiteOperationsTest


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.ui;
21
22 import java.util.Arrays JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.api.project.ProjectManager;
25 import org.netbeans.modules.apisupport.project.InstalledFileLocatorImpl;
26 import org.netbeans.modules.apisupport.project.NbModuleProject;
27 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
28 import org.netbeans.modules.apisupport.project.TestBase;
29 import org.netbeans.modules.apisupport.project.Util;
30 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
31 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
32 import org.netbeans.modules.apisupport.project.suite.SuiteProjectTest;
33 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils;
34 import org.netbeans.spi.project.ActionProvider;
35 import org.netbeans.spi.project.support.ProjectOperations;
36 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
37 import org.openide.filesystems.FileObject;
38 import org.openide.filesystems.FileUtil;
39
40 /**
41  * Test {@link SuiteOperations}.
42  *
43  * @author Martin Krauskopf
44  */

45 public class SuiteOperationsTest extends TestBase {
46     
47     static {
48         // #65461: do not try to load ModuleInfo instances from ant module
49
System.setProperty("org.netbeans.core.startup.ModuleSystem.CULPRIT", "true");
50         LayerTestBase.Lkp.setLookup(new Object JavaDoc[0]);
51     }
52     
53     public SuiteOperationsTest(String JavaDoc name) {
54         super(name);
55     }
56     
57     protected void setUp() throws Exception JavaDoc {
58         super.setUp();
59         InstalledFileLocatorImpl.registerDestDir(destDirF);
60     }
61     
62     public void testDeleteOfEmptySuite() throws Exception JavaDoc {
63         SuiteProject suite = generateSuite("suite");
64         SuiteProjectTest.openSuite(suite);
65         SuiteActions ap = (SuiteActions) suite.getLookup().lookup(ActionProvider.class);
66         assertNotNull("have an action provider", ap);
67         assertTrue("delete action is enabled", ap.isActionEnabled(ActionProvider.COMMAND_DELETE, null));
68         
69         FileObject prjDir = suite.getProjectDirectory();
70         
71         // build project
72
ap.invokeActionImpl(ActionProvider.COMMAND_BUILD, suite.getLookup()).waitFinished();
73         assertNotNull("suite was build", prjDir.getFileObject("build"));
74         
75         FileObject[] expectedMetadataFiles = new FileObject[] {
76             prjDir.getFileObject(GeneratedFilesHelper.BUILD_XML_PATH),
77             prjDir.getFileObject("nbproject"),
78         };
79         assertEquals("correct metadata files", Arrays.asList(expectedMetadataFiles), ProjectOperations.getMetadataFiles(suite));
80         assertTrue("no data files", ProjectOperations.getDataFiles(suite).isEmpty());
81         
82         // It is hard to simulate exact scenario invoked by user. Let's test at least something.
83
ProjectOperations.notifyDeleting(suite);
84         prjDir.getFileSystem().refresh(true);
85         assertNull(prjDir.getFileObject("build"));
86     }
87     
88     public void testDeleteOfNonEmptySuite() throws Exception JavaDoc {
89         SuiteProject suite = generateSuite("suite");
90         FileObject prjDir = suite.getProjectDirectory();
91         prjDir.createFolder("branding");
92         NbModuleProject module1 = TestBase.generateSuiteComponent(suite, "module1");
93         NbModuleProject module2 = TestBase.generateSuiteComponent(suite, "module2");
94         assertEquals("module1 is suite component", NbModuleProvider.SUITE_COMPONENT, Util.getModuleType(module1));
95         assertEquals("module2 is suite component", NbModuleProvider.SUITE_COMPONENT, Util.getModuleType(module2));
96         module1.open();
97         module2.open();
98         
99         SuiteProjectTest.openSuite(suite);
100         SuiteActions ap = (SuiteActions) suite.getLookup().lookup(ActionProvider.class);
101         assertNotNull("have an action provider", ap);
102         assertTrue("delete action is enabled", ap.isActionEnabled(ActionProvider.COMMAND_DELETE, null));
103         
104         
105         // build project
106
ap.invokeActionImpl(ActionProvider.COMMAND_BUILD, suite.getLookup()).waitFinished();
107         assertNotNull("suite was build", prjDir.getFileObject("build"));
108         
109         FileObject[] expectedMetadataFiles = new FileObject[] {
110             prjDir.getFileObject(GeneratedFilesHelper.BUILD_XML_PATH),
111             prjDir.getFileObject("nbproject"),
112         };
113         assertEquals("correct metadata files", Arrays.asList(expectedMetadataFiles), ProjectOperations.getMetadataFiles(suite));
114         FileObject[] expectedDataFiles = new FileObject[] {
115             prjDir.getFileObject("branding"),
116         };
117         assertEquals("correct data files", Arrays.asList(expectedDataFiles), ProjectOperations.getDataFiles(suite));
118         
119         // It is hard to simulate exact scenario invoked by user. Let's test at least something.
120
ProjectOperations.notifyDeleting(suite);
121         prjDir.getFileSystem().refresh(true);
122         assertNull(prjDir.getFileObject("build"));
123         
124         assertEquals("module1 became standalone module", NbModuleProvider.STANDALONE, Util.getModuleType(module1));
125         assertEquals("module2 became standalone module", NbModuleProvider.STANDALONE, Util.getModuleType(module2));
126     }
127     
128     public void testMoveModule() throws Exception JavaDoc {
129         SuiteProject suite = generateSuite("suite");
130         NbModuleProject outer = generateSuiteComponent(suite, getWorkDir(), "outer");
131         outer.open();
132         NbModuleProject customOuter = generateSuiteComponent(suite, getWorkDir(), "customOuter");
133         FileUtil.createData(customOuter.getProjectDirectory(), "mydocs/index.html");
134         customOuter.open();
135         
136         Project inner = SuiteOperations.moveModule(outer, suite.getProjectDirectory());
137         assertNotNull("inner successfully moved", inner);
138         assertSame("inner is still in the same suite component", suite, SuiteUtils.findSuite(inner));
139         assertFalse(ProjectManager.getDefault().isValid(outer));
140         assertFalse(outer.getProjectDirectory().isValid());
141         
142         Project customInner = SuiteOperations.moveModule(customOuter, suite.getProjectDirectory());
143         assertNotNull("customInner successfully moved", customInner);
144         assertSame("customInner is still in the same suite component", suite, SuiteUtils.findSuite(customInner));
145         assertFalse(ProjectManager.getDefault().isValid(customOuter));
146         assertFalse("customOuter directory is not valid anymore", customOuter.getProjectDirectory().isValid());
147         FileObject mydocsIndex = customInner.getProjectDirectory().getFileObject("mydocs/index.html");
148         assertNotNull("mydocs was also moved", mydocsIndex);
149         assertTrue("mydocs is valid", mydocsIndex.isValid());
150     }
151     
152 }
153
Popular Tags