01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.xml.validation;
18:
19: import javax.xml.XMLConstants;
20: import javax.xml.validation.Schema;
21:
22: import junit.framework.TestCase;
23: import org.springframework.core.io.ClassPathResource;
24: import org.springframework.core.io.Resource;
25:
26: public class SchemaLoaderUtilsTest extends TestCase {
27:
28: public void testLoadSchema() throws Exception {
29: Resource resource = new ClassPathResource("schema.xsd",
30: getClass());
31: Schema schema = SchemaLoaderUtils.loadSchema(resource,
32: XMLConstants.W3C_XML_SCHEMA_NS_URI);
33: assertNotNull("No schema returned", schema);
34: assertFalse("Resource not closed", resource.isOpen());
35: }
36:
37: public void testLoadNonExistantSchema() throws Exception {
38: try {
39: Resource nonExistant = new ClassPathResource("bla");
40: SchemaLoaderUtils.loadSchema(nonExistant,
41: XMLConstants.W3C_XML_SCHEMA_NS_URI);
42: fail("Should have thrown an IllegalArgumentException");
43: } catch (IllegalArgumentException e) {
44: // expected
45: }
46: }
47:
48: public void testLoadNullSchema() throws Exception {
49: try {
50: SchemaLoaderUtils.loadSchema((Resource) null,
51: XMLConstants.W3C_XML_SCHEMA_NS_URI);
52: fail("Should have thrown an IllegalArgumentException");
53: } catch (IllegalArgumentException e) {
54: // expected
55: }
56: }
57:
58: public void testLoadMultipleSchemas() throws Exception {
59: Resource envelope = new ClassPathResource("envelope.xsd",
60: getClass());
61: Resource encoding = new ClassPathResource("encoding.xsd",
62: getClass());
63: Schema schema = SchemaLoaderUtils.loadSchema(new Resource[] {
64: envelope, encoding },
65: XMLConstants.W3C_XML_SCHEMA_NS_URI);
66: assertNotNull("No schema returned", schema);
67: assertFalse("Resource not closed", envelope.isOpen());
68: assertFalse("Resource not closed", encoding.isOpen());
69: }
70: }
|