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 java.io.File;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.net.URI;
23 import java.net.URL;
24
25 import junit.framework.TestCase;
26
27 import org.springframework.core.io.ClassPathResource;
28 import org.springframework.core.io.Resource;
29 import org.springframework.core.io.AbstractResource;
30
31 public class XmlValidatorFactoryTest extends TestCase {
32
33 public void testCreateValidator() throws Exception {
34 Resource resource = new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class);
35 XmlValidator validator = XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
36 assertNotNull("No validator returned", validator);
37 }
38
39 public void testNonExistentResource() throws Exception {
40 Resource resource = new NonExistentResource();
41 try {
42 XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
43 fail("IllegalArgumentException expected");
44 }
45 catch (IllegalArgumentException ex) {
46
47 }
48 }
49
50 public void testInvalidSchemaLanguage() throws Exception {
51 Resource resource = new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class);
52 try {
53 XmlValidatorFactory.createValidator(resource, "bla");
54 fail("IllegalArgumentException expected");
55 }
56 catch (IllegalArgumentException ex) {
57
58 }
59 }
60
61 private static class NonExistentResource extends AbstractResource {
62
63 public Resource createRelative(String relativePath) throws IOException {
64 throw new IOException();
65 }
66
67 public boolean exists() {
68 return false;
69 }
70
71 public String getDescription() {
72 return null;
73 }
74
75 public File getFile() throws IOException {
76 throw new IOException();
77 }
78
79 public String getFilename() {
80 return null;
81 }
82
83 public URL getURL() throws IOException {
84 throw new IOException();
85 }
86
87 public URI getURI() throws IOException {
88 throw new IOException();
89 }
90
91 public boolean isOpen() {
92 return false;
93 }
94
95 public InputStream getInputStream() throws IOException {
96 throw new IOException();
97 }
98
99 public boolean isReadable() {
100 return false;
101 }
102 }
103 }