KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > varia > property > PropertyEditorManagerServiceTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import java.beans.PropertyEditorManager JavaDoc;
26
27 import java.util.Properties JavaDoc;
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 Scott.Stark@jboss.org
36  * @author Dimitris.Andreadis@jboss.org
37  *
38  * @version $Revision: 37406 $
39  */

40 public class PropertyEditorManagerServiceTestCase extends JBossTestCase
41 {
42
43    PropertyEditorManagerService s = new PropertyEditorManagerService();
44    Class JavaDoc bc = Byte JavaDoc.class;
45    Class JavaDoc be = org.jboss.util.propertyeditor.ByteEditor.class;
46    Class JavaDoc sc = String JavaDoc.class;
47    Class JavaDoc de = DummyEditor.class;
48
49    public PropertyEditorManagerServiceTestCase(String JavaDoc name)
50    {
51       super(name);
52    }
53
54    public static class DummyEditor extends java.beans.PropertyEditorSupport JavaDoc
55    {
56       public void setAsText(String JavaDoc 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    /**
70     * Tests opertions.
71     * @throws Exception
72     */

73    public void testOperations()
74       throws Exception JavaDoc
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 JavaDoc 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 JavaDoc p = new Properties JavaDoc();
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 JavaDoc
97    {
98       PropertyEditorManagerService s = new PropertyEditorManagerService();
99       Class JavaDoc tc = Thread JavaDoc.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