This project has retired. For details please refer to its Attic page.
WSDL2UDDITest 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.v3.client.mapping.wsdl;
16  
17  import java.util.HashSet;
18  import java.util.Map;
19  import java.util.Properties;
20  import java.util.Set;
21  import java.util.logging.Level;
22  import java.util.logging.Logger;
23  
24  import javax.wsdl.Binding;
25  import javax.wsdl.Definition;
26  import javax.wsdl.PortType;
27  import javax.wsdl.WSDLException;
28  import javax.xml.bind.JAXBException;
29  import javax.xml.namespace.QName;
30  
31  import org.apache.commons.configuration.ConfigurationException;
32  import org.apache.juddi.jaxb.PrintUDDI;
33  import org.apache.juddi.v3.client.mapping.URLLocalizerDefaultImpl;
34  import org.apache.juddi.v3.client.mapping.wsdl.ReadWSDL;
35  import org.apache.juddi.v3.client.mapping.wsdl.WSDL2UDDI;
36  import org.junit.Assert;
37  import org.junit.Test;
38  import org.uddi.api_v3.TModel;
39  
40  /**
41   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
42   */
43  public class WSDL2UDDITest {
44  
45  	PrintUDDI<TModel> pTModel = new PrintUDDI<TModel>();
46  	ReadWSDL rw = new ReadWSDL();
47  	
48          static boolean serialize = false;
49  
50      public WSDL2UDDITest() {
51          if (System.getProperty("debug") != null && System.getProperty("debug").equalsIgnoreCase("true")) {
52              serialize = true;
53          }
54      }
55      
56          @Test
57          public void Nulltest1()
58          {
59              try {
60                  WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, null, new Properties());
61              } catch (ConfigurationException ex) {
62                  Logger.getLogger(WSDL2UDDITest.class.getName()).log(Level.SEVERE, null, ex);
63              }
64          }
65          @Test(expected = IllegalArgumentException.class)
66          public void Nulltest2()
67          {
68              try {
69                  WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), null);
70              } catch (ConfigurationException ex) {
71                  
72              }
73              
74          }
75  	@Test
76  	public void testUDDIBindingModel() throws WSDLException, JAXBException, ConfigurationException , Exception{
77  
78  		// Reading the WSDL
79  		Definition wsdlDefinition = rw.readWSDL("wsdl/HelloWorld.wsdl");
80  		String wsdlURL = wsdlDefinition.getDocumentBaseURI();
81  		
82  		Properties properties = new Properties();
83  		properties.put("keyDomain", "juddi.apache.org");
84  		WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
85  		Set<TModel> tModels = new HashSet<TModel>();
86  	    @SuppressWarnings("unchecked")
87  		Map<QName,PortType> portTypes = (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
88  	    Set<TModel> portTypeTModels = wsdl2UDDI.createWSDLPortTypeTModels(wsdlURL, portTypes);
89  	    tModels.addAll(portTypeTModels);
90  	    
91  		for (TModel tModel : tModels) {
92  			System.out.println("UDDI PortType TModel " + tModel.getName().getValue());
93                          if (serialize)
94  			System.out.println(pTModel.print(tModel));
95  		}
96  		Assert.assertEquals(1,tModels.size());
97  	}
98  	
99  	@Test
100 	public void testWSDLBindingModel() throws WSDLException, JAXBException, ConfigurationException, Exception {
101 
102 		// Reading the WSDL
103 		Definition wsdlDefinition = rw.readWSDL("wsdl/HelloWorld.wsdl");
104 		String wsdlURL = wsdlDefinition.getDocumentBaseURI();
105 		
106 		Properties properties = new Properties();
107 		properties.put("keyDomain", "juddi.apache.org");
108 		WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
109 		Set<TModel> tModels = new HashSet<TModel>();
110 	    @SuppressWarnings("unchecked")
111 		Map<QName,Binding> bindings= (Map<QName,Binding>) wsdlDefinition.getAllBindings();
112 	    Set<TModel> bindingTModels = wsdl2UDDI.createWSDLBindingTModels(wsdlURL, bindings);
113 	    tModels.addAll(bindingTModels);
114 	    
115 		for (TModel tModel : tModels) {
116 			System.out.println("UDDI Binding TModel " + tModel.getName().getValue());
117                         if (serialize)
118 			System.out.println(pTModel.print(tModel));
119 		}
120 		Assert.assertEquals(1,tModels.size());
121 	}
122 	
123 }