1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.support;
14  
15  import javax.wsdl.BindingOperation;
16  import javax.wsdl.Definition;
17  import javax.wsdl.factory.WSDLFactory;
18  import javax.wsdl.xml.WSDLReader;
19  
20  import com.eviware.soapui.impl.wsdl.WsdlInterface;
21  import com.eviware.soapui.impl.wsdl.WsdlOperation;
22  import com.eviware.soapui.impl.wsdl.WsdlProject;
23  import com.eviware.soapui.impl.wsdl.WsdlRequest;
24  import com.eviware.soapui.impl.wsdl.WsdlSubmitContext;
25  import com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader;
26  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
27  import com.eviware.soapui.model.iface.Submit;
28  import com.eviware.soapui.support.TestCaseWithJetty;
29  
30  public class WsdlImporterTestCase extends TestCaseWithJetty
31  {
32  	public void testOneWayOperationImport() throws Exception
33     {
34     	WsdlProject project = new WsdlProject();
35     	WsdlInterface[] wsdls = WsdlImporter.getInstance().importWsdl( 
36     			project, "http://localhost:8082/testonewayop/TestService.wsdl");
37     	
38     	assertEquals( 1, wsdls.length );
39     	
40     	WsdlInterface iface = wsdls[0];
41     	
42     	assertNotNull( iface );
43     	assertEquals( 2, iface.getOperationCount() );
44  
45     	WsdlOperation operation = (WsdlOperation) iface.getOperationAt( 0 );
46     	
47     	assertNotNull( operation );
48     	assertEquals( "GetDefaultPageData", operation.getName() );
49     	
50     	Definition definition = readDefinition( "http://localhost:8082/testonewayop/TestService.wsdl" );
51     	
52     	BindingOperation bindingOperation = operation.findBindingOperation( definition );
53     	assertNotNull( bindingOperation );
54     	assertEquals( bindingOperation.getName(), operation.getBindingOperationName() );
55     	
56     	assertNull( operation.getOutputName() );
57     	
58     	WsdlRequest request = operation.addNewRequest( "TestRequest" );
59     	assertNotNull( request );
60  
61     	String requestXml = operation.createRequest( true );
62     	assertNotNull( requestXml );
63     	
64     	request.setRequestContent( requestXml );
65     	
66     	Submit submit = request.submit( new WsdlSubmitContext( null ), false );
67     	
68     	assertTrue( submit.getResponse().getContentAsString().indexOf( "Error 404 NOT_FOUND" ) > 0 );
69     }
70     
71     public Definition readDefinition( String wsdlUrl ) throws Exception 
72     {
73        WSDLFactory factory = WSDLFactory.newInstance();
74        WSDLReader wsdlReader = factory.newWSDLReader();
75        wsdlReader.setFeature("javax.wsdl.verbose", true);
76        wsdlReader.setFeature("javax.wsdl.importDocuments", true);
77        return wsdlReader.readWSDL( new UrlWsdlLoader( wsdlUrl ) );
78     }
79  }