1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.wsdl.wsdl11.provider;
18
19 import javax.wsdl.Definition;
20 import javax.wsdl.Types;
21 import javax.wsdl.extensions.schema.Schema;
22 import javax.wsdl.factory.WSDLFactory;
23
24 import org.springframework.core.io.ClassPathResource;
25 import org.springframework.core.io.Resource;
26 import org.springframework.xml.xsd.SimpleXsdSchema;
27 import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
28
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 public class InliningXsdSchemaTypesProviderTest {
34
35 private InliningXsdSchemaTypesProvider provider;
36
37 private Definition definition;
38
39 @Before
40 public void setUp() throws Exception {
41 provider = new InliningXsdSchemaTypesProvider();
42 WSDLFactory factory = WSDLFactory.newInstance();
43 definition = factory.newDefinition();
44 }
45
46 @Test
47 public void testSingle() throws Exception {
48 String definitionNamespace = "http://springframework.org/spring-ws";
49 definition.addNamespace("tns", definitionNamespace);
50 definition.setTargetNamespace(definitionNamespace);
51 String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
52 definition.addNamespace("schema", schemaNamespace);
53
54 Resource resource = new ClassPathResource("schema.xsd", getClass());
55 SimpleXsdSchema schema = new SimpleXsdSchema(resource);
56 schema.afterPropertiesSet();
57
58 provider.setSchema(schema);
59
60 provider.addTypes(definition);
61
62 Types types = definition.getTypes();
63 Assert.assertNotNull("No types created", types);
64 Assert.assertEquals("Invalid amount of schemas", 1, types.getExtensibilityElements().size());
65
66 Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
67 Assert.assertNotNull("No element defined", wsdlSchema.getElement());
68 }
69
70 @Test
71 public void testComplex() throws Exception {
72 String definitionNamespace = "http://springframework.org/spring-ws";
73 definition.addNamespace("tns", definitionNamespace);
74 definition.setTargetNamespace(definitionNamespace);
75 String schemaNamespace = "http://www.springframework.org/spring-ws/schema";
76 definition.addNamespace("schema", schemaNamespace);
77
78 Resource resource = new ClassPathResource("A.xsd", getClass());
79 CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(new Resource[]{resource});
80 collection.setInline(true);
81 collection.afterPropertiesSet();
82
83 provider.setSchemaCollection(collection);
84
85 provider.addTypes(definition);
86
87 Types types = definition.getTypes();
88 Assert.assertNotNull("No types created", types);
89 Assert.assertEquals("Invalid amount of schemas", 2, types.getExtensibilityElements().size());
90
91 Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
92 Assert.assertNotNull("No element defined", wsdlSchema.getElement());
93
94 wsdlSchema = (Schema) types.getExtensibilityElements().get(1);
95 Assert.assertNotNull("No element defined", wsdlSchema.getElement());
96 }
97 }