1 17 18 package org.apache.geronimo.gbean; 19 20 import java.io.Serializable ; 21 import java.util.Collections ; 22 import java.util.Set ; 23 24 import junit.framework.TestCase; 25 26 29 public class GBeanInfoFactoryTest extends TestCase { 30 33 public void testGBeanInfoFactoryClass() { 34 assertNotNull(new GBeanInfoBuilder(String .class)); 35 try { 36 new GBeanInfoBuilder(null); 37 fail("IllegalArgumentException expected"); 38 } catch (IllegalArgumentException expected) { 39 } 40 41 final Class className = String .class; 42 GBeanInfoBuilder gbeanInfoFactory = new GBeanInfoBuilder(className); 43 assertEquals(className.getName(), gbeanInfoFactory.getBeanInfo().getName()); 44 assertEquals(className.getName(), gbeanInfoFactory.getBeanInfo().getClassName()); 45 } 46 47 50 public void testGBeanInfoFactoryClassString() { 51 try { 52 new GBeanInfoBuilder((Class ) null, (String ) null); 53 fail("IllegalArgumentException expected"); 54 } catch (IllegalArgumentException expected) { 55 } 56 } 57 58 61 public void testGBeanInfoFactoryClassGBeanInfo() { 62 try { 63 new GBeanInfoBuilder((Class ) null, (GBeanInfo) null); 64 fail("IllegalArgumentException expected"); 65 } catch (IllegalArgumentException expected) { 66 } 67 68 GBeanInfoBuilder gbeanInfoFactory = new GBeanInfoBuilder(MockGBean.class, MockGBean.getGBeanInfo()); 69 assertEquals(MockGBean.class.getName(), gbeanInfoFactory.getBeanInfo().getName()); 70 assertEquals(MockGBean.class.getName(), gbeanInfoFactory.getBeanInfo().getClassName()); 71 assertEquals(5, gbeanInfoFactory.getBeanInfo().getAttributes().size()); 72 assertEquals(3, gbeanInfoFactory.getBeanInfo().getOperations().size()); 73 } 74 75 78 public void testAddInterfaceClass() { 79 GBeanInfoBuilder gbeanInfoFactory; 80 81 gbeanInfoFactory = new GBeanInfoBuilder(MockGBean.class); 82 gbeanInfoFactory.addInterface(Serializable .class); 83 assertEquals(3, gbeanInfoFactory.getBeanInfo().getAttributes().size()); 84 assertEquals(3, gbeanInfoFactory.getBeanInfo().getOperations().size()); 85 86 gbeanInfoFactory = new GBeanInfoBuilder(MockGBean.class); 87 gbeanInfoFactory.addInterface(GBeanLifecycle.class); 88 GBeanInfo gbeanInfo = gbeanInfoFactory.getBeanInfo(); 89 assertEquals(3, gbeanInfoFactory.getBeanInfo().getAttributes().size()); 90 assertEquals(3, gbeanInfoFactory.getBeanInfo().getOperations().size()); 91 92 gbeanInfoFactory = new GBeanInfoBuilder(MockGBean.class); 93 gbeanInfoFactory.addInterface(SetterOnlyInterface.class); 94 gbeanInfo = gbeanInfoFactory.getBeanInfo(); 95 assertEquals(3, gbeanInfo.getAttributes().size()); 96 GAttributeInfo gattrInfo = gbeanInfo.getAttribute("int"); 97 assertEquals("int", gattrInfo.getName()); 98 assertEquals("setInt", gattrInfo.getSetterName()); 99 assertEquals("getInt", gattrInfo.getGetterName()); 100 101 Set opsSet = gbeanInfo.getOperations(); 102 assertEquals(3, opsSet.size()); 103 } 104 105 private static interface SetterOnlyInterface { 106 public void setInt(int i); 107 } 108 109 private static interface GetterOnlyInterface { 110 public int getInt(); 111 } 112 113 final static GNotificationInfo notificationInfo = new GNotificationInfo("notification", Collections.singleton(null)); 114 115 public static final class MockGBean implements GBeanLifecycle, SetterOnlyInterface, GetterOnlyInterface { 116 117 public static final GBeanInfo GBEAN_INFO; 118 119 static { 120 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(MockGBean.class); 121 infoFactory.setConstructor(new String []{"foo", "bar"}); 122 infoFactory.addAttribute("foo", String .class, false); 123 infoFactory.addAttribute("bar", String .class, false); 124 infoFactory.addReference("reference", String .class, null); 125 GBEAN_INFO = infoFactory.getBeanInfo(); 126 } 127 128 public static GBeanInfo getGBeanInfo() { 129 return GBEAN_INFO; 130 } 131 132 public MockGBean() { 133 } 134 135 public MockGBean(String foo, String bar) { 136 } 137 138 public void setReference(String reference) { 139 } 140 141 public void setInt(int i) { 142 } 143 144 public int getInt() { 145 return 0; 146 } 147 148 public void doStart() { 149 } 150 151 public void doStop() { 152 } 153 154 public void doFail() { 155 } 156 } 157 158 } 159 | Popular Tags |