KickJava   Java API By Example, From Geeks To Geeks.

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


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.IRegistry;
19 import org.apache.juddi.datatype.RegistryObject;
20 import org.apache.juddi.datatype.response.DispositionReport;
21 import org.apache.juddi.datatype.response.ErrInfo;
22 import org.apache.juddi.datatype.response.Result;
23 import org.apache.juddi.util.xml.XMLUtils;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * @author anou_mana@apache.org
28  */

29 public class DispositionReportHandlerTests extends HandlerTestCase
30 {
31     private static final String JavaDoc TEST_ID = "juddi.handler.DeletePublisher.test";
32     private DispositionReportHandler handler = null;
33
34   public DispositionReportHandlerTests(String JavaDoc arg0)
35   {
36     super(arg0);
37   }
38
39   public static void main(String JavaDoc[] args)
40   {
41     junit.textui.TestRunner.run( DispositionReportHandlerTests.class);
42   }
43
44   public void setUp()
45   {
46         HandlerMaker maker = HandlerMaker.getInstance();
47         handler = ( DispositionReportHandler)maker.lookup( DispositionReportHandler.TAG_NAME);
48   }
49
50     private RegistryObject getRegistryObject()
51     {
52     ErrInfo errInfo = new ErrInfo();
53     errInfo.setErrCode("E_accountLimitExceeded");
54     errInfo.setErrMsg("Authentication token information has timed out.");
55
56     Result result = new Result();
57     result.setErrno(10160);
58     result.setErrInfo(errInfo);
59
60     ErrInfo errInfo2 = new ErrInfo();
61     errInfo2.setErrCode("E_success");
62     errInfo2.setErrMsg(null);
63
64         Result result2 = new Result();
65         result2.setErrno(Result.E_SUCCESS);
66         result2.setErrInfo(errInfo2);
67
68         DispositionReport object = new DispositionReport();
69         object.setGeneric(IRegistry.UDDI_V2_GENERIC);
70         object.setOperator("jUDDI.org");
71         object.addResult(result);
72         object.addResult(result2);
73
74         return object;
75
76     }
77
78     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
79     {
80         Element JavaDoc parent = XMLUtils.newRootElement();
81         Element JavaDoc child = null;
82
83         if(regObject == null)
84             regObject = this.getRegistryObject();
85
86         handler.marshal(regObject,parent);
87         child = (Element JavaDoc)parent.getFirstChild();
88         parent.removeChild(child);
89
90         return child;
91     }
92
93     public void testMarshal()
94     {
95         Element JavaDoc child = getMarshalledElement(null);
96
97         String JavaDoc marshalledString = this.getXMLString(child);
98
99         assertNotNull("Marshalled DispositionReport ", marshalledString);
100
101     }
102
103     public void testUnMarshal()
104     {
105
106         Element JavaDoc child = getMarshalledElement(null);
107         RegistryObject regObject = handler.unmarshal(child);
108
109         assertNotNull("UnMarshalled DispositionReport ", regObject);
110
111     }
112
113   public void testMarshUnMarshal()
114   {
115         Element JavaDoc child = getMarshalledElement(null);
116
117         String JavaDoc marshalledString = this.getXMLString(child);
118
119         assertNotNull("Marshalled DispositionReport ", marshalledString);
120
121         RegistryObject regObject = handler.unmarshal(child);
122
123         child = getMarshalledElement(regObject);
124
125         String JavaDoc unMarshalledString = this.getXMLString(child);
126
127         assertNotNull("Unmarshalled DispositionReport ", unMarshalledString);
128
129         boolean equals = marshalledString.equals(unMarshalledString);
130
131         assertEquals("Expected result: ", marshalledString, unMarshalledString );
132   }
133
134 }
135
Popular Tags