KickJava   Java API By Example, From Geeks To Geeks.

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


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.Description;
19 import org.apache.juddi.datatype.KeyedReference;
20 import org.apache.juddi.datatype.Name;
21 import org.apache.juddi.datatype.RegistryObject;
22 import org.apache.juddi.datatype.response.RelatedBusinessInfo;
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 RelatedBusinessInfoHandlerTests extends HandlerTestCase
30 {
31     private static final String JavaDoc TEST_ID = "juddi.handler.DeleteRelatedBusinessInfo.test";
32     private RelatedBusinessInfoHandler handler = null;
33
34   public RelatedBusinessInfoHandlerTests(String JavaDoc arg0)
35   {
36     super(arg0);
37   }
38
39   public static void main(String JavaDoc[] args)
40   {
41     junit.textui.TestRunner.run( RelatedBusinessInfoHandlerTests.class);
42   }
43
44   public void setUp()
45   {
46         HandlerMaker maker = HandlerMaker.getInstance();
47         handler = ( RelatedBusinessInfoHandler)maker.lookup( RelatedBusinessInfoHandler.TAG_NAME);
48   }
49
50     private RegistryObject getRegistryObject()
51     {
52         RelatedBusinessInfo object = new RelatedBusinessInfo();
53         object.setBusinessKey("");
54         object.setBusinessKey("6c0ac186-d36b-4b81-bd27-066a5fe0fc1f");
55         object.addName(new Name("businessNm"));
56         object.addName(new Name("businessNm2","en"));
57         object.addDescription(new Description("business whatever"));
58         object.addDescription(new Description("business whatever too","fr"));
59         object.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue"));
60         object.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2"));
61
62         return object;
63
64     }
65
66     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
67     {
68         Element JavaDoc parent = XMLUtils.newRootElement();
69         Element JavaDoc child = null;
70
71         if(regObject == null)
72             regObject = this.getRegistryObject();
73
74         handler.marshal(regObject,parent);
75         child = (Element JavaDoc)parent.getFirstChild();
76         parent.removeChild(child);
77
78         return child;
79     }
80
81     public void testMarshal()
82     {
83         Element JavaDoc child = getMarshalledElement(null);
84
85         String JavaDoc marshalledString = this.getXMLString(child);
86
87         assertNotNull("Marshalled RelatedBusinessInfo ", marshalledString);
88
89     }
90
91     public void testUnMarshal()
92     {
93
94         Element JavaDoc child = getMarshalledElement(null);
95         RegistryObject regObject = handler.unmarshal(child);
96
97         assertNotNull("UnMarshalled RelatedBusinessInfo ", regObject);
98
99     }
100
101   public void testMarshUnMarshal()
102   {
103         Element JavaDoc child = getMarshalledElement(null);
104
105         String JavaDoc marshalledString = this.getXMLString(child);
106
107         assertNotNull("Marshalled RelatedBusinessInfo ", marshalledString);
108
109         RegistryObject regObject = handler.unmarshal(child);
110
111         child = getMarshalledElement(regObject);
112
113         String JavaDoc unMarshalledString = this.getXMLString(child);
114
115         assertNotNull("Unmarshalled RelatedBusinessInfo ", unMarshalledString);
116
117         boolean equals = marshalledString.equals(unMarshalledString);
118
119         assertEquals("Expected result: ", marshalledString, unMarshalledString );
120   }
121
122 }
123
Popular Tags