1

我已经使用 Citrus 框架来测试 SOAP。这里我给出的有效负载必须从 XML 文件中获取,但在控制台中它指向不同的位置。

soap()
      .client(todoClient)
      .send()
      .soapAction("loginSOAP")
      .payload(new ClassPathResource("data/loginSOAP.xml"));  

soap()
      .client(todoClient)
      .receive()          
      .payload(new ClassPathResource("data/loginSOAPResponse.xml"));

在运行它时,我收到一个错误,如Unmarshalling Error: unexpected element (uri:"http://soap.myapp.mycomm.org/", local:"userName"). Expected elements are <{}password>,<{}userName>.

你能在这里帮我吗,为什么我收到错误消息。

更新 这里是堆栈跟踪

10:28:06,169 DEBUG estExecutionListener| After test method: context [DefaultTestContext@1bdaa23d testClass = SOAP, testInstance = com.consol.citrus.integration.Demo.SOAP@ec2bf82, testMethod = TestPost@SOAP, testException = com.consol.citrus.exceptions.TestCaseFailedException: Test case failed, mergedContextConfiguration = [MergedContextConfiguration@79f227a9 testClass = SOAP, locations = '{}', classes = '{class com.consol.citrus.config.CitrusSpringConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null], method ann
otated with @DirtiesContext [false] with mode [null].
10:28:06,189 DEBUG estExecutionListener| After test class: context [DefaultTestContext@1bdaa23d testClass = SOAP, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@79f227a9 testClass = SOAP, locations = '{}', classes = '{class com.consol.citrus.config.CitrusSpringConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null].
FAILED: TestPost({Param_18=, Param_17=, Param_16=, Param_15=, Param_9=, Param_14=, Param_8=, Param_13=, Param_7=, Param_12=, Param_6=, Param_11=, Param_5=, Param_10=, Param_4=, Runmode=Y, Param_3=, Param_2=admin, Param_1=admin})
com.consol.citrus.exceptions.TestCaseFailedException: Test case failed
    at com.consol.citrus.TestCase.executeAction(TestCase.java:236)
    at com.consol.citrus.TestCase.doExecute(TestCase.java:145)
    at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
    at com.consol.citrus.Citrus.run(Citrus.java:281)
    at com.consol.citrus.dsl.testng.TestNGCitrusTest.invokeTestMethod(TestNGCitrusTest.java:136)
    at com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner.invokeTestMethod(TestNGCitrusTestDesigner.java:73)
    at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:111)
    at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:194)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: org.springframework.ws.soap.client.SoapFaultClientException: Unmarshalling Error: unexpected element (uri:"http://soap.myapp.mycomm.org/", local:"userName"). Expected elements are <{}password>,<{}userName> 
    at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault(SoapFaultMessageResolver.java:38)
    at com.consol.citrus.ws.client.WebServiceClient$InternalFaultMessageResolver.resolveFault(WebServiceClient.java:243)
    at org.springframework.ws.client.core.WebServiceTemplate.handleFault(WebServiceTemplate.java:830)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:624)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:531)
    at com.consol.citrus.ws.client.WebServiceClient.send(WebServiceClient.java:126)
    at com.consol.citrus.actions.SendMessageAction.doExecute(SendMessageAction.java:118)
    at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
    at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:54)
    at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42)
    at com.consol.citrus.TestCase.executeAction(TestCase.java:229)
    ... 31 more


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================

219875 [main] INFO com.consol.citrus.Citrus - 
219875 [main] INFO com.consol.citrus.Citrus - ------------------------------------------------------------------------
219875 [main] INFO com.consol.citrus.Citrus - 
219876 [main] INFO com.consol.citrus.Citrus - 
219876 [main] INFO com.consol.citrus.Citrus - AFTER TEST SUITE: SUCCESS
219876 [main] INFO com.consol.citrus.Citrus - ------------------------------------------------------------------------
219876 [main] INFO com.consol.citrus.Citrus - 
219876 [main] INFO com.consol.citrus.Citrus - ------------------------------------------------------------------------
219876 [main] INFO com.consol.citrus.Citrus - 
219876 [main] INFO com.consol.citrus.Citrus - CITRUS TEST RESULTS
219876 [main] INFO com.consol.citrus.Citrus - 
219883 [main] INFO com.consol.citrus.Citrus -  SOAP.TestPost([{Param_18=, Param_17=, Param_16=, Param_15=, Param_9=, Param_14=, Param_8=, Param_13=, Param_7=, Param_12=, Param_6=, Param_11=, Param_5=, Param_10=, Param_4=, Runmode=Y, Param_3=, Param_2=admin, Param_1=admin}])  FAILED
219884 [main] INFO com.consol.citrus.Citrus -  FAILURE: Caused by: SoapFaultClientException: Unmarshalling Error: unexpected element (uri:"http://soap.myapp.mycomm.org/", local:"userName"). Expected elements are <{}password>,<{}userName> 
219884 [main] INFO com.consol.citrus.Citrus - 
219885 [main] INFO com.consol.citrus.Citrus - TOTAL:    1
219886 [main] INFO com.consol.citrus.Citrus - FAILED:   1 (100.0%)
219886 [main] INFO com.consol.citrus.Citrus - SUCCESS:  0 (0.0%)
219886 [main] INFO com.consol.citrus.Citrus - 
219886 [main] INFO com.consol.citrus.Citrus - ------------------------------------------------------------------------
220110 [main] INFO com.consol.citrus.report.HtmlReporter - Generated HTML test report

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
4

1 回答 1

3

您在这里遇到的错误不是在测试用例中引发的,而是在您正在调用的服务器上引发的。Citrus 作为客户端收到错误作为 SOAP 错误,导致SoapFaultClientException. loginSOAP.xml显然,服务器对您作为有效负载发送的内容不满意。

另请检查 SOAP 服务器日志。您应该在此处看到错误,因为它是在处理您的请求期间提出的。

于 2017-11-02T07:38:53.077 回答