1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.wizard; 21 22 import java.util.Arrays ; 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 36 public class DataModelTest extends LayerTestBase { 37 38 public DataModelTest(String name) { 39 super(name); 40 } 41 42 protected void setUp() throws Exception { 43 super.setUp(); 44 TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 45 } 46 47 public void testDataModelGenerationForCustomBranchingWizard() throws Exception { 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 data.setBranching(true); 55 data.setFileTemplateType(false); 56 data.setNumberOfSteps(2); 57 58 data.setClassNamePrefix("DocBook"); 60 data.setPackageName("org.example.module1"); 61 62 CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); 63 assertEquals("created files", 64 Arrays.asList(new String [] { 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 [] {"nbproject/project.xml"}), 76 Arrays.asList(cmf.getModifiedPaths())); 77 78 cmf.run(); 79 } 80 81 public void testDataModelGenerationForFileTemplateBranchingWizard() throws Exception { 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 data.setBranching(true); 89 data.setFileTemplateType(true); 90 data.setNumberOfSteps(2); 91 92 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 [] { 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 [] { 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 { 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 data.setBranching(false); 131 data.setFileTemplateType(false); 132 data.setNumberOfSteps(1); 133 134 data.setClassNamePrefix("DocBook"); 136 data.setPackageName("org.example.module1"); 137 138 CreatedModifiedFiles cmf = data.getCreatedModifiedFiles(); 139 assertEquals("created files", 140 Arrays.asList(new String [] { 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 [] {"nbproject/project.xml"}), 149 Arrays.asList(cmf.getModifiedPaths())); 150 151 cmf.run(); 152 } 153 154 public void testDataModelCMFUpdated() throws Exception { 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 [] { 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 [] { 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 [] { 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 |