KickJava   Java API By Example, From Geeks To Geeks.

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


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

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