1 19 20 package org.netbeans.modules.options.editor; 21 22 import java.net.URL ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import javax.swing.JComponent ; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.spi.options.OptionsCategory; 29 import org.netbeans.spi.options.OptionsPanelController; 30 import org.openide.filesystems.FileObject; 31 import org.openide.filesystems.Repository; 32 import org.openide.loaders.DataFolder; 33 import org.openide.loaders.FolderLookup; 34 import org.openide.util.Lookup; 35 36 import org.netbeans.modules.options.macros.MacrosPanelController; 37 import org.openide.util.lookup.Lookups; 38 import org.openide.util.lookup.ProxyLookup; 39 40 41 45 public class EditorOptionsTest extends NbTestCase { 46 47 48 static { 49 IDEInitializer.setup ( 50 new String [] { 51 "org/netbeans/modules/options/editor/mf-layer.xml", 52 "org/netbeans/modules/defaults/mf-layer.xml" 53 }, 54 new Object [] {} 55 ); 56 } 57 58 public EditorOptionsTest (String testName) { 59 super (testName); 60 } 61 62 public void testOptions () { 63 assertEquals (4, getCategories ().size ()); 64 } 65 66 public void testOptionsCategories () { 67 Iterator it = getCategories ().iterator (); 68 while (it.hasNext ()) { 69 OptionsCategory oc = (OptionsCategory) it.next (); 70 assertNotNull (oc.getCategoryName ()); 71 assertNotNull (oc.getIconBase ()); 72 assertNotNull (oc.getTitle ()); 73 } 74 } 75 76 public void testUpdateOk () { 77 List controllers = new ArrayList (); 78 List lookups = new ArrayList (); 79 Iterator it = getCategories ().iterator (); 80 while (it.hasNext ()) { 81 OptionsCategory oc = (OptionsCategory) it.next (); 82 OptionsPanelController pc = oc.create (); 83 controllers.add (pc); 84 lookups.add (pc.getLookup ()); 85 } 86 Lookup masterLookup = new ProxyLookup 87 ((Lookup[]) lookups.toArray (new Lookup [lookups.size ()])); 88 it = controllers.iterator (); 89 while (it.hasNext ()) { 90 OptionsPanelController pc = (OptionsPanelController) it.next (); 91 JComponent c = pc.getComponent (masterLookup); 92 pc.update (); 93 pc.applyChanges (); 94 } 95 } 96 97 public void testUpdateCancel () { 98 List controllers = new ArrayList (); 99 List lookups = new ArrayList (); 100 Iterator it = getCategories ().iterator (); 101 while (it.hasNext ()) { 102 OptionsCategory oc = (OptionsCategory) it.next (); 103 OptionsPanelController pc = oc.create (); 104 controllers.add (pc); 105 lookups.add (pc.getLookup ()); 106 } 107 Lookup masterLookup = new ProxyLookup 108 ((Lookup[]) lookups.toArray (new Lookup [lookups.size ()])); 109 it = controllers.iterator (); 110 while (it.hasNext ()) { 111 OptionsPanelController pc = (OptionsPanelController) it.next (); 112 JComponent c = pc.getComponent (masterLookup); 113 pc.update (); 114 pc.cancel (); 115 } 116 } 117 118 public void testOk () { 119 List controllers = new ArrayList (); 120 List lookups = new ArrayList (); 121 Iterator it = getCategories ().iterator (); 122 while (it.hasNext ()) { 123 OptionsCategory oc = (OptionsCategory) it.next (); 124 OptionsPanelController pc = oc.create (); 125 controllers.add (pc); 126 lookups.add (pc.getLookup ()); 127 } 128 Lookup masterLookup = new ProxyLookup 129 ((Lookup[]) lookups.toArray (new Lookup [lookups.size ()])); 130 it = controllers.iterator (); 131 while (it.hasNext ()) { 132 OptionsPanelController pc = (OptionsPanelController) it.next (); 133 JComponent c = pc.getComponent (masterLookup); 134 pc.applyChanges (); 135 } 136 } 137 138 public void testCancel () { 139 140 List controllers = new ArrayList (); 142 List lookups = new ArrayList (); 143 Iterator it = getCategories ().iterator (); 144 while (it.hasNext ()) { 145 OptionsCategory oc = (OptionsCategory) it.next (); 146 OptionsPanelController pc = oc.create (); 147 controllers.add (pc); 148 lookups.add (pc.getLookup ()); 149 } 150 Lookup masterLookup = new ProxyLookup 151 ((Lookup[]) lookups.toArray (new Lookup [lookups.size ()])); 152 153 it = controllers.iterator (); 155 while (it.hasNext ()) { 156 OptionsPanelController pc = (OptionsPanelController) it.next (); 157 JComponent c = pc.getComponent (masterLookup); 158 pc.cancel (); 159 } 160 } 161 162 public void testChangedAndValid () { 163 164 List controllers = new ArrayList (); 166 List lookups = new ArrayList (); 167 Iterator it = getCategories ().iterator (); 168 while (it.hasNext ()) { 169 OptionsCategory oc = (OptionsCategory) it.next (); 170 OptionsPanelController pc = oc.create (); 171 controllers.add (pc); 172 lookups.add (pc.getLookup ()); 173 } 174 Lookup masterLookup = new ProxyLookup 175 ((Lookup[]) lookups.toArray (new Lookup [lookups.size ()])); 176 177 it = controllers.iterator (); 179 while (it.hasNext ()) { 180 OptionsPanelController pc = (OptionsPanelController) it.next (); 181 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 182 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 183 JComponent c = pc.getComponent (masterLookup); 184 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 185 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 186 pc.update (); 187 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 188 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 189 pc.update (); 190 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 191 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 192 pc.cancel (); 193 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 194 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 195 pc.update (); 196 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 197 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 198 pc.applyChanges (); 199 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 200 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 201 } 202 203 it = controllers.iterator (); 204 while (it.hasNext ()) { 205 OptionsPanelController pc = (OptionsPanelController) it.next (); 206 JComponent c = pc.getComponent (masterLookup); 207 pc.update (); 208 assertFalse ("isChanged should be false if there is no change! (controller = " + pc + ")", pc.isChanged ()); 209 assertTrue ("isvalid should be true if there is no change! (controller = " + pc + ")", pc.isValid ()); 210 } 211 } 212 213 private List getCategories () { 214 FileObject fo = Repository.getDefault ().getDefaultFileSystem (). 215 findResource ("OptionsDialog"); 216 Lookup lookup = new FolderLookup (DataFolder.findFolder (fo)). 217 getLookup (); 218 return new ArrayList (lookup.lookup ( 219 new Lookup.Template (OptionsCategory.class) 220 ).allInstances ()); 221 } 222 } 223 224 225 | Popular Tags |