KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.xml.XMLUtils;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * @author anou_mana@apache.org
30  */

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