KickJava   Java API By Example, From Geeks To Geeks.

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


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.Address;
19 import org.apache.juddi.datatype.AddressLine;
20 import org.apache.juddi.datatype.CategoryBag;
21 import org.apache.juddi.datatype.Description;
22 import org.apache.juddi.datatype.DiscoveryURL;
23 import org.apache.juddi.datatype.DiscoveryURLs;
24 import org.apache.juddi.datatype.Email;
25 import org.apache.juddi.datatype.IdentifierBag;
26 import org.apache.juddi.datatype.KeyedReference;
27 import org.apache.juddi.datatype.Name;
28 import org.apache.juddi.datatype.OverviewDoc;
29 import org.apache.juddi.datatype.Phone;
30 import org.apache.juddi.datatype.RegistryObject;
31 import org.apache.juddi.datatype.binding.AccessPoint;
32 import org.apache.juddi.datatype.binding.BindingTemplate;
33 import org.apache.juddi.datatype.binding.BindingTemplates;
34 import org.apache.juddi.datatype.binding.HostingRedirector;
35 import org.apache.juddi.datatype.binding.InstanceDetails;
36 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
37 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
38 import org.apache.juddi.datatype.business.Contact;
39 import org.apache.juddi.datatype.business.Contacts;
40 import org.apache.juddi.datatype.service.BusinessService;
41 import org.apache.juddi.util.xml.XMLUtils;
42 import org.w3c.dom.Element JavaDoc;
43
44 /**
45  * @author anou_mana@apache.org
46  */

47 public class BusinessServiceHandlerTests extends HandlerTestCase
48 {
49     private static final String JavaDoc TEST_ID = "juddi.handler.BusinessService.test";
50     private BusinessServiceHandler handler = null;
51
52   public BusinessServiceHandlerTests(String JavaDoc arg0)
53   {
54     super(arg0);
55   }
56
57   public static void main(String JavaDoc[] args)
58   {
59     junit.textui.TestRunner.run(BusinessServiceHandlerTests.class);
60   }
61
62   public void setUp()
63   {
64         HandlerMaker maker = HandlerMaker.getInstance();
65         handler = (BusinessServiceHandler)maker.lookup(BusinessServiceHandler.TAG_NAME);
66   }
67
68     private RegistryObject getRegistryObject()
69     {
70
71         OverviewDoc overDoc = new OverviewDoc();
72         overDoc.setOverviewURL("http://www.juddi.org/service.html");
73         overDoc.addDescription(new Description("over-doc Descr"));
74         overDoc.addDescription(new Description("over-doc Descr Two","en"));
75
76         InstanceDetails instDetails = new InstanceDetails();
77         instDetails.addDescription(new Description("inst-det descr"));
78         instDetails.addDescription(new Description("inst-det descr in italy","it"));
79         instDetails.setInstanceParms("inst-det parameters");
80         instDetails.setOverviewDoc(overDoc);
81
82         TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
83         tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
84         tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
85         tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
86         tModInstInfo.setInstanceDetails(instDetails);
87
88         TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
89         tModInstDet.addTModelInstanceInfo(tModInstInfo);
90
91         BindingTemplate binding = new BindingTemplate();
92         binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
93         binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
94         binding.addDescription(new Description("whatever"));
95         binding.addDescription(new Description("whatever too","fr"));
96         binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
97         binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.juddi.org/service.wsdl"));
98         binding.setTModelInstanceDetails(tModInstDet);
99
100         BindingTemplates bindings = new BindingTemplates();
101         bindings.addBindingTemplate(binding);
102
103         CategoryBag catBag = new CategoryBag();
104         catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
105         catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2"));
106
107         IdentifierBag idBag = new IdentifierBag();
108         idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue"));
109         idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2"));
110
111         DiscoveryURLs discURLs = new DiscoveryURLs();
112         discURLs.addDiscoveryURL(new DiscoveryURL("http","http://www.juddi.org/service.wsdl"));
113         discURLs.addDiscoveryURL(new DiscoveryURL("https","https://www.juddi.org/service.wsdl"));
114         discURLs.addDiscoveryURL(new DiscoveryURL("smtp","servicemngr@juddi.org"));
115
116         Address address = new Address();
117         address.setUseType("myAddressUseType");
118         address.setSortCode("sortThis");
119         address.setTModelKey(null);
120         address.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr"));
121         address.addAddressLine(new AddressLine("AddressLine2"));
122
123         Contact contact = new Contact();
124         contact.setUseType("myAddressUseType");
125         contact.setPersonNameValue("Person Whatever");
126         contact.addDescription(new Description("Description1"));
127         contact.addDescription(new Description("Description2","es"));
128         contact.addEmail(new Email("person@whatever.com"));
129         contact.addPhone(new Phone("(123)456-7890"));
130         contact.addAddress(address);
131
132         Contacts contacts = new Contacts();
133         contacts.addContact(contact);
134
135         BusinessService object = new BusinessService();
136         object.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
137         object.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77");
138         object.setBindingTemplates(bindings);
139         object.setCategoryBag(catBag);
140         object.addName(new Name("serviceNm"));
141         object.addName(new Name("serviceNm2","en"));
142         object.addDescription(new Description("service whatever"));
143         object.addDescription(new Description("service whatever too","it"));
144
145         return object;
146
147     }
148
149     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
150     {
151         Element JavaDoc parent = XMLUtils.newRootElement();
152         Element JavaDoc child = null;
153
154         if(regObject == null)
155             regObject = this.getRegistryObject();
156
157         handler.marshal(regObject,parent);
158         child = (Element JavaDoc)parent.getFirstChild();
159         parent.removeChild(child);
160
161         return child;
162     }
163
164     public void testMarshal()
165     {
166         Element JavaDoc child = getMarshalledElement(null);
167
168         String JavaDoc marshalledString = this.getXMLString(child);
169
170         assertNotNull("Marshalled BusinessService ", marshalledString);
171
172     }
173
174     public void testUnMarshal()
175     {
176
177         Element JavaDoc child = getMarshalledElement(null);
178         RegistryObject regObject = handler.unmarshal(child);
179
180         assertNotNull("UnMarshalled BusinessService ", regObject);
181
182     }
183
184   public void testMarshUnMarshal()
185   {
186         Element JavaDoc child = getMarshalledElement(null);
187
188         String JavaDoc marshalledString = this.getXMLString(child);
189
190         assertNotNull("Marshalled BusinessService ", marshalledString);
191
192         RegistryObject regObject = handler.unmarshal(child);
193
194         child = getMarshalledElement(regObject);
195
196         String JavaDoc unMarshalledString = this.getXMLString(child);
197
198         assertNotNull("Unmarshalled BusinessService ", unMarshalledString);
199
200         boolean equals = marshalledString.equals(unMarshalledString);
201
202         assertEquals("Expected result: ", marshalledString, unMarshalledString );
203   }
204
205 }
206
Popular Tags