1 22 package org.jboss.test.varia.property; 23 24 import java.beans.PropertyEditor ; 25 import java.beans.PropertyEditorManager ; 26 27 import java.util.Properties ; 28 29 import org.jboss.test.JBossTestCase; 30 import org.jboss.varia.property.PropertyEditorManagerService; 31 32 40 public class PropertyEditorManagerServiceTestCase extends JBossTestCase 41 { 42 43 PropertyEditorManagerService s = new PropertyEditorManagerService(); 44 Class bc = Byte .class; 45 Class be = org.jboss.util.propertyeditor.ByteEditor.class; 46 Class sc = String .class; 47 Class de = DummyEditor.class; 48 49 public PropertyEditorManagerServiceTestCase(String name) 50 { 51 super(name); 52 } 53 54 public static class DummyEditor extends java.beans.PropertyEditorSupport 55 { 56 public void setAsText(String s) 57 { 58 setValue(s); 59 } 60 } 61 62 protected void setUp() 63 { 64 getLog().debug("+++ " + getName()); 65 PropertyEditorManager.registerEditor(bc, null); 66 PropertyEditorManager.registerEditor(sc, null); 67 } 68 69 73 public void testOperations() 74 throws Exception 75 { 76 s.registerEditor(bc, be); 77 assertEquals(be, s.findEditor(bc).getClass()); 78 assertEquals(be, s.findEditor("java.lang.Byte").getClass()); 79 s.registerEditor(bc.getName(), be.getName()); 80 81 String ed = "org.jboss.util.propertyeditor,org.example.editor"; 82 s.setEditorSearchPath(ed); 83 assertEquals(ed, s.getEditorSearchPath()); 84 85 s.setBootstrapEditors( 86 "# COMMENT \n" + 87 sc.getName() + "=" + de.getName() + "\n"); 88 assertEquals(de, s.findEditor(sc).getClass()); 89 Properties p = new Properties (); 90 p.put(sc.getName(), de.getName()); 91 s.setEditors(p); 92 assertEquals(de, s.findEditor(sc).getClass()); 93 } 94 95 public void testUnregister() 96 throws Exception 97 { 98 PropertyEditorManagerService s = new PropertyEditorManagerService(); 99 Class tc = Thread .class; 100 s.registerEditor(tc, de); 101 assertEquals(tc, s.getRegisteredEditors()[0]); 102 s.start(); 103 s.destroy(); 104 assertEquals(null, s.findEditor(tc)); 105 assertEquals(null, PropertyEditorManager.findEditor(tc)); 106 assertEquals(0, s.getRegisteredEditors().length); 107 } 108 109 } 110 111 | Popular Tags |