1 package org.objectweb.celtix.bus.configuration.spring; 2 3 import java.beans.PropertyEditor ; 4 import java.io.IOException ; 5 import java.lang.reflect.Method ; 6 import java.math.BigInteger ; 7 import java.net.URL ; 8 import java.util.Map ; 9 10 import org.xml.sax.EntityResolver ; 11 import org.xml.sax.SAXException ; 12 13 import junit.framework.TestCase; 14 15 import org.easymock.classextension.EasyMock; 16 import org.objectweb.celtix.bus.configuration.TopConfigurationBuilder; 17 import org.objectweb.celtix.configuration.Configuration; 18 import org.objectweb.celtix.configuration.ConfigurationException; 19 import org.objectweb.celtix.configuration.types.StringListType; 20 import org.springframework.core.io.UrlResource; 21 22 public class CeltixXmlBeanFactoryTest extends TestCase { 23 24 public void testEntityResolver() throws SAXException , IOException , NoSuchMethodException { 25 EntityResolver resolver = new CeltixBeansDtdResolver(); 26 assertNull(resolver.resolveEntity("-//SPRING//DTD BEAN//EN", 27 "http://www.springframework.org/dtd/spring-beans.dtd")); 28 assertNotNull(resolver.resolveEntity(null, 29 "http://celtix.objectweb.org/configuration/spring/celtix-spring-beans.dtd")); 30 31 32 CeltixBeansDtdResolver cer = EasyMock.createMock(CeltixBeansDtdResolver.class, 33 new Method [] {CeltixBeansDtdResolver.class.getDeclaredMethod("getDtdFile", (Class [])null)}); 34 35 cer.getDtdFile(); 36 org.easymock.EasyMock.expectLastCall().andReturn("celtixx-spring-beans.dtd"); 37 EasyMock.replay(cer); 38 try { 39 cer.resolveEntity(null, 40 "http://celtix.objectweb.org/configuration/spring/celtix-spring-beans.dtd"); 41 fail("Expected ConfigurationException not thrown."); 42 } catch (ConfigurationException ex) { 43 assertEquals("COULD_NOT_RESOLVE_BEANS_DTD_EXC", ex.getCode()); 44 } 45 } 46 47 public void testConstructor() { 48 49 URL url = CeltixXmlBeanFactoryTest.class.getResource("resources/top2.xml"); 50 UrlResource urlRes = new UrlResource(url); 51 CeltixXmlBeanFactory bf = new CeltixXmlBeanFactory(urlRes); 52 53 assertNotNull(bf); 54 55 } 56 57 public void testCustomEditorRegistration() { 58 59 URL url = CeltixXmlBeanFactoryTest.class.getResource("resources/top2.xml"); 60 UrlResource urlRes = new UrlResource(url); 61 CeltixXmlBeanFactory bf = new CeltixXmlBeanFactory(urlRes); 62 Configuration top = new TopConfigurationBuilder().build("top22"); 63 64 Map map = bf.getCustomEditors(); 65 66 68 assertNull(map.get(StringListType.class)); 69 70 72 PropertyEditor pe = null; 73 PropertyEditor pe2 = null; 74 75 pe = (PropertyEditor )map.get(String .class); 76 assertTrue(pe instanceof JaxbPropertyEditor); 77 78 pe = (PropertyEditor )map.get(BigInteger .class); 79 assertTrue(pe instanceof JaxbBigIntegerEditor); 80 81 pe = (PropertyEditor )map.get(Boolean .class); 82 assertTrue(pe instanceof JaxbBooleanEditor); 83 pe2 = (PropertyEditor )map.get(boolean.class); 84 assertTrue(pe == pe2); 85 86 pe = (PropertyEditor )map.get(Byte .class); 87 assertTrue(pe instanceof JaxbNumberEditor); 88 pe2 = (PropertyEditor )map.get(byte.class); 89 assertTrue(pe == pe2); 90 91 103 104 assertEquals(16, map.size()); 105 106 bf.registerCustomEditors(top); 107 108 assertEquals(17, map.size()); 109 110 pe = (PropertyEditor )map.get(StringListType.class); 111 assertNotNull(pe); 112 assertTrue(pe instanceof JaxbPropertyEditor); 113 assertTrue(pe == map.get(String .class)); 114 } 115 } 116 | Popular Tags |