KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > junit > DefaultValueTest


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.junit;
18
19 import java.io.StringReader JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
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 JavaDoc;
30
31 /**
32  * @author <a HREF="mailto:iasandcb@tmax.co.kr">Ias</a>
33  */

34 public class DefaultValueTest extends BaseTestCase {
35   public DefaultValueTest(String JavaDoc pName) {
36     super(pName);
37   }
38
39   private String JavaDoc getPersons() throws Exception JavaDoc {
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 JavaDoc {
53     String JavaDoc persons = getPersons();
54     InputSource JavaDoc isource = new InputSource JavaDoc(new StringReader JavaDoc(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 JavaDoc personList = unmarshalledPersons.getPerson();
60     Iterator JavaDoc 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