All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juddi.v3.tck.TckBusinessService Maven / Gradle / Ivy

There is a newer version: 3.3.10
Show newest version
/*
 * Copyright 2001-2009 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.juddi.v3.tck;

import static junit.framework.Assert.assertEquals;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.jaxb.EntityCreator;
import org.junit.Assert;
import org.uddi.api_v3.BindingTemplate;
import org.uddi.api_v3.BusinessService;
import org.uddi.api_v3.DeleteService;
import org.uddi.api_v3.GetServiceDetail;
import org.uddi.api_v3.SaveService;
import org.uddi.api_v3.ServiceDetail;
import org.uddi.v3_service.UDDIInquiryPortType;
import org.uddi.v3_service.UDDIPublicationPortType;
/**
 * @author Kurt T Stam
 * @author Jeff Faath
 */
public class TckBusinessService 
{
	
    public final static String NOTIFIER_SERVICE_XML = "uddi_data/subscriptionnotifier/businessService.xml";
    public final static String NOTIFIER_SERVICE_KEY = "uddi:uddi.joepublisher.com:notifierone";
    public final static String JOE_SERVICE_XML = "uddi_data/joepublisher/businessService.xml";
    public final static String JOE_SERVICE_KEY = "uddi:uddi.joepublisher.com:serviceone";
    public final static String JOE_SERVICE_XML_2 = "uddi_data/joepublisher/businessService2.xml";
    public final static String JOE_SERVICE_KEY_2 = "uddi:uddi.joepublisher.com:servicetwo";
    public final static String SAM_SERVICE_XML = "uddi_data/samsyndicator/businessService.xml";
    public final static String SAM_SERVICE_KEY = "uddi:www.samco.com:listingservice";
    public final static String SAM_SERVICE_BINDING_KEY="uddi:www.samco.com:listservice-accesspoint";
    public final static String RIFTSAW_PROCESS_XML = "uddi_data/bpel/riftsaw/WSDLPort.xml";
    public final static String RIFTSAW_PROCESS_KEY = "uddi:riftsaw.jboss.org:ticket-service";
    public final static String JOE_BINDING_KEY_1="uddi:uddi.joepublisher.com:bindingone";
    private Log logger = LogFactory.getLog(this.getClass());
    private UDDIPublicationPortType publication = null;
    private UDDIInquiryPortType inquiry = null;
	
	public TckBusinessService(UDDIPublicationPortType publication, 
				  UDDIInquiryPortType inquiry) {
		super();
		this.publication = publication;
		this.inquiry = inquiry;
	}

	public String saveJoePublisherService(String authInfoJoe) {
		return saveService(authInfoJoe, JOE_SERVICE_XML, JOE_SERVICE_KEY);
	}
	
	public void updateJoePublisherService(String authInfoJoe, String description) {
		saveService(authInfoJoe, JOE_SERVICE_XML, JOE_SERVICE_KEY, description);
	}
	
	public void saveJoePublisherService2(String authInfoJoe) {
		saveService2(authInfoJoe, JOE_SERVICE_KEY, JOE_SERVICE_XML_2, JOE_SERVICE_KEY_2);
	}

	public void saveJoePublisherServices(String authInfoJoe, int businessInt, int numberOfCopies) {
		saveServices(authInfoJoe, businessInt, JOE_SERVICE_XML, JOE_SERVICE_KEY, numberOfCopies, TckBusiness.JOE_BUSINESS_KEY);
	}
	
	public void deleteJoePublisherService(String authInfoJoe) {
		deleteService(authInfoJoe, JOE_SERVICE_KEY);
	}
	
	public void deleteJoePublisherService2(String authInfoJoe) {
		deleteService(authInfoJoe, JOE_SERVICE_KEY_2);
	}

	public void saveNotifierService(String authInfoJoe) {
		saveService(authInfoJoe, NOTIFIER_SERVICE_XML, NOTIFIER_SERVICE_KEY);
	}
	
	public void deleteNotifierService(String authInfoJoe) {
		deleteService(authInfoJoe, NOTIFIER_SERVICE_KEY);
	}

	
	public void deleteJoePublisherServices(String authInfoJoe, int businessInt, int numberOfCopies) {
		deleteServices(authInfoJoe, businessInt,JOE_SERVICE_KEY, numberOfCopies);
	}
	
