1 17 package org.apache.ws.jaxme.junit; 18 19 import java.io.StringReader ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import javax.xml.bind.JAXBContext; 24 25 import org.apache.ws.jaxme.test.misc.defaults.Persons; 26 import org.apache.ws.jaxme.test.misc.defaults.PersonsType.PersonType; 27 import org.apache.ws.jaxme.test.misc.defaults.PersonsType.PersonType.NameType; 28 import org.apache.ws.jaxme.test.misc.defaults.impl.PersonsTypeImpl.PersonTypeImpl.NameTypeImpl; 29 import org.xml.sax.InputSource ; 30 31 34 public class DefaultValueTest extends BaseTestCase { 35 public DefaultValueTest(String pName) { 36 super(pName); 37 } 38 39 private String getPersons() throws Exception { 40 return "<Persons xmlns=\"http://ws.apache.org/jaxme/test/misc/defaults\">\n" 41 + " <Person>\n" 42 + " <Name>\n" 43 + " <Last>Lee</Last>\n" 44 + " </Name>\n" 45 + " </Person>\n" 46 + " <Person Alias=\"Cb\">\n" 47 + " <Age>30</Age>\n" 48 + " </Person>\n" 49 + "</Persons>"; 50 } 51 52 public void testDefaults() throws Exception { 53 String persons = getPersons(); 54 InputSource isource = new InputSource (new StringReader (persons)); 55 JAXBContext context = 56 JAXBContext.newInstance("org.apache.ws.jaxme.test.misc.defaults"); 57 Persons unmarshalledPersons = 58 (Persons) context.createUnmarshaller().unmarshal(isource); 59 List personList = unmarshalledPersons.getPerson(); 60 Iterator i = personList.iterator(); 61 i.hasNext(); 62 PersonType person = (PersonType) i.next(); 63 NameType name = person.getName(); 64 assertEquals("Anonymous", name.getFirst()); 65 assertEquals("Lee", name.getLast()); 66 assertEquals("Ias", person.getAlias()); 67 assertEquals(25, person.getAge()); 68 69 i.hasNext(); 70 person = (PersonType) i.next(); 71 name = person.getName(); 72 if (name == null) { 73 name = new NameTypeImpl(); 74 } 75 assertEquals("Anonymous", name.getFirst()); 76 assertEquals(null, name.getLast()); 77 assertEquals("Cb", person.getAlias()); 78 assertEquals(30, person.getAge()); 79 } 80 } 81 | Popular Tags |