This project has retired. For details please refer to its Attic page.
MapUDDI23Test xref
View Javadoc
1   /*
2    * Copyright 2014 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    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.juddi.v3.client.mapping;
18  
19  import java.io.StringWriter;
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.List;
23  import javax.xml.bind.JAXB;
24  import org.apache.juddi.api_v3.AccessPointType;
25  import org.junit.Assert;
26  import org.junit.Ignore;
27  import org.junit.Test;
28  import org.uddi.api_v3.AccessPoint;
29  import org.uddi.api_v3.Address;
30  import org.uddi.api_v3.AddressLine;
31  import org.uddi.api_v3.BindingTemplate;
32  import org.uddi.api_v3.BindingTemplates;
33  import org.uddi.api_v3.BusinessEntity;
34  import org.uddi.api_v3.BusinessService;
35  import org.uddi.api_v3.BusinessServices;
36  import org.uddi.api_v3.CategoryBag;
37  import org.uddi.api_v3.Contact;
38  import org.uddi.api_v3.Contacts;
39  import org.uddi.api_v3.Description;
40  import org.uddi.api_v3.DiscoveryURL;
41  import org.uddi.api_v3.DiscoveryURLs;
42  import org.uddi.api_v3.Email;
43  import org.uddi.api_v3.IdentifierBag;
44  import org.uddi.api_v3.InstanceDetails;
45  import org.uddi.api_v3.KeyedReference;
46  import org.uddi.api_v3.Name;
47  import org.uddi.api_v3.OverviewDoc;
48  import org.uddi.api_v3.OverviewURL;
49  import org.uddi.api_v3.PersonName;
50  import org.uddi.api_v3.TModelInstanceDetails;
51  import org.uddi.api_v3.TModelInstanceInfo;
52  
53  /**
54   *
55   * @author Alex O'Ree
56   */
57  public class MapUDDI23Test {
58  
59          static final String domainprefix="uddi:businessdomain:";
60          static BusinessEntity getBus(){
61                  BusinessEntity be = new BusinessEntity();
62                  be.setBusinessKey(domainprefix+"businesskey");
63                  be.setBusinessServices(getServices());
64                  be.setCategoryBag(getCatbag());
65                  be.setContacts(getContacts());
66                  be.setDiscoveryURLs(getDisco());
67                  be.setIdentifierBag(getIdentbag());
68                  be.getDescription().addAll(getDescriptions());
69                  be.getName().addAll(getNames());
70                  return be;
71          }
72  
73          private static BusinessServices getServices() {
74                  BusinessServices r = new BusinessServices();
75                  BusinessService x = new BusinessService();
76                  x.setBusinessKey(domainprefix+"businesskey");
77                  x.setServiceKey(domainprefix+"servicekey");
78                  x.setCategoryBag(getCatbag());
79                  x.getDescription().addAll(getDescriptions());
80                  x.getName().addAll(getNames());
81                  x.setBindingTemplates(getBindingTemplates());
82                  r.getBusinessService().add(x);
83                  return r;
84          }
85  
86          private static CategoryBag getCatbag() {
87                  
88                  CategoryBag c = new CategoryBag();
89                  c.getKeyedReference().add(new KeyedReference(domainprefix+"key", "name", "value"));
90                  return c;
91          }
92  
93          private static Contacts getContacts() {
94                  Contacts c = new Contacts();
95                  Contact admin = new Contact();
96                  admin.setUseType("it support");
97                  admin.getEmail().add(new Email("admin@localhost", "primary"));
98                  admin.getDescription().add(new Description("the guy in that keeps the lights green", "en"));
99                  admin.getPersonName().add(new PersonName("admin1", "en"));
100                 Address r=new Address();
101                 r.setLang("en");
102                 r.setSortCode("none");
103                 r.setTModelKey(domainprefix + "address");
104                 r.setUseType("mailing address");
105                 r.getAddressLine().add(new AddressLine("keyname","keyval","1313 mockingbird lane"));
106                 admin.getAddress().add(r);
107                 c.getContact().add(admin);
108                 return c;
109                 
110         }
111 
112         private static DiscoveryURLs getDisco() {
113                 DiscoveryURLs r = new DiscoveryURLs();
114                 r.getDiscoveryURL().add(new DiscoveryURL("public website", "http://localhost"));
115                 return r;
116                 
117         }
118 
119         private static IdentifierBag getIdentbag() {
120                 IdentifierBag ret = new IdentifierBag();
121                 ret.getKeyedReference().add(new KeyedReference(domainprefix + "key", "keyname", "keyval"));
122                 return ret;
123         }
124 
125         private static Collection<? extends Description> getDescriptions() {
126                 
127                 List<Description> r = new ArrayList<Description>();
128                 r.add(new Description("description", "en"));
129                 return r;
130         }
131 
132         private static Collection<? extends Name> getNames() {
133                 List<Name> r = new ArrayList<Name>();
134                 r.add(new Name("name1", "en"));
135                 return r;
136         }
137 
138         private static BindingTemplates getBindingTemplates() {
139                 BindingTemplates bt = new BindingTemplates();
140                 BindingTemplate t = new BindingTemplate();
141                 t.setAccessPoint(new AccessPoint("http://localhost", AccessPointType.END_POINT.toString()));
142                 t.setBindingKey(domainprefix+"binding");
143 //                t.setCategoryBag(getCatbag());
144                 t.getDescription().addAll(getDescriptions());
145                 t.setHostingRedirector(null);
146                 t.setServiceKey(domainprefix+"servicekey");
147                 
148                 t.setTModelInstanceDetails(getTID());
149                 
150                 bt.getBindingTemplate().add(t);
151                 return bt;
152         }
153 
154         private static TModelInstanceDetails getTID() {
155                 TModelInstanceDetails r = new TModelInstanceDetails();
156                 TModelInstanceInfo x = new TModelInstanceInfo();
157                 x.getDescription().addAll(getDescriptions());
158                 x.setTModelKey(domainprefix+"tid");
159                 x.setInstanceDetails(new InstanceDetails());
160                 x.getInstanceDetails().getDescription().addAll(getDescriptions());
161                 x.getInstanceDetails().setInstanceParms("asdasdasdasdasd");
162                 OverviewDoc o = new OverviewDoc();
163   //              o.getDescription().addAll(getDescriptions());
164                 o.setOverviewURL(new OverviewURL("http://localhost", "overview"));
165                 x.getInstanceDetails().getOverviewDoc().add(o);
166                 r.getTModelInstanceInfo().add(x);
167                 return r;
168         }
169         
170         @Test
171         @Ignore //ignoring this for now, 100% mapping is not possible, this works as of 1-23-2014
172         public void AssertCloseEnoughBusinessUDDI3to2to3(){
173                 BusinessEntity before = getBus();
174                 BusinessEntity after =MapUDDIv2Tov3.MapBusiness(MapUDDIv3Tov2.MapBusiness(before, "node"));
175                 StringWriter sw1= new StringWriter();
176                 JAXB.marshal(before, sw1);
177                 
178                 StringWriter sw2= new StringWriter();
179                 JAXB.marshal(after, sw2);
180                 System.out.println(sw1.toString());
181                 System.out.println(sw2.toString());
182                 Assert.assertEquals("these should be the same", sw1.toString(), sw2.toString());
183                 
184         }
185 }