KickJava   Java API By Example, From Geeks To Geeks.

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


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.UploadRegister;
25 import org.apache.juddi.datatype.request.AuthInfo;
26 import org.apache.juddi.datatype.request.SaveTModel;
27 import org.apache.juddi.datatype.tmodel.TModel;
28 import org.apache.juddi.util.xml.XMLUtils;
29 import org.w3c.dom.Element JavaDoc;
30
31 /**
32  * @author anou_mana@apache.org
33  */

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