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.v2.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_v2.*;
26  import org.uddi.v2_service.Inquire;
27  import org.uddi.v2_service.Publish;
28  /**
29   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
30   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
31   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
32   */
33  public class TckBindingTemplate 
34  {
35  	final static String JOE_BINDING_XML               = "uddi_data_v2/joepublisher/bindingTemplate.xml";
36      final static String JOE_BINDING_KEY               = "afc4954d-3f0e-4e33-a1c2-30bd6bb04175";
37    
38  	private Log logger = LogFactory.getLog(this.getClass());
39  	private Publish publication = null;
40      private Inquire inquiry = null;
41  	
42  	public TckBindingTemplate(Publish publication, 
43  				  Inquire inquiry) {
44  		super();
45  		this.publication = publication;
46  		this.inquiry = inquiry;
47  	}
48  
49  	public void saveJoePublisherBinding(String authInfoJoe) {
50  		saveBinding(authInfoJoe, JOE_BINDING_XML, JOE_BINDING_KEY);
51  	}
52  	
53  	public void deleteJoePublisherBinding(String authInfoJoe) {
54  		deleteBinding(authInfoJoe, JOE_BINDING_KEY);
55  	}
56  	
57  	public void saveBinding(String authInfo, String bindingXML, String bindingKey) {
58  		try {
59  			// First save the entity
60  			SaveBinding sb = new SaveBinding();
61  			sb.setAuthInfo(authInfo);
62                 sb.setGeneric("2.0");
63  			
64  			BindingTemplate btIn = (BindingTemplate)EntityCreator.buildFromDoc(bindingXML, "org.uddi.api_v2");
65  			sb.getBindingTemplate().add(btIn);
66  			publication.saveBinding(sb);
67  			
68  			// Now get the entity and check the values
69  			GetBindingDetail gb = new GetBindingDetail();
70                 gb.setGeneric("2.0");
71  			gb.getBindingKey().add(bindingKey);
72  			BindingDetail bd = inquiry.getBindingDetail(gb);
73  			List<BindingTemplate> btOutList = bd.getBindingTemplate();
74  			BindingTemplate btOut = btOutList.get(0);
75  
76  			assertEquals(btIn.getServiceKey(), btOut.getServiceKey());
77  			assertEquals(btIn.getBindingKey(), btOut.getBindingKey());
78  			
79  			TckValidator.checkDescriptions(btIn.getDescription(), btOut.getDescription());
80  
81  		}
82  		catch(Exception e) {
83  			logger.error(e.getMessage(), e);
84  			Assert.fail("No exception should be thrown: " + e.getMessage());
85  		}
86  		
87  	}
88  	
89  	public void deleteBinding(String authInfo, String bindingKey) {
90  		try {
91  			// Delete the entity and make sure it is removed
92  			DeleteBinding db = new DeleteBinding();
93  			db.setAuthInfo(authInfo);
94  			db.setGeneric("2.0");
95  			db.getBindingKey().add(bindingKey);
96  			publication.deleteBinding(db);
97  		}
98  		catch(Exception e) {
99  			logger.error(e.getMessage(), e);
100 			Assert.fail("No exception should be thrown.");
101 		}
102 		
103 	}
104 }