如何使用Arquillian测试SOAP WebService CLIENT

时间:2015-08-13 09:20:28

标签: wsdl java-ee-6 soap-client jboss-arquillian

我尝试通过TestNG测试确保Java SOAP WS Client(对服务器存根不感兴趣)的生成正常工作,并且不会导致空指针异常。我甚至不想发出服务请求 - 只需要测试对象的调用。

@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测试中做到这一点?

2 个答案:

答案 0 :(得分:0)

您可以使用Arquillian client mode,在这种情况下,ARQ将部署/取消部署您的服务器部分并在本地JVM上运行客户端部分。

答案 1 :(得分:0)

正如Franck建议您可以使用客户端模式,这与运行常规TestNG测试几乎相同。您可以使用@RunAsClient注释在测试级别执行此操作。

如果您需要部署它,您还需要在部署中包含任何生成的类,这可能会也可能不会发生,因为您没有包含测试类的那部分