1 package org.objectweb.celtix.tools.processors.xsd2; 2 3 import java.io.File ; 4 import java.io.FileReader ; 5 6 import org.objectweb.celtix.tools.XSDToWSDL; 7 import org.objectweb.celtix.tools.common.ToolConstants; 8 import org.objectweb.celtix.tools.processors.ProcessorTestBase; 9 10 public class XSDToWSDLProcessorTest 11 extends ProcessorTestBase { 12 public void setUp() throws Exception { 13 super.setUp(); 14 env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath()); 15 } 16 17 public void testNewTypes() throws Exception { 18 String [] args = new String [] {"-t", "http://org.objectweb/invoice", "-n", "Invoice", "-d", 19 output.getCanonicalPath(), "-o", "Invoice_xsd.wsdl", 20 getLocation("/wsdl/Invoice.xsd")}; 21 XSDToWSDL.main(args); 22 23 File outputFile = new File (output, "Invoice_xsd.wsdl"); 24 assertTrue("New wsdl file is not generated", outputFile.exists()); 25 FileReader fileReader = new FileReader (outputFile); 26 char[] chars = new char[100]; 27 int size = 0; 28 StringBuffer sb = new StringBuffer (); 29 while (size < outputFile.length()) { 30 int readLen = fileReader.read(chars); 31 sb.append(chars, 0, readLen); 32 size = size + readLen; 33 } 34 String serviceString = new String (sb); 35 assertTrue(serviceString.indexOf("<wsdl:types>") >= 0); 36 assertTrue(serviceString.indexOf("<schema targetNamespace=\"http:/" 37 + "/objectweb.org/Invoice\" xmlns=\"http:/" 38 + "/www.w3.org/2001/XMLSchema\" xmlns:soap=\"http:/" 39 + "/schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"http:/" 40 + "/objectweb.org/Invoice\" xmlns:wsdl=\"http:/" 41 + "/schemas.xmlsoap.org/wsdl/\">") >= 0); 42 assertTrue(serviceString.indexOf("<complexType name=\"InvoiceHeader\">") >= 0); 43 44 } 45 46 public void testDefaultFileName() throws Exception { 47 String [] args = new String [] {"-t", "http://org.objectweb/invoice", "-n", "Invoice", "-d", 48 output.getCanonicalPath(), getLocation("/wsdl/Invoice.xsd")}; 49 XSDToWSDL.main(args); 50 51 File outputFile = new File (output, "Invoice.wsdl"); 52 assertTrue("PortType file is not generated", outputFile.exists()); 53 FileReader fileReader = new FileReader (outputFile); 54 char[] chars = new char[100]; 55 int size = 0; 56 StringBuffer sb = new StringBuffer (); 57 while (size < outputFile.length()) { 58 int readLen = fileReader.read(chars); 59 sb.append(chars, 0, readLen); 60 size = size + readLen; 61 } 62 String serviceString = new String (sb); 63 assertTrue(serviceString.indexOf("<wsdl:types>") >= 0); 64 assertTrue(serviceString.indexOf("<schema targetNamespace=\"http:/" 65 + "/objectweb.org/Invoice\" xmlns=\"http:/" 66 + "/www.w3.org/2001/XMLSchema\" xmlns:soap=\"http:/" 67 + "/schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"http:/" 68 + "/objectweb.org/Invoice\" xmlns:wsdl=\"http:/" 69 + "/schemas.xmlsoap.org/wsdl/\">") >= 0); 70 assertTrue(serviceString.indexOf("<complexType name=\"InvoiceHeader\">") >= 0); 71 } 72 73 74 private String getLocation(String wsdlFile) { 75 return XSDToWSDLProcessorTest.class.getResource(wsdlFile).getFile(); 76 } 77 78 } 79 | Popular Tags |