This project has retired. For details please refer to its
Attic page.
TckValidator xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.apache.juddi.v2.tck;
16
17
18
19
20
21
22
23 import static junit.framework.Assert.assertEquals;
24 import static junit.framework.Assert.assertTrue;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.uddi.api_v2.*;
30
31 public class TckValidator {
32
33
34
35
36 public static void checkNames(List<Name> names1, List<Name> names2) {
37 if (names1 == null || names2 == null) {
38 assertEquals(names1, names2);
39 return;
40 }
41 assertEquals(names1.size(), names2.size());
42 Iterator<Name> names1Itr = names1.iterator();
43 Iterator<Name> names2Itr = names2.iterator();
44 while (names1Itr.hasNext()) {
45 Name name1 = names1Itr.next();
46 Name name2 = names2Itr.next();
47 assertEquals(name1.getLang(), name2.getLang());
48 assertEquals(name1.getValue(), name2.getValue());
49 }
50 }
51
52 public static void checkDescriptions(List<Description> descriptions1, List<Description> descriptions2) {
53 if (descriptions1 == null || descriptions2 == null) {
54 assertEquals(descriptions1, descriptions2);
55 return;
56 }
57 assertEquals(descriptions1.size(), descriptions2.size());
58 Iterator<Description> descriptions1Itr = descriptions1.iterator();
59 Iterator<Description> descriptions2Itr = descriptions2.iterator();
60 while (descriptions1Itr.hasNext()) {
61 Description description1 = descriptions1Itr.next();
62 Description description2 = descriptions2Itr.next();
63 assertEquals(description1.getLang(), description2.getLang());
64 assertEquals(description1.getValue(), description2.getValue());
65 }
66 }
67
68 public static void checkDiscoveryUrls(DiscoveryURLs discs1, DiscoveryURLs discs2) {
69 if (discs1 == null || discs2 == null) {
70 assertEquals(discs1, discs2);
71 return;
72 }
73 List<DiscoveryURL> discList1 = discs1.getDiscoveryURL();
74 List<DiscoveryURL> discList2 = discs2.getDiscoveryURL();
75
76 if (discList1 == null || discList2 == null) {
77 assertEquals(discList1, discList2);
78 return;
79 }
80 assertEquals(discList1.size(), discList2.size());
81 Iterator<DiscoveryURL> discList1Itr = discList1.iterator();
82 Iterator<DiscoveryURL> discList2Itr = discList2.iterator();
83 while (discList1Itr.hasNext()) {
84 DiscoveryURL disc1 = discList1Itr.next();
85 DiscoveryURL disc2 = discList2Itr.next();
86 assertEquals(disc1.getUseType(), disc2.getUseType());
87 assertEquals(disc1.getValue(), disc2.getValue());
88 }
89 }
90
91
92 public static void checkContacts(Contacts contacts1, Contacts contacts2) {
93 if (contacts1 == null || contacts2 == null) {
94 assertEquals(contacts1, contacts2);
95 return;
96 }
97 List<Contact> contactList1 = contacts1.getContact();
98 List<Contact> contactList2 = contacts2.getContact();
99 if (contactList1 == null || contactList2 == null) {
100 assertEquals(contactList1, contactList2);
101 return;
102 }
103 assertEquals(contactList1.size(), contactList2.size());
104 Iterator<Contact> contactList1Itr = contactList1.iterator();
105 Iterator<Contact> contactList2Itr = contactList2.iterator();
106 while (contactList1Itr.hasNext()) {
107 Contact contact1 = contactList1Itr.next();
108 Contact contact2 = contactList2Itr.next();
109 assertEquals(contact1.getUseType(), contact2.getUseType());
110 assertEquals(contact1.getPersonName(), contact2.getPersonName());
111 checkDescriptions(contact1.getDescription(), contact2.getDescription());
112 }
113 }
114 public static void checkCategories(CategoryBag cbag1, CategoryBag cbag2) {
115 if (cbag1 == null || cbag2 == null) {
116 assertEquals(cbag1, cbag2);
117 return;
118 }
119 List<KeyedReference> elemList1 = cbag1.getKeyedReference();
120 List<KeyedReference> elemList2 = cbag2.getKeyedReference();
121 if (elemList1 == null || elemList2 == null) {
122 assertEquals(elemList1, elemList2);
123 return;
124 }
125
126
127 Iterator<KeyedReference> elemList1Itr = elemList1.iterator();
128 Iterator<KeyedReference> elemList2Itr = elemList2.iterator();
129 while (elemList1Itr.hasNext()) {
130 KeyedReference elem1 = elemList1Itr.next();
131 if (elem1 instanceof KeyedReference) {
132 KeyedReference elem2 = elemList2Itr.next();
133 assertEquals(elem1.getTModelKey(), elem2.getTModelKey());
134 assertEquals(elem1.getKeyName(), elem2.getKeyName());
135 assertEquals(elem1.getKeyValue(), elem2.getKeyValue());
136 }
137
138 }
139 }
140
141 public static void checkBindingTemplates(BindingTemplates bts1, BindingTemplates bts2) {
142 if (bts1 == null || bts2 == null) {
143 assertEquals(bts1, bts2);
144 return;
145 }
146 assertEquals(bts1.getBindingTemplate().size(), bts2.getBindingTemplate().size());
147 Iterator<BindingTemplate> bt1Iter = bts1.getBindingTemplate().iterator();
148 Iterator<BindingTemplate> bt2Iter = bts2.getBindingTemplate().iterator();
149 while (bt1Iter.hasNext()) {
150 BindingTemplate bt1 = bt1Iter.next();
151 BindingTemplate bt2 = bt2Iter.next();
152 assertEquals(bt1.getAccessPoint().getValue(),bt2.getAccessPoint().getValue());
153 assertEquals(bt1.getAccessPoint().getURLType(),bt2.getAccessPoint().getURLType());
154 assertEquals(bt1.getBindingKey().toLowerCase(),bt2.getBindingKey());
155 checkDescriptions(bt1.getDescription(),bt2.getDescription());
156 checkHostingRedirector(bt1.getHostingRedirector(),bt2.getHostingRedirector());
157
158 if (bt1.getServiceKey()!=null) {
159 assertEquals(bt1.getServiceKey(),bt2.getServiceKey());
160 }
161 checkTModelInstanceDetails(bt1.getTModelInstanceDetails(),bt2.getTModelInstanceDetails());
162 }
163 }
164
165 public static void checkTModelInstanceDetails(TModelInstanceDetails tmds1, TModelInstanceDetails tmds2) {
166 if (tmds1 == null || tmds2 == null) {
167 assertEquals(tmds1, tmds2);
168 return;
169 }
170 assertEquals(tmds1.getTModelInstanceInfo().size(),tmds2.getTModelInstanceInfo().size());
171 Iterator<TModelInstanceInfo> tmIter1 = tmds1.getTModelInstanceInfo().iterator();
172 Iterator<TModelInstanceInfo> tmIter2 = tmds2.getTModelInstanceInfo().iterator();
173 while (tmIter1.hasNext()) {
174 TModelInstanceInfo tmI1 = tmIter1.next();
175 TModelInstanceInfo tmI2 = tmIter2.next();
176 checkDescriptions(tmI1.getDescription(), tmI2.getDescription());
177 checkInstanceDetails(tmI1.getInstanceDetails(), tmI2.getInstanceDetails());
178 assertEquals(tmI1.getTModelKey().toLowerCase(),tmI2.getTModelKey());
179 }
180 }
181
182 public static void checkInstanceDetails(InstanceDetails ids1, InstanceDetails ids2) {
183 if (ids1 == null || ids2 == null) {
184 return;
185 }
186 List<Description> elem1s = ids1.getDescription();
187 List<Description> elem2s = ids2.getDescription();
188 Iterator<Description> elem1 = elem1s.iterator();
189
190 checkDescriptions(elem2s, elem2s);
191
192 OverviewDoc odoc1s = ids1.getOverviewDoc();
193 OverviewDoc odoc2s = ids2.getOverviewDoc();
194
195 if (odoc1s==null&& odoc2s == null) {
196 }else if (odoc1s!=null && odoc2s!=null)
197 {
198 checkDescriptions(odoc1s.getDescription(), odoc2s.getDescription());
199 assertEquals("overview doc mismatch",odoc1s.getOverviewURL(), odoc2s.getOverviewURL());
200 }else
201 {
202 assertTrue("overview doc missing one one item", false);
203 }
204 assertEquals("instance params mismatch",ids1.getInstanceParms(),ids2.getInstanceParms());
205 }
206
207 public static void checkOverviewDocs(OverviewDoc doc1, OverviewDoc elem2s) {
208 boolean isMatch=false;
209
210
211 isMatch = compareOverviewDocs(doc1, elem2s);
212
213
214 assertTrue(isMatch);
215 }
216
217
218 public static boolean compareOverviewDocs(OverviewDoc doc1, OverviewDoc doc2)
219 {
220 if (doc1==null && doc2==null) return true;
221 if (doc1!=null && doc2==null) return false;
222 if (doc1==null && doc2!=null) return false;
223 boolean descMatch=false;
224 boolean urlMatch =false;
225
226 String url1 = doc1.getOverviewURL();
227 String url2 = doc2.getOverviewURL();
228 if (url1.equals(url2) ) {
229 urlMatch=true;
230 }
231
232
233 List<Description> descList1 = doc1.getDescription();
234 Iterator<Description> descIter1 = descList1.iterator();
235 if (descList1.size() == 0 && doc2.getDescription().size() == 0) {
236 descMatch = true;
237 }
238 while (descIter1.hasNext()) {
239 Description descr1 = (Description) descIter1.next();
240 List<Description> descList2 = doc2.getDescription();
241 Iterator<Description> descElem2 = descList2.iterator();
242 while (descElem2.hasNext()) {
243 Description descr2 = descElem2.next();
244 if (descr1.getLang().equals(descr2.getLang()) && descr1.getValue().equals(descr2.getValue())) {
245 descMatch=true;
246 }
247 }
248 }
249
250 if (urlMatch && descMatch) {
251 return true;
252 }
253 return false;
254 }
255
256
257
258 public static void checkHostingRedirector(HostingRedirector hr1, HostingRedirector hr2) {
259 if (hr1 == null || hr2 == null) {
260 assertEquals(hr1, hr2);
261 return;
262 }
263 assertEquals(hr1.getBindingKey(),hr2.getBindingKey());
264 }
265
266 }