This project has retired. For details please refer to its Attic page.
API_150_ValueSetValidationTest xref
View Javadoc
1   /*
2    * Copyright 2013 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.api.impl;
17  
18  import java.util.UUID;
19  import org.apache.commons.configuration.ConfigurationException;
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.juddi.Registry;
23  import org.apache.juddi.v3.client.UDDIConstants;
24  import org.apache.juddi.v3.error.ValueNotAllowedException;
25  import org.apache.juddi.v3.tck.TckPublisher;
26  import org.apache.juddi.v3.tck.TckSecurity;
27  import org.apache.juddi.v3.tck.TckTModel;
28  import org.junit.AfterClass;
29  import org.junit.Assert;
30  import org.junit.BeforeClass;
31  import org.junit.Ignore;
32  import org.junit.Test;
33  import org.uddi.api_v3.AccessPoint;
34  import org.uddi.api_v3.BindingDetail;
35  import org.uddi.api_v3.BindingTemplate;
36  import org.uddi.api_v3.BusinessDetail;
37  import org.uddi.api_v3.BusinessEntity;
38  import org.uddi.api_v3.BusinessService;
39  import org.uddi.api_v3.BusinessServices;
40  import org.uddi.api_v3.CategoryBag;
41  import org.uddi.api_v3.Description;
42  import org.uddi.api_v3.GetBindingDetail;
43  import org.uddi.api_v3.IdentifierBag;
44  import org.uddi.api_v3.KeyedReference;
45  import org.uddi.api_v3.Name;
46  import org.uddi.api_v3.SaveBinding;
47  import org.uddi.api_v3.SaveBusiness;
48  import org.uddi.api_v3.SaveTModel;
49  import org.uddi.api_v3.TModel;
50  import org.uddi.api_v3.TModelDetail;
51  import org.uddi.api_v3.TModelInstanceDetails;
52  import org.uddi.v3_service.UDDIInquiryPortType;
53  import org.uddi.v3_service.UDDIPublicationPortType;
54  import org.uddi.v3_service.UDDISecurityPortType;
55  
56  /**
57   *
58   * @author Alex O'Ree
59   */
60  public class API_150_ValueSetValidationTest {
61  
62          private static Log logger = LogFactory.getLog(API_141_JIRATest.class);
63          static UDDISecurityPortType security = new UDDISecurityImpl();
64          static UDDIInquiryPortType inquiry = new UDDIInquiryImpl();
65          static UDDIPublicationPortType publication = new UDDIPublicationImpl();
66          static JUDDIApiImpl juddi = new JUDDIApiImpl();
67          static UDDIValueSetValidationImpl vsv = new UDDIValueSetValidationImpl();
68          static TckTModel tckTModel = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
69          protected static String authInfoJoe = null;
70          protected static String authInfoMary = null;
71          protected static String authInfoSam = null;
72          protected static String authInfoRoot = null;
73          protected static String authInfoUDDI = null;
74  
75          @AfterClass
76          public static void stopManager() throws ConfigurationException {
77                  Registry.stop();
78          }
79  
80          @BeforeClass
81          public static void startManager() throws ConfigurationException {
82                  Registry.start();
83  
84                  logger.debug("Getting auth tokens..");
85                  try {
86                          authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
87                          authInfoMary = TckSecurity.getAuthToken(security, TckPublisher.getMaryPublisherId(), TckPublisher.getMaryPassword());
88                          authInfoSam = TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
89                          authInfoRoot = TckSecurity.getAuthToken(security, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
90                          authInfoUDDI = TckSecurity.getAuthToken(security, TckPublisher.getUDDIPublisherId(), TckPublisher.getUDDIPassword());
91                          Assert.assertNotNull(authInfoJoe);
92                          Assert.assertNotNull(authInfoSam);
93                          String authInfoUDDI = TckSecurity.getAuthToken(security, TckPublisher.getUDDIPublisherId(), TckPublisher.getUDDIPassword());
94                          tckTModel.saveUDDIPublisherTmodel(authInfoUDDI);
95                          tckTModel.saveTModels(authInfoUDDI, TckTModel.TMODELS_XML);
96                          tckTModel.saveJoePublisherTmodel(authInfoJoe);
97                          tckTModel.saveMaryPublisherTmodel(authInfoMary);
98                          
99                  } catch (Exception e) {
100                         logger.error(e.getMessage(), e);
101                         Assert.fail("Could not obtain authInfo token.");
102                 }
103         }
104         static String VSV_KEY = "uddi:juddi.apache.org:node1";
105         //VIA InVM transport
106         final static String VSV_BT_KEY = "uddi:juddi.apache.org:servicebindings-valueset-cp";
107         //VIA JAXWS Transport "uddi:juddi.apache.org:servicebindings-valueset-ws";
108         final static String TMODEL = "uddi:uddi.org:categorization:nodes";
109 
110         /**
111          * scenario 1
112          * <ul>
113          * <ol>create checked tmodel x</ol>
114          * <ol>register business/service/bt for validatevalues service</ol>
115          * <ol>add/alter BT to include instance info for ref to tmodel
116          * checked</ol>
117          * <ol>alter checked tmodel x, add reference to the BT for the
118          * validator</ol>
119          * <ol>someone tries to use the checked tmodel as a KR from some other
120          * entity</ol>
121          * <ol>on publish, the server attempts to validate the KR's value
122          * against the VV service via the binding Template</ol>
123          * </ul>
124          *
125          * @throws Exception
126          */
127         @Ignore
128         @Test
129         public void Scenario1() throws Exception {
130                 //create checked tmodel x
131                 //no longer needed, included with default install data
132                 //SaveCheckedTModel(TckTModel.JOE_PUBLISHER_KEY_PREFIX + TMODEL);
133                 //register business/service/bt for validatevalues service
134                 //this is done by the install process using the built in vsv
135 
136                 //add/alter BT to include instance info for ref to tmodel checked
137                 //turns out we don't need this either, its in the default install data
138                 //AlterRootBusiness();
139                 //configure jUDDI API service to "set" the valid values
140                 //SaveVSVValues(TckTModel.JOE_PUBLISHER_KEY_PREFIX + TMODEL);
141                 //add a new service for joe, reference the checked tmodel with an invalid token 
142                 SaveBusiness(authInfoJoe, true, TMODEL);
143 
144                 //add a new service for joe, reference the checked tmodel with invalid token
145         }
146 
147         @Ignore
148         @Test(expected = ValueNotAllowedException.class)
149         public void Scenario1Invalid() throws Exception {
150                 //create checked tmodel x
151                 //logger.info("Saving checked tModel");
152                 // SaveCheckedTModel(TckTModel.JOE_PUBLISHER_KEY_PREFIX + TMODEL);
153                 //register business/service/bt for validatevalues service
154                 //this is done by the install process using the built in vsv
155 
156                 //add/alter BT to include instance info for ref to tmodel checked
157                 //turns out we don't need this either, its in the default install data
158                 //AlterRootBusiness();
159                 //configure jUDDI API service to "set" the valid values
160                 //logger.info("Saving VS valid values");
161                 //SaveVSVValues(TckTModel.JOE_PUBLISHER_KEY_PREFIX + TMODEL);
162                 //add a new service for joe, reference the checked tmodel with an invalid token 
163                 logger.info("Saving a business using those values");
164                 SaveBusiness(authInfoJoe, false, TMODEL);
165 
166                 //add a new service for joe, reference the checked tmodel with invalid token
167         }
168 
169         @Ignore
170         @Test
171         public void Scenarion2() {
172                 /*
173                  * use x has a keyed reference for service xyz
174                  register business/service/bt for validatevalues service
175                  add/alter BT to include instance info for ref to tmodel checked
176                  alter checked tmodel, add reference to the BT for the validator
177                  >>> open question? do we check existing instances of tmodel x at this point? do we reject the request if validation fails?
178                  someone tries to use the checked tmodel as a KR
179                  on publish, the server attempts to validate the KR's value against the VV service via the binding Template
180                  */
181         }
182 
183         private void SaveCheckedTModel(String key) throws Exception {
184                 TModel tm = new TModel();
185                 tm.setTModelKey(key);
186                 tm.setCategoryBag(new CategoryBag());
187                 tm.setName(new Name("My Custom validated key", "en"));
188                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
189                 tm.getCategoryBag().getKeyedReference().add(
190                      new KeyedReference(UDDIConstants.IS_VALIDATED_BY, UDDIConstants.IS_VALIDATED_BY_KEY_NAME, VSV_BT_KEY));
191                 SaveTModel stm = new SaveTModel();
192                 stm.setAuthInfo(authInfoJoe);
193                 stm.getTModel().add(tm);
194                 publication.saveTModel(stm);
195         }
196 
197         /**
198          * The bindingTemplate for the get_allValidValues or the validate_values
199          * Web service SHOULD reference in its tModelInstanceDetails the
200          * appropriate value set API tModel (Section 11.2.7 Value Set Caching
201          * API tModel or Section 11.2.8 Value Set Validation API tModel) as well
202          * tModels for all of the value sets the service applies to.
203          *
204          * @throws Exception
205          */
206         private void AlterRootBusiness() throws Exception {
207                 GetBindingDetail gsd = new GetBindingDetail();
208                 gsd.getBindingKey().add(VSV_BT_KEY);
209                 BindingDetail bindingDetail = inquiry.getBindingDetail(gsd);
210                 if (bindingDetail.getBindingTemplate().get(0).getTModelInstanceDetails() == null) {
211                         bindingDetail.getBindingTemplate().get(0).setTModelInstanceDetails(new TModelInstanceDetails());
212                 }
213                 for (int i = 0; i < bindingDetail.getBindingTemplate().get(0).getTModelInstanceDetails().getTModelInstanceInfo().size(); i++) {
214                 }
215         }
216 
217         private void SaveBusiness(String authInfoJoe, boolean isValid, String key) throws Exception {
218                 SaveBusiness sb = new SaveBusiness();
219                 sb.setAuthInfo(authInfoJoe);
220                 BusinessEntity be = new BusinessEntity();
221                 be.getName().add(new Name("VSV", null));
222                 be.setCategoryBag(new CategoryBag());
223                 if (isValid) {
224                         be.getCategoryBag().getKeyedReference().add(new KeyedReference(key, "node", "node"));
225                 } else {
226                         be.getCategoryBag().getKeyedReference().add(new KeyedReference(key, "name", "qwerty"));
227                 }
228                 sb.getBusinessEntity().add(be);
229                 publication.saveBusiness(sb);
230         }
231 
232      
233 
234         public void DerviedFromValid() throws Exception {
235 
236                 TModel tm = new TModel();
237                 //tm.setTModelKey();
238                 tm.setCategoryBag(new CategoryBag());
239                 tm.setName(new Name("My Custom validated key", "en"));
240                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
241                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_DERIVED_FROM, "", "uddi:uddi.org:categorization:nodes"));
242                 SaveTModel stm = new SaveTModel();
243                 stm.setAuthInfo(authInfoJoe);
244                 stm.getTModel().add(tm);
245                 publication.saveTModel(stm);
246         }
247 
248         @Test(expected = ValueNotAllowedException.class)
249         public void DerviedFromInValid() throws Exception {
250 
251                 TModel tm = new TModel();
252                 //tm.setTModelKey();
253                 tm.setCategoryBag(new CategoryBag());
254                 tm.setName(new Name("My Custom validated key", "en"));
255                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
256                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_DERIVED_FROM, "", "uddi:juddi.apache.org:" + UUID.randomUUID().toString()));
257                 SaveTModel stm = new SaveTModel();
258                 stm.setAuthInfo(authInfoJoe);
259                 stm.getTModel().add(tm);
260                 publication.saveTModel(stm);
261         }
262 
263         @Test
264         public void EntitKeyValuesValid() throws Exception {
265                 TModel tm = new TModel();
266                 //tm.setTModelKey();
267                 tm.setCategoryBag(new CategoryBag());
268                 tm.setName(new Name("My Custom validated key", "en"));
269                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
270                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.ENTITY_KEY_VALUES, "", "tModelKey"));
271                 SaveTModel stm = new SaveTModel();
272                 stm.setAuthInfo(authInfoJoe);
273                 stm.getTModel().add(tm);
274                 publication.saveTModel(stm);
275 
276         }
277 
278         @Test(expected = ValueNotAllowedException.class)
279         public void EntitKeyValuesInValid() throws Exception {
280                 TModel tm = new TModel();
281                 //tm.setTModelKey();
282                 tm.setCategoryBag(new CategoryBag());
283                 tm.setName(new Name("My Custom validated key", "en"));
284                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
285                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.ENTITY_KEY_VALUES, "", "asdasdasd"));
286                 SaveTModel stm = new SaveTModel();
287                 stm.setAuthInfo(authInfoJoe);
288                 stm.getTModel().add(tm);
289                 publication.saveTModel(stm);
290         }
291 
292         @Test
293         @Ignore
294         public void UDDINodeValid() throws Exception {
295                 BusinessEntity be = new BusinessEntity();
296                 be.getName().add(new Name("test", "en"));
297                 be.setCategoryBag(new CategoryBag());
298                 be.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:nodes", "", "node"));
299                 SaveBusiness sb = new SaveBusiness();
300                 sb.setAuthInfo(authInfoRoot);
301                 sb.getBusinessEntity().add(be);
302                 publication.saveBusiness(sb);
303         }
304 
305         @Test(expected = ValueNotAllowedException.class)
306         public void UDDINodeInValid1() throws Exception {
307                 BusinessEntity be = new BusinessEntity();
308                 be.getName().add(new Name("test", "en"));
309                 be.setCategoryBag(new CategoryBag());
310                 be.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:nodes", "", "asdasd"));
311                 SaveBusiness sb = new SaveBusiness();
312                 sb.setAuthInfo(authInfoRoot);
313                 sb.getBusinessEntity().add(be);
314                 publication.saveBusiness(sb);
315         }
316 
317         @Test(expected = ValueNotAllowedException.class)
318         public void UDDINodeInValid2() throws Exception {
319                 BusinessEntity be = new BusinessEntity();
320                 be.getName().add(new Name("test", "en"));
321                 be.setBusinessServices(new BusinessServices());
322                 BusinessService bs = new BusinessService();
323                 bs.setCategoryBag(new CategoryBag());
324                 bs.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:nodes", "", "asdasd"));
325                 be.getBusinessServices().getBusinessService().add(bs);
326                 be.setCategoryBag(new CategoryBag());
327 
328                 SaveBusiness sb = new SaveBusiness();
329                 sb.setAuthInfo(authInfoRoot);
330                 sb.getBusinessEntity().add(be);
331                 publication.saveBusiness(sb);
332         }
333 
334         @Test
335         public void OwningBusinessValid() throws Exception {
336                 TModel tm = new TModel();
337                 //tm.setTModelKey();
338                 tm.setCategoryBag(new CategoryBag());
339                 tm.setName(new Name("My Custom validated key", "en"));
340                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
341                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.OWNING_BUSINESS, "",VSV_KEY));
342                 SaveTModel stm = new SaveTModel();
343                 stm.setAuthInfo(authInfoJoe);
344                 stm.getTModel().add(tm);
345                 publication.saveTModel(stm);
346         }
347 
348         @Test(expected = ValueNotAllowedException.class)
349         public void OwningBusinessInValid() throws Exception {
350                 BusinessEntity be = new BusinessEntity();
351                 be.getName().add(new Name("test", "en"));
352                 be.setCategoryBag(new CategoryBag());
353                 be.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.OWNING_BUSINESS, "", "uddi:juddi.apache.org:" + UUID.randomUUID().toString()));
354                 SaveBusiness sb = new SaveBusiness();
355                 sb.setAuthInfo(authInfoJoe);
356                 sb.getBusinessEntity().add(be);
357                 publication.saveBusiness(sb);
358         }
359 
360         @Test(expected = ValueNotAllowedException.class)
361         public void OwningBusinessInValid2() throws Exception {
362                 TModel tm = new TModel();
363                 //tm.setTModelKey();
364                 tm.setCategoryBag(new CategoryBag());
365                 tm.setName(new Name("My Custom validated key", "en"));
366                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
367                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.OWNING_BUSINESS, "", "uddi:juddi.apache.org:" + UUID.randomUUID().toString()));
368                 SaveTModel stm = new SaveTModel();
369                 stm.setAuthInfo(authInfoJoe);
370                 stm.getTModel().add(tm);
371                 publication.saveTModel(stm);
372         }
373 
374         @Test
375         public void TypeTmodelValid() throws Exception {
376                 TModel tm = new TModel();
377                 //tm.setTModelKey();
378                 tm.setCategoryBag(new CategoryBag());
379                 tm.setName(new Name("My Custom validated key", "en"));
380                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
381                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:types", "", "namespace"));
382                 SaveTModel stm = new SaveTModel();
383                 stm.setAuthInfo(authInfoJoe);
384                 stm.getTModel().add(tm);
385                 publication.saveTModel(stm);
386 
387         }
388 
389         @Test(expected = ValueNotAllowedException.class)
390         public void TypeTModelInValid() throws Exception {
391                 TModel tm = new TModel();
392                 //tm.setTModelKey();
393                 tm.setCategoryBag(new CategoryBag());
394                 tm.setName(new Name("My Custom validated key", "en"));
395                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
396                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:types", "", "wsdlDeployment"));
397                 SaveTModel stm = new SaveTModel();
398                 stm.setAuthInfo(authInfoJoe);
399                 stm.getTModel().add(tm);
400                 publication.saveTModel(stm);
401 
402         }
403 
404         @Test(expected = ValueNotAllowedException.class)
405         public void TypeBindingInValid() throws Exception {
406                 SaveBinding sb = new SaveBinding();
407                 sb.setAuthInfo(authInfoRoot);
408                 BindingTemplate bt = new BindingTemplate();
409                 bt.setServiceKey("uddi:juddi.apache.org:services-inquiry");
410                 bt.setAccessPoint(new AccessPoint("http://test", "endPoint"));
411                 bt.setCategoryBag(new CategoryBag());
412                 bt.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:types", "", "namespace"));
413                 publication.saveBinding(sb);
414         }
415 
416         @Test
417         public void TypeBindingValid() throws Exception {
418                 SaveBinding sb = new SaveBinding();
419                 sb.setAuthInfo(authInfoRoot);
420                 BindingTemplate bt = new BindingTemplate();
421                 bt.setServiceKey("uddi:juddi.apache.org:services-inquiry");
422                 bt.setAccessPoint(new AccessPoint("http://test", "endPoint"));
423                 bt.setCategoryBag(new CategoryBag());
424                 bt.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:types", "", "wsdlDeployment"));
425                 sb.getBindingTemplate().add(bt);
426                 publication.saveBinding(sb);
427         }
428 
429         @Test(expected = ValueNotAllowedException.class)
430         public void ValidatedByInValid() throws Exception {
431                 TModel tm = new TModel();
432                 //tm.setTModelKey();
433                 tm.setCategoryBag(new CategoryBag());
434                 tm.setName(new Name("My Custom validated key", "en"));
435                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
436                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_VALIDATED_BY, UDDIConstants.IS_VALIDATED_BY_KEY_NAME, "uddi:juddi.apache.org:s:nonexistentvalidator"));
437                 SaveTModel stm = new SaveTModel();
438                 stm.setAuthInfo(authInfoJoe);
439                 stm.getTModel().add(tm);
440                 publication.saveTModel(stm);
441 
442         }
443 
444         @Test
445         @Ignore
446         public void ValidatedByValid() throws Exception {
447                 //this is covered by the default install
448         }
449 
450         @Test
451         public void ReplacedByValid() throws Exception {
452                 TModel tm = new TModel();
453                 tm.setName(new Name("My old tmodel", "en"));
454                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
455                 SaveTModel stm = new SaveTModel();
456                 stm.setAuthInfo(authInfoJoe);
457                 stm.getTModel().add(tm);
458                 TModelDetail saveTModel = publication.saveTModel(stm);
459 
460                 tm = new TModel();
461                 tm.setName(new Name("My new tmodel", "en"));
462                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
463                 tm.setIdentifierBag(new IdentifierBag());
464                 tm.getIdentifierBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", saveTModel.getTModel().get(0).getTModelKey()));
465                 stm = new SaveTModel();
466                 stm.setAuthInfo(authInfoJoe);
467                 stm.getTModel().add(tm);
468                 publication.saveTModel(stm);
469         }
470 
471         @Test
472         public void ReplacedByValid2() throws Exception {
473                 TModel tm = new TModel();
474                 tm.setName(new Name("My old tmodel", "en"));
475                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
476                 SaveTModel stm = new SaveTModel();
477                 stm.setAuthInfo(authInfoJoe);
478                 stm.getTModel().add(tm);
479                 TModelDetail saveTModel = publication.saveTModel(stm);
480 
481                 tm = new TModel();
482                 tm.setName(new Name("My new tmodel", "en"));
483                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
484                 tm.setCategoryBag(new CategoryBag());
485                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", saveTModel.getTModel().get(0).getTModelKey()));
486                 stm = new SaveTModel();
487                 stm.setAuthInfo(authInfoJoe);
488                 stm.getTModel().add(tm);
489                 publication.saveTModel(stm);
490         }
491 
492         @Test
493         public void ReplacedByValid3() throws Exception {
494                 BusinessEntity tm = new BusinessEntity();
495                 tm.getName().add(new Name("My old business", "en"));
496                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
497                 SaveBusiness stm = new SaveBusiness();
498                 stm.setAuthInfo(authInfoJoe);
499                 stm.getBusinessEntity().add(tm);
500                 BusinessDetail saveBusiness = publication.saveBusiness(stm);
501 
502                 tm = new BusinessEntity();
503                 tm.getName().add(new Name("My new business", "en"));
504                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
505                 tm.setIdentifierBag(new IdentifierBag());
506                 tm.getIdentifierBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", saveBusiness.getBusinessEntity().get(0).getBusinessKey()));
507                 stm = new SaveBusiness();
508                 stm.setAuthInfo(authInfoJoe);
509                 stm.getBusinessEntity().add(tm);
510                 publication.saveBusiness(stm);
511         }
512 
513         @Test
514         public void ReplacedByValid4() throws Exception {
515                 BusinessEntity tm = new BusinessEntity();
516                 tm.getName().add(new Name("My old business", "en"));
517                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
518                 SaveBusiness stm = new SaveBusiness();
519                 stm.setAuthInfo(authInfoJoe);
520                 stm.getBusinessEntity().add(tm);
521                 BusinessDetail saveBusiness = publication.saveBusiness(stm);
522 
523                 tm = new BusinessEntity();
524                 tm.getName().add(new Name("My new business", "en"));
525                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
526                 tm.setCategoryBag(new CategoryBag());
527                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", saveBusiness.getBusinessEntity().get(0).getBusinessKey()));
528                 stm = new SaveBusiness();
529                 stm.setAuthInfo(authInfoJoe);
530                 stm.getBusinessEntity().add(tm);
531                 publication.saveBusiness(stm);
532         }
533 
534         @Test
535         public void ReplacedByValid5Projected() throws Exception {
536                 BusinessEntity tm = new BusinessEntity();
537                 tm.setBusinessKey(TckTModel.JOE_PUBLISHER_KEY_PREFIX + "testbiz");
538                 tm.getName().add(new Name("My old business", "en"));
539                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
540                 SaveBusiness stm = new SaveBusiness();
541                 stm.setAuthInfo(authInfoJoe);
542                 stm.getBusinessEntity().add(tm);
543 
544                 tm = new BusinessEntity();
545                 tm.setBusinessKey(TckTModel.JOE_PUBLISHER_KEY_PREFIX + "oldbiz");
546                 tm.getName().add(new Name("My new business", "en"));
547                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
548                 tm.setCategoryBag(new CategoryBag());
549                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", TckTModel.JOE_PUBLISHER_KEY_PREFIX + "testbiz"));
550                 stm.getBusinessEntity().add(tm);
551                 publication.saveBusiness(stm);
552         }
553         
554         
555          @Test
556         public void ReplacedByValid6DifferentOwners() throws Exception {
557                 BusinessEntity tm = new BusinessEntity();
558                 tm.setBusinessKey(TckTModel.MARY_KEY_PREFIX + "testbiz");
559                 tm.getName().add(new Name("My old business", "en"));
560                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
561                 SaveBusiness stm = new SaveBusiness();
562                 stm.setAuthInfo(authInfoMary);
563                 stm.getBusinessEntity().add(tm);
564                 publication.saveBusiness(stm);
565 
566                 tm = new BusinessEntity();
567                 tm.setBusinessKey(TckTModel.JOE_PUBLISHER_KEY_PREFIX + "oldbiz");
568                 tm.getName().add(new Name("My new business", "en"));
569                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
570                 tm.setCategoryBag(new CategoryBag());
571                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", TckTModel.MARY_KEY_PREFIX + "testbiz"));
572                 stm = new SaveBusiness();
573                 stm.setAuthInfo(authInfoJoe);
574                 stm.getBusinessEntity().add(tm);
575                 publication.saveBusiness(stm);
576         }
577         
578            @Test
579         public void ReplacedByValid7DifferentOwners() throws Exception {
580                 BusinessEntity tm = new BusinessEntity();
581                 tm.setBusinessKey(TckTModel.MARY_KEY_PREFIX + "testbiz");
582                 tm.getName().add(new Name("My old business", "en"));
583                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
584                 SaveBusiness stm = new SaveBusiness();
585                 stm.setAuthInfo(authInfoMary);
586                 stm.getBusinessEntity().add(tm);
587                 publication.saveBusiness(stm);
588 
589                 tm = new BusinessEntity();
590                 tm.setBusinessKey(TckTModel.JOE_PUBLISHER_KEY_PREFIX + "oldbiz");
591                 tm.getName().add(new Name("My new business", "en"));
592                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
593                 tm.setIdentifierBag(new IdentifierBag());
594                 tm.getIdentifierBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", TckTModel.MARY_KEY_PREFIX + "testbiz"));
595                 stm = new SaveBusiness();
596                 stm.setAuthInfo(authInfoJoe);
597                 stm.getBusinessEntity().add(tm);
598                 publication.saveBusiness(stm);
599         }
600 
601         /**
602          * reference undefined tmodel
603          *
604          * @throws Exception
605          */
606         @Test(expected = ValueNotAllowedException.class)
607         public void ReplacedByInValid() throws Exception {
608 
609                 TModel tm = new TModel();
610                 tm.setName(new Name("My new tmodel", "en"));
611                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
612                 tm.setCategoryBag(new CategoryBag());
613                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "", TckTModel.JOE_PUBLISHER_KEY_PREFIX + UUID.randomUUID().toString()));
614                 SaveTModel stm = new SaveTModel();
615                 stm.setAuthInfo(authInfoJoe);
616                 stm.getTModel().add(tm);
617                 publication.saveTModel(stm);
618         }
619 
620         /**
621          * reference business key
622          *
623          * @throws Exception
624          */
625         @Test(expected = ValueNotAllowedException.class)
626         public void ReplacedByInValid2() throws Exception {
627 
628                 TModel tm = new TModel();
629                 tm.setName(new Name("My new tmodel", "en"));
630                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
631                 tm.setCategoryBag(new CategoryBag());
632                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_REPLACED_BY, "",VSV_KEY));
633                 SaveTModel stm = new SaveTModel();
634                 stm.setAuthInfo(authInfoJoe);
635                 stm.getTModel().add(tm);
636                 publication.saveTModel(stm);
637         }
638 
639         @Test
640         public void RelationshipsValid() throws Exception {
641                 TModel tm = new TModel();
642                 tm.setCategoryBag(new CategoryBag());
643                 tm.setName(new Name("My Custom validated key", "en"));
644                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
645                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.RELATIONSHIPS, "", "peer-peer"));
646                 SaveTModel stm = new SaveTModel();
647                 stm.setAuthInfo(authInfoJoe);
648                 stm.getTModel().add(tm);
649                 publication.saveTModel(stm);
650 
651         }
652 
653         @Test(expected = ValueNotAllowedException.class)
654         public void RelationshipsInValid() throws Exception {
655                 TModel tm = new TModel();
656                 //tm.setTModelKey();
657                 tm.setCategoryBag(new CategoryBag());
658                 tm.setName(new Name("My Custom validated key", "en"));
659                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
660                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.RELATIONSHIPS, "", "asdasdasd"));
661                 SaveTModel stm = new SaveTModel();
662                 stm.setAuthInfo(authInfoJoe);
663                 stm.getTModel().add(tm);
664                 publication.saveTModel(stm);
665 
666         }
667 
668         @Test(expected = ValueNotAllowedException.class)
669         public void ClassLoadingTestsInValid() throws Exception {
670 
671                 //save a tmodel that's is validated but no validator exists
672                 TModel tm = new TModel();
673                 //tm.setTModelKey();
674                 tm.setCategoryBag(new CategoryBag());
675                 tm.setTModelKey(TckTModel.JOE_PUBLISHER_KEY_PREFIX + "nonexistentvalidator");
676                 tm.setName(new Name("My Custom validated key", "en"));
677                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
678                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(UDDIConstants.IS_VALIDATED_BY, UDDIConstants.IS_VALIDATED_BY_KEY_NAME, "uddi:juddi.apache.org:servicebindings-valueset-cp"));
679                 SaveTModel stm = new SaveTModel();
680                 stm.setAuthInfo(authInfoJoe);
681                 stm.getTModel().add(tm);
682                 publication.saveTModel(stm);
683 
684                 tm = new TModel();
685                 //tm.setTModelKey();
686                 tm.setCategoryBag(new CategoryBag());
687                 // tm.setTModelKey("uddi:uddi.org:categorization:nonexistentvalidator");
688                 tm.setName(new Name("My Custom validated key", "en"));
689                 tm.getDescription().add(new Description("valid values include 'one', 'two', 'three'", "en"));
690                 tm.getCategoryBag().getKeyedReference().add(new KeyedReference(TckTModel.JOE_PUBLISHER_KEY_PREFIX + "nonexistentvalidator", "", "asdasd"));
691                 stm = new SaveTModel();
692                 stm.setAuthInfo(authInfoJoe);
693                 stm.getTModel().add(tm);
694                 publication.saveTModel(stm);
695 
696                 //use it has a keyed reference, expect failure
697         }
698 }