This project has retired. For details please refer to its Attic page.
API_040_BusinessServiceTest 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.api.impl;
16  
17  import java.rmi.RemoteException;
18  
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.tck.TckBusiness;
24  import org.apache.juddi.v3.tck.TckBusinessService;
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.Test;
32  import org.uddi.v3_service.UDDISecurityPortType;
33  
34  /**
35   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
36   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
37   */
38  public class API_040_BusinessServiceTest 
39  {
40  	private static Log logger                        = LogFactory.getLog(API_040_BusinessServiceTest.class);
41  	
42  	private static API_010_PublisherTest api010      = new API_010_PublisherTest();
43  	private static TckTModel tckTModel               = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
44  	private static TckBusiness tckBusiness           = new TckBusiness(new UDDIPublicationImpl(), new UDDIInquiryImpl());
45  	private static TckBusinessService tckBusinessService  = new TckBusinessService(new UDDIPublicationImpl(), new UDDIInquiryImpl());
46  	
47  	private static String authInfoJoe                = null;
48  	private static String authInfoSam                = null;
49  	
50  	@BeforeClass
51  	public static void setup() throws ConfigurationException {
52  		Registry.start();
53                  logger.info("API_040_BusinessServiceTest");
54  		logger.debug("Getting auth tokens..");
55                  
56  		try {
57  			api010.saveJoePublisher();
58  			api010.saveSamSyndicator();
59  			UDDISecurityPortType security      = new UDDISecurityImpl();
60  			authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(),  TckPublisher.getJoePassword());
61  			authInfoSam = TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(),  TckPublisher.getSamPassword());
62  			String authInfoUDDI  = TckSecurity.getAuthToken(security, TckPublisher.getUDDIPublisherId(),  TckPublisher.getUDDIPassword());
63  			tckTModel.saveUDDIPublisherTmodel(authInfoUDDI);
64  			tckTModel.saveTModels(authInfoUDDI, TckTModel.TMODELS_XML);
65  		} catch (RemoteException e) {
66  			logger.error(e.getMessage(), e);
67  			Assert.fail("Could not obtain authInfo token.");
68  		}
69  	}
70  
71  	@AfterClass
72  	public static void stopRegistry() throws ConfigurationException {
73                  tckTModel.deleteCreatedTModels(authInfoJoe);
74  		Registry.stop();
75  	}
76  	
77  	@Test
78  	public void joepublisher() {
79  		try {
80  			tckTModel.saveJoePublisherTmodel(authInfoJoe);
81  			tckBusiness.saveJoePublisherBusiness(authInfoJoe);
82  			tckBusinessService.saveJoePublisherService(authInfoJoe);
83  			tckBusinessService.deleteJoePublisherService(authInfoJoe);
84  		} finally {
85  			tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
86  			tckTModel.deleteJoePublisherTmodel(authInfoJoe);
87  		}
88  	}
89  	
90  	@Test
91  	public void joepublisher2Services() {
92  		try {
93  			tckTModel.saveJoePublisherTmodel(authInfoJoe);
94  			tckBusiness.saveJoePublisherBusiness(authInfoJoe);
95  			tckBusinessService.saveJoePublisherService(authInfoJoe);
96  			tckBusinessService.saveJoePublisherService2(authInfoJoe);
97  			tckBusinessService.deleteJoePublisherService(authInfoJoe);
98  			tckBusinessService.deleteJoePublisherService2(authInfoJoe);
99  		} finally {
100 			tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
101 			tckTModel.deleteJoePublisherTmodel(authInfoJoe);
102 		}
103 	}
104 	
105 	@Test
106 	public void joepublisher2UpdateBusiness() {
107 		try {
108 			tckTModel.saveJoePublisherTmodel(authInfoJoe);
109 			tckBusiness.saveJoePublisherBusiness(authInfoJoe);
110 			tckBusinessService.saveJoePublisherService(authInfoJoe);
111 			tckBusinessService.saveJoePublisherService2(authInfoJoe);
112 			tckBusiness.updateJoePublisherBusiness(authInfoJoe);
113 			tckBusinessService.deleteJoePublisherService(authInfoJoe);
114 			tckBusinessService.deleteJoePublisherService2(authInfoJoe);
115 		} finally {
116 			tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
117 			tckTModel.deleteJoePublisherTmodel(authInfoJoe);
118 		}
119 	}
120 	/**
121 	 * 5.2.16.3 paragraph 4
122 	 * Data contained within businessEntity structures can be rearranged with 
123 	 * this API call. This can be done by redefining parent container relationships 
124 	 * for other registered information. For instance, if a new businessEntity 
125 	 * is saved with information about a businessService that is registered 
126 	 * already as part of a different businessEntity, this results in the 
127 	 * businessService being moved from its current container to the new businessEntity.	
128 	 * This condition occurs when the businessKey of the businessService being 
129 	 * saved matches the businessKey of the businessEntity being saved. 
130 	 * An attempt to delete or move a businessService in this manner by 
131 	 * a party who is not the publisher of the businessService MUST be 
132 	 * rejected with an error E_userMismatch.
133 	 */
134 	@Test
135 	public void joepublisherMoveBusinessService() {
136 		try {
137 			tckTModel.saveJoePublisherTmodel(authInfoJoe);
138 			tckBusiness.saveJoePublisherBusiness(authInfoJoe);
139 			tckBusinessService.saveJoePublisherService(authInfoJoe);
140 			tckBusiness.checkServicesBusinessOne(1);
141 			tckBusiness.saveJoePublisherBusiness3(authInfoJoe);
142 			//check that this business has no services
143 			tckBusiness.checkServicesBusinessThree(0);
144 			//Now move the service from one to three
145 			tckBusiness.saveJoePublisherBusiness1to3(authInfoJoe);
146 			tckBusiness.checkServicesBusinessOne(0);
147 			tckBusiness.checkServicesBusinessThree(1);
148 		} catch (Exception e) {
149 			e.printStackTrace();
150 			Assert.fail(e.getMessage());
151 		} finally {
152 			tckBusinessService.deleteJoePublisherService(authInfoJoe);
153 			tckBusiness.deleteJoePublisherBusiness3(authInfoJoe);
154 			tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
155 			tckTModel.deleteJoePublisherTmodel(authInfoJoe);
156 		}
157 	}
158 	
159 	@Test
160 	public void samsyndicator() {
161 		try {
162 			// For sam's service projection, joe's information must be loaded
163 			tckTModel.saveJoePublisherTmodel(authInfoJoe);
164 			tckBusiness.saveJoePublisherBusiness(authInfoJoe);
165 			tckBusinessService.saveJoePublisherService(authInfoJoe);
166 			
167 			tckTModel.saveSamSyndicatorTmodel(authInfoSam);
168 			tckBusiness.saveSamSyndicatorBusinessWithProjection(authInfoSam);
169 			tckBusinessService.saveSamSyndicatorService(authInfoSam);
170 			tckBusinessService.deleteSamSyndicatorService(authInfoSam);
171 		} finally {
172 			tckBusiness.deleteSamSyndicatorBusiness(authInfoSam);
173 			tckTModel.deleteSamSyndicatorTmodel(authInfoSam);
174 			
175 			tckBusinessService.deleteJoePublisherService(authInfoJoe);
176 			tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
177 			tckTModel.deleteJoePublisherTmodel(authInfoJoe);
178 		}
179 	}
180 
181 }