KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > wizard > 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.wizard;
21
22 import java.util.Arrays JavaDoc;
23 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
24 import org.netbeans.modules.apisupport.project.NbModuleProject;
25 import org.netbeans.modules.apisupport.project.TestBase;
26 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
27 import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
28 import org.openide.WizardDescriptor;
29 import org.openide.WizardDescriptor.Panel;
30
31 /**
32  * Tests {@link DataModel}.
33  *
34  * @author Martin Krauskopf
35  */

36 public class DataModelTest extends LayerTestBase {
37     
38     public DataModelTest(String JavaDoc name) {
39         super(name);
40     }
41     
42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
45     }
46     
47     public void testDataModelGenerationForCustomBranchingWizard() throws Exception JavaDoc {
48         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
49         WizardDescriptor wd = new WizardDescriptor(new Panel[] {});
50         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
51         DataModel data = new DataModel(wd);
52         
53         // first panel data (Wizard Type)
54
data.setBranching(true);
55         data.setFileTemplateType(false);
56         data.setNumberOfSteps(2);
57         
58         // second panel data (Name and Location)
59
data.setClassNamePrefix("DocBook");
60         data.setPackageName("org.example.module1");
61         
62         CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
63         assertEquals("created files",
64                 Arrays.asList(new String JavaDoc[] {
65                     "src/org/example/module1/DocBookVisualPanel1.form",
66                     "src/org/example/module1/DocBookVisualPanel1.java",
67                     "src/org/example/module1/DocBookVisualPanel2.form",
68                     "src/org/example/module1/DocBookVisualPanel2.java",
69                     "src/org/example/module1/DocBookWizardIterator.java",
70                     "src/org/example/module1/DocBookWizardPanel1.java",
71                     "src/org/example/module1/DocBookWizardPanel2.java",
72                 }),
73                 Arrays.asList(cmf.getCreatedPaths()));
74         assertEquals("project.xml was modified",
75                 Arrays.asList(new String JavaDoc[] {"nbproject/project.xml"}),
76                 Arrays.asList(cmf.getModifiedPaths()));
77         
78         cmf.run();
79     }
80     
81     public void testDataModelGenerationForFileTemplateBranchingWizard() throws Exception JavaDoc {
82         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
83         WizardDescriptor wd = new WizardDescriptor(new Panel[] {});
84         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
85         DataModel data = new DataModel(wd);
86         
87         // first panel data (Wizard Type)
88
data.setBranching(true);
89         data.setFileTemplateType(true);
90         data.setNumberOfSteps(2);
91         
92         // second panel data (Name and Location)
93
data.setClassNamePrefix("DocBook");
94         data.setDisplayName("DocBook Document");
95         data.setCategory("Templates/XML");
96         data.setPackageName("org.example.module1");
97         
98         
99         CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
100         assertEquals("created files",
101                 Arrays.asList(new String JavaDoc[] {
102                     "src/org/example/module1/DocBookVisualPanel1.form",
103                     "src/org/example/module1/DocBookVisualPanel1.java",
104                     "src/org/example/module1/DocBookVisualPanel2.form",
105                     "src/org/example/module1/DocBookVisualPanel2.java",
106                     "src/org/example/module1/DocBookWizardIterator.java",
107                     "src/org/example/module1/DocBookWizardPanel1.java",
108                     "src/org/example/module1/DocBookWizardPanel2.java",
109                     "src/org/example/module1/docBook.html"
110                 }),
111                 Arrays.asList(cmf.getCreatedPaths()));
112         assertEquals("modified files",
113                 Arrays.asList(new String JavaDoc[] {
114                     "nbproject/project.xml",
115                     "src/org/example/module1/resources/Bundle.properties",
116                     "src/org/example/module1/resources/layer.xml"
117                 }),
118                 Arrays.asList(cmf.getModifiedPaths()));
119
120         cmf.run();
121     }
122     
123     public void testDataModelGenerationForCustomSimpleWizard() throws Exception JavaDoc {
124         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
125         WizardDescriptor wd = new WizardDescriptor(new Panel[] {});
126         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
127         DataModel data = new DataModel(wd);
128         
129         // first panel data (Wizard Type)
130
data.setBranching(false);
131         data.setFileTemplateType(false);
132         data.setNumberOfSteps(1);
133         
134         // second panel data (Name and Location)
135
data.setClassNamePrefix("DocBook");
136         data.setPackageName("org.example.module1");
137         
138         CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
139         assertEquals("created files",
140                 Arrays.asList(new String JavaDoc[] {
141                     "src/org/example/module1/DocBookVisualPanel1.form",
142                     "src/org/example/module1/DocBookVisualPanel1.java",
143                     "src/org/example/module1/DocBookWizardAction.java",
144                     "src/org/example/module1/DocBookWizardPanel1.java",
145                 }),
146                 Arrays.asList(cmf.getCreatedPaths()));
147         assertEquals("project.xml was modified",
148                 Arrays.asList(new String JavaDoc[] {"nbproject/project.xml"}),
149                 Arrays.asList(cmf.getModifiedPaths()));
150         
151         cmf.run();
152     }
153     
154     public void testDataModelCMFUpdated() throws Exception JavaDoc {
155         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
156         WizardDescriptor wd = new WizardDescriptor(new Panel[] {});
157         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
158         DataModel data = new DataModel(wd);
159         data.setBranching(false);
160         data.setFileTemplateType(false);
161         data.setNumberOfSteps(1);
162         data.setClassNamePrefix("X");
163         data.setPackageName("x");
164         assertEquals("initial files correct",
165                 Arrays.asList(new String JavaDoc[] {
166                     "src/x/XVisualPanel1.form",
167                     "src/x/XVisualPanel1.java",
168                     "src/x/XWizardAction.java",
169                     "src/x/XWizardPanel1.java",
170                 }),
171                 Arrays.asList(data.getCreatedModifiedFiles().getCreatedPaths()));
172         data.setClassNamePrefix("Y");
173         assertEquals("class name change takes effect",
174                 Arrays.asList(new String JavaDoc[] {
175                     "src/x/YVisualPanel1.form",
176                     "src/x/YVisualPanel1.java",
177                     "src/x/YWizardAction.java",
178                     "src/x/YWizardPanel1.java",
179                 }),
180                 Arrays.asList(data.getCreatedModifiedFiles().getCreatedPaths()));
181         data.setPackageName("y");
182         assertEquals("package change takes effect",
183                 Arrays.asList(new String JavaDoc[] {
184                     "src/y/YVisualPanel1.form",
185                     "src/y/YVisualPanel1.java",
186                     "src/y/YWizardAction.java",
187                     "src/y/YWizardPanel1.java",
188                 }),
189                 Arrays.asList(data.getCreatedModifiedFiles().getCreatedPaths()));
190     }
191     
192 }
193
Popular Tags