KickJava   Java API By Example, From Geeks To Geeks.

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


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.Description;
20 import org.apache.juddi.datatype.IdentifierBag;
21 import org.apache.juddi.datatype.KeyedReference;
22 import org.apache.juddi.datatype.OverviewDoc;
23 import org.apache.juddi.datatype.RegistryObject;
24 import org.apache.juddi.datatype.response.TModelDetail;
25 import org.apache.juddi.datatype.tmodel.TModel;
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 TModelDetailHandlerTests extends HandlerTestCase
33 {
34     private static final String JavaDoc TEST_ID = "juddi.handler.DeleteTModelDetail.test";
35     private TModelDetailHandler handler = null;
36
37   public TModelDetailHandlerTests(String JavaDoc arg0)
38   {
39     super(arg0);
40   }
41
42   public static void main(String JavaDoc[] args)
43   {
44     junit.textui.TestRunner.run( TModelDetailHandlerTests.class);
45   }
46
47   public void setUp()
48   {
49         HandlerMaker maker = HandlerMaker.getInstance();
50         handler = ( TModelDetailHandler)maker.lookup( TModelDetailHandler.TAG_NAME);
51   }
52
53     private RegistryObject getRegistryObject()
54     {
55
56         OverviewDoc overDoc = new OverviewDoc();
57         overDoc.setOverviewURL("http://www.juddi.org/service.html");
58         overDoc.addDescription(new Description("over-doc Descr"));
59         overDoc.addDescription(new Description("over-doc Descr Two","en"));
60
61         CategoryBag catBag = new CategoryBag();
62         catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
63         catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2"));
64
65         IdentifierBag idBag = new IdentifierBag();
66         idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue"));
67         idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2"));
68
69         TModel tModel = new TModel();
70         tModel.setTModelKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038");
71         tModel.setOperator("jUDDI");
72         tModel.setAuthorizedName("Guest");
73         tModel.setName("jUDDI TModel");
74         tModel.addDescription(new Description("tModel whatever"));
75         tModel.addDescription(new Description("tModel whatever too","fr"));
76         tModel.setCategoryBag(catBag);
77         tModel.setIdentifierBag(idBag);
78         tModel.setOverviewDoc(overDoc);
79
80         TModelDetail object = new TModelDetail();
81         object.setGeneric("2.0");
82         object.setOperator("jUDDI.org");
83         object.setTruncated(true);
84         object.addTModel(tModel);
85         object.addTModel(tModel);
86
87         return object;
88
89     }
90
91     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
92     {
93         Element JavaDoc parent = XMLUtils.newRootElement();
94         Element JavaDoc child = null;
95
96         if(regObject == null)
97             regObject = this.getRegistryObject();
98
99         handler.marshal(regObject,parent);
100         child = (Element JavaDoc)parent.getFirstChild();
101         parent.removeChild(child);
102
103         return child;
104     }
105
106     public void testMarshal()
107     {
108         Element JavaDoc child = getMarshalledElement(null);
109
110         String JavaDoc marshalledString = this.getXMLString(child);
111
112         assertNotNull("Marshalled TModelDetail ", marshalledString);
113
114     }
115
116     public void testUnMarshal()
117     {
118
119         Element JavaDoc child = getMarshalledElement(null);
120         RegistryObject regObject = handler.unmarshal(child);
121
122         assertNotNull("UnMarshalled TModelDetail ", regObject);
123
124     }
125
126   public void testMarshUnMarshal()
127   {
128         Element JavaDoc child = getMarshalledElement(null);
129
130         String JavaDoc marshalledString = this.getXMLString(child);
131
132         assertNotNull("Marshalled TModelDetail ", marshalledString);
133
134         RegistryObject regObject = handler.unmarshal(child);
135
136         child = getMarshalledElement(regObject);
137
138         String JavaDoc unMarshalledString = this.getXMLString(child);
139
140         assertNotNull("Unmarshalled TModelDetail ", unMarshalledString);
141
142         boolean equals = marshalledString.equals(unMarshalledString);
143
144         assertEquals("Expected TModelDetail: ", marshalledString, unMarshalledString );
145   }
146
147 }
148
Popular Tags