001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestWsdlWriter.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.wsdl2.impl;
030:
031: import com.sun.jbi.wsdl2.Description;
032: import com.sun.jbi.wsdl2.Definitions;
033: import com.sun.jbi.wsdl2.Interface;
034:
035: import java.io.StringWriter;
036: import com.sun.jbi.wsdl2.InterfaceOperation;
037:
038: /**
039: * Unit tests for the WSDL factory.
040: *
041: * @author Sun Microsystems Inc.
042: */
043: public class TestWsdlWriter extends junit.framework.TestCase {
044: /** Writer to be used in various tests */
045: private com.sun.jbi.wsdl2.WsdlWriter mWriter = null;
046:
047: /** Old system property value for java.protocol.handler.pkgs */
048: private String mOldJavaProtocolHandlerPkgs = null;
049:
050: /**
051: * Set up for each test.
052: *
053: * @exception Exception when set up fails for any reason. This tells JUnit
054: * that it cannot run the test.
055: */
056: public void setUp() throws Exception {
057: super .setUp();
058:
059: com.sun.jbi.wsdl2.WsdlFactory factory = WsdlFactory
060: .newInstance();
061:
062: this .mWriter = factory.newWsdlWriter();
063:
064: this .mOldJavaProtocolHandlerPkgs = System.setProperty(
065: "java.protocol.handler.pkgs", "com.sun.jbi.wsdl2.impl");
066: }
067:
068: /**
069: * Clean up after each test case.
070: *
071: * @exception Exception when clean up fails for any reason.
072: */
073: public void tearDown() throws Exception {
074: if (this .mOldJavaProtocolHandlerPkgs != null) {
075: System.setProperty("java.protocol.handler.pkgs",
076: this .mOldJavaProtocolHandlerPkgs);
077: }
078: }
079:
080: /**
081: * Test use of a WsldWriter instance.
082: *
083: * @exception Exception when any unexpected error occurs.
084: */
085: public void testWriter() throws Exception {
086: final String tns = "uri:org.test:TestWsldWriter";
087: final String binding1 = "binding1";
088: final String op1 = "op1";
089: final String if1 = "if1";
090: com.sun.jbi.wsdl2.WsdlFactory factory = WsdlFactory
091: .newInstance();
092: Description defs = factory.newDescription(tns);
093: Interface iface = defs.addNewInterface(if1);
094: StringWriter sw = new StringWriter();
095: InterfaceOperation ifop = iface.addNewOperation();
096:
097: ifop.setName(op1);
098: defs.addNewBinding(binding1).addNewOperation()
099: .setInterfaceOperation(ifop.getQualifiedName());
100:
101: mWriter.writeDescription(defs, sw);
102: sw.flush();
103: sw.close();
104:
105: String result = sw.getBuffer().toString();
106:
107: assertTrue(result.length() > 0);
108: assertTrue(result.indexOf("description") > 0);
109: assertTrue(result.indexOf(tns) > 0);
110: assertTrue(result.indexOf("\"" + binding1 + "\"") > 0);
111: assertTrue(result.indexOf("\"" + op1 + "\"") > 0);
112: assertTrue(result.indexOf(Constants.WSDL_NAMESPACE_NAME) > 0);
113:
114: mWriter.writeWsdl((Definitions) defs, sw);
115: sw.flush();
116: sw.close();
117:
118: String result1 = sw.getBuffer().toString();
119:
120: assertTrue(result1.length() > 0);
121: assertTrue(result1.indexOf("description") > 0);
122: assertTrue(result1.indexOf(tns) > 0);
123: assertTrue(result1.indexOf("\"" + binding1 + "\"") > 0);
124: assertTrue(result1.indexOf("\"" + op1 + "\"") > 0);
125: assertTrue(result1.indexOf(Constants.WSDL_NAMESPACE_NAME) > 0);
126: }
127: }
|