KickJava   Java API By Example, From Geeks To Geeks.

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


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

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