2015-08-13 76 views
0

我嘗試通過TestNG測試確保Java SOAP WS客戶端(對服務器存根控件不感興趣)的生成工作正常,並且不會導致空指針異常。我甚至不想發起服務請求 - 只需要測試對象的調用。如何使用Arquillian測試SOAP WebService客戶端

@Test(enabled=true) 
    public void getServiceClientTest() { 
     WebServiceClient annotation = MyWS.class.getAnnotation(WebServiceClient.class); 
     QName qname = new QName(annotation.targetNamespace(), annotation.name()); 
     URL wsdlURL = getClass().getClassLoader().getResource(annotation.wsdlLocation()); 
     MyWS svc = new MyWS(wsdlURL, qname); 

     // Ensure the client stub is created successfully. 
     org.testng.Assert.assertNotNull(svc); 
    } 

在單元測試中,這將導致例外,因爲用於客戶端生成的文件對於測試來說是不可及的。 - >見下面/ myWebService

這個僞集成測試應該可以與Arquillian兼容,對吧?

javax.xml.ws.WebServiceException: Failed to access the WSDL at: file:/myWebService. It failed with: 
    /myWebService (No such file or directory). 
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:162) 
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:144) 
    at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:265) 
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:228) 
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:176) 
    at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:104) 
    at javax.xml.ws.Service.<init>(Service.java:77) 
    at myWS.services.v2.MyWS.<init>(AlertTaskServiceV2.java:42) 
    at WebserviceTest.getServiceClientTest(VerificationTaskImplTest.java:25) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
Caused by: java.io.FileNotFoundException: /myWebService (No such file or directory) 
    at java.io.FileInputStream.open(Native Method) 
    at java.io.FileInputStream.<init>(FileInputStream.java:146) 
    at java.io.FileInputStream.<init>(FileInputStream.java:101) 
    at java.net.URL.openStream(URL.java:1037) 
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:804) 
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:262) 
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:129) 
    ... 9 more 

你如何在Arquillian測試中做到這一點?

回答

0

您可以使用Arquillian client mode在這種情況下,ARQ將部署/取消部署您的服務器部件並在本地JVM上運行客戶端部件。

0

正如弗蘭克建議你可以使用客戶端模式,這與運行常規TestNG測試幾乎相同。您可以在@RunAsClient註釋的測試級別執行此操作。

如果你需要它來部署還就需要包括任何生成的類到您的部署,這可能會或可能尚未發生的事情,你不包括測試類的一部分

相關問題