KickJava   Java API By Example, From Geeks To Geeks.

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


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