KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 public class FindServiceHandlerTests extends HandlerTestCase
33 {
34     private static final String JavaDoc TEST_ID = "juddi.handler.DeletePublisher.test";
35     private FindServiceHandler handler = null;
36
37   public FindServiceHandlerTests(String JavaDoc arg0)
38   {
39     super(arg0);
40   }
41
42   public static void main(String JavaDoc[] args)
43   {
44     junit.textui.TestRunner.run( FindServiceHandlerTests.class);
45   }
46
47   public void setUp()
48   {
49         HandlerMaker maker = HandlerMaker.getInstance();
50         handler = ( FindServiceHandler)maker.lookup( FindServiceHandler.TAG_NAME);
51   }
52
53     private RegistryObject getRegistryObject()
54     {
55         FindService object = new FindService();
56
57         CategoryBag catBag = new CategoryBag();
58         catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
59         catBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2"));
60
61         TModelBag tModBag = new TModelBag();
62         tModBag.addTModelKey("uuid:35d9793b-9911-4b85-9f0e-5d4c65b4f253");
63         tModBag.addTModelKey(new TModelKey("uuid:c5ab113f-0d6b-4247-b3c4-8c012726acd8"));
64
65         object.addName(new Name("serviceNm"));
66         object.addName(new Name("serviceNm2","en"));
67         object.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC));
68         object.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS));
69         object.setMaxRows(50);
70         object.setBusinessKey("fd36dbce-bc3e-468b-8346-5374975a0843");
71         object.setTModelBag(tModBag);
72         object.setCategoryBag(catBag);
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 FindService ", 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 FindService ", 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 FindService ", 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 FindService ", unMarshalledString);
128
129         boolean equals = marshalledString.equals(unMarshalledString);
130
131         assertEquals("Expected result: ", marshalledString, unMarshalledString );
132   }
133
134 }
135
Popular Tags