1 package org.objectweb.celtix.tools.processors.wsdl2; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.PrintStream ; 5 6 import org.objectweb.celtix.tools.WSDLValidator; 7 import org.objectweb.celtix.tools.common.ToolConstants; 8 import org.objectweb.celtix.tools.processors.ProcessorTestBase; 9 import org.objectweb.celtix.tools.processors.wsdl2.validators.WSDL11Validator; 10 11 public class WSDLValidationTest extends ProcessorTestBase { 12 13 private WSDLToJavaProcessor processor = new WSDLToJavaProcessor(); 14 15 public void setUp() throws Exception { 16 super.setUp(); 17 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 18 } 19 20 public void tearDown() { 21 super.tearDown(); 22 processor = null; 23 } 24 25 public void testValidateWSDL() { 26 try { 27 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/doc_lit_bare.wsdl")); 28 env.put(ToolConstants.CFG_VALIDATE_WSDL, ToolConstants.CFG_VALIDATE_WSDL); 29 System.setProperty(ToolConstants.CELTIX_SCHEMA_DIR, getLocation("/schemas")); 30 processor.setEnvironment(env); 31 processor.process(); 32 fail("WSDL Validation Exception Should Be Thrown"); 33 } catch (Exception e) { 34 } 36 } 37 38 public void testMixedStyle() { 39 try { 40 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_mixed_style.wsdl")); 41 processor.setEnvironment(env); 42 processor.process(); 43 fail("WSDL Validation Exception Should Be Thrown"); 44 } catch (Exception e) { 45 } 47 } 48 49 public void testDocType() { 50 try { 51 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_doc_lit_type.wsdl")); 52 env.put(ToolConstants.CFG_VALIDATE_WSDL, ToolConstants.CFG_VALIDATE_WSDL); 53 System.setProperty(ToolConstants.CELTIX_SCHEMA_DIR, getLocation("/schemas")); 54 processor.setEnvironment(env); 55 processor.process(); 56 fail("WSDL Validation Exception Should Be Thrown"); 57 } catch (Exception e) { 58 } 60 } 61 62 public void testValidationHandlerWSDL() throws Exception { 63 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/handler_test.wsdl")); 64 processor.setEnvironment(env); 65 processor.process(); 66 67 } 68 69 70 public void testValidationHandlerWSDL2() throws Exception { 71 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/addNumbers.wsdl")); 72 processor.setEnvironment(env); 73 processor.process(); 74 75 } 76 77 public void testCommand() { 78 PrintStream oldStdErr = System.err; 79 try { 80 ByteArrayOutputStream stdErr = new ByteArrayOutputStream (); 81 System.setErr(new PrintStream (stdErr)); 82 83 WSDLValidator.main(new String [] {"-d", getLocation("/schemas"), 84 getLocation("/wsdl/hello_world_error_attribute.wsdl")}); 85 86 assertNotNull("validate exception should be thrown", stdErr.toString()); 87 88 assertTrue("Error should be located ", stdErr.toString().indexOf("line 53 column 56") > -1); 89 90 } catch (Exception e) { 91 } finally { 93 System.setErr(oldStdErr); 94 } 95 } 96 97 public void testValidator() { 98 try { 99 env.put(ToolConstants.CFG_SCHEMA_DIR, getLocation("/schemas")); 100 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_error_attribute.wsdl")); 101 WSDL11Validator validator = new WSDL11Validator(null, env); 102 validator.isValid(); 103 fail("validate exception should be thrown"); 104 } catch (Exception e) { 105 } 107 } 108 109 public void testWsdlReferenceValidator() { 110 try { 111 env.put(ToolConstants.CFG_SCHEMA_DIR, getLocation("/schemas")); 112 env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl/hello_world_error_reference.wsdl")); 113 WSDL11Validator validator = new WSDL11Validator(null, env); 114 validator.isValid(); 115 fail("validate exception should be thrown"); 116 } catch (Exception e) { 117 String errMsg = e.getMessage(); 118 assertTrue("Part reference error should be located ", errMsg.indexOf("line 57 column 54") > -1); 119 assertTrue("Part reference error should be located ", errMsg.indexOf("line 69 column 46") > -1); 120 assertTrue("PortType reference should be located ", errMsg.indexOf("line 99 column 63") > -1); 121 assertTrue("Binding Reference should be located ", errMsg.indexOf("line 129 column 65") > -1); 122 } 123 } 124 125 126 127 128 private String getLocation(String wsdlFile) { 129 return WSDLValidationTest.class.getResource(wsdlFile).getFile(); 130 } 131 } 132 | Popular Tags |