1 7 package com.inversoft.beans.test; 8 9 10 import junit.framework.TestCase; 11 12 import com.inversoft.beans.BeanException; 13 import com.inversoft.beans.BeanProperty; 14 import com.inversoft.beans.SynchronizedBeanProperty; 15 import com.inversoft.util.typeconverter.TypeConversionException; 16 17 18 23 public class ThreadSafeTest extends TestCase { 24 25 public ThreadSafeTest(String name) { 26 super(name); 27 } 28 29 32 public void testThreadSafeBeanPropertyMethods() { 33 34 try { 36 Bean1 bean1 = new Bean1(); 37 BeanProperty prop = new SynchronizedBeanProperty("readOnly", Bean1.class); 38 39 assertTrue("Should return readOnly", prop.getPropertyValue(bean1).equals("readOnly")); 40 41 } catch (BeanException be) { 42 fail(be.toString()); 43 } 44 45 try { 47 Bean1 bean1 = new Bean1(); 48 SynchronizedBeanProperty prop = new SynchronizedBeanProperty("readOnly", Bean1.class); 49 50 prop.setPropertyValue(bean1, "foo", true); 52 fail("Should have failed because read-only"); 53 54 } catch (BeanException be) { 55 assertTrue("Should have no root cause or target", 57 be.getCause() == null && be.getTarget() == null); 58 } catch (TypeConversionException tce) { 59 fail(tce.toString()); 60 } 61 62 try { 64 Bean1 bean1 = new Bean1(); 65 SynchronizedBeanProperty prop = new SynchronizedBeanProperty("string1", Bean1.class); 66 String value = "foo"; 67 68 prop.setPropertyValue(bean1, value); 70 71 assertTrue("Should point to same object", prop.getPropertyValue(bean1) == value); 73 } catch (BeanException be) { 74 fail(be.toString()); 75 } 76 77 try { 79 Bean1 bean1 = new Bean1(); 80 SynchronizedBeanProperty prop = new SynchronizedBeanProperty("string1", Bean1.class); 81 String [] values = null; 82 83 prop.setPropertyValue(bean1, values, true); 84 } catch (BeanException be) { 85 fail(be.toString()); 86 } catch (TypeConversionException tce) { 87 fail(tce.toString()); 88 } 89 90 try { 92 Bean1 bean1 = new Bean1(); 93 SynchronizedBeanProperty prop = new SynchronizedBeanProperty("integer1", Bean1.class); 94 String [] values = null; 95 96 prop.setPropertyValue(bean1, values, true); 97 } catch (BeanException be) { 98 fail(be.toString()); 99 } catch (TypeConversionException tce) { 100 fail(tce.toString()); 101 } 102 103 try { 106 Bean1 bean1 = new Bean1(); 107 SynchronizedBeanProperty prop = new SynchronizedBeanProperty("integer1", Bean1.class); 108 String [] values = new String [0]; 109 110 prop.setPropertyValue(bean1, values, true); 111 } catch (BeanException be) { 112 fail(be.toString()); 113 } catch (TypeConversionException tce) { 114 fail(tce.toString()); 115 } 116 117 try { 119 Bean1 bean1 = new Bean1(); 120 SynchronizedBeanProperty prop = new SynchronizedBeanProperty("integer1", Bean1.class); 121 String value = "1024"; 122 123 prop.setPropertyValue(bean1, value, true); 124 125 assertTrue("Should have converted value to new Integer(1024)", 126 bean1.getInteger1().intValue() == 1024); 127 } catch (BeanException be) { 128 fail(be.toString()); 129 } catch (TypeConversionException tce) { 130 fail(tce.toString()); 131 } 132 } 133 } 134 135 | Popular Tags |