KickJava   Java API By Example, From Geeks To Geeks.

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


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