This project has retired. For details please refer to its Attic page.
TckPublisherAssertion 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.AddPublisherAssertions;
26  import org.uddi.api_v2.DeletePublisherAssertions;
27  import org.uddi.api_v2.GetPublisherAssertions;
28  import org.uddi.api_v2.KeyedReference;
29  import org.uddi.api_v2.PublisherAssertion;
30  import org.uddi.api_v2.PublisherAssertions;
31  import org.uddi.v2_service.Publish;
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   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
36   */
37  public class TckPublisherAssertion 
38  {
39  	final static String JOE_ASSERT_XML    = "uddi_data_v2/joepublisher/publisherAssertion.xml";
40  	final static String MARY_ASSERT_XML    = "uddi_data_v2/marypublisher/publisherAssertion.xml";
41  	final static String JOE_ASSERT2_XML    = "uddi_data_v2/joepublisher/publisherAssertion2.xml";
42  	final static String SAM_ASSERT_XML    = "uddi_data_v2/samsyndicator/publisherAssertion.xml";
43  	
44  	private Log logger = LogFactory.getLog(this.getClass());
45  	private Publish publication = null;
46   
47  	public TckPublisherAssertion(Publish publication) {
48  		super();
49  		this.publication = publication;
50  	}
51  	
52  	public void saveJoePublisherPublisherAssertion(String authInfoJoe) {
53  		addPublisherAssertion(authInfoJoe, JOE_ASSERT_XML);
54  	}
55  	
56  	public void saveSamPublisherPublisherAssertion(String authInfoSam) {
57  		addPublisherAssertion(authInfoSam, SAM_ASSERT_XML);
58  	}
59  	
60  	public void saveMaryPublisherPublisherAssertion(String authInfoMary) {
61  		addPublisherAssertion(authInfoMary, MARY_ASSERT_XML);
62  	}
63  	
64  	public void saveJoePublisherPublisherAssertion2(String authInfoJoe) {
65  		addPublisherAssertion(authInfoJoe, JOE_ASSERT2_XML);
66  	}
67  	
68  	public void deleteJoePublisherPublisherAssertion(String authInfoJoe) {
69  		deletePublisherAssertion(authInfoJoe, JOE_ASSERT_XML);
70  	}
71  	
72  	public void deleteMaryPublisherPublisherAssertion(String authInfoMary) {
73  		deletePublisherAssertion(authInfoMary, MARY_ASSERT_XML);
74  	}
75  	
76  	public void deleteSamPublisherPublisherAssertion(String authInfoSam) {
77  		deletePublisherAssertion(authInfoSam, SAM_ASSERT_XML);
78  	}
79  	
80  	public void deleteJoePublisherPublisherAssertion2(String authInfoJoe) {
81  		deletePublisherAssertion(authInfoJoe, JOE_ASSERT2_XML);
82  	}
83  
84  	
85  	public void addPublisherAssertion(String authInfo, String pubassertXML) {
86  		try {
87  			AddPublisherAssertions ap = new AddPublisherAssertions();
88  			ap.setAuthInfo(authInfo);
89                 ap.setGeneric("2.0");
90  			PublisherAssertion paIn = (PublisherAssertion)EntityCreator.buildFromDoc(pubassertXML, "org.uddi.api_v2");
91  			ap.getPublisherAssertion().add(paIn);
92  			publication.addPublisherAssertions(ap);
93  	
94                 GetPublisherAssertions body = new GetPublisherAssertions();
95                 body.setAuthInfo(authInfo);
96                 body.setGeneric("2.0");
97                 // Now get the entity and check the values
98                 PublisherAssertions publisherAssertions = publication.getPublisherAssertions(body);
99  			List<PublisherAssertion> paOutList =publisherAssertions.getPublisherAssertion();
100 			if (paOutList.size()==1) {
101 				PublisherAssertion paOut = paOutList.get(0);
102 	
103 				assertEquals(paIn.getFromKey(), paOut.getFromKey());
104 				assertEquals(paIn.getToKey(), paOut.getToKey());
105 				
106 				KeyedReference keyRefIn = paIn.getKeyedReference();
107 				KeyedReference keyRefOut = paOut.getKeyedReference();
108 				
109 				assertEquals(keyRefIn.getTModelKey(), keyRefOut.getTModelKey());
110 				assertEquals(keyRefIn.getKeyName(), keyRefOut.getKeyName());
111 				assertEquals(keyRefIn.getKeyValue(), keyRefOut.getKeyValue());
112 			}
113 			
114 		}
115 		catch(Exception e) {
116 			logger.error(e.getMessage(), e);
117 			Assert.fail("No exception should be thrown");
118 		}
119 
120 	}
121 
122 	public void deletePublisherAssertion(String authInfo, String pubassertXML) {
123 		try {
124 			// Delete the entity and make sure it is removed
125 			DeletePublisherAssertions dp = new DeletePublisherAssertions();
126 			dp.setAuthInfo(authInfo);
127 			dp.setGeneric("2.0");
128 			PublisherAssertion paIn = (PublisherAssertion)EntityCreator.buildFromDoc(pubassertXML, "org.uddi.api_v2");
129 			dp.getPublisherAssertion().add(paIn);
130 			
131 			publication.deletePublisherAssertions(dp);
132 		}
133 		catch(Exception e) {
134 			logger.error(e.getMessage(), e);
135 			Assert.fail("No exception should be thrown");
136 		}
137 		
138 	}
139 }