This project has retired. For details please refer to its Attic page.
TckBindingTemplate xref
View Javadoc
1   /*
2    * Copyright 2001-2009 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    *      http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.apache.juddi.v3.tck;
16  
17  import static junit.framework.Assert.assertEquals;
18  
19  import java.util.List;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.juddi.jaxb.EntityCreator;
24  import org.junit.Assert;
25  import org.uddi.api_v3.BindingDetail;
26  import org.uddi.api_v3.BindingTemplate;
27  import org.uddi.api_v3.DeleteBinding;
28  import org.uddi.api_v3.GetBindingDetail;
29  import org.uddi.api_v3.SaveBinding;
30  import org.uddi.v3_service.UDDIInquiryPortType;
31  import org.uddi.v3_service.UDDIPublicationPortType;
32  /**
33   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
34   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
35   */
36  public class TckBindingTemplate 
37  {
38  	public final static String JOE_BINDING_XML               = "uddi_data/joepublisher/bindingTemplate.xml";
39     public final static String JOE_BINDING_KEY               = "uddi:uddi.joepublisher.com:bindingtwo";
40    
41  	private Log logger = LogFactory.getLog(this.getClass());
42  	private UDDIPublicationPortType publication = null;
43      private UDDIInquiryPortType inquiry = null;
44  	
45  	public TckBindingTemplate(UDDIPublicationPortType publication, 
46  				  UDDIInquiryPortType inquiry) {
47  		super();
48  		this.publication = publication;
49  		this.inquiry = inquiry;
50  	}
51  
52  	public void saveJoePublisherBinding(String authInfoJoe) throws Exception {
53  		saveBinding(authInfoJoe, JOE_BINDING_XML, JOE_BINDING_KEY);
54  	}
55  	
56  	public void deleteJoePublisherBinding(String authInfoJoe) {
57  		deleteBinding(authInfoJoe, JOE_BINDING_KEY);
58  	}
59  	
60  	public void saveBinding(String authInfo, String bindingXML, String bindingKey) throws Exception {
61              saveBinding(authInfo, bindingXML, bindingKey, true);
62          }
63  	public void saveBinding(String authInfo, String bindingXML, String bindingKey, boolean withAssertFail) throws Exception {
64  		try {
65  			// First save the entity
66  			SaveBinding sb = new SaveBinding();
67  			sb.setAuthInfo(authInfo);
68  			
69  			BindingTemplate btIn = (BindingTemplate)EntityCreator.buildFromDoc(bindingXML, "org.uddi.api_v3");
70  			sb.getBindingTemplate().add(btIn);
71  			publication.saveBinding(sb);
72  			
73  			// Now get the entity and check the values
74  			GetBindingDetail gb = new GetBindingDetail();
75  			gb.getBindingKey().add(bindingKey);
76  			BindingDetail bd = inquiry.getBindingDetail(gb);
77  			List<BindingTemplate> btOutList = bd.getBindingTemplate();
78  			BindingTemplate btOut = btOutList.get(0);
79  
80  			assertEquals(btIn.getServiceKey(), btOut.getServiceKey());
81  			assertEquals(btIn.getBindingKey(), btOut.getBindingKey());
82  			
83  			TckValidator.checkDescriptions(btIn.getDescription(), btOut.getDescription());
84  			TckValidator.checkCategories(btIn.getCategoryBag(), btOut.getCategoryBag());
85  		}
86  		catch(Exception e) {
87  			logger.error(e.getMessage(), e);
88                          if(withAssertFail)
89  			Assert.fail("No exception should be thrown: " + e.getMessage());
90                          else throw e;
91                          
92  		}
93  		
94  	}
95  	
96  	public void deleteBinding(String authInfo, String bindingKey) {
97  		try {
98  			// Delete the entity and make sure it is removed
99  			DeleteBinding db = new DeleteBinding();
100 			db.setAuthInfo(authInfo);
101 			
102 			db.getBindingKey().add(bindingKey);
103 			publication.deleteBinding(db);
104 		}
105 		catch(Exception e) {
106 			logger.error(e.getMessage(), e);
107 			Assert.fail("No exception should be thrown.");
108 		}
109 		
110 	}
111 }