KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > ContactsHandlerTests


1 /*
2  * Copyright 2001-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 package org.apache.juddi.handler;
17
18 import org.apache.juddi.datatype.Address;
19 import org.apache.juddi.datatype.AddressLine;
20 import org.apache.juddi.datatype.Description;
21 import org.apache.juddi.datatype.Email;
22 import org.apache.juddi.datatype.Phone;
23 import org.apache.juddi.datatype.RegistryObject;
24 import org.apache.juddi.datatype.business.Contact;
25 import org.apache.juddi.datatype.business.Contacts;
26 import org.apache.juddi.util.xml.XMLUtils;
27 import org.w3c.dom.Element JavaDoc;
28
29 /**
30  * @author anou_mana@apache.org
31  */

32 public class ContactsHandlerTests extends HandlerTestCase
33 {
34     private static final String JavaDoc TEST_ID = "juddi.handler.Contacts.test";
35     private ContactsHandler handler = null;
36
37   public ContactsHandlerTests(String JavaDoc arg0)
38   {
39     super(arg0);
40   }
41
42   public static void main(String JavaDoc[] args)
43   {
44     junit.textui.TestRunner.run(ContactsHandlerTests.class);
45   }
46
47   public void setUp()
48   {
49         HandlerMaker maker = HandlerMaker.getInstance();
50         handler = (ContactsHandler)maker.lookup(ContactsHandler.TAG_NAME);
51   }
52
53     private RegistryObject getRegistryObject()
54     {
55
56
57         Address address = new Address();
58         address.setUseType("myAddressUseType");
59         address.setSortCode("sortThis");
60         address.setTModelKey(null);
61         address.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr"));
62         address.addAddressLine(new AddressLine("AddressLine2"));
63
64         Contact contact = new Contact();
65         contact.setUseType("myAddressUseType");
66         contact.setPersonNameValue("Person Whatever");
67         contact.addDescription(new Description("Description1"));
68         contact.addDescription(new Description("Description2","es"));
69         contact.addEmail(new Email("person@whatever.com"));
70         contact.addPhone(new Phone("(123)456-7890"));
71         contact.addAddress(address);
72
73
74         Contacts object = new Contacts();
75         object.addContact(contact);
76         object.addContact(contact);
77
78         return object;
79
80     }
81
82     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
83     {
84         Element JavaDoc parent = XMLUtils.newRootElement();
85         Element JavaDoc child = null;
86
87         if(regObject == null)
88             regObject = this.getRegistryObject();
89
90         handler.marshal(regObject,parent);
91         child = (Element JavaDoc)parent.getFirstChild();
92         parent.removeChild(child);
93
94         return child;
95     }
96
97     public void testMarshal()
98     {
99         Element JavaDoc child = getMarshalledElement(null);
100
101         String JavaDoc marshalledString = this.getXMLString(child);
102
103         assertNotNull("Marshalled Contacts ", marshalledString);
104
105     }
106
107     public void testUnMarshal()
108     {
109
110         Element JavaDoc child = getMarshalledElement(null);
111         RegistryObject regObject = handler.unmarshal(child);
112
113         assertNotNull("UnMarshalled Contacts ", regObject);
114
115     }
116
117   public void testMarshUnMarshal()
118   {
119         Element JavaDoc child = getMarshalledElement(null);
120
121         String JavaDoc marshalledString = this.getXMLString(child);
122
123         assertNotNull("Marshalled Contacts ", marshalledString);
124
125         RegistryObject regObject = handler.unmarshal(child);
126
127         child = getMarshalledElement(regObject);
128
129         String JavaDoc unMarshalledString = this.getXMLString(child);
130
131         assertNotNull("Unmarshalled Contacts ", unMarshalledString);
132
133         boolean equals = marshalledString.equals(unMarshalledString);
134
135         assertEquals("Expected result: ", marshalledString, unMarshalledString );
136   }
137
138 }
139
Popular Tags