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.wizard.updatecenter;
043:
044: import java.io.File;
045: import java.util.Arrays;
046: import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
047: import org.netbeans.modules.apisupport.project.CreatedModifiedFilesTest;
048: import org.netbeans.modules.apisupport.project.NbModuleProject;
049: import org.netbeans.modules.apisupport.project.TestBase;
050: import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
051: import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
052: import org.openide.WizardDescriptor;
053:
054: /**
055: * Tests {@link DataModel}.
056: *
057: * @author Jiri Rechtacek
058: */
059: public class DataModelTest extends LayerTestBase {
060: NbModuleProject project = null;
061:
062: public DataModelTest(String name) {
063: super (name);
064: }
065:
066: protected void setUp() throws Exception {
067: super .setUp();
068: TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
069: project = TestBase.generateStandaloneModule(getWorkDir(),
070: "module1");
071: }
072:
073: private void testAddUpdateCenter(String[] supposedContent)
074: throws Exception {
075: WizardDescriptor wd = new WizardDescriptor() {
076: };
077: wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT,
078: project);
079: DataModel data = new DataModel(wd);
080:
081: // create declaration UC panel, sets the default values into model
082: UpdateCenterRegistrationPanel p = new UpdateCenterRegistrationPanel(
083: wd, data);
084: p.updateData();
085:
086: CreatedModifiedFiles cmf = data.refreshCreatedModifiedFiles();
087: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(cmf
088: .getCreatedPaths()));
089: assertEquals(Arrays.asList(new String[] {
090: "nbproject/project.xml",
091: "src/org/example/module1/resources/Bundle.properties",
092: "src/org/example/module1/resources/layer.xml" }),
093: Arrays.asList(cmf.getModifiedPaths()));
094:
095: cmf.run();
096:
097: CreatedModifiedFilesTest
098: .assertLayerContent(
099: supposedContent,
100: new File(getWorkDir(),
101: "module1/src/org/example/module1/resources/layer.xml"));
102: }
103:
104: public void testAddUpdateCenterWithDefaultValues() throws Exception {
105: String[] supposedContent = new String[] {
106: "<filesystem>",
107: "<folder name=\"Services\">",
108: "<folder name=\"AutoupdateType\">",
109: "<file name=\"org_example_module1_update_center.instance\">",
110: "<attr name=\"SystemFileSystem.localizingBundle\" stringvalue=\"org.example.module1.resources.Bundle\"/>",
111: "<attr name=\"enabled\" boolvalue=\"true\"/>",
112: "<attr name=\"instanceCreate\" methodvalue=\"org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogFactory.createUpdateProvider\"/>",
113: "<attr name=\"instanceOf\" stringvalue=\"org.netbeans.spi.autoupdate.UpdateProvider\"/>",
114: "<attr name=\"url_key\" stringvalue=\"org_example_module1_update_center\"/>",
115: "</file>", "</folder>", "</folder>", "</filesystem>" };
116:
117: testAddUpdateCenter(supposedContent);
118: }
119:
120: public void testAddUpdateCenterDouble() throws Exception {
121: String[] supposedContent = new String[] {
122: "<filesystem>",
123: "<folder name=\"Services\">",
124: "<folder name=\"AutoupdateType\">",
125: "<file name=\"org_example_module1_update_center.instance\">",
126: "<attr name=\"SystemFileSystem.localizingBundle\" stringvalue=\"org.example.module1.resources.Bundle\"/>",
127: "<attr name=\"enabled\" boolvalue=\"true\"/>",
128: "<attr name=\"instanceCreate\" methodvalue=\"org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogFactory.createUpdateProvider\"/>",
129: "<attr name=\"instanceOf\" stringvalue=\"org.netbeans.spi.autoupdate.UpdateProvider\"/>",
130: "<attr name=\"url_key\" stringvalue=\"org_example_module1_update_center\"/>",
131: "</file>",
132: "<file name=\"org_example_module1_update_center_1.instance\">",
133: "<attr name=\"SystemFileSystem.localizingBundle\" stringvalue=\"org.example.module1.resources.Bundle\"/>",
134: "<attr name=\"enabled\" boolvalue=\"true\"/>",
135: "<attr name=\"instanceCreate\" methodvalue=\"org.netbeans.modules.autoupdate.updateprovider.AutoupdateCatalogFactory.createUpdateProvider\"/>",
136: "<attr name=\"instanceOf\" stringvalue=\"org.netbeans.spi.autoupdate.UpdateProvider\"/>",
137: "<attr name=\"url_key\" stringvalue=\"org_example_module1_update_center_1\"/>",
138: "</file>", "</folder>", "</folder>", "</filesystem>" };
139:
140: testAddUpdateCenterWithDefaultValues();
141: testAddUpdateCenter(supposedContent);
142: }
143:
144: }
|