import org.junit.Test;
import org.apache.juddi.ClassUtil;
import org.apache.juddi.v3.client.config.UDDIClientContainer;
import org.apache.juddi.v3.client.transport.Transport;
import org.uddi.v3_service.UDDISecurityPortType;
import org.uddi.api_v3.GetAuthToken;
import org.uddi.api_v3.AuthToken;
import org.uddi.v3_service.UDDIPublicationPortType;
import org.uddi.api_v3.SaveBusiness;
import org.uddi.api_v3.BusinessEntity;
import org.uddi.api_v3.DiscoveryURLs;
import org.uddi.api_v3.DiscoveryURL;
import org.uddi.api_v3.Name;
import org.uddi.api_v3.SaveTModel;
import org.uddi.api_v3.TModel;
import org.uddi.api_v3.TModelDetail;
import org.uddi.api_v3.Description;
import org.uddi.api_v3.OverviewDoc;
import org.uddi.api_v3.OverviewURL;
import org.uddi.api_v3.TModelInstanceInfo;
import org.uddi.api_v3.TModelInstanceDetails;
import org.uddi.api_v3.BusinessService;
import org.uddi.api_v3.BusinessServices;
import org.uddi.api_v3.BindingTemplate;
import org.uddi.api_v3.BindingTemplates;
import org.uddi.api_v3.AccessPoint;
public class test3 {
@Test
public void testAuthToken()
{
try
{
String clazz = UDDIClientContainer.getDefaultTransportClass();
Class<?>transportClass=ClassUtil.forName(clazz, Transport.class);
if(transportClass!=null)
{
//获得authtoken
Transport transport=(Transport)transportClass.newInstance();
UDDISecurityPortType securityService=transport.getUDDISecurityService();
GetAuthToken getauthToken=new GetAuthToken();
getauthToken.setUserID("root");
getauthToken.setCred("root");
AuthToken authtoken=securityService.getAuthToken(getauthToken);
String authinfo=authtoken.getAuthInfo();
System.out.println(authinfo);
UDDIPublicationPortType publication = transport.getUDDIPublishService();
SaveBusiness sb = new SaveBusiness();
//添加BusinessEntity
BusinessEntity be=new BusinessEntity();
DiscoveryURLs urls=new DiscoveryURLs();
DiscoveryURL url=new DiscoveryURL();
url.setValue("
http://www.xiaozhan.com ");
urls.getDiscoveryURL().add(url);
be.setDiscoveryURLs(urls);
Name name=new Name();
name.setValue("TicketBooking");
be.getName().add(name);
//添加tModel
SaveTModel ST=new SaveTModel();
ST.setAuthInfo(authinfo);
TModel tm=new TModel();
Name n=new Name();
n.setValue("http://www.tour.com ");
tm.setName(n);
Description des=new Description();
des.setValue("Ticket");
tm.getDescription().add(des);
OverviewDoc od=new OverviewDoc();
OverviewURL ou=new OverviewURL();
ou.setValue("http://localhost:8080/axis2/services/Ticket?wsdl ");
od.setOverviewURL(ou);
tm.getOverviewDoc().add(od);
ST.getTModel().add(tm);
TModelDetail Tt=publication.saveTModel(ST);
//添加BusinessService;
BusinessServices bss=new BusinessServices();
BusinessService bs=new BusinessService();
Name na=new Name();
na.setValue("Ticket");
bs.getName().add(na);
BindingTemplate bt=new BindingTemplate();
BindingTemplates bts=new BindingTemplates();
AccessPoint ap=new AccessPoint();
ap.setUseType("http");
ap.setValue("
http://localhost:8080/axis2/services/Ticket.TicketHttpSoap11Endpoint/ ");
bt.setAccessPoint(ap);
TModelInstanceDetails TD=new TModelInstanceDetails();
TModelInstanceInfo TI=new TModelInstanceInfo();
TI.setTModelKey(Tt.getTModel().get(0).getTModelKey());
TD.getTModelInstanceInfo().add(TI);
bt.setTModelInstanceDetails(TD);
bts.getBindingTemplate().add(bt);
bs.setBindingTemplates(bts);
bss.getBusinessService().add(bs);
be.setBusinessServices(bss);
sb.setAuthInfo(authinfo);
sb.getBusinessEntity().add(be);
publication.saveBusiness(sb);
}
else
{
Assert.fail();
}
}
catch(Exception e)
{
e.printStackTrace();
Assert.fail("Could not obtain authInfo token.");
}
}
}