jdk/test/javax/xml/jaxp/testng/validation/jdk8037819/BasicTest.java
author joehw
Mon, 13 Oct 2014 14:11:20 -0700
changeset 27037 5a6ef51923c4
permissions -rw-r--r--
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27037
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     1
/*
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     2
 * Licensed to the Apache Software Foundation (ASF) under one or more
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     3
 * contributor license agreements.  See the NOTICE file distributed with
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     4
 * this work for additional information regarding copyright ownership.
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     5
 * The ASF licenses this file to You under the Apache License, Version 2.0
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     6
 * (the "License"); you may not use this file except in compliance with
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     7
 * the License.  You may obtain a copy of the License at
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     8
 *
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
     9
 *      http://www.apache.org/licenses/LICENSE-2.0
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    10
 *
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    11
 * Unless required by applicable law or agreed to in writing, software
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    12
 * distributed under the License is distributed on an "AS IS" BASIS,
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    14
 * See the License for the specific language governing permissions and
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    15
 * limitations under the License.
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    16
 */
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    17
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    18
package validation.jdk8037819;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    19
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    20
import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    21
import com.sun.org.apache.xerces.internal.xs.ItemPSVI;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    22
import org.testng.annotations.AfterClass;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    23
import org.testng.annotations.BeforeClass;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    24
import org.testng.annotations.Test;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    25
import validation.BaseTest;
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    26
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    27
public class BasicTest extends BaseTest {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    28
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    29
    protected String getXMLDocument() {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    30
        return "base.xml";
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    31
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    32
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    33
    protected String getSchemaFile() {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    34
        return "base.xsd";
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    35
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    36
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    37
    public BasicTest(String name) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    38
        super(name);
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    39
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    40
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    41
    @BeforeClass
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    42
    protected void setUp() throws Exception {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    43
        super.setUp();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    44
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    45
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    46
    @AfterClass
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    47
    protected void tearDown() throws Exception {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    48
        super.tearDown();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    49
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    50
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    51
    @Test
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    52
    public void testSimpleValidation() {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    53
        try {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    54
            reset();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    55
            validateDocument();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    56
        } catch (Exception e) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    57
            fail("Validation failed: " + e.getMessage());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    58
        }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    59
        doValidityAsserts();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    60
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    61
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    62
    @Test
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    63
    public void testSimpleValidationWithTrivialXSIType() {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    64
        try {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    65
            reset();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    66
            ((PSVIElementNSImpl) fRootNode).setAttributeNS(
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    67
                "http://www.w3.org/2001/XMLSchema-instance", "type", "X");
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    68
            validateDocument();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    69
        } catch (Exception e) {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    70
            fail("Validation failed: " + e.getMessage());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    71
        }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    72
        doValidityAsserts();
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    73
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    74
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    75
    private void doValidityAsserts() {
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    76
        assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    77
        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    78
                .getValidationAttempted());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    79
        assertElementName("A", fRootNode.getElementDeclaration().getName());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    80
        assertElementNamespaceNull(fRootNode.getElementDeclaration()
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    81
                .getNamespace());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    82
        assertTypeName("X", fRootNode.getTypeDefinition().getName());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    83
        assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    84
    }
5a6ef51923c4 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff changeset
    85
}