	public void saveSamSyndicatorService(String authInfoSam) {
		saveService(authInfoSam, SAM_SERVICE_XML, SAM_SERVICE_KEY);
	}
	
	public void saveSamSyndicatorServices(String authInfoSam, int businessInt, int numberOfCopies) {
		saveServices(authInfoSam, businessInt, SAM_SERVICE_XML, SAM_SERVICE_KEY, numberOfCopies, TckBusiness.SAM_BUSINESS_KEY);
	}
	
	public void deleteSamSyndicatorService(String authInfoSam) {
		deleteService(authInfoSam, SAM_SERVICE_KEY);
	}
	
	public void deleteSamSyndicatorServices(String authInfoSam, int businessInt, int numberOfCopies) {
		deleteServices(authInfoSam, businessInt, SAM_SERVICE_KEY, numberOfCopies);
	}
	
	public void saveServices(String authInfo, int businessInt, String serviceXML, String serviceKey, int numberOfCopies, String parentBusinessKey) {
		SaveService ss = null;
		try {
			org.uddi.api_v3.BusinessService bsIn = (org.uddi.api_v3.BusinessService)EntityCreator.buildFromDoc(serviceXML, "org.uddi.api_v3");
			String serviceName = bsIn.getName().get(0).getValue();
			String bindingKey = bsIn.getBindingTemplates().getBindingTemplate().get(0).getBindingKey();
			for (int i=0; i bsOutList = sd.getBusinessService();
			BusinessService bsOut = bsOutList.get(0);

			assertEquals(bsIn.getServiceKey().toLowerCase(), bsOut.getServiceKey());
			
			TckValidator.checkNames(bsIn.getName(), bsOut.getName());
			TckValidator.checkDescriptions(bsIn.getDescription(), bsOut.getDescription());
			TckValidator.checkBindingTemplates(bsIn.getBindingTemplates(), bsOut.getBindingTemplates());
			TckValidator.checkCategories(bsIn.getCategoryBag(), bsOut.getCategoryBag());
                        if (bsOut.getBindingTemplates()!=null && !bsOut.getBindingTemplates().getBindingTemplate().isEmpty())
                            return bsOut.getBindingTemplates().getBindingTemplate().get(0).getBindingKey();
		}
		catch(Exception e) {
			logger.error(e.getMessage(), e);
			Assert.fail("No exception should be thrown.");
		}
		return null;
	}
	
	public void saveService2(String authInfo, String serviceKey, String serviceXML2,  String serviceKey2) {
		try {
			// First save the entity
			SaveService ss = new SaveService();
			ss.setAuthInfo(authInfo);
			
			org.uddi.api_v3.BusinessService bsIn = (org.uddi.api_v3.BusinessService)EntityCreator.buildFromDoc(serviceXML2, "org.uddi.api_v3");
			ss.getBusinessService().add(bsIn);
			publication.saveService(ss);
			
			// Now get the entity and check the values
			GetServiceDetail gs = new GetServiceDetail();
			gs.getServiceKey().add(serviceKey);
			gs.getServiceKey().add(serviceKey2);
			ServiceDetail sd = inquiry.getServiceDetail(gs);
			List bsOutList = sd.getBusinessService();
			int size = bsOutList.size();

			assertEquals(2, size);
			
			
		}
		catch(Exception e) {
			logger.error(e.getMessage(), e);
			Assert.fail("No exception should be thrown.");
		}
		
	}
	
	public void deleteService(String authInfo, String serviceKey) {
		try {
			// Delete the entity and make sure it is removed
			DeleteService ds = new DeleteService();
			ds.setAuthInfo(authInfo);
			
			ds.getServiceKey().add(serviceKey);
			publication.deleteService(ds);
		}
		catch(Exception e) {
			logger.error(e.getMessage(), e);
			Assert.fail("No exception should be thrown.");
		}
	}
	
	public void deleteServices(String authInfo, int businessInt, String serviceKey, int numberOfCopies) {
		try {
			for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy