KickJava   Java API By Example, From Geeks To Geeks.

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


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.RegistryObject;
19 import org.apache.juddi.datatype.publisher.PublisherID;
20 import org.apache.juddi.util.xml.XMLUtils;
21 import org.w3c.dom.Element JavaDoc;
22
23 /**
24  * @author anou_mana@apache.org
25  */

26 public class PublisherIDHandlerTests extends HandlerTestCase
27 {
28     private static final String JavaDoc TEST_ID = "juddi.handler.DeletePublisherID.test";
29     private PublisherIDHandler handler = null;
30
31   public PublisherIDHandlerTests(String JavaDoc arg0)
32   {
33     super(arg0);
34   }
35
36   public static void main(String JavaDoc[] args)
37   {
38     junit.textui.TestRunner.run( PublisherIDHandlerTests.class);
39   }
40
41   public void setUp()
42   {
43         HandlerMaker maker = HandlerMaker.getInstance();
44         handler = ( PublisherIDHandler)maker.lookup( PublisherIDHandler.TAG_NAME);
45   }
46
47     private RegistryObject getRegistryObject()
48     {
49         PublisherID object = new PublisherID();
50         object.setValue("guest");
51
52         return object;
53
54     }
55
56     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
57     {
58         Element JavaDoc parent = XMLUtils.newRootElement();
59         Element JavaDoc child = null;
60
61         if(regObject == null)
62             regObject = this.getRegistryObject();
63
64         handler.marshal(regObject,parent);
65         child = (Element JavaDoc)parent.getFirstChild();
66         parent.removeChild(child);
67
68         return child;
69     }
70
71     public void testMarshal()
72     {
73         Element JavaDoc child = getMarshalledElement(null);
74
75         String JavaDoc marshalledString = this.getXMLString(child);
76
77         assertNotNull("Marshalled PublisherID ", marshalledString);
78
79     }
80
81     public void testUnMarshal()
82     {
83
84         Element JavaDoc child = getMarshalledElement(null);
85         RegistryObject regObject = handler.unmarshal(child);
86
87         assertNotNull("UnMarshalled PublisherID ", regObject);
88
89     }
90
91   public void testMarshUnMarshal()
92   {
93         Element JavaDoc child = getMarshalledElement(null);
94
95         String JavaDoc marshalledString = this.getXMLString(child);
96
97         assertNotNull("Marshalled PublisherID ", marshalledString);
98
99         RegistryObject regObject = handler.unmarshal(child);
100
101         child = getMarshalledElement(regObject);
102
103         String JavaDoc unMarshalledString = this.getXMLString(child);
104
105         assertNotNull("Unmarshalled PublisherID ", unMarshalledString);
106
107         boolean equals = marshalledString.equals(unMarshalledString);
108
109         assertEquals("Expected result: ", marshalledString, unMarshalledString );
110   }
111
112 }
113
Popular Tags