File: XMLTest.java

package info (click to toggle)
libjdo-api-java 3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,540 kB
  • ctags: 33,888
  • sloc: java: 120,520; sql: 20,353; xml: 3,969; makefile: 4
file content (129 lines) | stat: -rw-r--r-- 4,950 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

package javax.jdo.schema;

import java.io.File;
import java.io.IOException;
import java.io.FilenameFilter;

import java.util.Arrays;
import java.util.List;

import javax.jdo.JDOFatalException;
import javax.jdo.util.AbstractTest;
import javax.jdo.util.BatchTestRunner;
import javax.jdo.util.XMLTestUtil;

import javax.xml.parsers.*;
import org.w3c.dom.Document;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

/**
 * Tests schema files.
 * <p>
 */
public class XMLTest extends AbstractTest {

    /** */
    protected static String BASEDIR = System.getProperty("basedir", ".");

    /** File prefix */
    protected static final String FILE_PREFIX = BASEDIR + "/test/schema/";

    /** */
    protected static final File JDO_XSD_FILE = 
        new File(BASEDIR + "/target/classes/javax/jdo/jdo_2_2.xsd");

    /** */
    protected static final File ORM_XSD_FILE = 
        new File(BASEDIR + "/target/classes/javax/jdo/orm_2_2.xsd");

    /** */
    protected static final File JDOQUERY_XSD_FILE = 
        new File(BASEDIR + "/target/classes/javax/jdo/jdoquery_2_2.xsd");

    /** .xsd files */
    protected static final File[] XSD_FILES = 
        new File[] {JDO_XSD_FILE, ORM_XSD_FILE, JDOQUERY_XSD_FILE};
    
    /** XSD metadata files. */
    protected static File[] positiveXSDJDO = getFiles("Positive", "-xsd.jdo");
    protected static File[] negativeXSDJDO = getFiles("Negative", "-xsd.jdo");
    protected static File[] positiveXSDORM = getFiles("Positive", "-xsd.orm");
    protected static File[] negativeXSDORM = getFiles("Negative", "-xsd.orm");
    protected static File[] positiveXSDJDOQUERY = getFiles("Positive", "-xsd.jdoquery");
    protected static File[] negativeXSDJDOQUERY = getFiles("Negative", "-xsd.jdoquery");
    
    /** DTD metadata files. */
    protected static File[] positiveDTDJDO = getFiles("Positive", "-dtd.jdo");
    protected static File[] negativeDTDJDO = getFiles("Negative", "-dtd.jdo");
    protected static File[] positiveDTDORM = getFiles("Positive", "-dtd.orm");
    protected static File[] negativeDTDORM = getFiles("Negative", "-dtd.orm");
    protected static File[] positiveDTDJDOQUERY = getFiles("Positive", "-dtd.jdoquery");
    protected static File[] negativeDTDJDOQUERY = getFiles("Negative", "-dtd.jdoquery");
    
    /** Returns array of files of matching file names. */
    protected static File[] getFiles(final String prefix, final String suffix) {
        FilenameFilter filter = new FilenameFilter () {
            public boolean accept(File file, String name) {
                return (name.startsWith(prefix) && name.endsWith(suffix));
            }
        };
        File dir = new File(FILE_PREFIX);
        return dir.listFiles(filter);
    }

    /** */
    public static void main(String args[]) {
        BatchTestRunner.run(XMLTest.class);
    }

    /** Test XSD files jdo.xsd, orm.xsd, and jdoquery.xsd. */
    public void testXSD() {
        XMLTestUtil util = new XMLTestUtil();
        appendMessage(util.checkXMLNonValidating(XSD_FILES));
        failOnError();
    }

    /** Test XSD based .jdo, .orm and .jdoquery files. */
    public void testXSDBased() {
        XMLTestUtil util = new XMLTestUtil();
        appendMessage(util.checkXML(positiveXSDJDO, true));
        appendMessage(util.checkXML(negativeXSDJDO, false));
        appendMessage(util.checkXML(positiveXSDORM, true));
        appendMessage(util.checkXML(negativeXSDORM, false));
        appendMessage(util.checkXML(positiveXSDJDOQUERY, true));
        appendMessage(util.checkXML(negativeXSDJDOQUERY, false));
        failOnError();
    }

    /** Test DTD based .jdo, .orm and .jdoquery files. */
    public void testDTDBased() {
        XMLTestUtil util = new XMLTestUtil();
        appendMessage(util.checkXML(positiveDTDJDO, true));
        appendMessage(util.checkXML(negativeDTDJDO, false));
        appendMessage(util.checkXML(positiveDTDORM, true));
        appendMessage(util.checkXML(negativeDTDORM, false));
        appendMessage(util.checkXML(positiveDTDJDOQUERY, true));
        appendMessage(util.checkXML(negativeDTDJDOQUERY, false));
        failOnError();
    }

}