01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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: /** Unit tests for the PropertyEditorManagerServiceTestCase utility service.
33: *
34: * @see org.jboss.varia.property.PropertyEditorManagerService
35: * @author genman@jboss.org
36: *
37: * @version $Revision: 57211 $
38: */
39: public class PropertyEditorManagerServiceTestCase extends JBossTestCase {
40:
41: PropertyEditorManagerService s = new PropertyEditorManagerService();
42: Class bc = Byte.class;
43: Class be = org.jboss.util.propertyeditor.ByteEditor.class;
44: Class sc = String.class;
45: Class de = DummyEditor.class;
46:
47: public PropertyEditorManagerServiceTestCase(String name) {
48: super (name);
49: }
50:
51: public static class DummyEditor extends
52: java.beans.PropertyEditorSupport {
53: public void setAsText(String s) {
54: setValue(s);
55: }
56: }
57:
58: protected void setUp() {
59: getLog().debug("+++ " + getName());
60: PropertyEditorManager.registerEditor(bc, null);
61: PropertyEditorManager.registerEditor(sc, null);
62: }
63:
64: /**
65: * Tests opertions.
66: * @throws Exception
67: */
68: public void testOperations() throws Exception {
69: s.registerEditor(bc, be);
70: assertEquals(be, s.findEditor(bc).getClass());
71: assertEquals(be, s.findEditor("java.lang.Byte").getClass());
72: s.registerEditor(bc.getName(), be.getName());
73:
74: String ed = "org.jboss.util.propertyeditor,org.example.editor";
75: s.setEditorSearchPath(ed);
76: assertEquals(ed, s.getEditorSearchPath());
77:
78: s.setBootstrapEditors("# COMMENT \n" + sc.getName() + "="
79: + de.getName() + "\n");
80: assertEquals(de, s.findEditor(sc).getClass());
81: Properties p = new Properties();
82: p.put(sc.getName(), de.getName());
83: s.setEditors(p);
84: assertEquals(de, s.findEditor(sc).getClass());
85: }
86:
87: public void testUnregister() throws Exception {
88: PropertyEditorManagerService s = new PropertyEditorManagerService();
89: Class tc = Thread.class;
90: s.registerEditor(tc, de);
91: assertEquals(tc, s.getRegisteredEditors()[0]);
92: s.start();
93: s.destroy();
94: assertEquals(null, s.findEditor(tc));
95: assertEquals(null, PropertyEditorManager.findEditor(tc));
96: assertEquals(0, s.getRegisteredEditors().length);
97: }
98:
99: }
|