1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12   
13  package com.eviware.soapui.impl.wsdl.support;
14  
15  import java.io.File;
16  import java.util.Map;
17  
18  import javax.xml.namespace.QName;
19  
20  import org.apache.xmlbeans.SchemaTypeLoader;
21  import org.apache.xmlbeans.XmlObject;
22  
23  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
24  import com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader;
25  import com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils;
26  import com.eviware.soapui.support.TestCaseWithJetty;
27  
28  public class SchemaUtilsTestCase extends TestCaseWithJetty
29  {
30  	public void testFileImport() throws Exception
31     {
32     	File file = new File( "src//test-resources//test1//TestService.wsdl" );
33     	validate( file.toURL().toString(), 3 );
34     }
35  
36     public void testHttpImport() throws Exception
37     {
38     	validate("http://localhost:8082/test1/TestService.wsdl", 3);
39     	validate( new File( "src//test-resources//test1//TestService.wsdl" ).toURL().toString(), 3);
40     }
41  
42     public void testHttpImport2() throws Exception
43     {
44     	validate("http://localhost:8082/test2/TestService.wsdl", 3);   
45     	validate( new File( "src//test-resources//test2//TestService.wsdl" ).toURL().toString(), 3);
46     }
47     
48     public void testHttpImport3() throws Exception
49     {
50     	validate("http://localhost:8082/test3/TestService.wsdl", 3);  
51     	validate( new File( "src//test-resources//test3//TestService.wsdl" ).toURL().toString(), 3);
52     }
53     
54     public void testHttpImport4() throws Exception
55     {
56     	validate("http://localhost:8082/test4/TestService.wsdl", 3);  
57     	validate( new File( "src//test-resources//test4//TestService.wsdl" ).toURL().toString(), 3);
58     }
59     
60     public void testHttpImport5() throws Exception
61     {
62     	validate("http://localhost:8082/test5/TestService.wsdl", 4);  
63     	validate( new File( "src//test-resources//test5//TestService.wsdl" ).toURL().toString(), 4);
64     }
65     
66     public void testHttpImport6() throws Exception
67     {
68     	SchemaTypeLoader schemaTypes = validate("http://localhost:8082/test6/TestService.wsdl", 4);  
69     	assertNotNull( schemaTypes.findType(  new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
70  
71     	schemaTypes = validate( new File( "src//test-resources//test6//TestService.wsdl" ).toURL().toString(), 4);
72     	assertNotNull( schemaTypes.findType(  new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
73     }
74     
75     public void testHttpImport7() throws Exception
76     {
77     	SchemaTypeLoader schemaTypes = validate("http://localhost:8082/test7/TestService.wsdl", 4);  
78     	assertNotNull( schemaTypes.findType(  new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
79  
80     	schemaTypes = validate( new File( "src//test-resources//test7//TestService.wsdl" ).toURL().toString(), 4);
81     	assertNotNull( schemaTypes.findType(  new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
82     }
83     
84     public void testHttpImport8() throws Exception
85     {
86     	SchemaTypeLoader schemaTypes = validate("http://localhost:8082/test8/TestService.wsdl", 4);  
87     	assertNotNull( schemaTypes.findType(  new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
88  
89     	schemaTypes = validate( new File( "src//test-resources//test8//TestService.wsdl" ).toURL().toString(), 4);
90     	assertNotNull( schemaTypes.findType(  new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
91  }
92     
93  	private SchemaTypeLoader validate( String url, int cnt ) throws Exception
94  	{
95  		SchemaTypeLoader schemaTypes = SchemaUtils.loadSchemaTypes( url, SoapVersion.Soap11, new UrlWsdlLoader( url ) );
96     	Map<String, XmlObject> definitionUrls = SchemaUtils.getDefinitionParts( new UrlWsdlLoader( url ) );
97  		
98     	assertNotNull( schemaTypes );
99     	assertNotNull( definitionUrls );
100    	assertEquals( cnt, definitionUrls.size() );
101    	
102    	assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v1/", "PageReference")));
103    	
104    	return schemaTypes;
105 	}
106 
107 }