KickJava   Java API By Example, From Geeks To Geeks.

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


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.CategoryBag;
19 import org.apache.juddi.datatype.DiscoveryURL;
20 import org.apache.juddi.datatype.DiscoveryURLs;
21 import org.apache.juddi.datatype.IdentifierBag;
22 import org.apache.juddi.datatype.KeyedReference;
23 import org.apache.juddi.datatype.Name;
24 import org.apache.juddi.datatype.RegistryObject;
25 import org.apache.juddi.datatype.TModelBag;
26 import org.apache.juddi.datatype.TModelKey;
27 import org.apache.juddi.datatype.request.FindBusiness;
28 import org.apache.juddi.datatype.request.FindQualifier;
29 import org.apache.juddi.util.xml.XMLUtils;
30 import org.w3c.dom.Element JavaDoc;
31
32 /**
33  * @author anou_mana@apache.org
34  */

35 public class FindBusinessHandlerTests extends HandlerTestCase
36 {
37     private static final String JavaDoc TEST_ID = "juddi.handler.DeletePublisher.test";
38     private FindBusinessHandler handler = null;
39
40   public FindBusinessHandlerTests(String JavaDoc arg0)
41   {
42     super(arg0);
43   }
44
45   public static void main(String JavaDoc[] args)
46   {
47     junit.textui.TestRunner.run( FindBusinessHandlerTests.class);
48   }
49
50   public void setUp()
51   {
52         HandlerMaker maker = HandlerMaker.getInstance();
53         handler = ( FindBusinessHandler)maker.lookup( FindBusinessHandler.TAG_NAME);
54   }
55
56     private RegistryObject getRegistryObject()
57     {
58         DiscoveryURLs discURLs = new DiscoveryURLs();
59         discURLs.addDiscoveryURL(new DiscoveryURL("businessEntity","http://www.juddi.org"));
60
61         IdentifierBag idBag = new IdentifierBag();
62         idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagKeyValue"));
63         idBag.addKeyedReference(new KeyedReference("uuid:3860b975-9e0c-4cec-bad6-87dfe00e3864","idBagKeyName2","idBagKeyValue2"));
64
65         CategoryBag catBag = new CategoryBag();
66         catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
67         catBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2"));
68
69         TModelBag tModBag = new TModelBag();
70         tModBag.addTModelKey("uuid:35d9793b-9911-4b85-9f0e-5d4c65b4f253");
71         tModBag.addTModelKey(new TModelKey("uuid:c5ab113f-0d6b-4247-b3c4-8c012726acd8"));
72
73         FindBusiness object = new FindBusiness();
74         object.addName(new Name("serviceNm"));
75         object.addName(new Name("serviceNm2","en"));
76         object.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC));
77         object.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS));
78         object.setMaxRows(43);
79         object.setDiscoveryURLs(discURLs);
80         object.setIdentifierBag(idBag);
81         object.setTModelBag(tModBag);
82         object.setCategoryBag(catBag);
83
84
85         return object;
86
87     }
88
89     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
90     {
91         Element JavaDoc parent = XMLUtils.newRootElement();
92         Element JavaDoc child = null;
93
94         if(regObject == null)
95             regObject = this.getRegistryObject();
96
97         handler.marshal(regObject,parent);
98         child = (Element JavaDoc)parent.getFirstChild();
99         parent.removeChild(child);
100
101         return child;
102     }
103
104     public void testMarshal()
105     {
106         Element JavaDoc child = getMarshalledElement(null);
107
108         String JavaDoc marshalledString = this.getXMLString(child);
109
110         assertNotNull("Marshalled FindBusiness ", marshalledString);
111
112     }
113
114     public void testUnMarshal()
115     {
116
117         Element JavaDoc child = getMarshalledElement(null);
118         RegistryObject regObject = handler.unmarshal(child);
119
120         assertNotNull("UnMarshalled FindBusiness ", regObject);
121
122     }
123
124   public void testMarshUnMarshal()
125   {
126         Element JavaDoc child = getMarshalledElement(null);
127
128         String JavaDoc marshalledString = this.getXMLString(child);
129
130         assertNotNull("Marshalled FindBusiness ", marshalledString);
131
132         RegistryObject regObject = handler.unmarshal(child);
133
134         child = getMarshalledElement(regObject);
135
136         String JavaDoc unMarshalledString = this.getXMLString(child);
137
138         assertNotNull("Unmarshalled FindBusiness ", unMarshalledString);
139
140         boolean equals = marshalledString.equals(unMarshalledString);
141
142         assertEquals("Expected result: ", marshalledString, unMarshalledString );
143   }
144
145 }
146
Popular Tags