RootSimpleTypeDefinitionTest.java revision 10791:745a5e1d4508
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * Licensed to the Apache Software Foundation (ASF) under one or more
30Sstevel@tonic-gate * contributor license agreements.  See the NOTICE file distributed with
40Sstevel@tonic-gate * this work for additional information regarding copyright ownership.
50Sstevel@tonic-gate * The ASF licenses this file to You under the Apache License, Version 2.0
60Sstevel@tonic-gate * (the "License"); you may not use this file except in compliance with
70Sstevel@tonic-gate * the License.  You may obtain a copy of the License at
80Sstevel@tonic-gate *
90Sstevel@tonic-gate *      http://www.apache.org/licenses/LICENSE-2.0
100Sstevel@tonic-gate *
110Sstevel@tonic-gate * Unless required by applicable law or agreed to in writing, software
120Sstevel@tonic-gate * distributed under the License is distributed on an "AS IS" BASIS,
130Sstevel@tonic-gate * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140Sstevel@tonic-gate * See the License for the specific language governing permissions and
150Sstevel@tonic-gate * limitations under the License.
160Sstevel@tonic-gate */
170Sstevel@tonic-gate
180Sstevel@tonic-gatepackage validation.jdk8036951;
190Sstevel@tonic-gate
200Sstevel@tonic-gateimport com.sun.org.apache.xerces.internal.xs.ItemPSVI;
210Sstevel@tonic-gateimport javax.xml.XMLConstants;
220Sstevel@tonic-gateimport javax.xml.namespace.QName;
230Sstevel@tonic-gateimport org.testng.annotations.AfterClass;
240Sstevel@tonic-gateimport org.testng.annotations.BeforeClass;
250Sstevel@tonic-gateimport org.testng.annotations.Test;
260Sstevel@tonic-gateimport org.xml.sax.SAXException;
270Sstevel@tonic-gateimport validation.BaseTest;
280Sstevel@tonic-gate
29/**
30 * @author Peter McCracken, IBM
31 * @version $Id$
32 */
33public class RootSimpleTypeDefinitionTest extends BaseTest {
34
35    private QName typeString;
36    private QName typeNonNegInt;
37
38    private final static String INVALID_TYPE_ERROR = "cvc-type.3.1.3";
39    private final static String MININCLUSIVE_DERIVATION_ERROR = "cvc-minInclusive-valid";
40
41    protected String getXMLDocument() {
42        return "simpleType.xml";
43    }
44
45    protected String getSchemaFile() {
46        return "base.xsd";
47    }
48
49    protected String[] getRelevantErrorIDs() {
50        return new String[] { INVALID_TYPE_ERROR, MININCLUSIVE_DERIVATION_ERROR };
51    }
52
53    @BeforeClass
54    protected void setUp() throws Exception {
55        super.setUp();
56    }
57
58    @AfterClass
59    protected void tearDown() throws Exception {
60        super.tearDown();
61    }
62
63    public RootSimpleTypeDefinitionTest(String name) {
64        super(name);
65        // This is a roundabout way of making sure that we're not using an
66        // interned string (so that == doesn't work)
67        String ns = "x" + XMLConstants.W3C_XML_SCHEMA_NS_URI;
68        ns = ns.substring(1);
69        typeString = new QName(ns, "string", "xsd");
70        typeNonNegInt = new QName(ns, "nonNegativeInteger", "xsd");
71    }
72
73    @Test
74    public void testSettingSimpleType() throws Exception {
75        try {
76            reset();
77            fValidator.setProperty(ROOT_TYPE, typeString);
78        } catch (SAXException e1) {
79            fail("Problem setting property: " + e1.getMessage());
80        }
81
82        try {
83            validateDocument();
84        } catch (Exception e) {
85            fail("Validation failed: " + e.getMessage());
86        }
87
88        assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
89        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
90                .getValidationAttempted());
91        assertElementNull(fRootNode.getElementDeclaration());
92        assertTypeName("string", fRootNode.getTypeDefinition().getName());
93    }
94
95    @Test
96    public void testSettingInvalidSimpleType() throws Exception {
97        try {
98            reset();
99            fValidator.setProperty(ROOT_TYPE, typeNonNegInt);
100        } catch (SAXException e1) {
101            fail("Problem setting property: " + e1.getMessage());
102        }
103
104        try {
105            validateDocument();
106        } catch (Exception e) {
107            fail("Validation failed: " + e.getMessage());
108        }
109
110        assertError(INVALID_TYPE_ERROR);
111        assertError(MININCLUSIVE_DERIVATION_ERROR);
112        assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());
113        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
114                .getValidationAttempted());
115        assertElementNull(fRootNode.getElementDeclaration());
116        assertTypeName("nonNegativeInteger", fRootNode.getTypeDefinition().getName());
117    }
118}
119