1 7 package com.inversoft.config.component.test; 8 9 10 import java.util.MissingResourceException ; 11 12 import junit.framework.TestCase; 13 14 import com.inversoft.config.ConfigurationException; 15 import com.inversoft.config.component.ComponentConfigBuilder; 16 import com.inversoft.config.component.ComponentConfigBuilderRegistry; 17 18 19 26 public class ComponentConfigRegistryTest extends TestCase { 27 28 31 public ComponentConfigRegistryTest(String name) { 32 super(name); 33 } 34 35 36 39 public void testLoad() { 40 try { 41 ComponentConfigBuilderRegistry reg = new ComponentConfigBuilderRegistry( 42 "com.inversoft.config.component.test.TestBuilders"); 43 ComponentConfigBuilder builder = reg.lookup("test"); 44 assertNotNull(builder); 45 assertEquals(TestComponentConfigBuilder.class, builder.getClass()); 46 assertSame(reg, builder.getRegistry()); 47 48 ComponentConfigBuilder builder2 = new TestComponentConfigBuilder(); 49 reg.register("test2", builder2); 50 builder = reg.lookup("test2"); 51 assertNotNull(builder); 52 assertEquals(TestComponentConfigBuilder.class, builder.getClass()); 53 assertSame(builder, builder2); 54 assertSame(reg, builder.getRegistry()); 55 assertSame(reg, builder2.getRegistry()); 56 57 reg.unregister("test2"); 58 builder = reg.lookup("test2"); 59 assertNull(builder); 60 } catch (ConfigurationException ce) { 61 fail(ce.toString()); 62 } 63 } 64 65 68 public void testBadBundle() { 69 try { 70 new ComponentConfigBuilderRegistry( 71 "com.inversoft.config.component.test.NotARealBundle"); 72 fail("Should have failed because bundle doesn't exist"); 73 } catch (ConfigurationException ce) { 74 assertFalse(ce.getErrors().isEmpty()); 75 assertEquals(MissingResourceException .class, ce.getCause().getClass()); 76 } 77 } 78 79 82 public void testBadBuilder() { 83 try { 84 new ComponentConfigBuilderRegistry( 85 "com.inversoft.config.component.test.BadBundle"); 86 fail("Should have failed because builder doesn't extend interface"); 87 } catch (ConfigurationException ce) { 88 assertFalse(ce.getErrors().isEmpty()); 89 assertEquals(2, ce.getErrors().getAllErrors().size()); 90 assertEquals("com.inversoft.config.component.test.BadComponentConfigBuilder is not a ConfigBuilder", 91 ce.getErrors().getError(1).getMessage()); 92 } 93 } 94 95 98 public void testConstructionFailure() { 99 try { 100 new ComponentConfigBuilderRegistry( 101 "com.inversoft.config.component.test.FailConstruction"); 102 fail("Should have failed because builder can't be constructed"); 103 } catch (ConfigurationException ce) { 104 assertFalse(ce.getErrors().isEmpty()); 105 assertTrue(ce.getErrors().getError(0).getMessage().indexOf("instantiating") != -1); 106 } 107 } 108 } | Popular Tags |