KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > updatecenter > DataModelTest


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.wizard.updatecenter;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
25 import org.netbeans.modules.apisupport.project.CreatedModifiedFilesTest;
26 import org.netbeans.modules.apisupport.project.NbModuleProject;
27 import org.netbeans.modules.apisupport.project.TestBase;
28 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
29 import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
30 import org.openide.WizardDescriptor;
31 import org.openide.WizardDescriptor.Panel;
32
33 /**
34  * Tests {@link DataModel}.
35  *
36  * @author Jiri Rechtacek
37  */

38 public class DataModelTest extends LayerTestBase {
39     NbModuleProject project = null;
40     
41     public DataModelTest(String JavaDoc name) {
42         super(name);
43     }
44     
45     protected void setUp() throws Exception JavaDoc {
46         super.setUp();
47         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
48         project = TestBase.generateStandaloneModule (getWorkDir(), "module1");
49     }
50     
51     private void testAddUpdateCenter (String JavaDoc pathToSettingsFile, String JavaDoc[] supposedContent) throws Exception JavaDoc {
52         WizardDescriptor wd = new WizardDescriptor (new Panel [] {});
53         wd.putProperty (ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
54         DataModel data = new DataModel (wd);
55         
56         // create declaration UC panel, sets the default values into model
57
UpdateCenterRegistrationPanel p = new UpdateCenterRegistrationPanel (wd, data);
58         p.updateData ();
59         
60         CreatedModifiedFiles cmf = data.refreshCreatedModifiedFiles ();
61         assertEquals (
62                 Arrays.asList (new String JavaDoc[] {pathToSettingsFile}),
63                 Arrays.asList (cmf.getCreatedPaths ()));
64         assertEquals(
65                 Arrays.asList(new String JavaDoc[] {"nbproject/project.xml", "src/org/example/module1/resources/Bundle.properties", "src/org/example/module1/resources/layer.xml"}),
66                 Arrays.asList(cmf.getModifiedPaths()));
67         
68         cmf.run();
69         
70         CreatedModifiedFilesTest.assertLayerContent(supposedContent,
71                 new File JavaDoc(getWorkDir(), "module1/src/org/example/module1/resources/layer.xml"));
72     }
73     
74     public void testAddUpdateCenterWithDefaultValues () throws Exception JavaDoc {
75         String JavaDoc[] supposedContent = new String JavaDoc [] {
76             "<filesystem>",
77                 "<folder name=\"Services\">",
78                     "<folder name=\"AutoupdateType\">",
79                         "<file name=\"org_example_module1_update_center.settings\" url=\"org_example_module1_update_centerSettings.xml\">",
80                             "<attr name=\"SystemFileSystem.localizingBundle\" stringvalue=\"org.example.module1.resources.Bundle\"/>",
81                             "<attr name=\"enabled\" boolvalue=\"true\"/>",
82                             "<attr name=\"url_key\" stringvalue=\"org_example_module1_update_center\"/>",
83                         "</file>",
84                     "</folder>",
85                 "</folder>",
86             "</filesystem>"
87         };
88
89         testAddUpdateCenter ("src/org/example/module1/resources/org_example_module1_update_centerSettings.xml", supposedContent);
90     }
91     
92     public void testAddUpdateCenterDouble () throws Exception JavaDoc {
93         String JavaDoc[] supposedContent = new String JavaDoc [] {
94             "<filesystem>",
95                 "<folder name=\"Services\">",
96                     "<folder name=\"AutoupdateType\">",
97                         "<file name=\"org_example_module1_update_center.settings\" url=\"org_example_module1_update_centerSettings.xml\">",
98                             "<attr name=\"SystemFileSystem.localizingBundle\" stringvalue=\"org.example.module1.resources.Bundle\"/>",
99                             "<attr name=\"enabled\" boolvalue=\"true\"/>",
100                             "<attr name=\"url_key\" stringvalue=\"org_example_module1_update_center\"/>",
101                         "</file>",
102                         "<file name=\"org_example_module1_update_center_1.settings\" url=\"org_example_module1_update_center_1Settings.xml\">",
103                             "<attr name=\"SystemFileSystem.localizingBundle\" stringvalue=\"org.example.module1.resources.Bundle\"/>",
104                             "<attr name=\"enabled\" boolvalue=\"true\"/>",
105                             "<attr name=\"url_key\" stringvalue=\"org_example_module1_update_center_1\"/>",
106                         "</file>",
107                     "</folder>",
108                 "</folder>",
109             "</filesystem>"
110         };
111
112         testAddUpdateCenterWithDefaultValues ();
113         testAddUpdateCenter ("src/org/example/module1/resources/org_example_module1_update_center_1Settings.xml", supposedContent);
114     }
115     
116 }
117
118
Popular Tags