我的springwebservice测试出错了。以下是错误。
org.springframework.ws.test.support.SourceAssertionError: Messages are different, org.custommonkey.xmlunit.Diff
[different] Expected namespace URI 'http://schemas.xmlsoap.org/soap/envelope/' but was 'http://openmindnetworks.com/cconf/webservices' - comparing <soapenv:Envelope...> at /Envelope[1] to <ns4:itemRequest...> at /itemRequest[1]
Payload: <ns4:itemRequest xmlns:ns4="http://openmindnetworks.com/cconf/webservices" xmlns:ns3="http://openmindnetworks.com/engage/"><user><userName>omn</userName><password>omn</password></user><itemId><menuLeafId>mos_esme_in_smpp</menuLeafId><name>MEP-Trans-Reporting-f832b210-92ec-11eb-a8b3-0242ac130003</name></itemId></ns4:itemRequest>
at org.springframework.ws.test.support.AssertionErrors.fail(AssertionErrors.java:50)
at org.springframework.ws.test.support.AssertionErrors.assertTrue(AssertionErrors.java:76)
at org.springframework.ws.test.support.matcher.DiffMatcher.match(DiffMatcher.java:42)
at org.springframework.ws.test.client.WebServiceMessageMatcherAdapter.match(WebServiceMessageMatcherAdapter.java:43)
at org.springframework.ws.test.client.MockSenderConnection.send(MockSenderConnection.java:76)
at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:658)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at com.openmind.primecast.cconfwebservices.impl.CconfClientImpl.deleteItem(CconfClientImpl.java:71)
at com.openmind.primecast.cconfwebservices.CconfClientIntTest.deleteItem(CconfClientIntTest.java:77)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
下面是我的junit测试代码。
@RunWith(SpringRunner.class)
@SpringBootTest(classes = PrimecastApp.class)
public class CconfClientIntTest {
@Autowired
private WingUICredentials wingUICredentials;
@Autowired
private CconfServiceConfiguration cconfServiceConfiguration;
@Autowired
private Jaxb2Marshaller jaxb2Marshaller;
private CconfClientImpl cconfClient;
private MockWebServiceServer mockServer;
@Before
public void init() {
cconfClient = new CconfClientImpl(jaxb2Marshaller, wingUICredentials, cconfServiceConfiguration);
mockServer = MockWebServiceServer.createServer(cconfClient);
}
@Test
public void deleteItem() {
Source expectedRequestPayload = new StringSource("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://openmindnetworks.com/cconf/webservices\"><soapenv:Header/><soapenv:Body><web:deleteItemRequest><user><userName>omn</userName><password>omn</password></user><itemId><menuLeafId>mos_esme_in_smpp</menuLeafId><name>MEP-Trans-Reporting-f832b210-92ec-11eb-a8b3-0242ac130003</name></itemId></web:deleteItemRequest></soapenv:Body></soapenv:Envelope>\n" +
"");
Source responsePayload = new StringSource("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://openmindnetworks.com/cconf/webservices\"><soapenv:Header/><soapenv:Body><web:deleteItemResponse><isError>false</isError></web:deleteItemResponse></soapenv:Body></soapenv:Envelope>");
mockServer.expect(payload(expectedRequestPayload)).andExpect(connectionTo(cconfServiceConfiguration.getServices().getLocation())).andRespond(withPayload(responsePayload));
Result i = cconfClient.deleteItem("f832b210-92ec-11eb-a8b3-0242ac130003");
}
}
下面是调用soapws的webservice客户机类
public class CconfClientImpl extends CconfBaseClient implements CconfClient {
private static final Logger log = LoggerFactory.getLogger(CconfBaseClient.class);
private static final String esmeGroupPrefix = "MEP-Trans-Reporting";
private static final String menuLeafId = "mos_esme_in_smpp";
private WingUICredentials wingUICredentials;
private CconfServiceConfiguration cconfServiceConfiguration;
public CconfClientImpl(Jaxb2Marshaller marshaller, WingUICredentials wingUICredentials,
CconfServiceConfiguration cconfServiceConfiguration) {
this.wingUICredentials = wingUICredentials;
this.cconfServiceConfiguration = cconfServiceConfiguration;
setMarshaller(marshaller);
setUnmarshaller(marshaller);
}
@Override
protected Logger getLogger() {
return log;
}
@Override
public Result deleteItem(String primecastAccountId) {
ItemRequest itemRequest = new ItemRequest();
UserToken userToken = new UserToken();
userToken.setUserName(this.wingUICredentials.getGui().getUsername());
userToken.setPassword(this.wingUICredentials.getGui().getPassword());
itemRequest.setUser(userToken);
ItemId itemId = new ItemId();
itemId.setMenuLeafId(menuLeafId);
itemId.setName(String.join("-", esmeGroupPrefix, primecastAccountId));
itemRequest.setItemId(itemId);
Result result = (Result) getWebServiceTemplate().marshalSendAndReceive(
this.cconfServiceConfiguration.getServices().getLocation(), itemRequest,
new SoapActionCallback(this.cconfServiceConfiguration.getServices().getDeleteItemAction()));
return result;
}
}
itemreques源代码如下
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ItemRequest", propOrder = {
"user",
"itemId"
})
@XmlRootElement
public class ItemRequest {
@XmlElement(required = true)
protected UserToken user;
@XmlElement(required = true)
protected ItemId itemId;
/**
* Gets the value of the user property.
*
* @return
* possible object is
* {@link UserToken }
*
*/
public UserToken getUser() {
return user;
}
/**
* Sets the value of the user property.
*
* @param value
* allowed object is
* {@link UserToken }
*
*/
public void setUser(UserToken value) {
this.user = value;
}
/**
* Gets the value of the itemId property.
*
* @return
* possible object is
* {@link ItemId }
*
*/
public ItemId getItemId() {
return itemId;
}
/**
* Sets the value of the itemId property.
*
* @param value
* allowed object is
* {@link ItemId }
*
*/
public void setItemId(ItemId value) {
this.itemId = value;
}
}
最后,供参考的wsdl文件如下所示。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:sch="http://openmindnetworks.com/cconf/webservices"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://openmindnetworks.com/cconf/webservices" targetNamespace="http://openmindnetworks.com/cconf/webservices">
<wsdl:types>
<schema
xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://openmindnetworks.com/cconf/webservices">
<complexType name="UserToken">
<sequence>
<element name="userName" type="string"/>
<element name="password" type="string"/>
</sequence>
</complexType>
<complexType name="Item">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="values"
type="sch:NameValue" />
</sequence>
</complexType>
<complexType name="NameValueBase">
<sequence>
<element name="name" type="string" />
<element name="value" type="string" maxOccurs="1" minOccurs="0"/>
<element name="description" type="string" maxOccurs="1" minOccurs="0"></element>
</sequence>
</complexType>
<complexType name="NameValue">
<complexContent>
<extension base="sch:NameValueBase">
<sequence>
<element name="rows" type="sch:Row"
maxOccurs="unbounded" minOccurs="0"></element>
</sequence>
</extension>
</complexContent>
</complexType>
<complexType name="StoreItemRequest">
<sequence>
<element name="user" type="tns:UserToken"/>
<element name="itemId" type="tns:ItemId"/>
<element name="item" type="sch:Item"/>
</sequence>
</complexType>
<element name="storeItemRequest" type="tns:StoreItemRequest"/>
<element name="storeItemResponse" type="tns:Result"/>
<element name="deleteItemRequest" type="tns:ItemRequest"/>
<element name="deleteItemResponse" type="tns:Result"/>
<complexType name="ItemId">
<sequence>
<element name="menuLeafId" type="string"/>
<element name="name" type="string"/>
</sequence>
</complexType>
<element name="getItemRequest" type="tns:ItemRequest"/>
<complexType name="Result">
<sequence>
<element name="isError" type="boolean"/>
<element minOccurs="0" name="errorMessage" type="string"/>
</sequence>
</complexType>
<element name="result" type="tns:Result"/>
<complexType name="ItemResponse">
<sequence>
<element name="result" type="tns:Result"/>
<element minOccurs="0" name="item" type="sch:Item"/>
</sequence>
</complexType>
<element name="getItemResponse" type="tns:ItemResponse"/>
<element name="listNamesRequest" type="tns:ListNamesRequest"/>
<complexType name="ListNamesResponse">
<sequence>
<element name="result" type="tns:Result"/>
<element maxOccurs="unbounded" minOccurs="0" name="name" type="string"/>
</sequence>
</complexType>
<element name="listNamesResponse" type="tns:ListNamesResponse"/>
<complexType name="ItemRequest">
<sequence>
<element name="user" type="tns:UserToken"/>
<element name="itemId" type="tns:ItemId"/>
</sequence>
</complexType>
<complexType name="ListNamesRequest">
<sequence>
<element name="user" type="tns:UserToken"/>
<element name="menuLeafId" type="string"/>
</sequence>
</complexType>
<complexType name="Row">
<sequence>
<element name="index" type="int"></element>
<element name="columns" type="sch:NameValueBase"
maxOccurs="unbounded" minOccurs="1"></element>
</sequence>
</complexType>
<element name="getDummyItemWithDescriptionRequest" type="tns:GetDummyItemWithDescriptionRequest" />
<complexType name="GetDummyItemWithDescriptionRequest">
<sequence>
<element name="user" type="sch:UserToken"></element>
<element name="menuLeafId" type="string"></element>
</sequence>
</complexType>
<element name="getDummyItemWithDescriptionResponse" type="tns:ItemResponse" />
</schema>
</wsdl:types>
<wsdl:message name="deleteItemRequest">
<wsdl:part element="tns:deleteItemRequest" name="deleteItemRequest" />
</wsdl:message>
<wsdl:message name="storeItemRequest">
<wsdl:part element="tns:storeItemRequest" name="storeItemRequest" />
</wsdl:message>
<wsdl:message name="getItemRequest">
<wsdl:part element="tns:getItemRequest" name="getItemRequest" />
</wsdl:message>
<wsdl:message name="listNamesRequest">
<wsdl:part element="tns:listNamesRequest" name="listNamesRequest" />
</wsdl:message>
<wsdl:message name="storeItemResponse">
<wsdl:part element="tns:storeItemResponse" name="storeItemResponse" />
</wsdl:message>
<wsdl:message name="listNamesResponse">
<wsdl:part element="tns:listNamesResponse" name="listNamesResponse" />
</wsdl:message>
<wsdl:message name="getItemResponse">
<wsdl:part element="tns:getItemResponse" name="getItemResponse" />
</wsdl:message>
<wsdl:message name="deleteItemResponse">
<wsdl:part element="tns:deleteItemResponse" name="deleteItemResponse" />
</wsdl:message>
<wsdl:message name="getDummyItemWithDescriptionRequest">
<wsdl:part name="getDummyItemWithDescriptionRequest"
element="sch:getDummyItemWithDescriptionRequest"></wsdl:part>
</wsdl:message>
<wsdl:message name="getDummyItemWithDescriptionResponse">
<wsdl:part name="getDummyItemWithDescriptionResponse"
element="tns:getDummyItemWithDescriptionResponse"></wsdl:part>
</wsdl:message>
<wsdl:portType name="CconfService">
<wsdl:operation name="deleteItem">
<wsdl:input message="tns:deleteItemRequest" name="deleteItemRequest" />
<wsdl:output message="tns:deleteItemResponse" name="deleteItemResponse" />
</wsdl:operation>
<wsdl:operation name="storeItem">
<wsdl:input message="tns:storeItemRequest" name="storeItemRequest" />
<wsdl:output message="tns:storeItemResponse" name="storeItemResponse" />
</wsdl:operation>
<wsdl:operation name="getItem">
<wsdl:input message="tns:getItemRequest" name="getItemRequest" />
<wsdl:output message="tns:getItemResponse" name="getItemResponse" />
</wsdl:operation>
<wsdl:operation name="listNames">
<wsdl:input message="tns:listNamesRequest" name="listNamesRequest" />
<wsdl:output message="tns:listNamesResponse" name="listNamesResponse" />
</wsdl:operation>
<wsdl:operation name="getDummyItemWithDescription">
<wsdl:input message="tns:getDummyItemWithDescriptionRequest" name="getDummyItemWithDescriptionRequest" />
<wsdl:output message="tns:getDummyItemWithDescriptionResponse" name="getDummyItemWithDescriptionResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CconfServiceSoap11" type="tns:CconfService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="deleteItem">
<soap:operation soapAction=""/>
<wsdl:input name="deleteItemRequest">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="deleteItemResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="storeItem">
<soap:operation soapAction=""/>
<wsdl:input name="storeItemRequest">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="storeItemResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getItem">
<soap:operation soapAction=""/>
<wsdl:input name="getItemRequest">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getItemResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="listNames">
<soap:operation soapAction=""/>
<wsdl:input name="listNamesRequest">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="listNamesResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getDummyItemWithDescription">
<soap:operation
soapAction="" />
<wsdl:input name="getDummyItemWithDescriptionRequest">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getDummyItemWithDescriptionResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CconfServiceService">
<wsdl:port binding="tns:CconfServiceSoap11" name="CconfServiceSoap11">
<soap:address location="http://localhost:8090/Wing/services" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
如果你能提供错误的信息,我将不胜感激。
谢谢您
暂无答案!
目前还没有任何答案,快来回答吧!