1 15 package hivemind.test; 16 17 import java.util.HashMap ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.definition.ImplementationConstructionContext; 21 import org.apache.hivemind.impl.CreateClassServiceConstructor; 22 import org.apache.hivemind.impl.ModuleImpl; 23 import org.apache.hivemind.impl.ServicePointImpl; 24 import org.apache.hivemind.internal.ImplementationConstructionContextImpl; 25 import org.apache.hivemind.internal.Module; 26 import org.apache.hivemind.internal.ServicePoint; 27 28 33 public class TestMisc extends FrameworkTestCase 34 { 35 private Module newModule() 36 { 37 ModuleImpl result = new ModuleImpl(); 38 result.setClassResolver(getClassResolver()); 39 40 return result; 41 } 42 43 public void testApplicationRuntimeExceptionGetComponent() 44 { 45 ApplicationRuntimeException ex = new ApplicationRuntimeException("My Message", this, null, 46 null); 47 48 assertSame(this, ex.getComponent()); 49 } 50 51 public void testApplicationRuntimeExceptionThrowableConstructor() 52 { 53 RuntimeException re = new RuntimeException ("Now it can be told."); 54 ApplicationRuntimeException ex = new ApplicationRuntimeException(re); 55 56 assertEquals("Now it can be told.", ex.getMessage()); 57 assertSame(re, ex.getRootCause()); 58 } 59 60 public void testCreateClassServiceConstructorAccessors() 61 { 62 replayControls(); 63 64 CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(), 65 "java.util.HashMap"); 66 67 c.setInstanceClassName("java.util.HashMap"); 68 69 assertEquals("java.util.HashMap", c.getInstanceClassName()); 70 71 verifyControls(); 72 } 73 74 public void testCreateClassServiceConstructorTwice() 75 { 76 Module m = newModule(); 77 78 ServicePoint sp = new ServicePointImpl(m, null); 79 80 replayControls(); 81 82 CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(), 83 "java.util.HashMap"); 84 85 ImplementationConstructionContext context = new ImplementationConstructionContextImpl(m, sp); 86 Object o1 = c.constructCoreServiceImplementation(context); 87 Object o2 = c.constructCoreServiceImplementation(context); 88 89 assertNotSame(o1, o2); 90 91 assertTrue(o1 instanceof HashMap ); 92 assertTrue(o2 instanceof HashMap ); 93 } 94 95 96 97 public void testCreateInstanceWithInitializer() 98 { 99 Module m = newModule(); 100 101 ServicePoint sp = new ServicePointImpl(m, null); 102 103 CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(), 104 SimpleBean.class.getName() + ",value=HiveMind"); 105 106 ImplementationConstructionContext context = new ImplementationConstructionContextImpl(m, sp); 107 SimpleBean b = (SimpleBean) c.constructCoreServiceImplementation(context); 108 109 assertEquals("HiveMind", b.getValue()); 110 } 111 112 public void testCreateClassServiceConstructorFailure() 113 { 114 Module m = newModule(); 115 116 ServicePoint sp = new ServicePointImpl(m, null); 117 118 CreateClassServiceConstructor c = new CreateClassServiceConstructor(newLocation(), 119 PrivateBean.class.getName()); 120 121 try 122 { 123 ImplementationConstructionContext context = new ImplementationConstructionContextImpl(m, sp); 124 c.constructCoreServiceImplementation(context); 125 unreachable(); 126 } 127 catch (Exception ex) 128 { 129 assertExceptionSubstring( 130 ex, 131 "Unable to instantiate instance of class hivemind.test.PrivateBean"); 132 } 133 134 } 135 } | Popular Tags |