KickJava   Java API By Example, From Geeks To Geeks.

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


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.Publisher;
20 import org.apache.juddi.datatype.response.PublisherDetail;
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 PublisherDetailHandlerTests extends HandlerTestCase
28 {
29     private static final String JavaDoc TEST_ID = "juddi.handler.DeletePublisher.test";
30     private PublisherDetailHandler handler = null;
31
32   public PublisherDetailHandlerTests(String JavaDoc arg0)
33   {
34     super(arg0);
35   }
36
37   public static void main(String JavaDoc[] args)
38   {
39     junit.textui.TestRunner.run( PublisherDetailHandlerTests.class);
40   }
41
42   public void setUp()
43   {
44         HandlerMaker maker = HandlerMaker.getInstance();
45         handler = ( PublisherDetailHandler)maker.lookup( PublisherDetailHandler.TAG_NAME);
46   }
47
48     private RegistryObject getRegistryObject()
49     {
50         Publisher publisher = new Publisher();
51         publisher.setPublisherID("bcrosby");
52         publisher.setName("Bing Crosby");
53         publisher.setEmailAddress("bcrosby@juddi.org");
54         publisher.setAdmin(true);
55
56         PublisherDetail object = new PublisherDetail();
57         object.setGeneric("1.0");
58         object.setOperator("jUDDI.org");
59         object.setTruncated(false);
60         object.addPublisher(publisher);
61         object.addPublisher(publisher);
62
63         return object;
64
65     }
66
67     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
68     {
69         Element JavaDoc parent = XMLUtils.newRootElement();
70         Element JavaDoc child = null;
71
72         if(regObject == null)
73             regObject = this.getRegistryObject();
74
75         handler.marshal(regObject,parent);
76         child = (Element JavaDoc)parent.getFirstChild();
77         parent.removeChild(child);
78
79         return child;
80     }
81
82     public void testMarshal()
83     {
84         Element JavaDoc child = getMarshalledElement(null);
85
86         String JavaDoc marshalledString = this.getXMLString(child);
87
88         assertNotNull("Marshalled PublisherDetail ", marshalledString);
89
90     }
91
92     public void testUnMarshal()
93     {
94
95         Element JavaDoc child = getMarshalledElement(null);
96         RegistryObject regObject = handler.unmarshal(child);
97
98         assertNotNull("UnMarshalled PublisherDetail ", regObject);
99
100     }
101
102   public void testMarshUnMarshal()
103   {
104         Element JavaDoc child = getMarshalledElement(null);
105
106         String JavaDoc marshalledString = this.getXMLString(child);
107
108         assertNotNull("Marshalled PublisherDetail ", marshalledString);
109
110         RegistryObject regObject = handler.unmarshal(child);
111
112         child = getMarshalledElement(regObject);
113
114         String JavaDoc unMarshalledString = this.getXMLString(child);
115
116         assertNotNull("Unmarshalled PublisherDetail ", unMarshalledString);
117
118         boolean equals = marshalledString.equals(unMarshalledString);
119
120         assertEquals("Expected result: ", marshalledString, unMarshalledString );
121   }
122
123 }
124
Popular Tags