1 package org.jbpm.instantiation; 2 3 import org.dom4j.*; 4 import org.jbpm.instantiation.BeanInstantiator; 5 6 import junit.framework.*; 7 8 public class BeanInstantiatorTest extends TestCase { 9 10 public BeanInstantiator beanInstantiator = new BeanInstantiator(); 11 12 public static class Mix { 15 private String s = null; 16 private Element structuredElement = null; 17 private RuntimeException stringConstructor = null; 18 private String memberWithoutSetter = null; 19 20 private int callCounter = 0; 21 22 private void setS(String s) { 23 this.s = s; 24 callCounter++; 25 } 26 27 protected void warningSurpresser() { 28 setS(null); 29 } 30 31 protected void setStructuredElement(Element structuredElement) { 32 this.structuredElement = structuredElement; 33 callCounter++; 34 } 35 36 public void setStringConstructor(RuntimeException stringConstructor) { 37 this.stringConstructor = stringConstructor; 38 callCounter++; 39 } 40 } 41 42 public void testBasicTypes() { 43 String configuration = 44 "<s>hello</s>" + 45 "<stringConstructor>" + 46 " i want yoghurt" + 47 "</stringConstructor>" + 48 "<structuredElement>" + 49 " <surfboard length=\"270\" />" + 50 " <mast length=\"475\" />" + 51 " <boom length=\"160\" />" + 52 " <sail size=\"5.7\" />" + 53 "</structuredElement>" + 54 "<memberWithoutSetter>hello</memberWithoutSetter>"; 55 56 Mix mix = (Mix) beanInstantiator.instantiate(Mix.class, configuration); 57 58 assertEquals( "hello", mix.s ); 59 60 assertEquals("i want yoghurt", mix.stringConstructor.getMessage()); 61 62 assertEquals(4, mix.structuredElement.elements().size()); 63 Element firstElement = (Element) mix.structuredElement.elementIterator().next(); 64 assertEquals("surfboard", firstElement.getName()); 65 assertEquals("270", firstElement.attributeValue("length")); 66 67 assertNull(mix.memberWithoutSetter); 68 } 69 } 70 | Popular Tags |