KickJava   Java API By Example, From Geeks To Geeks.

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


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.KeyedReference;
21 import org.apache.juddi.datatype.Name;
22 import org.apache.juddi.datatype.OverviewDoc;
23 import org.apache.juddi.datatype.RegistryObject;
24 import org.apache.juddi.datatype.binding.AccessPoint;
25 import org.apache.juddi.datatype.binding.BindingTemplate;
26 import org.apache.juddi.datatype.binding.BindingTemplates;
27 import org.apache.juddi.datatype.binding.HostingRedirector;
28 import org.apache.juddi.datatype.binding.InstanceDetails;
29 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
30 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
31 import org.apache.juddi.datatype.response.ServiceDetail;
32 import org.apache.juddi.datatype.service.BusinessService;
33 import org.apache.juddi.util.xml.XMLUtils;
34 import org.w3c.dom.Element JavaDoc;
35
36 /**
37  * @author anou_mana@apache.org
38  */

39 public class ServiceDetailHandlerTests extends HandlerTestCase
40 {
41     private static final String JavaDoc TEST_ID = "juddi.handler.DeleteServiceDetail.test";
42     private ServiceDetailHandler handler = null;
43
44   public ServiceDetailHandlerTests(String JavaDoc arg0)
45   {
46     super(arg0);
47   }
48
49   public static void main(String JavaDoc[] args)
50   {
51     junit.textui.TestRunner.run( ServiceDetailHandlerTests.class);
52   }
53
54   public void setUp()
55   {
56         HandlerMaker maker = HandlerMaker.getInstance();
57         handler = ( ServiceDetailHandler)maker.lookup( ServiceDetailHandler.TAG_NAME);
58   }
59
60     private RegistryObject getRegistryObject()
61     {
62         OverviewDoc overDoc = new OverviewDoc();
63         overDoc.setOverviewURL("http://www.juddi.org/service.html");
64         overDoc.addDescription(new Description("over-doc Descr"));
65         overDoc.addDescription(new Description("over-doc Descr Two","en"));
66
67         InstanceDetails instDetails = new InstanceDetails();
68         instDetails.addDescription(new Description("Description1"));
69         instDetails.addDescription(new Description("Description2","it"));
70         instDetails.setInstanceParms("inst-det parameters");
71         instDetails.setOverviewDoc(overDoc);
72
73         TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
74         tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
75         tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
76         tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
77         tModInstInfo.setInstanceDetails(instDetails);
78
79         TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
80         tModInstDet.addTModelInstanceInfo(tModInstInfo);
81
82         BindingTemplate binding = new BindingTemplate();
83         binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
84         binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
85         binding.addDescription(new Description("whatever"));
86         binding.addDescription(new Description("whatever too","fr"));
87         binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
88         binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.juddi.org/service.wsdl"));
89         binding.setTModelInstanceDetails(tModInstDet);
90
91         BindingTemplates bindings = new BindingTemplates();
92         bindings.addBindingTemplate(binding);
93
94         CategoryBag catBag = new CategoryBag();
95         catBag.addKeyedReference(new KeyedReference("keyName","keyValue"));
96         catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","keyName2","keyValue2"));
97
98         BusinessService service = new BusinessService();
99         service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
100         service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77");
101         service.setBindingTemplates(bindings);
102         service.setCategoryBag(catBag);
103         service.addName(new Name("serviceNm"));
104         service.addName(new Name("serviceNm2","en"));
105         service.addDescription(new Description("service whatever"));
106         service.addDescription(new Description("service whatever too","it"));
107
108         ServiceDetail object = new ServiceDetail();
109         object.setGeneric("2.0");
110         object.setOperator("jUDDI.org");
111         object.setTruncated(false);
112         object.addBusinessService(service);
113         object.addBusinessService(service);
114
115         return object;
116
117     }
118
119     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
120     {
121         Element JavaDoc parent = XMLUtils.newRootElement();
122         Element JavaDoc child = null;
123
124         if(regObject == null)
125             regObject = this.getRegistryObject();
126
127         handler.marshal(regObject,parent);
128         child = (Element JavaDoc)parent.getFirstChild();
129         parent.removeChild(child);
130
131         return child;
132     }
133
134     public void testMarshal()
135     {
136         Element JavaDoc child = getMarshalledElement(null);
137
138         String JavaDoc marshalledString = this.getXMLString(child);
139
140         assertNotNull("Marshalled ServiceDetail ", marshalledString);
141
142     }
143
144     public void testUnMarshal()
145     {
146
147         Element JavaDoc child = getMarshalledElement(null);
148         RegistryObject regObject = handler.unmarshal(child);
149
150         assertNotNull("UnMarshalled ServiceDetail ", regObject);
151
152     }
153
154   public void testMarshUnMarshal()
155   {
156         Element JavaDoc child = getMarshalledElement(null);
157
158         String JavaDoc marshalledString = this.getXMLString(child);
159
160         assertNotNull("Marshalled ServiceDetail ", marshalledString);
161
162         RegistryObject regObject = handler.unmarshal(child);
163
164         child = getMarshalledElement(regObject);
165
166         String JavaDoc unMarshalledString = this.getXMLString(child);
167
168         assertNotNull("Unmarshalled ServiceDetail ", unMarshalledString);
169
170         boolean equals = marshalledString.equals(unMarshalledString);
171
172         assertEquals("Expected ServiceDetail: ", marshalledString, unMarshalledString );
173   }
174
175 }
176
Popular Tags