KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > processors > xsd2 > XSDToWSDLProcessorTest


1 package org.objectweb.celtix.tools.processors.xsd2;
2
3 import java.io.File JavaDoc;
4 import java.io.FileReader JavaDoc;
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 JavaDoc {
13         super.setUp();
14         env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
15     }
16
17     public void testNewTypes() throws Exception JavaDoc {
18         String JavaDoc[] args = new String JavaDoc[] {"-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 JavaDoc outputFile = new File JavaDoc(output, "Invoice_xsd.wsdl");
24         assertTrue("New wsdl file is not generated", outputFile.exists());
25         FileReader JavaDoc fileReader = new FileReader JavaDoc(outputFile);
26         char[] chars = new char[100];
27         int size = 0;
28         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
29         while (size < outputFile.length()) {
30             int readLen = fileReader.read(chars);
31             sb.append(chars, 0, readLen);
32             size = size + readLen;
33         }
34         String JavaDoc serviceString = new String JavaDoc(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 JavaDoc {
47         String JavaDoc[] args = new String JavaDoc[] {"-t", "http://org.objectweb/invoice", "-n", "Invoice", "-d",
48                                       output.getCanonicalPath(), getLocation("/wsdl/Invoice.xsd")};
49         XSDToWSDL.main(args);
50
51         File JavaDoc outputFile = new File JavaDoc(output, "Invoice.wsdl");
52         assertTrue("PortType file is not generated", outputFile.exists());
53         FileReader JavaDoc fileReader = new FileReader JavaDoc(outputFile);
54         char[] chars = new char[100];
55         int size = 0;
56         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
57         while (size < outputFile.length()) {
58             int readLen = fileReader.read(chars);
59             sb.append(chars, 0, readLen);
60             size = size + readLen;
61         }
62         String JavaDoc serviceString = new String JavaDoc(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 JavaDoc getLocation(String JavaDoc wsdlFile) {
75         return XSDToWSDLProcessorTest.class.getResource(wsdlFile).getFile();
76     }
77
78 }
79
Popular Tags