KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > validation > schema > SchemaTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation.schema;
21
22 import java.net.URL JavaDoc;
23 import javax.xml.XMLConstants JavaDoc;
24 import javax.xml.transform.Source JavaDoc;
25 import javax.xml.transform.stream.StreamSource JavaDoc;
26 import javax.xml.validation.Schema JavaDoc;
27 import javax.xml.validation.SchemaFactory JavaDoc;
28 import junit.framework.*;
29 import org.xml.sax.ErrorHandler JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31 import org.xml.sax.SAXParseException JavaDoc;
32
33 /**
34  *
35  * @author radval
36  */

37 public class SchemaTest extends TestCase {
38     
39     private Exception JavaDoc mLastError;
40     
41      
42     public SchemaTest(String JavaDoc testName) {
43         super(testName);
44     }
45
46     protected void setUp() throws Exception JavaDoc {
47     }
48
49     protected void tearDown() throws Exception JavaDoc {
50     }
51     
52     // TODO add test methods here. The name must begin with 'test'. For example:
53
// public void testHello() {}
54
public void testSchemaPartnerLinkType() throws Exception JavaDoc {
55         MyErrorHandler errorHandler = new MyErrorHandler();
56         SchemaFactory JavaDoc sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
57         sf.setErrorHandler(errorHandler);
58         PartnerLinkTypeValidatorSchemaFactory fac = new PartnerLinkTypeValidatorSchemaFactory();
59         Source JavaDoc s = fac.getSchemaSource();
60         Schema JavaDoc schema = sf.newSchema(s);
61         
62         assertNotNull("schema should not be null", schema);
63         
64         assertNull("No exception should occur in schema parsing", mLastError);
65     }
66     
67     public void testSchemaPropertyAndPropertyAlias() throws Exception JavaDoc {
68         MyErrorHandler errorHandler = new MyErrorHandler();
69         SchemaFactory JavaDoc sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
70         sf.setErrorHandler(errorHandler);
71         BPELPropertiesValidatorSchemaFactory fac = new BPELPropertiesValidatorSchemaFactory();
72         Source JavaDoc s = fac.getSchemaSource();
73         Schema JavaDoc schema = sf.newSchema(s);
74         
75         assertNotNull("schema should not be null", schema);
76         
77         assertNull("No exception should occur in schema parsing", mLastError);
78     }
79     
80     class MyErrorHandler implements ErrorHandler JavaDoc {
81         
82         public void error(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
83             mLastError = exception;
84             exception.printStackTrace();
85         }
86
87         public void fatalError(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
88             mLastError = exception;
89             exception.printStackTrace();
90         }
91
92         public void warning(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
93             exception.printStackTrace();
94         }
95     }
96 }
97
Popular Tags