|
1
|
|
/*
|
|
2
|
|
* JBind
|
|
3
|
|
*
|
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
|
5
|
|
*
|
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
|
8
|
|
* 'Apache Software License V 1.1'.
|
|
9
|
|
*/
|
|
10
|
|
package org.jbind.xml.test;
|
|
11
|
|
|
|
12
|
|
import java.io.File;
|
|
13
|
|
import java.net.URL;
|
|
14
|
|
import java.util.List;
|
|
15
|
|
|
|
16
|
|
import junit.framework.TestCase;
|
|
17
|
|
|
|
18
|
|
import org.jbind.xml.core.cmp.ISchema;
|
|
19
|
|
import org.jbind.xml.facade.JBindFacade;
|
|
20
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
|
21
|
|
import org.jbind.xml.msg.XmlException;
|
|
22
|
|
import org.jbind.xml.msg.XmlMessages;
|
|
23
|
|
import org.jbind.xml.schema.cmp.Schemas;
|
|
24
|
|
import org.jbind.xml.schema.compiler.Compiler;
|
|
25
|
|
import org.jbind.xml.schema.compiler.ICompiler;
|
|
26
|
|
import org.jbind.xml.schema.instantiation.ISchemaReader;
|
|
27
|
|
|
|
28
|
|
public class SchemaTest extends TestCase {
|
|
29
|
|
|
|
30
|
|
private File mySchemaFile = null;
|
|
31
|
|
private boolean myMustBeValid;
|
|
32
|
|
|
|
33
|
148
|
public SchemaTest(File aSchemaFile, boolean aMustBeValid) {
|
|
34
|
148
|
super(aSchemaFile.toString());
|
|
35
|
148
|
mySchemaFile = aSchemaFile;
|
|
36
|
148
|
myMustBeValid = aMustBeValid;
|
|
37
|
|
}
|
|
38
|
|
|
|
39
|
148
|
public void runTest() throws Exception {
|
|
40
|
|
// System.out.println("-->SchemaTest: " + mySchemaFile);
|
|
41
|
|
//
|
|
42
|
|
// Instantiate the schema
|
|
43
|
|
//
|
|
44
|
|
|
|
45
|
148
|
URL schemaUrl = mySchemaFile.toURL();
|
|
46
|
|
|
|
47
|
148
|
ISchemaReader reader = JBindFacade.createSchemaReader();
|
|
48
|
|
|
|
49
|
148
|
try {
|
|
50
|
148
|
ISchema schema = reader.readSchema(schemaUrl, true, null);
|
|
51
|
81
|
assertTrue("invalid schema was not detected", myMustBeValid);
|
|
52
|
81
|
Schemas.getInstance().setSchema(schema);
|
|
53
|
81
|
IConstraintViolations violations = XmlMessages.constraintViolations();
|
|
54
|
81
|
ICompiler compiler = new Compiler();
|
|
55
|
81
|
List fileInfos = compiler.compileSchema(schema, violations);
|
|
56
|
|
|
|
57
|
81
|
assertTrue(violations.toString(), violations.isEmpty());
|
|
58
|
|
|
|
59
|
|
} catch (XmlException e) {
|
|
60
|
67
|
assertTrue(e.getXmlMessage().toString(), !myMustBeValid);
|
|
61
|
|
}
|
|
62
|
|
// System.out.println("<--SchemaTest: " + mySchemaFile);
|
|
63
|
|
}
|
|
64
|
|
}
|
|
65
|
|
|