001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.ui;
043:
044: import java.util.Arrays;
045: import org.netbeans.api.project.Project;
046: import org.netbeans.api.project.ProjectManager;
047: import org.netbeans.modules.apisupport.project.InstalledFileLocatorImpl;
048: import org.netbeans.modules.apisupport.project.NbModuleProject;
049: import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
050: import org.netbeans.modules.apisupport.project.TestBase;
051: import org.netbeans.modules.apisupport.project.Util;
052: import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
053: import org.netbeans.modules.apisupport.project.suite.SuiteProject;
054: import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils;
055: import org.netbeans.spi.project.ActionProvider;
056: import org.netbeans.spi.project.support.ProjectOperations;
057: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
058: import org.openide.filesystems.FileObject;
059: import org.openide.filesystems.FileUtil;
060:
061: /**
062: * Test {@link SuiteOperations}.
063: *
064: * @author Martin Krauskopf
065: */
066: public class SuiteOperationsTest extends TestBase {
067:
068: static {
069: // #65461: do not try to load ModuleInfo instances from ant module
070: System.setProperty(
071: "org.netbeans.core.startup.ModuleSystem.CULPRIT",
072: "true");
073: LayerTestBase.Lkp.setLookup(new Object[0]);
074: }
075:
076: public SuiteOperationsTest(String name) {
077: super (name);
078: }
079:
080: protected @Override
081: void setUp() throws Exception {
082: super .setUp();
083: InstalledFileLocatorImpl.registerDestDir(destDirF);
084: }
085:
086: public void testDeleteOfEmptySuite() throws Exception {
087: SuiteProject suite = generateSuite("suite");
088: suite.open();
089: SuiteActions ap = (SuiteActions) suite.getLookup().lookup(
090: ActionProvider.class);
091: assertNotNull("have an action provider", ap);
092: assertTrue("delete action is enabled", ap.isActionEnabled(
093: ActionProvider.COMMAND_DELETE, null));
094:
095: FileObject prjDir = suite.getProjectDirectory();
096:
097: // build project
098: ap.invokeActionImpl(ActionProvider.COMMAND_BUILD,
099: suite.getLookup()).waitFinished();
100: assertNotNull("suite was build", prjDir.getFileObject("build"));
101:
102: FileObject[] expectedMetadataFiles = {
103: prjDir
104: .getFileObject(GeneratedFilesHelper.BUILD_XML_PATH),
105: prjDir.getFileObject("nbproject"), };
106: assertEquals("correct metadata files", Arrays
107: .asList(expectedMetadataFiles), ProjectOperations
108: .getMetadataFiles(suite));
109: assertTrue("no data files", ProjectOperations.getDataFiles(
110: suite).isEmpty());
111:
112: // It is hard to simulate exact scenario invoked by user. Let's test at least something.
113: ProjectOperations.notifyDeleting(suite);
114: prjDir.getFileSystem().refresh(true);
115: assertNull(prjDir.getFileObject("build"));
116: }
117:
118: public void testDeleteOfNonEmptySuite() throws Exception {
119: SuiteProject suite = generateSuite("suite");
120: FileObject prjDir = suite.getProjectDirectory();
121: prjDir.createFolder("branding");
122: NbModuleProject module1 = TestBase.generateSuiteComponent(
123: suite, "module1");
124: NbModuleProject module2 = TestBase.generateSuiteComponent(
125: suite, "module2");
126: assertEquals("module1 is suite component",
127: NbModuleProvider.SUITE_COMPONENT, Util
128: .getModuleType(module1));
129: assertEquals("module2 is suite component",
130: NbModuleProvider.SUITE_COMPONENT, Util
131: .getModuleType(module2));
132: module1.open();
133: module2.open();
134:
135: suite.open();
136: SuiteActions ap = (SuiteActions) suite.getLookup().lookup(
137: ActionProvider.class);
138: assertNotNull("have an action provider", ap);
139: assertTrue("delete action is enabled", ap.isActionEnabled(
140: ActionProvider.COMMAND_DELETE, null));
141:
142: // build project
143: ap.invokeActionImpl(ActionProvider.COMMAND_BUILD,
144: suite.getLookup()).waitFinished();
145: assertNotNull("suite was build", prjDir.getFileObject("build"));
146:
147: FileObject[] expectedMetadataFiles = new FileObject[] {
148: prjDir
149: .getFileObject(GeneratedFilesHelper.BUILD_XML_PATH),
150: prjDir.getFileObject("nbproject"), };
151: assertEquals("correct metadata files", Arrays
152: .asList(expectedMetadataFiles), ProjectOperations
153: .getMetadataFiles(suite));
154: FileObject[] expectedDataFiles = new FileObject[] { prjDir
155: .getFileObject("branding"), };
156: assertEquals("correct data files", Arrays
157: .asList(expectedDataFiles), ProjectOperations
158: .getDataFiles(suite));
159:
160: // It is hard to simulate exact scenario invoked by user. Let's test at least something.
161: ProjectOperations.notifyDeleting(suite);
162: prjDir.getFileSystem().refresh(true);
163: assertNull(prjDir.getFileObject("build"));
164:
165: assertEquals("module1 became standalone module",
166: NbModuleProvider.STANDALONE, Util
167: .getModuleType(module1));
168: assertEquals("module2 became standalone module",
169: NbModuleProvider.STANDALONE, Util
170: .getModuleType(module2));
171: }
172:
173: public void testMoveModule() throws Exception {
174: SuiteProject suite = generateSuite("suite");
175: NbModuleProject outer = generateSuiteComponent(suite,
176: getWorkDir(), "outer");
177: outer.open();
178: NbModuleProject customOuter = generateSuiteComponent(suite,
179: getWorkDir(), "customOuter");
180: FileUtil.createData(customOuter.getProjectDirectory(),
181: "mydocs/index.html");
182: customOuter.open();
183:
184: Project inner = SuiteOperations.moveModule(outer, suite
185: .getProjectDirectory());
186: assertNotNull("inner successfully moved", inner);
187: assertSame("inner is still in the same suite component", suite,
188: SuiteUtils.findSuite(inner));
189: assertFalse(ProjectManager.getDefault().isValid(outer));
190: assertFalse(outer.getProjectDirectory().isValid());
191:
192: Project customInner = SuiteOperations.moveModule(customOuter,
193: suite.getProjectDirectory());
194: assertNotNull("customInner successfully moved", customInner);
195: assertSame("customInner is still in the same suite component",
196: suite, SuiteUtils.findSuite(customInner));
197: assertFalse(ProjectManager.getDefault().isValid(customOuter));
198: assertFalse("customOuter directory is not valid anymore",
199: customOuter.getProjectDirectory().isValid());
200: FileObject mydocsIndex = customInner.getProjectDirectory()
201: .getFileObject("mydocs/index.html");
202: assertNotNull("mydocs was also moved", mydocsIndex);
203: assertTrue("mydocs is valid", mydocsIndex.isValid());
204: }
205:
206: }
|