1   /*
2    * Copyright ${YEAR} the original author or authors.
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.springframework.ws.wsdl.wsdl11.builder;
18  
19  import java.util.List;
20  import javax.xml.namespace.QName;
21  
22  import junit.framework.TestCase;
23  import org.springframework.core.io.ClassPathResource;
24  import org.springframework.core.io.Resource;
25  
26  public class XsdSchemaHelperTest extends TestCase {
27  
28      public void testSingle() throws Exception {
29          Resource resource = new ClassPathResource("single.xsd", getClass());
30          XsdSchemaHelper helper = new XsdSchemaHelper(resource);
31          assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/single/schema",
32                  helper.getTargetNamespace());
33          List elementDeclarations = helper.getElementDeclarations(true);
34          assertEquals("Invalid amount of elements", 3, elementDeclarations.size());
35          assertEquals("Invalid element declaration name",
36                  new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderRequest"),
37                  elementDeclarations.get(0));
38          assertEquals("Invalid element declaration name",
39                  new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderResponse"),
40                  elementDeclarations.get(1));
41          assertEquals("Invalid element declaration name",
42                  new QName("http://www.springframework.org/spring-ws/single/schema", "GetOrderFault"),
43                  elementDeclarations.get(2));
44      }
45  
46      public void testFollowInclude() throws Exception {
47          Resource resource = new ClassPathResource("including.xsd", getClass());
48          XsdSchemaHelper helper = new XsdSchemaHelper(resource);
49          assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include/schema",
50                  helper.getTargetNamespace());
51          List elementDeclarations = helper.getElementDeclarations(true);
52          assertEquals("Invalid amount of elements", 2, elementDeclarations.size());
53          assertEquals("Invalid element declaration name",
54                  new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderResponse"),
55                  elementDeclarations.get(0));
56          assertEquals("Invalid element declaration name",
57                  new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderRequest"),
58                  elementDeclarations.get(1));
59      }
60  
61      public void testNotFollowInclude() throws Exception {
62          Resource resource = new ClassPathResource("including.xsd", getClass());
63          XsdSchemaHelper helper = new XsdSchemaHelper(resource);
64          assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/include/schema",
65                  helper.getTargetNamespace());
66          List elementDeclarations = helper.getElementDeclarations(false);
67          assertEquals("Invalid amount of elements", 1, elementDeclarations.size());
68          assertEquals("Invalid element declaration name",
69                  new QName("http://www.springframework.org/spring-ws/include/schema", "GetOrderRequest"),
70                  elementDeclarations.get(0));
71      }
72  
73      public void testFollowImport() throws Exception {
74          Resource resource = new ClassPathResource("importing.xsd", getClass());
75          XsdSchemaHelper helper = new XsdSchemaHelper(resource);
76          assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing/schema",
77                  helper.getTargetNamespace());
78          List elementDeclarations = helper.getElementDeclarations(true);
79          assertEquals("Invalid amount of elements", 2, elementDeclarations.size());
80          assertEquals("Invalid element declaration name",
81                  new QName("http://www.springframework.org/spring-ws/imported/schema", "GetOrderResponse"),
82                  elementDeclarations.get(0));
83          assertEquals("Invalid element declaration name",
84                  new QName("http://www.springframework.org/spring-ws/importing/schema", "GetOrderRequest"),
85                  elementDeclarations.get(1));
86      }
87  
88      public void testNotFollowImport() throws Exception {
89          Resource resource = new ClassPathResource("importing.xsd", getClass());
90          XsdSchemaHelper helper = new XsdSchemaHelper(resource);
91          assertEquals("Invalid target namespace", "http://www.springframework.org/spring-ws/importing/schema",
92                  helper.getTargetNamespace());
93          List elementDeclarations = helper.getElementDeclarations(false);
94          assertEquals("Invalid amount of elements", 1, elementDeclarations.size());
95          assertEquals("Invalid element declaration name",
96                  new QName("http://www.springframework.org/spring-ws/importing/schema", "GetOrderRequest"),
97                  elementDeclarations.get(0));
98      }
99  }