1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.xml.validation;
18
19 import javax.xml.XMLConstants;
20 import javax.xml.validation.Schema;
21
22 import org.springframework.core.io.ClassPathResource;
23 import org.springframework.core.io.Resource;
24
25 import org.junit.Assert;
26 import org.junit.Test;
27
28 public class SchemaLoaderUtilsTest {
29
30 @Test
31 public void testLoadSchema() throws Exception {
32 Resource resource = new ClassPathResource("schema.xsd", getClass());
33 Schema schema = SchemaLoaderUtils.loadSchema(resource, XMLConstants.W3C_XML_SCHEMA_NS_URI);
34 Assert.assertNotNull("No schema returned", schema);
35 Assert.assertFalse("Resource not closed", resource.isOpen());
36 }
37
38 @Test
39 public void testLoadNonExistantSchema() throws Exception {
40 try {
41 Resource nonExistant = new ClassPathResource("bla");
42 SchemaLoaderUtils.loadSchema(nonExistant, XMLConstants.W3C_XML_SCHEMA_NS_URI);
43 Assert.fail("Should have thrown an IllegalArgumentException");
44 }
45 catch (IllegalArgumentException e) {
46
47 }
48 }
49
50 @Test
51 public void testLoadNullSchema() throws Exception {
52 try {
53 SchemaLoaderUtils.loadSchema((Resource) null, XMLConstants.W3C_XML_SCHEMA_NS_URI);
54 Assert.fail("Should have thrown an IllegalArgumentException");
55 }
56 catch (IllegalArgumentException e) {
57
58 }
59 }
60
61 @Test
62 public void testLoadMultipleSchemas() throws Exception {
63 Resource envelope = new ClassPathResource("envelope.xsd", getClass());
64 Resource encoding = new ClassPathResource("encoding.xsd", getClass());
65 Schema schema =
66 SchemaLoaderUtils.loadSchema(new Resource[]{envelope, encoding}, XMLConstants.W3C_XML_SCHEMA_NS_URI);
67 Assert.assertNotNull("No schema returned", schema);
68 Assert.assertFalse("Resource not closed", envelope.isOpen());
69 Assert.assertFalse("Resource not closed", encoding.isOpen());
70 }
71 }