001: package org.objectweb.celtix.tools.processors.wsdl2;
002:
003: import java.io.ByteArrayOutputStream;
004: import java.io.PrintStream;
005:
006: import org.objectweb.celtix.tools.WSDLValidator;
007: import org.objectweb.celtix.tools.common.ToolConstants;
008: import org.objectweb.celtix.tools.processors.ProcessorTestBase;
009: import org.objectweb.celtix.tools.processors.wsdl2.validators.WSDL11Validator;
010:
011: public class WSDLValidationTest extends ProcessorTestBase {
012:
013: private WSDLToJavaProcessor processor = new WSDLToJavaProcessor();
014:
015: public void setUp() throws Exception {
016: super .setUp();
017: env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
018: }
019:
020: public void tearDown() {
021: super .tearDown();
022: processor = null;
023: }
024:
025: public void testValidateWSDL() {
026: try {
027: env.put(ToolConstants.CFG_WSDLURL,
028: getLocation("/wsdl/doc_lit_bare.wsdl"));
029: env.put(ToolConstants.CFG_VALIDATE_WSDL,
030: ToolConstants.CFG_VALIDATE_WSDL);
031: System.setProperty(ToolConstants.CELTIX_SCHEMA_DIR,
032: getLocation("/schemas"));
033: processor.setEnvironment(env);
034: processor.process();
035: fail("WSDL Validation Exception Should Be Thrown");
036: } catch (Exception e) {
037: // do nothing
038: }
039: }
040:
041: public void testMixedStyle() {
042: try {
043: env.put(ToolConstants.CFG_WSDLURL,
044: getLocation("/wsdl/hello_world_mixed_style.wsdl"));
045: processor.setEnvironment(env);
046: processor.process();
047: fail("WSDL Validation Exception Should Be Thrown");
048: } catch (Exception e) {
049: // do nothing
050: }
051: }
052:
053: public void testDocType() {
054: try {
055: env.put(ToolConstants.CFG_WSDLURL,
056: getLocation("/wsdl/hello_world_doc_lit_type.wsdl"));
057: env.put(ToolConstants.CFG_VALIDATE_WSDL,
058: ToolConstants.CFG_VALIDATE_WSDL);
059: System.setProperty(ToolConstants.CELTIX_SCHEMA_DIR,
060: getLocation("/schemas"));
061: processor.setEnvironment(env);
062: processor.process();
063: fail("WSDL Validation Exception Should Be Thrown");
064: } catch (Exception e) {
065: // do nothing
066: }
067: }
068:
069: public void testValidationHandlerWSDL() throws Exception {
070: env.put(ToolConstants.CFG_WSDLURL,
071: getLocation("/wsdl/handler_test.wsdl"));
072: processor.setEnvironment(env);
073: processor.process();
074:
075: }
076:
077: public void testValidationHandlerWSDL2() throws Exception {
078: env.put(ToolConstants.CFG_WSDLURL,
079: getLocation("/wsdl/addNumbers.wsdl"));
080: processor.setEnvironment(env);
081: processor.process();
082:
083: }
084:
085: public void testCommand() {
086: PrintStream oldStdErr = System.err;
087: try {
088: ByteArrayOutputStream stdErr = new ByteArrayOutputStream();
089: System.setErr(new PrintStream(stdErr));
090:
091: WSDLValidator
092: .main(new String[] {
093: "-d",
094: getLocation("/schemas"),
095: getLocation("/wsdl/hello_world_error_attribute.wsdl") });
096:
097: assertNotNull("validate exception should be thrown", stdErr
098: .toString());
099:
100: assertTrue("Error should be located ", stdErr.toString()
101: .indexOf("line 53 column 56") > -1);
102:
103: } catch (Exception e) {
104: // ignore
105: } finally {
106: System.setErr(oldStdErr);
107: }
108: }
109:
110: public void testValidator() {
111: try {
112: env.put(ToolConstants.CFG_SCHEMA_DIR,
113: getLocation("/schemas"));
114: env
115: .put(
116: ToolConstants.CFG_WSDLURL,
117: getLocation("/wsdl/hello_world_error_attribute.wsdl"));
118: WSDL11Validator validator = new WSDL11Validator(null, env);
119: validator.isValid();
120: fail("validate exception should be thrown");
121: } catch (Exception e) {
122: // ignore exception
123: }
124: }
125:
126: public void testWsdlReferenceValidator() {
127: try {
128: env.put(ToolConstants.CFG_SCHEMA_DIR,
129: getLocation("/schemas"));
130: env
131: .put(
132: ToolConstants.CFG_WSDLURL,
133: getLocation("/wsdl/hello_world_error_reference.wsdl"));
134: WSDL11Validator validator = new WSDL11Validator(null, env);
135: validator.isValid();
136: fail("validate exception should be thrown");
137: } catch (Exception e) {
138: String errMsg = e.getMessage();
139: assertTrue("Part reference error should be located ",
140: errMsg.indexOf("line 57 column 54") > -1);
141: assertTrue("Part reference error should be located ",
142: errMsg.indexOf("line 69 column 46") > -1);
143: assertTrue("PortType reference should be located ", errMsg
144: .indexOf("line 99 column 63") > -1);
145: assertTrue("Binding Reference should be located ", errMsg
146: .indexOf("line 129 column 65") > -1);
147: }
148: }
149:
150: private String getLocation(String wsdlFile) {
151: return WSDLValidationTest.class.getResource(wsdlFile).getFile();
152: }
153: }
|