I ve try to implement integration tests for a working application (spring, hibernate, soap, cxf). I build an SOAP-XML by hand and handle it to my endpoint. Like this:
private Source createRequest(String domainName, String email, String userId, String password) {
String content = "";
content += "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sup="[...]">";
content += " <soapenv:Header/>";
content += " <soapenv:Body>";
content += " <sup:RegisterRequest>";
content += " <sup:domain>" + domainName + "</sup:domain>";
content += " <sup:email>" + email + "</sup:email>";
content += " <sup:userId>" + userId + "</sup:userId>";
content += " <sup:password>" + password + "</sup:password>";
content += " </sup:RegisterRequest>";
content += " </soapenv:Body>";
content += "</soapenv:Envelope>";
return new StringSource(content);
}
In my test I handle it to my endpoint like this:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "../../WEB-INF/applicationContext.xml", "../../WEB-INF/test.xml" })
@Transactional
public class TestRegisterEndpoint extends AbstractTransactionalJUnit4SpringContextTests {
@Resource
private RegisterEndpoint registerEndpoint;
@Test
public void registerUserFailsForUnexistantDomain() throws Exception {
Source result = registerEndpoint.invoke(createRequest("unexistant_domain", "test@test.de", "test@test.de", "myPassword1"));
}
}
But when I try to run the test I get an exception "Cannot find the declaration of element soapenv:Envelope .".
org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: null; nested exception is javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element soapenv:Envelope .]
at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:75)
[...]
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element soapenv:Envelope .]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
[...]
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element soapenv:Envelope .
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
I would guess I have to define the "soapenv" namespace somewhere where I havn t it. But if so, I don t know where.
Start of "applicationContext.xml":
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
Start of "test.xml":
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
How can I get rid of the exception?