1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.support;
14
15 import com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader;
16 import com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils;
17 import com.eviware.soapui.support.TestCaseWithJetty;
18 import org.apache.xmlbeans.SchemaTypeLoader;
19 import org.apache.xmlbeans.XmlObject;
20
21 import javax.xml.namespace.QName;
22 import java.io.File;
23 import java.util.Map;
24
25 public class SchemaUtilsTestCase extends TestCaseWithJetty
26 {
27 public void testFileImport() throws Exception
28 {
29 File file = new File( "src//test-resources//test1//TestService.wsdl" );
30 validate( file.toURL().toString(), 3 );
31 }
32
33 public void testHttpImport() throws Exception
34 {
35 validate("http://localhost:8082/test1/TestService.wsdl", 3);
36 validate( new File( "src//test-resources//test1//TestService.wsdl" ).toURL().toString(), 3);
37 }
38
39 public void testHttpImport2() throws Exception
40 {
41 validate("http://localhost:8082/test2/TestService.wsdl", 3);
42 validate( new File( "src//test-resources//test2//TestService.wsdl" ).toURL().toString(), 3);
43 }
44
45 public void testHttpImport3() throws Exception
46 {
47 validate("http://localhost:8082/test3/TestService.wsdl", 3);
48 validate( new File( "src//test-resources//test3//TestService.wsdl" ).toURL().toString(), 3);
49 }
50
51 public void testHttpImport4() throws Exception
52 {
53 validate("http://localhost:8082/test4/TestService.wsdl", 3);
54 validate( new File( "src//test-resources//test4//TestService.wsdl" ).toURL().toString(), 3);
55 }
56
57 public void testHttpImport5() throws Exception
58 {
59 validate("http://localhost:8082/test5/TestService.wsdl", 4);
60 validate( new File( "src//test-resources//test5//TestService.wsdl" ).toURL().toString(), 4);
61 }
62
63 public void testHttpImport6() throws Exception
64 {
65 SchemaTypeLoader schemaTypes = validate("http://localhost:8082/test6/TestService.wsdl", 4);
66 assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
67
68 schemaTypes = validate( new File( "src//test-resources//test6//TestService.wsdl" ).toURL().toString(), 4);
69 assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
70 }
71
72 public void testHttpImport7() throws Exception
73 {
74 SchemaTypeLoader schemaTypes = validate("http://localhost:8082/test7/TestService.wsdl", 4);
75 assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
76
77 schemaTypes = validate( new File( "src//test-resources//test7//TestService.wsdl" ).toURL().toString(), 4);
78 assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
79 }
80
81 public void testHttpImport8() throws Exception
82 {
83 SchemaTypeLoader schemaTypes = validate("http://localhost:8082/test8/TestService.wsdl", 4);
84 assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
85
86 schemaTypes = validate( new File( "src//test-resources//test8//TestService.wsdl" ).toURL().toString(), 4);
87 assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v2/", "TestType")));
88 }
89
90 public void testHttpImport9() throws Exception
91 {
92 String url = "http://localhost:8082/test9/testcase.wsdl";
93 SchemaTypeLoader schemaTypes = SchemaUtils.loadSchemaTypes( url, new UrlWsdlLoader( url ));
94 assertNotNull( schemaTypes.findElement( new QName( "http://testcase/wsdl", "One")));
95 assertNotNull( schemaTypes.findElement( new QName( "http://testcase/wsdl", "Two")));
96 assertNotNull( schemaTypes.findType( new QName( "http://testcase/one", "OneType")));
97 assertNotNull( schemaTypes.findType( new QName( "http://testcase/two", "TwoType")));
98
99 url = new File( "src//test-resources//test9//testcase.wsdl" ).toURI().toURL().toString();
100 schemaTypes = SchemaUtils.loadSchemaTypes( url, new UrlWsdlLoader( url ));
101 assertNotNull( schemaTypes.findElement( new QName( "http://testcase/wsdl", "One")));
102 assertNotNull( schemaTypes.findElement( new QName( "http://testcase/wsdl", "Two")));
103 }
104
105 private SchemaTypeLoader validate( String url, int cnt ) throws Exception
106 {
107 SchemaTypeLoader schemaTypes = SchemaUtils.loadSchemaTypes( url, new UrlWsdlLoader( url ) );
108 Map<String, XmlObject> definitionUrls = SchemaUtils.getDefinitionParts( new UrlWsdlLoader( url ) );
109
110 assertNotNull( schemaTypes );
111 assertNotNull( definitionUrls );
112 assertEquals( cnt, definitionUrls.size() );
113
114 assertNotNull( schemaTypes.findType( new QName( "http://schemas.eviware.com/TestService/v1/", "PageReference")));
115
116 return schemaTypes;
117 }
118
119 public void testWadlImport() throws Exception
120 {
121 String file = new File("src//test-resources//wadl//YahooSearch.wadl").toURI().toURL().toString();
122 SchemaTypeLoader types = SchemaUtils.loadSchemaTypes(file, new UrlSchemaLoader( file ));
123
124 assertNotNull( types.findElement( new QName( "urn:yahoo:yn", "ResultSet")));
125 assertNotNull( types.findElement( new QName( "urn:yahoo:api", "Error")));
126 }
127
128 }