KickJava   Java API By Example, From Geeks To Geeks.

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


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