KickJava   Java API By Example, From Geeks To Geeks.

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


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

31 public class FindTModelHandlerTests extends HandlerTestCase
32 {
33     private static final String JavaDoc TEST_ID = "juddi.handler.DeletePublisher.test";
34     private FindTModelHandler handler = null;
35
36   public FindTModelHandlerTests(String JavaDoc arg0)
37   {
38     super(arg0);
39   }
40
41   public static void main(String JavaDoc[] args)
42   {
43     junit.textui.TestRunner.run( FindTModelHandlerTests.class);
44   }
45
46   public void setUp()
47   {
48         HandlerMaker maker = HandlerMaker.getInstance();
49         handler = ( FindTModelHandler)maker.lookup( FindTModelHandler.TAG_NAME);
50   }
51
52     private RegistryObject getRegistryObject()
53     {
54         FindTModel object = new FindTModel();
55
56         IdentifierBag idBag = new IdentifierBag();
57         idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagKeyValue"));
58         idBag.addKeyedReference(new KeyedReference("uuid:3860b975-9e0c-4cec-bad6-87dfe00e3864","idBagKeyName2","idBagKeyValue2"));
59
60         CategoryBag catBag = new CategoryBag();
61         catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
62         catBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2"));
63
64         object.setName(new Name("serviceNm2","en"));
65         object.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC));
66         object.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS));
67         object.setMaxRows(37);
68         object.setIdentifierBag(idBag);
69         object.setCategoryBag(catBag);
70
71         return object;
72
73     }
74
75     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
76     {
77         Element JavaDoc parent = XMLUtils.newRootElement();
78         Element JavaDoc child = null;
79
80         if(regObject == null)
81             regObject = this.getRegistryObject();
82
83         handler.marshal(regObject,parent);
84         child = (Element JavaDoc)parent.getFirstChild();
85         parent.removeChild(child);
86
87         return child;
88     }
89
90     public void testMarshal()
91     {
92         Element JavaDoc child = getMarshalledElement(null);
93
94         String JavaDoc marshalledString = this.getXMLString(child);
95
96         assertNotNull("Marshalled FindTModel ", marshalledString);
97
98     }
99
100     public void testUnMarshal()
101     {
102
103         Element JavaDoc child = getMarshalledElement(null);
104         RegistryObject regObject = handler.unmarshal(child);
105
106         assertNotNull("UnMarshalled FindTModel ", regObject);
107
108     }
109
110   public void testMarshUnMarshal()
111   {
112         Element JavaDoc child = getMarshalledElement(null);
113
114         String JavaDoc marshalledString = this.getXMLString(child);
115
116         assertNotNull("Marshalled FindTModel ", marshalledString);
117
118         RegistryObject regObject = handler.unmarshal(child);
119
120         child = getMarshalledElement(regObject);
121
122         String JavaDoc unMarshalledString = this.getXMLString(child);
123
124         assertNotNull("Unmarshalled FindTModel ", unMarshalledString);
125
126         boolean equals = marshalledString.equals(unMarshalledString);
127
128         assertEquals("Expected result: ", marshalledString, unMarshalledString );
129   }
130
131 }
132
Popular Tags