KickJava   Java API By Example, From Geeks To Geeks.

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


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.Description;
19 import org.apache.juddi.datatype.OverviewDoc;
20 import org.apache.juddi.datatype.RegistryObject;
21 import org.apache.juddi.datatype.binding.AccessPoint;
22 import org.apache.juddi.datatype.binding.BindingTemplate;
23 import org.apache.juddi.datatype.binding.BindingTemplates;
24 import org.apache.juddi.datatype.binding.HostingRedirector;
25 import org.apache.juddi.datatype.binding.InstanceDetails;
26 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
27 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
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 BindingTemplatesHandlerTests extends HandlerTestCase
35 {
36     private static final String JavaDoc TEST_ID = "juddi.handler.BindingTemplates.test";
37     private BindingTemplatesHandler handler = null;
38
39   public BindingTemplatesHandlerTests(String JavaDoc arg0)
40   {
41     super(arg0);
42   }
43
44   public static void main(String JavaDoc[] args)
45   {
46     junit.textui.TestRunner.run(BindingTemplatesHandlerTests.class);
47   }
48
49   public void setUp()
50   {
51         HandlerMaker maker = HandlerMaker.getInstance();
52         handler = (BindingTemplatesHandler)maker.lookup(BindingTemplatesHandler.TAG_NAME);
53   }
54
55     private RegistryObject getRegistryObject()
56     {
57
58         OverviewDoc overDoc = new OverviewDoc();
59         overDoc.setOverviewURL("http://www.juddi.org/service.html");
60         overDoc.addDescription(new Description("over-doc Descr"));
61         overDoc.addDescription(new Description("over-doc Descr Two","en"));
62
63         InstanceDetails instDetails = new InstanceDetails();
64         instDetails.addDescription(new Description("inst-det descr"));
65         instDetails.addDescription(new Description("inst-det descr in italy","it"));
66         instDetails.setInstanceParms("inst-det parameters");
67         instDetails.setOverviewDoc(overDoc);
68
69         TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
70         tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
71         tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
72         tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
73         tModInstInfo.setInstanceDetails(instDetails);
74
75         TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
76         tModInstDet.addTModelInstanceInfo(tModInstInfo);
77
78         BindingTemplate binding = new BindingTemplate();
79         binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
80         binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
81         binding.addDescription(new Description("whatever"));
82         binding.addDescription(new Description("whatever too","fr"));
83         binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
84         binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.juddi.org/service.wsdl"));
85         binding.setTModelInstanceDetails(tModInstDet);
86
87         BindingTemplates object = new BindingTemplates();
88         object.addBindingTemplate(binding);
89         object.addBindingTemplate(binding);
90         return object;
91
92     }
93
94     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
95     {
96         Element JavaDoc parent = XMLUtils.newRootElement();
97         Element JavaDoc child = null;
98
99         if(regObject == null)
100             regObject = this.getRegistryObject();
101
102         handler.marshal(regObject,parent);
103         child = (Element JavaDoc)parent.getFirstChild();
104         parent.removeChild(child);
105
106         return child;
107     }
108
109     public void testMarshal()
110     {
111         Element JavaDoc child = getMarshalledElement(null);
112
113         String JavaDoc marshalledString = this.getXMLString(child);
114
115         assertNotNull("Marshalled BindingTemplates ", marshalledString);
116
117     }
118
119     public void testUnMarshal()
120     {
121
122         Element JavaDoc child = getMarshalledElement(null);
123         RegistryObject regObject = handler.unmarshal(child);
124
125         assertNotNull("UnMarshalled BindingTemplates ", regObject);
126
127     }
128
129   public void testMarshUnMarshal()
130   {
131         Element JavaDoc child = getMarshalledElement(null);
132
133         String JavaDoc marshalledString = this.getXMLString(child);
134
135         assertNotNull("Marshalled BindingTemplates ", marshalledString);
136
137         RegistryObject regObject = handler.unmarshal(child);
138
139         child = getMarshalledElement(regObject);
140
141         String JavaDoc unMarshalledString = this.getXMLString(child);
142
143         assertNotNull("Unmarshalled BindingTemplates ", unMarshalledString);
144
145         boolean equals = marshalledString.equals(unMarshalledString);
146
147         assertEquals("Expected result: ", marshalledString, unMarshalledString );
148   }
149
150 }
151
Popular Tags