获取错误消息为"解组错误:意外元素"在运行SOAP脚本时

时间:2017-11-01 15:31:49

标签: citrus-framework

我使用Citrus Framework来测试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>

你可以在这里帮助我吗,为什么我会收到错误。

更新 这是Stack Trace

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
===============================================

1 个答案:

答案 0 :(得分:3)

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

还请检查SOAP服务器日志。您应该在处理请求期间看到错误。