Upgrading tests.
This commit is contained in:
@@ -16,20 +16,23 @@
|
||||
|
||||
package org.springframework.ws;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class AbstractWebServiceMessageFactoryTestCase extends TestCase {
|
||||
public abstract class AbstractWebServiceMessageFactoryTestCase {
|
||||
|
||||
protected WebServiceMessageFactory messageFactory;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
messageFactory = createMessageFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEmptyMessage() throws Exception {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
assertNotNull("WebServiceMessage is null", message);
|
||||
Assert.assertNotNull("WebServiceMessage is null", message);
|
||||
}
|
||||
|
||||
protected abstract WebServiceMessageFactory createMessageFactory() throws Exception;
|
||||
|
||||
@@ -16,18 +16,21 @@
|
||||
|
||||
package org.springframework.ws.server.endpoint.mapping;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
public class SimpleMethodEndpointMappingTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SimpleMethodEndpointMappingTest {
|
||||
|
||||
private SimpleMethodEndpointMapping mapping;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapping = new SimpleMethodEndpointMapping();
|
||||
mapping.setMethodPrefix("prefix");
|
||||
mapping.setMethodSuffix("Suffix");
|
||||
@@ -36,24 +39,27 @@ public class SimpleMethodEndpointMappingTest extends TestCase {
|
||||
mapping.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistration() throws Exception {
|
||||
assertNotNull("Endpoint not registered", mapping.lookupEndpoint("MyRequest"));
|
||||
assertNull("Endpoint registered", mapping.lookupEndpoint("request"));
|
||||
Assert.assertNotNull("Endpoint not registered", mapping.lookupEndpoint("MyRequest"));
|
||||
Assert.assertNull("Endpoint registered", mapping.lookupEndpoint("request"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLookupKeyForMessageNoNamespace() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage("<MyRequest/>");
|
||||
MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
String result = mapping.getLookupKeyForMessage(messageContext);
|
||||
assertEquals("Invalid lookup key", "MyRequest", result);
|
||||
Assert.assertEquals("Invalid lookup key", "MyRequest", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLookupKeyForMessageNamespace() throws Exception {
|
||||
MockWebServiceMessage request =
|
||||
new MockWebServiceMessage("<MyRequest xmlns='http://springframework.org/spring-ws/' />");
|
||||
MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
String result = mapping.getLookupKeyForMessage(messageContext);
|
||||
assertEquals("Invalid lookup key", "MyRequest", result);
|
||||
Assert.assertEquals("Invalid lookup key", "MyRequest", result);
|
||||
}
|
||||
|
||||
private static class MyBean {
|
||||
|
||||
@@ -18,9 +18,6 @@ package org.springframework.ws.server.endpoint.mapping;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
@@ -28,35 +25,48 @@ import org.springframework.ws.transport.WebServiceConnection;
|
||||
import org.springframework.ws.transport.context.DefaultTransportContext;
|
||||
import org.springframework.ws.transport.context.TransportContextHolder;
|
||||
|
||||
public class UriEndpointMappingTest extends TestCase {
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class UriEndpointMappingTest {
|
||||
|
||||
private UriEndpointMapping mapping;
|
||||
|
||||
private MessageContext context;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapping = new UriEndpointMapping();
|
||||
context = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
}
|
||||
|
||||
public void testGetLookupKeyForMessage() throws Exception {
|
||||
MockControl control = MockControl.createControl(WebServiceConnection.class);
|
||||
WebServiceConnection connectionMock = (WebServiceConnection) control.getMock();
|
||||
TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));
|
||||
|
||||
URI uri = new URI("jms://exampleQueue");
|
||||
control.expectAndReturn(connectionMock.getUri(), uri);
|
||||
control.replay();
|
||||
|
||||
assertEquals("Invalid lookup key", uri.toString(), mapping.getLookupKeyForMessage(context));
|
||||
|
||||
control.verify();
|
||||
@After
|
||||
public void clearContext() {
|
||||
TransportContextHolder.setTransportContext(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLookupKeyForMessage() throws Exception {
|
||||
WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
|
||||
TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));
|
||||
|
||||
URI uri = new URI("jms://exampleQueue");
|
||||
expect(connectionMock.getUri()).andReturn(uri);
|
||||
|
||||
replay(connectionMock);
|
||||
|
||||
Assert.assertEquals("Invalid lookup key", uri.toString(), mapping.getLookupKeyForMessage(context));
|
||||
|
||||
verify(connectionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateLookupKey() throws Exception {
|
||||
assertTrue("URI not valid", mapping.validateLookupKey("http://example.com/services"));
|
||||
assertFalse("URI not valid", mapping.validateLookupKey("some string"));
|
||||
Assert.assertTrue("URI not valid", mapping.validateLookupKey("http://example.com/services"));
|
||||
Assert.assertFalse("URI not valid", mapping.validateLookupKey("some string"));
|
||||
}
|
||||
}
|
||||
@@ -16,21 +16,25 @@
|
||||
|
||||
package org.springframework.ws.server.endpoint.mapping;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
|
||||
public class XPathPayloadEndpointMappingTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class XPathPayloadEndpointMappingTest {
|
||||
|
||||
private XPathPayloadEndpointMapping mapping;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapping = new XPathPayloadEndpointMapping();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLookupKeyForMessage() throws Exception {
|
||||
mapping.setExpression("/root/text()");
|
||||
mapping.afterPropertiesSet();
|
||||
@@ -39,7 +43,7 @@ public class XPathPayloadEndpointMappingTest extends TestCase {
|
||||
MessageContext context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
|
||||
String result = mapping.getLookupKeyForMessage(context);
|
||||
assertNotNull("mapping returns null", result);
|
||||
assertEquals("mapping returns invalid result", "value", result);
|
||||
Assert.assertNotNull("mapping returns null", result);
|
||||
Assert.assertEquals("mapping returns invalid result", "value", result);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,15 +28,18 @@ import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
public class PayloadRootUtilsTest extends TestCase {
|
||||
@SuppressWarnings("Since15")
|
||||
public class PayloadRootUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetQNameForDomSource() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
@@ -45,46 +48,50 @@ public class PayloadRootUtilsTest extends TestCase {
|
||||
document.appendChild(element);
|
||||
Source source = new DOMSource(document);
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
assertNotNull("getQNameForNode returns null", qName);
|
||||
assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQNameForStaxSource() throws Exception {
|
||||
String contents = "<prefix:localname xmlns:prefix='namespace'/>";
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(contents));
|
||||
Source source = new StaxSource(streamReader);
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
assertNotNull("getQNameForNode returns null", qName);
|
||||
assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQNameForStreamSource() throws Exception {
|
||||
String contents = "<prefix:localname xmlns:prefix='namespace'/>";
|
||||
Source source = new StreamSource(new StringReader(contents));
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
assertNotNull("getQNameForNode returns null", qName);
|
||||
assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQNameForSaxSource() throws Exception {
|
||||
String contents = "<prefix:localname xmlns:prefix='namespace'/>";
|
||||
Source source = new SAXSource(new InputSource(new StringReader(contents)));
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(source, TransformerFactory.newInstance());
|
||||
assertNotNull("getQNameForNode returns null", qName);
|
||||
assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNullSource() throws Exception {
|
||||
QName qName = PayloadRootUtils.getPayloadRootQName(null, TransformerFactory.newInstance());
|
||||
assertNull("Qname returned", qName);
|
||||
Assert.assertNull("Qname returned", qName);
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,16 @@ package org.springframework.ws.soap;
|
||||
import java.util.Locale;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoapBodyTestCase extends AbstractSoapElementTestCase {
|
||||
|
||||
@@ -38,12 +42,14 @@ public abstract class AbstractSoapBodyTestCase extends AbstractSoapElementTestCa
|
||||
|
||||
protected abstract SoapBody createSoapBody() throws Exception;
|
||||
|
||||
@Test
|
||||
public void testPayload() throws Exception {
|
||||
String payload = "<payload xmlns='http://www.springframework.org' />";
|
||||
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
|
||||
assertPayloadEqual(payload);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPayloadResultTwice() throws Exception {
|
||||
String payload = "<payload xmlns='http://www.springframework.org' />";
|
||||
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
|
||||
@@ -55,10 +61,12 @@ public abstract class AbstractSoapBodyTestCase extends AbstractSoapElementTestCa
|
||||
assertEquals("Invalid amount of child nodes", 1, children.getLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFault() throws Exception {
|
||||
assertFalse("body has fault", soapBody.hasFault());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultWithExistingPayload() throws Exception {
|
||||
StringSource contents = new StringSource("<payload xmlns='http://www.springframework.org' />");
|
||||
transformer.transform(contents, soapBody.getPayloadResult());
|
||||
|
||||
@@ -21,16 +21,18 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class AbstractSoapElementTestCase extends XMLTestCase {
|
||||
public abstract class AbstractSoapElementTestCase {
|
||||
|
||||
private SoapElement soapElement;
|
||||
|
||||
protected Transformer transformer;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
soapElement = createSoapElement();
|
||||
@@ -38,21 +40,24 @@ public abstract class AbstractSoapElementTestCase extends XMLTestCase {
|
||||
|
||||
protected abstract SoapElement createSoapElement() throws Exception;
|
||||
|
||||
@Test
|
||||
public void testAttributes() throws Exception {
|
||||
QName name = new QName("http://springframework.org/spring-ws", "attribute");
|
||||
String value = "value";
|
||||
soapElement.addAttribute(name, value);
|
||||
assertEquals("Invalid attribute value", value, soapElement.getAttributeValue(name));
|
||||
Iterator allAttributes = soapElement.getAllAttributes();
|
||||
assertTrue("Iterator is empty", allAttributes.hasNext());
|
||||
Assert.assertEquals("Invalid attribute value", value, soapElement.getAttributeValue(name));
|
||||
Iterator<QName> allAttributes = soapElement.getAllAttributes();
|
||||
Assert.assertTrue("Iterator is empty", allAttributes.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNamespaceDeclaration() throws Exception {
|
||||
String prefix = "p";
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
soapElement.addNamespaceDeclaration(prefix, namespace);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDefaultNamespaceDeclaration() throws Exception {
|
||||
String prefix = "";
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.ws.soap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public abstract class AbstractSoapEnvelopeTestCase extends AbstractSoapElementTestCase {
|
||||
|
||||
protected SoapEnvelope soapEnvelope;
|
||||
@@ -28,11 +32,13 @@ public abstract class AbstractSoapEnvelopeTestCase extends AbstractSoapElementTe
|
||||
|
||||
protected abstract SoapEnvelope createSoapEnvelope() throws Exception;
|
||||
|
||||
@Test
|
||||
public void testGetHeader() throws Exception {
|
||||
SoapHeader header = soapEnvelope.getHeader();
|
||||
assertNotNull("No header returned", header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBody() throws Exception {
|
||||
SoapBody body = soapEnvelope.getBody();
|
||||
assertNotNull("No body returned", body);
|
||||
|
||||
@@ -22,6 +22,11 @@ import javax.xml.namespace.QName;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTestCase {
|
||||
|
||||
protected SoapHeader soapHeader;
|
||||
@@ -38,12 +43,13 @@ public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTest
|
||||
|
||||
protected abstract SoapHeader createSoapHeader() throws Exception;
|
||||
|
||||
@Test
|
||||
public void testAddHeaderElement() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName", PREFIX);
|
||||
SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName);
|
||||
assertNotNull("No SoapHeaderElement returned", headerElement);
|
||||
assertEquals("Invalid qName for element", qName, headerElement.getName());
|
||||
Iterator iterator = soapHeader.examineAllHeaderElements();
|
||||
Iterator<SoapHeaderElement> iterator = soapHeader.examineAllHeaderElements();
|
||||
assertTrue("SoapHeader has no elements", iterator.hasNext());
|
||||
String payload = "<content xmlns='http://www.springframework.org'/>";
|
||||
transformer.transform(new StringSource(payload), headerElement.getResult());
|
||||
@@ -51,15 +57,17 @@ public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTest
|
||||
"<spring:localName xmlns:spring='http://www.springframework.org'><spring:content/></spring:localName>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveHeaderElement() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName", PREFIX);
|
||||
soapHeader.removeHeaderElement(qName);
|
||||
soapHeader.addHeaderElement(qName);
|
||||
soapHeader.removeHeaderElement(qName);
|
||||
Iterator iterator = soapHeader.examineAllHeaderElements();
|
||||
Iterator<SoapHeaderElement> iterator = soapHeader.examineAllHeaderElements();
|
||||
assertFalse("SoapHeader has elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineAllHeaderElement() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName", PREFIX);
|
||||
SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName);
|
||||
@@ -67,10 +75,10 @@ public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTest
|
||||
assertNotNull("No SoapHeaderElement returned", headerElement);
|
||||
String payload = "<content xmlns='http://www.springframework.org'/>";
|
||||
transformer.transform(new StringSource(payload), headerElement.getResult());
|
||||
Iterator iterator = soapHeader.examineAllHeaderElements();
|
||||
Iterator<SoapHeaderElement> iterator = soapHeader.examineAllHeaderElements();
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
assertTrue("header element iterator has no elements", iterator.hasNext());
|
||||
headerElement = (SoapHeaderElement) iterator.next();
|
||||
headerElement = iterator.next();
|
||||
assertEquals("Invalid qName for element", qName, headerElement.getName());
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(headerElement.getSource(), result);
|
||||
@@ -80,6 +88,7 @@ public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTest
|
||||
assertFalse("header element iterator has too many elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineMustUnderstandHeaderElements() throws Exception {
|
||||
QName qName1 = new QName(NAMESPACE, "localName1", PREFIX);
|
||||
SoapHeaderElement headerElement1 = soapHeader.addHeaderElement(qName1);
|
||||
@@ -89,23 +98,24 @@ public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTest
|
||||
SoapHeaderElement headerElement2 = soapHeader.addHeaderElement(qName2);
|
||||
headerElement2.setMustUnderstand(true);
|
||||
headerElement2.setActorOrRole("role2");
|
||||
Iterator iterator = soapHeader.examineMustUnderstandHeaderElements("role1");
|
||||
Iterator<SoapHeaderElement> iterator = soapHeader.examineMustUnderstandHeaderElements("role1");
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
assertTrue("header element iterator has no elements", iterator.hasNext());
|
||||
SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
|
||||
SoapHeaderElement headerElement = iterator.next();
|
||||
assertEquals("Invalid name on header element", qName1, headerElement.getName());
|
||||
assertTrue("MustUnderstand not set on header element", headerElement.getMustUnderstand());
|
||||
assertEquals("Invalid role on header element", "role1", headerElement.getActorOrRole());
|
||||
assertFalse("header element iterator has too many elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResult() throws Exception {
|
||||
String content =
|
||||
"<spring:localName xmlns:spring='http://www.springframework.org'><spring:content/></spring:localName>";
|
||||
transformer.transform(new StringSource(content), soapHeader.getResult());
|
||||
Iterator iterator = soapHeader.examineAllHeaderElements();
|
||||
Iterator<SoapHeaderElement> iterator = soapHeader.examineAllHeaderElements();
|
||||
assertTrue("Header has no children", iterator.hasNext());
|
||||
SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
|
||||
SoapHeaderElement headerElement = iterator.next();
|
||||
assertFalse("Header has too many children", iterator.hasNext());
|
||||
assertHeaderElementEqual(headerElement, content);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,16 +19,24 @@ package org.springframework.ws.soap;
|
||||
import org.springframework.ws.AbstractWebServiceMessageFactoryTestCase;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class AbstractSoapMessageFactoryTestCase extends AbstractWebServiceMessageFactoryTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreateEmptySoapMessage() throws Exception {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public abstract void testCreateSoapMessageNoAttachment() throws Exception;
|
||||
|
||||
@Test
|
||||
public abstract void testCreateSoapMessageSwA() throws Exception;
|
||||
|
||||
@Test
|
||||
public abstract void testCreateSoapMessageMtom() throws Exception;
|
||||
}
|
||||
|
||||
@@ -18,22 +18,25 @@ package org.springframework.ws.soap.addressing.messageid;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RandomGuidMessageIdStrategyTest extends TestCase {
|
||||
public class RandomGuidMessageIdStrategyTest {
|
||||
|
||||
private MessageIdStrategy strategy;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
strategy = new RandomGuidMessageIdStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrategy() {
|
||||
URI messageId1 = strategy.newMessageId(null);
|
||||
assertNotNull("Empty messageId", messageId1);
|
||||
Assert.assertNotNull("Empty messageId", messageId1);
|
||||
URI messageId2 = strategy.newMessageId(null);
|
||||
assertNotNull("Empty messageId", messageId2);
|
||||
assertFalse("Equal messageIds", messageId1.equals(messageId2));
|
||||
Assert.assertNotNull("Empty messageId", messageId2);
|
||||
Assert.assertFalse("Equal messageIds", messageId1.equals(messageId2));
|
||||
}
|
||||
}
|
||||
@@ -18,22 +18,25 @@ package org.springframework.ws.soap.addressing.messageid;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UuidMessageIdStrategyTest extends TestCase {
|
||||
public class UuidMessageIdStrategyTest {
|
||||
|
||||
private MessageIdStrategy strategy;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
strategy = new UuidMessageIdStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrategy() {
|
||||
URI messageId1 = strategy.newMessageId(null);
|
||||
assertNotNull("Empty messageId", messageId1);
|
||||
Assert.assertNotNull("Empty messageId", messageId1);
|
||||
URI messageId2 = strategy.newMessageId(null);
|
||||
assertNotNull("Empty messageId", messageId2);
|
||||
assertFalse("Equal messageIds", messageId1.equals(messageId2));
|
||||
Assert.assertNotNull("Empty messageId", messageId2);
|
||||
Assert.assertFalse("Equal messageIds", messageId1.equals(messageId2));
|
||||
}
|
||||
}
|
||||
@@ -16,14 +16,15 @@
|
||||
|
||||
package org.springframework.ws.soap.axiom;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.soap11.AbstractSoap11BodyTestCase;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AxiomSoap11BodyTest extends AbstractSoap11BodyTestCase {
|
||||
|
||||
@Override
|
||||
@@ -33,6 +34,7 @@ public class AxiomSoap11BodyTest extends AbstractSoap11BodyTestCase {
|
||||
return axiomSoapMessage.getSoapBody();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadNoCaching() throws Exception {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
messageFactory.setPayloadCaching(false);
|
||||
|
||||
@@ -22,9 +22,6 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.soap.soap11.AbstractSoap11MessageFactoryTestCase;
|
||||
@@ -32,6 +29,13 @@ import org.springframework.ws.transport.MockTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryTestCase {
|
||||
|
||||
private Transformer transformer;
|
||||
@@ -45,6 +49,7 @@ public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryT
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCharsetEncoding() {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
|
||||
@@ -53,6 +58,7 @@ public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryT
|
||||
assertEquals("Invalid charset", "utf-8", messageFactory.getCharSetEncoding("application/xop+xml;type=\"text/xml; charset=utf-8\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepetitiveReadCaching() throws Exception {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
messageFactory.setPayloadCaching(true);
|
||||
@@ -69,6 +75,7 @@ public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryT
|
||||
transformer.transform(message.getPayloadSource(), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepetitiveReadNoCaching() throws Exception {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
messageFactory.setPayloadCaching(false);
|
||||
@@ -94,6 +101,7 @@ public class AxiomSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryT
|
||||
/**
|
||||
* See http://jira.springframework.org/browse/SWS-502
|
||||
*/
|
||||
@Test
|
||||
public void testSWS502() throws Exception {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
messageFactory.setPayloadCaching(false);
|
||||
|
||||
@@ -16,14 +16,15 @@
|
||||
|
||||
package org.springframework.ws.soap.axiom;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.soap12.AbstractSoap12BodyTestCase;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AxiomSoap12BodyTest extends AbstractSoap12BodyTestCase {
|
||||
|
||||
@Override
|
||||
@@ -33,6 +34,7 @@ public class AxiomSoap12BodyTest extends AbstractSoap12BodyTestCase {
|
||||
return axiomSoapMessage.getSoapBody();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadNoCaching() throws Exception {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
messageFactory.setPayloadCaching(false);
|
||||
|
||||
@@ -20,14 +20,17 @@ import java.io.StringReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.axiom.soap.SOAPMessage;
|
||||
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
|
||||
|
||||
import org.springframework.ws.soap.SoapFault;
|
||||
import org.springframework.ws.soap.SoapFaultDetail;
|
||||
|
||||
public class AxiomSoapFaultDetailTest extends TestCase {
|
||||
import org.apache.axiom.soap.SOAPMessage;
|
||||
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings("Since15")
|
||||
public class AxiomSoapFaultDetailTest {
|
||||
|
||||
private static final String FAILING_FAULT =
|
||||
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
|
||||
@@ -53,8 +56,8 @@ public class AxiomSoapFaultDetailTest extends TestCase {
|
||||
|
||||
private AxiomSoapMessage succeedingMessage;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(FAILING_FAULT));
|
||||
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser);
|
||||
SOAPMessage soapMessage = builder.getSoapMessage();
|
||||
@@ -69,22 +72,24 @@ public class AxiomSoapFaultDetailTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDetailEntriesWorksWithWhitespaceNodes() throws Exception {
|
||||
SoapFault fault = failingMessage.getSoapBody().getFault();
|
||||
assertNotNull("Fault is null", fault);
|
||||
assertNotNull("Fault detail is null", fault.getFaultDetail());
|
||||
Assert.assertNotNull("Fault is null", fault);
|
||||
Assert.assertNotNull("Fault detail is null", fault.getFaultDetail());
|
||||
SoapFaultDetail detail = fault.getFaultDetail();
|
||||
assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
|
||||
Assert.assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
|
||||
detail.getDetailEntries().next();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDetailEntriesWorksWithoutWhitespaceNodes() throws Exception {
|
||||
SoapFault fault = succeedingMessage.getSoapBody().getFault();
|
||||
assertNotNull("Fault is null", fault);
|
||||
assertNotNull("Fault detail is null", fault.getFaultDetail());
|
||||
Assert.assertNotNull("Fault is null", fault);
|
||||
Assert.assertNotNull("Fault detail is null", fault.getFaultDetail());
|
||||
SoapFaultDetail detail = fault.getFaultDetail();
|
||||
assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
|
||||
Assert.assertTrue("No next detail entry present", detail.getDetailEntries().hasNext());
|
||||
detail.getDetailEntries().next();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,11 @@ import javax.xml.soap.SOAPMessage;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.soap11.AbstractSoap11BodyTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class SaajSoap11BodyTest extends AbstractSoap11BodyTestCase {
|
||||
|
||||
@Override
|
||||
@@ -34,6 +39,7 @@ public class SaajSoap11BodyTest extends AbstractSoap11BodyTestCase {
|
||||
return new SaajSoap11Body(saajMessage.getSOAPPart().getEnvelope().getBody(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLangAttributeOnSoap11FaultString() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage saajMessage = messageFactory.createMessage();
|
||||
|
||||
@@ -29,10 +29,13 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public class SaajContentHandlerTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SaajContentHandlerTest {
|
||||
|
||||
private SaajContentHandler handler;
|
||||
|
||||
@@ -40,8 +43,8 @@ public class SaajContentHandlerTest extends TestCase {
|
||||
|
||||
private SOAPEnvelope envelope;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
envelope = message.getSOAPPart().getEnvelope();
|
||||
@@ -49,6 +52,7 @@ public class SaajContentHandlerTest extends TestCase {
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandler() throws Exception {
|
||||
String content = "<Root xmlns='http://springframework.org/spring-ws/1' " +
|
||||
"xmlns:child='http://springframework.org/spring-ws/2'>" +
|
||||
@@ -57,15 +61,15 @@ public class SaajContentHandlerTest extends TestCase {
|
||||
Result result = new SAXResult(handler);
|
||||
transformer.transform(source, result);
|
||||
Name rootName = envelope.createName("Root", "", "http://springframework.org/spring-ws/1");
|
||||
Iterator iterator = envelope.getBody().getChildElements(rootName);
|
||||
assertTrue("No child found", iterator.hasNext());
|
||||
Iterator<?> iterator = envelope.getBody().getChildElements(rootName);
|
||||
Assert.assertTrue("No child found", iterator.hasNext());
|
||||
SOAPBodyElement rootElement = (SOAPBodyElement) iterator.next();
|
||||
Name childName = envelope.createName("Child", "child", "http://springframework.org/spring-ws/2");
|
||||
iterator = rootElement.getChildElements(childName);
|
||||
assertTrue("No child found", iterator.hasNext());
|
||||
Assert.assertTrue("No child found", iterator.hasNext());
|
||||
SOAPElement childElement = (SOAPElement) iterator.next();
|
||||
assertEquals("Invalid contents", "Content", childElement.getValue());
|
||||
Assert.assertEquals("Invalid contents", "Content", childElement.getValue());
|
||||
Name attributeName = envelope.createName("attribute");
|
||||
assertEquals("Invalid attribute value", "value", childElement.getAttributeValue(attributeName));
|
||||
Assert.assertEquals("Invalid attribute value", "value", childElement.getAttributeValue(attributeName));
|
||||
}
|
||||
}
|
||||
@@ -36,24 +36,25 @@ import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.ws.soap.soap12.Soap12Fault;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SoapMessageDispatcherTest extends TestCase {
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SoapMessageDispatcherTest {
|
||||
|
||||
private SoapMessageDispatcher dispatcher;
|
||||
|
||||
private MockControl interceptorControl;
|
||||
|
||||
private SoapEndpointInterceptor interceptorMock;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
interceptorControl = MockControl.createControl(SoapEndpointInterceptor.class);
|
||||
interceptorMock = (SoapEndpointInterceptor) interceptorControl.getMock();
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
interceptorMock = createMock(SoapEndpointInterceptor.class);
|
||||
dispatcher = new SoapMessageDispatcher();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMustUnderstandHeadersUnderstoodSoap11() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
@@ -63,19 +64,20 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
header.setMustUnderstand(true);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
interceptorControl.replay();
|
||||
expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true);
|
||||
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain =
|
||||
new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[]{interceptorMock});
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertTrue("Header not understood", result);
|
||||
interceptorControl.verify();
|
||||
Assert.assertTrue("Header not understood", result);
|
||||
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMustUnderstandHeadersUnderstoodSoap12() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
@@ -85,19 +87,20 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
header.setRole(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
interceptorControl.replay();
|
||||
expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true);
|
||||
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain =
|
||||
new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[]{interceptorMock});
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertTrue("Header not understood", result);
|
||||
interceptorControl.verify();
|
||||
Assert.assertTrue("Header not understood", result);
|
||||
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMustUnderstandHeadersNotUnderstoodSoap11() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
@@ -107,28 +110,29 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
header.setMustUnderstand(true);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(false);
|
||||
interceptorControl.replay();
|
||||
expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(false);
|
||||
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain =
|
||||
new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[]{interceptorMock});
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertFalse("Header understood", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertFalse("Header understood", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapBody responseBody = ((SoapMessage) context.getResponse()).getSoapBody();
|
||||
assertTrue("Response body has no fault", responseBody.hasFault());
|
||||
Assert.assertTrue("Response body has no fault", responseBody.hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) responseBody.getFault();
|
||||
assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "MustUnderstand"),
|
||||
Assert.assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "MustUnderstand"),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string", SoapMessageDispatcher.DEFAULT_MUST_UNDERSTAND_FAULT_STRING,
|
||||
Assert.assertEquals("Invalid fault string", SoapMessageDispatcher.DEFAULT_MUST_UNDERSTAND_FAULT_STRING,
|
||||
fault.getFaultStringOrReason());
|
||||
assertEquals("Invalid fault string locale", Locale.ENGLISH, fault.getFaultStringLocale());
|
||||
interceptorControl.verify();
|
||||
Assert.assertEquals("Invalid fault string locale", Locale.ENGLISH, fault.getFaultStringLocale());
|
||||
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMustUnderstandHeadersNotUnderstoodSoap12() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
@@ -138,34 +142,35 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
header.setRole(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(false);
|
||||
interceptorControl.replay();
|
||||
expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(false);
|
||||
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain =
|
||||
new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[]{interceptorMock});
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertFalse("Header understood", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertFalse("Header understood", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
SoapBody responseBody = response.getSoapBody();
|
||||
assertTrue("Response body has no fault", responseBody.hasFault());
|
||||
Assert.assertTrue("Response body has no fault", responseBody.hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) responseBody.getFault();
|
||||
assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "MustUnderstand"),
|
||||
Assert.assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "MustUnderstand"),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string", SoapMessageDispatcher.DEFAULT_MUST_UNDERSTAND_FAULT_STRING,
|
||||
Assert.assertEquals("Invalid fault string", SoapMessageDispatcher.DEFAULT_MUST_UNDERSTAND_FAULT_STRING,
|
||||
fault.getFaultReasonText(Locale.ENGLISH));
|
||||
SoapHeader responseHeader = response.getSoapHeader();
|
||||
Iterator iterator = responseHeader.examineAllHeaderElements();
|
||||
assertTrue("Response header has no elements", iterator.hasNext());
|
||||
SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next();
|
||||
assertEquals("No NotUnderstood header", new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "NotUnderstood"),
|
||||
headerElement.getName());
|
||||
interceptorControl.verify();
|
||||
Iterator<SoapHeaderElement> iterator = responseHeader.examineAllHeaderElements();
|
||||
Assert.assertTrue("Response header has no elements", iterator.hasNext());
|
||||
SoapHeaderElement headerElement = iterator.next();
|
||||
Assert.assertEquals("No NotUnderstood header",
|
||||
new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "NotUnderstood"), headerElement.getName());
|
||||
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMustUnderstandHeadersForActorSoap11() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
@@ -176,19 +181,20 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
header.setMustUnderstand(true);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
interceptorControl.replay();
|
||||
expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true);
|
||||
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(),
|
||||
new SoapEndpointInterceptor[]{interceptorMock}, new String[]{headerActor}, true);
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertTrue("actor-specific header not understood", result);
|
||||
interceptorControl.verify();
|
||||
Assert.assertTrue("actor-specific header not understood", result);
|
||||
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMustUnderstandHeadersForRoleSoap12() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
@@ -199,35 +205,37 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
header.setMustUnderstand(true);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorMock.understands(null);
|
||||
interceptorControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
interceptorControl.setReturnValue(true);
|
||||
interceptorControl.replay();
|
||||
expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true);
|
||||
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(),
|
||||
new SoapEndpointInterceptor[]{interceptorMock}, new String[]{headerRole}, true);
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertTrue("role-specific header not understood", result);
|
||||
interceptorControl.verify();
|
||||
Assert.assertTrue("role-specific header not understood", result);
|
||||
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessNoHeader() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
request.getSOAPHeader().detachNode();
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorControl.replay();
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(),
|
||||
new SoapEndpointInterceptor[]{interceptorMock}, new String[]{"role"}, true);
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertTrue("Invalid result", result);
|
||||
interceptorControl.verify();
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMustUnderstandHeadersNoInterceptors() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SOAPMessage request = messageFactory.createMessage();
|
||||
@@ -237,13 +245,13 @@ public class SoapMessageDispatcherTest extends TestCase {
|
||||
header.setMustUnderstand(true);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);
|
||||
interceptorControl.replay();
|
||||
replay(interceptorMock);
|
||||
|
||||
SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), null);
|
||||
|
||||
boolean result = dispatcher.handleRequest(chain, context);
|
||||
assertFalse("Header understood", result);
|
||||
interceptorControl.verify();
|
||||
Assert.assertFalse("Header understood", result);
|
||||
verify(interceptorMock);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
@@ -40,14 +39,18 @@ import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
public class FaultCreatingValidatingMarshallingPayloadEndpointTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FaultCreatingValidatingMarshallingPayloadEndpointTest {
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
private ResourceBundleMessageSource messageSource;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.messageSource = new ResourceBundleMessageSource();
|
||||
this.messageSource.setBasename("org.springframework.ws.soap.server.endpoint.messages");
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
@@ -57,6 +60,7 @@ public class FaultCreatingValidatingMarshallingPayloadEndpointTest extends TestC
|
||||
new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationIncorrect() throws Exception {
|
||||
Person p = new Person("", -1);
|
||||
PersonMarshaller marshaller = new PersonMarshaller(p);
|
||||
@@ -66,7 +70,7 @@ public class FaultCreatingValidatingMarshallingPayloadEndpointTest extends TestC
|
||||
|
||||
@Override
|
||||
protected Object invokeInternal(Object requestObject) throws Exception {
|
||||
fail("No expected");
|
||||
Assert.fail("No expected");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -78,27 +82,28 @@ public class FaultCreatingValidatingMarshallingPayloadEndpointTest extends TestC
|
||||
endpoint.invoke(messageContext);
|
||||
|
||||
SOAPMessage response = ((SaajSoapMessage) messageContext.getResponse()).getSaajMessage();
|
||||
assertTrue("Response has no fault", response.getSOAPBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSOAPBody().hasFault());
|
||||
SOAPFault fault = response.getSOAPBody().getFault();
|
||||
assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "Client"),
|
||||
Assert.assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "Client"),
|
||||
fault.getFaultCodeAsQName());
|
||||
assertEquals("Invalid fault string", endpoint.getFaultStringOrReason(), fault.getFaultString());
|
||||
Assert.assertEquals("Invalid fault string", endpoint.getFaultStringOrReason(), fault.getFaultString());
|
||||
Detail detail = fault.getDetail();
|
||||
assertNotNull("No detail", detail);
|
||||
Iterator iterator = detail.getDetailEntries();
|
||||
assertTrue("No detail entry", iterator.hasNext());
|
||||
Assert.assertNotNull("No detail", detail);
|
||||
Iterator<?> iterator = detail.getDetailEntries();
|
||||
Assert.assertTrue("No detail entry", iterator.hasNext());
|
||||
DetailEntry detailEntry = (DetailEntry) iterator.next();
|
||||
assertEquals("Invalid detail entry name", new QName("http://springframework.org/spring-ws", "ValidationError"),
|
||||
detailEntry.getElementQName());
|
||||
assertEquals("Invalid detail entry text", "Name is required", detailEntry.getTextContent());
|
||||
assertTrue("No detail entry", iterator.hasNext());
|
||||
Assert.assertEquals("Invalid detail entry name",
|
||||
new QName("http://springframework.org/spring-ws", "ValidationError"), detailEntry.getElementQName());
|
||||
Assert.assertEquals("Invalid detail entry text", "Name is required", detailEntry.getTextContent());
|
||||
Assert.assertTrue("No detail entry", iterator.hasNext());
|
||||
detailEntry = (DetailEntry) iterator.next();
|
||||
assertEquals("Invalid detail entry name", new QName("http://springframework.org/spring-ws", "ValidationError"),
|
||||
detailEntry.getElementQName());
|
||||
assertEquals("Invalid detail entry text", "Age Cannot be negative", detailEntry.getTextContent());
|
||||
assertFalse("Too many detail entries", iterator.hasNext());
|
||||
Assert.assertEquals("Invalid detail entry name",
|
||||
new QName("http://springframework.org/spring-ws", "ValidationError"), detailEntry.getElementQName());
|
||||
Assert.assertEquals("Invalid detail entry text", "Age Cannot be negative", detailEntry.getTextContent());
|
||||
Assert.assertFalse("Too many detail entries", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationCorrect() throws Exception {
|
||||
Person p = new Person("John", 42);
|
||||
PersonMarshaller marshaller = new PersonMarshaller(p);
|
||||
@@ -118,12 +123,12 @@ public class FaultCreatingValidatingMarshallingPayloadEndpointTest extends TestC
|
||||
endpoint.invoke(messageContext);
|
||||
|
||||
SOAPMessage response = ((SaajSoapMessage) messageContext.getResponse()).getSaajMessage();
|
||||
assertFalse("Response has fault", response.getSOAPBody().hasFault());
|
||||
Assert.assertFalse("Response has fault", response.getSOAPBody().hasFault());
|
||||
}
|
||||
|
||||
private static class PersonValidator implements Validator {
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return Person.class.equals(clazz);
|
||||
}
|
||||
|
||||
@@ -183,7 +188,7 @@ public class FaultCreatingValidatingMarshallingPayloadEndpointTest extends TestC
|
||||
return person;
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return Person.class.equals(clazz);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.ws.soap.server.endpoint;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
@@ -27,49 +25,45 @@ import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.soap11.Soap11Body;
|
||||
|
||||
public class SimpleSoapExceptionResolverTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SimpleSoapExceptionResolverTest {
|
||||
|
||||
private SimpleSoapExceptionResolver exceptionResolver;
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
private MockControl messageControl;
|
||||
|
||||
private SoapMessage messageMock;
|
||||
|
||||
private MockControl bodyControl;
|
||||
|
||||
private Soap11Body bodyMock;
|
||||
|
||||
private MockControl factoryControl;
|
||||
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
exceptionResolver = new SimpleSoapExceptionResolver();
|
||||
factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
|
||||
factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
|
||||
factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
messageContext = new DefaultMessageContext(new MockWebServiceMessage(), factoryMock);
|
||||
messageControl = MockControl.createControl(SoapMessage.class);
|
||||
messageMock = (SoapMessage) messageControl.getMock();
|
||||
bodyControl = MockControl.createControl(Soap11Body.class);
|
||||
bodyControl.setDefaultMatcher(MockControl.ARRAY_MATCHER);
|
||||
bodyMock = (Soap11Body) bodyControl.getMock();
|
||||
messageMock = createMock(SoapMessage.class);
|
||||
bodyMock = createMock(Soap11Body.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionInternal() throws Exception {
|
||||
Exception exception = new Exception("message");
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), messageMock);
|
||||
messageControl.expectAndReturn(messageMock.getSoapBody(), bodyMock);
|
||||
bodyControl.expectAndReturn(bodyMock.addServerOrReceiverFault(exception.getMessage(), Locale.ENGLISH), null);
|
||||
factoryControl.replay();
|
||||
messageControl.replay();
|
||||
bodyControl.replay();
|
||||
expect(factoryMock.createWebServiceMessage()).andReturn(messageMock);
|
||||
expect(messageMock.getSoapBody()).andReturn(bodyMock);
|
||||
expect(bodyMock.addServerOrReceiverFault(exception.getMessage(), Locale.ENGLISH)).andReturn(null);
|
||||
|
||||
replay(factoryMock, messageMock, bodyMock);
|
||||
|
||||
boolean result = exceptionResolver.resolveExceptionInternal(messageContext, null, exception);
|
||||
assertTrue("Invalid result", result);
|
||||
factoryControl.verify();
|
||||
messageControl.verify();
|
||||
bodyControl.verify();
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
|
||||
verify(factoryMock, messageMock, bodyMock);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
@@ -35,66 +34,74 @@ import org.springframework.ws.soap.server.endpoint.annotation.SoapFault;
|
||||
import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.ws.soap.soap12.Soap12Fault;
|
||||
|
||||
public class SoapFaultAnnotationExceptionResolverTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SoapFaultAnnotationExceptionResolverTest {
|
||||
|
||||
private SoapFaultAnnotationExceptionResolver resolver;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new SoapFaultAnnotationExceptionResolver();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionClientSoap11() throws Exception {
|
||||
MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
|
||||
MessageContext context = new DefaultMessageContext(factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new MyClientException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionSenderSoap12() throws Exception {
|
||||
MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
|
||||
MessageContext context = new DefaultMessageContext(factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new MySenderException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Sender error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Sender error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionServerSoap11() throws Exception {
|
||||
MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
|
||||
MessageContext context = new DefaultMessageContext(factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new MyServerException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Server error", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Server error", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionReceiverSoap12() throws Exception {
|
||||
MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
SOAPMessage message = saajFactory.createMessage();
|
||||
@@ -102,17 +109,18 @@ public class SoapFaultAnnotationExceptionResolverTest extends TestCase {
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new MyReceiverException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getServerOrReceiverFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getServerOrReceiverFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Receiver error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Receiver error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionDefault() throws Exception {
|
||||
SoapFaultDefinition defaultFault = new SoapFaultDefinition();
|
||||
defaultFault.setFaultCode(SoapFaultDefinition.CLIENT);
|
||||
@@ -123,66 +131,69 @@ public class SoapFaultAnnotationExceptionResolverTest extends TestCase {
|
||||
MessageContext context = new DefaultMessageContext(factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new NonAnnotatedException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "faultstring", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "faultstring", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionCustom() throws Exception {
|
||||
MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
|
||||
MessageContext context = new DefaultMessageContext(factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new MyCustomException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", new QName("http://springframework.org/spring-ws", "Fault"),
|
||||
Assert.assertEquals("Invalid fault code on fault", new QName("http://springframework.org/spring-ws", "Fault"),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "MyCustomException thrown", fault.getFaultStringOrReason());
|
||||
assertEquals("Invalid fault locale on fault", new Locale("nl"), fault.getFaultStringLocale());
|
||||
Assert.assertEquals("Invalid fault string on fault", "MyCustomException thrown", fault.getFaultStringOrReason());
|
||||
Assert.assertEquals("Invalid fault locale on fault", new Locale("nl"), fault.getFaultStringLocale());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionInheritance() throws Exception {
|
||||
MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
|
||||
MessageContext context = new DefaultMessageContext(factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new MySubClientException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionExceptionMessage() throws Exception {
|
||||
MessageFactory saajFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
|
||||
SoapMessageFactory factory = new SaajSoapMessageFactory(saajFactory);
|
||||
MessageContext context = new DefaultMessageContext(factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new NoStringOrReasonException("Exception message"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Resonse has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Exception message", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Exception message", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@SoapFault(faultCode = FaultCode.CLIENT, faultStringOrReason = "Client error")
|
||||
|
||||
@@ -19,51 +19,58 @@ package org.springframework.ws.soap.server.endpoint;
|
||||
import java.util.Locale;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SoapFaultDefinitionEditorTest extends TestCase {
|
||||
public class SoapFaultDefinitionEditorTest {
|
||||
|
||||
private SoapFaultDefinitionEditor editor;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
editor = new SoapFaultDefinitionEditor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextNoLocale() throws Exception {
|
||||
editor.setAsText("Server, Server error");
|
||||
SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
|
||||
assertNotNull("fault not set", definition);
|
||||
assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
|
||||
assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
assertEquals("Invalid fault string locale", Locale.ENGLISH, definition.getLocale());
|
||||
Assert.assertNotNull("fault not set", definition);
|
||||
Assert.assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
|
||||
Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
Assert.assertEquals("Invalid fault string locale", Locale.ENGLISH, definition.getLocale());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextLocale() throws Exception {
|
||||
editor.setAsText("Server, Server error, nl");
|
||||
SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
|
||||
assertNotNull("fault not set", definition);
|
||||
assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
|
||||
assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
assertEquals("Invalid fault string locale", new Locale("nl"), definition.getLocale());
|
||||
Assert.assertNotNull("fault not set", definition);
|
||||
Assert.assertEquals("Invalid fault code", new QName("Server"), definition.getFaultCode());
|
||||
Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
Assert.assertEquals("Invalid fault string locale", new Locale("nl"), definition.getLocale());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextSender() throws Exception {
|
||||
editor.setAsText("SENDER, Server error");
|
||||
SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
|
||||
assertNotNull("fault not set", definition);
|
||||
assertEquals("Invalid fault code", SoapFaultDefinition.SENDER, definition.getFaultCode());
|
||||
assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
Assert.assertNotNull("fault not set", definition);
|
||||
Assert.assertEquals("Invalid fault code", SoapFaultDefinition.SENDER, definition.getFaultCode());
|
||||
Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextReceiver() throws Exception {
|
||||
editor.setAsText("RECEIVER, Server error");
|
||||
SoapFaultDefinition definition = (SoapFaultDefinition) editor.getValue();
|
||||
assertNotNull("fault not set", definition);
|
||||
assertEquals("Invalid fault code", SoapFaultDefinition.RECEIVER, definition.getFaultCode());
|
||||
assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
Assert.assertNotNull("fault not set", definition);
|
||||
Assert.assertEquals("Invalid fault code", SoapFaultDefinition.RECEIVER, definition.getFaultCode());
|
||||
Assert.assertEquals("Invalid fault string", "Server error", definition.getFaultStringOrReason());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextIllegalArgument() throws Exception {
|
||||
try {
|
||||
editor.setAsText("SOAP-ENV:Server");
|
||||
@@ -72,8 +79,9 @@ public class SoapFaultDefinitionEditorTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsTextEmpty() throws Exception {
|
||||
editor.setAsText("");
|
||||
assertNull("definition not set to null", editor.getValue());
|
||||
Assert.assertNull("definition not set to null", editor.getValue());
|
||||
}
|
||||
}
|
||||
@@ -16,20 +16,23 @@
|
||||
|
||||
package org.springframework.ws.soap.server.endpoint.interceptor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
import org.apache.log4j.AppenderSkeleton;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
public class SoapEnvelopeLoggingInterceptorTest extends TestCase {
|
||||
public class SoapEnvelopeLoggingInterceptorTest {
|
||||
|
||||
private SoapEnvelopeLoggingInterceptor interceptor;
|
||||
|
||||
@@ -37,8 +40,8 @@ public class SoapEnvelopeLoggingInterceptorTest extends TestCase {
|
||||
|
||||
private MessageContext messageContext;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
interceptor = new SoapEnvelopeLoggingInterceptor();
|
||||
appender = new SoapEnvelopeLoggingInterceptorTest.CountingAppender();
|
||||
BasicConfigurator.configure(appender);
|
||||
@@ -49,54 +52,60 @@ public class SoapEnvelopeLoggingInterceptorTest extends TestCase {
|
||||
appender.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
BasicConfigurator.resetConfiguration();
|
||||
ClassPathResource resource = new ClassPathResource("log4j.properties");
|
||||
PropertyConfigurator.configure(resource.getURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleRequestDisabled() throws Exception {
|
||||
interceptor.setLogRequest(false);
|
||||
int eventCount = appender.getCount();
|
||||
interceptor.handleRequest(messageContext, null);
|
||||
assertEquals("interceptor logged when disabled", appender.getCount(), eventCount);
|
||||
Assert.assertEquals("interceptor logged when disabled", appender.getCount(), eventCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleRequestEnabled() throws Exception {
|
||||
int eventCount = appender.getCount();
|
||||
interceptor.handleRequest(messageContext, null);
|
||||
assertTrue("interceptor did not log", appender.getCount() > eventCount);
|
||||
Assert.assertTrue("interceptor did not log", appender.getCount() > eventCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleResponseDisabled() throws Exception {
|
||||
messageContext.getResponse();
|
||||
interceptor.setLogResponse(false);
|
||||
int eventCount = appender.getCount();
|
||||
interceptor.handleResponse(messageContext, null);
|
||||
assertEquals("interceptor logged when disabled", appender.getCount(), eventCount);
|
||||
Assert.assertEquals("interceptor logged when disabled", appender.getCount(), eventCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleResponseEnabled() throws Exception {
|
||||
messageContext.getResponse();
|
||||
int eventCount = appender.getCount();
|
||||
interceptor.handleResponse(messageContext, null);
|
||||
assertTrue("interceptor did not log", appender.getCount() > eventCount);
|
||||
Assert.assertTrue("interceptor did not log", appender.getCount() > eventCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleFaultDisabled() throws Exception {
|
||||
messageContext.getResponse();
|
||||
interceptor.setLogFault(false);
|
||||
int eventCount = appender.getCount();
|
||||
interceptor.handleFault(messageContext, null);
|
||||
assertEquals("interceptor logged when disabled", appender.getCount(), eventCount);
|
||||
Assert.assertEquals("interceptor logged when disabled", appender.getCount(), eventCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleFaultEnabled() throws Exception {
|
||||
messageContext.getResponse();
|
||||
int eventCount = appender.getCount();
|
||||
interceptor.handleResponse(messageContext, null);
|
||||
assertTrue("interceptor did not log", appender.getCount() > eventCount);
|
||||
Assert.assertTrue("interceptor did not log", appender.getCount() > eventCount);
|
||||
}
|
||||
|
||||
private static class CountingAppender extends AppenderSkeleton {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.ws.soap.server.endpoint.mapping;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
@@ -25,33 +23,40 @@ import org.springframework.ws.server.EndpointInvocationChain;
|
||||
import org.springframework.ws.server.EndpointMapping;
|
||||
import org.springframework.ws.soap.server.SoapEndpointInvocationChain;
|
||||
|
||||
public class DelegatingSoapEndpointMappingTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class DelegatingSoapEndpointMappingTest {
|
||||
|
||||
private DelegatingSoapEndpointMapping endpointMapping;
|
||||
|
||||
private MockControl control;
|
||||
|
||||
private EndpointMapping mock;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
endpointMapping = new DelegatingSoapEndpointMapping();
|
||||
control = MockControl.createControl(EndpointMapping.class);
|
||||
mock = (EndpointMapping) control.getMock();
|
||||
mock = createMock(EndpointMapping.class);
|
||||
endpointMapping.setDelegate(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEndpointMapping() throws Exception {
|
||||
String role = "http://www.springframework.org/spring-ws/role";
|
||||
endpointMapping.setActorOrRole(role);
|
||||
MessageContext context = new DefaultMessageContext(new MockWebServiceMessageFactory());
|
||||
EndpointInvocationChain delegateChain = new EndpointInvocationChain(new Object());
|
||||
control.expectAndReturn(mock.getEndpoint(context), delegateChain);
|
||||
control.replay();
|
||||
expect(mock.getEndpoint(context)).andReturn(delegateChain);
|
||||
|
||||
replay(mock);
|
||||
|
||||
SoapEndpointInvocationChain resultChain = (SoapEndpointInvocationChain) endpointMapping.getEndpoint(context);
|
||||
assertNotNull("No chain returned", resultChain);
|
||||
assertEquals("Invalid ampount of roles returned", 1, resultChain.getActorsOrRoles().length);
|
||||
assertEquals("Invalid role returned", role, resultChain.getActorsOrRoles()[0]);
|
||||
control.verify();
|
||||
Assert.assertNotNull("No chain returned", resultChain);
|
||||
Assert.assertEquals("Invalid ampount of roles returned", 1, resultChain.getActorsOrRoles().length);
|
||||
Assert.assertEquals("Invalid role returned", role, resultChain.getActorsOrRoles()[0]);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,6 @@ package org.springframework.ws.soap.server.endpoint.mapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
@@ -31,14 +28,20 @@ import org.springframework.ws.server.endpoint.annotation.Endpoint;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.server.endpoint.annotation.SoapAction;
|
||||
|
||||
public class SoapActionAnnotationMethodEndpointMappingTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SoapActionAnnotationMethodEndpointMappingTest {
|
||||
|
||||
private SoapActionAnnotationMethodEndpointMapping mapping;
|
||||
|
||||
private StaticApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
applicationContext = new StaticApplicationContext();
|
||||
applicationContext.registerSingleton("mapping", SoapActionAnnotationMethodEndpointMapping.class);
|
||||
applicationContext.registerSingleton("endpoint", MyEndpoint.class);
|
||||
@@ -46,6 +49,7 @@ public class SoapActionAnnotationMethodEndpointMappingTest extends TestCase {
|
||||
mapping = (SoapActionAnnotationMethodEndpointMapping) applicationContext.getBean("mapping");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistration() throws Exception {
|
||||
SoapMessage requestMock = createMock(SoapMessage.class);
|
||||
expect(requestMock.getSoapAction()).andReturn("http://springframework.org/spring-ws/SoapAction");
|
||||
@@ -54,10 +58,10 @@ public class SoapActionAnnotationMethodEndpointMappingTest extends TestCase {
|
||||
|
||||
MessageContext context = new DefaultMessageContext(requestMock, factoryMock);
|
||||
EndpointInvocationChain chain = mapping.getEndpoint(context);
|
||||
assertNotNull("MethodEndpoint not registered", chain);
|
||||
Assert.assertNotNull("MethodEndpoint not registered", chain);
|
||||
Method doIt = MyEndpoint.class.getMethod("doIt", new Class[0]);
|
||||
MethodEndpoint expected = new MethodEndpoint("endpoint", applicationContext, doIt);
|
||||
assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
|
||||
Assert.assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
|
||||
|
||||
verify(requestMock, factoryMock);
|
||||
}
|
||||
|
||||
@@ -18,38 +18,43 @@ package org.springframework.ws.soap.server.endpoint.mapping;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
public class SoapActionEndpointMappingTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SoapActionEndpointMappingTest {
|
||||
|
||||
private SoapActionEndpointMapping mapping;
|
||||
|
||||
private MessageContext context;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mapping = new SoapActionEndpointMapping();
|
||||
context = new DefaultMessageContext(new SaajSoapMessageFactory(MessageFactory.newInstance()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLookupKeyForMessage() throws Exception {
|
||||
String soapAction = "http://springframework.org/spring-ws/SoapAction";
|
||||
((SoapMessage) context.getRequest()).setSoapAction(soapAction);
|
||||
assertEquals("Invalid lookup key", soapAction, mapping.getLookupKeyForMessage(context));
|
||||
Assert.assertEquals("Invalid lookup key", soapAction, mapping.getLookupKeyForMessage(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLookupKeyForMessageQuoted() throws Exception {
|
||||
String soapAction = "http://springframework.org/spring-ws/SoapAction";
|
||||
((SoapMessage) context.getRequest()).setSoapAction(soapAction);
|
||||
assertEquals("Invalid lookup key", soapAction, mapping.getLookupKeyForMessage(context));
|
||||
Assert.assertEquals("Invalid lookup key", soapAction, mapping.getLookupKeyForMessage(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateLookupKey() throws Exception {
|
||||
assertTrue("Soapaction not valid", mapping.validateLookupKey("SoapAction"));
|
||||
Assert.assertTrue("Soapaction not valid", mapping.validateLookupKey("SoapAction"));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,16 +27,24 @@ import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
assertTrue("Invalid type returned", soapBody instanceof Soap11Body);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals("Invalid qualified name", SoapVersion.SOAP_11.getBodyName(), soapBody.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(soapBody.getSource(), result);
|
||||
@@ -44,6 +52,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddMustUnderstandFault() throws Exception {
|
||||
SoapFault fault = soapBody.addMustUnderstandFault("SOAP Must Understand Error", null);
|
||||
assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "MustUnderstand"),
|
||||
@@ -53,6 +62,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"<faultstring>SOAP Must Understand Error</faultstring></SOAP-ENV:Fault>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddClientFault() throws Exception {
|
||||
SoapFault fault = soapBody.addClientOrSenderFault("faultString", null);
|
||||
assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "Client"),
|
||||
@@ -62,6 +72,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"<faultstring>faultString</faultstring>" + "</SOAP-ENV:Fault>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddServerFault() throws Exception {
|
||||
SoapFault fault = soapBody.addServerOrReceiverFault("faultString", null);
|
||||
assertEquals("Invalid fault code", new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"),
|
||||
@@ -71,6 +82,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"<faultstring>faultString</faultstring>" + "</SOAP-ENV:Fault>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFault() throws Exception {
|
||||
QName faultCode = new QName("http://www.springframework.org", "fault", "spring");
|
||||
String faultString = "faultString";
|
||||
@@ -90,6 +102,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"</faultactor>" + "</SOAP-ENV:Fault>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultNoPrefix() throws Exception {
|
||||
QName faultCode = new QName("http://www.springframework.org", "fault");
|
||||
String faultString = "faultString";
|
||||
@@ -105,6 +118,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
assertEquals("Invalid fault actor", actor, fault.getFaultActorOrRole());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultWithDetail() throws Exception {
|
||||
QName faultCode = new QName("http://www.springframework.org", "fault", "spring");
|
||||
String faultString = "faultString";
|
||||
@@ -127,6 +141,7 @@ public abstract class AbstractSoap11BodyTestCase extends AbstractSoapBodyTestCas
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultWithDetailResult() throws Exception {
|
||||
SoapFault fault = ((Soap11Body) soapBody)
|
||||
.addFault(new QName("namespace", "localPart", "prefix"), "Fault", null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,14 +22,21 @@ import org.springframework.ws.soap.AbstractSoapEnvelopeTestCase;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class AbstractSoap11EnvelopeTestCase extends AbstractSoapEnvelopeTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals("Invalid qualified name",
|
||||
new QName(SoapVersion.SOAP_11.getEnvelopeNamespaceUri(), "Envelope"),
|
||||
soapEnvelope.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContent() throws Exception {
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(soapEnvelope.getSource(), result);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,19 +24,27 @@ import org.springframework.ws.soap.SoapHeaderElement;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap11HeaderTestCase extends AbstractSoapHeaderTestCase {
|
||||
|
||||
private static final String PREFIX = "spring";
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
assertTrue("Invalid type returned", soapHeader instanceof Soap11Header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals("Invalid qualified name", new QName(SoapVersion.SOAP_11.getEnvelopeNamespaceUri(), "Header"),
|
||||
soapHeader.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(soapHeader.getSource(), result);
|
||||
@@ -44,6 +52,7 @@ public abstract class AbstractSoap11HeaderTestCase extends AbstractSoapHeaderTes
|
||||
"<SOAP-ENV:Header xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' />", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineHeaderElementsToProcessActors() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName1", PREFIX);
|
||||
SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName);
|
||||
@@ -54,7 +63,7 @@ public abstract class AbstractSoap11HeaderTestCase extends AbstractSoapHeaderTes
|
||||
qName = new QName(NAMESPACE, "localName3", PREFIX);
|
||||
headerElement = soapHeader.addHeaderElement(qName);
|
||||
headerElement.setActorOrRole(SoapVersion.SOAP_11.getNextActorOrRoleUri());
|
||||
Iterator iterator = ((Soap11Header) soapHeader).examineHeaderElementsToProcess(new String[]{"role1"});
|
||||
Iterator<SoapHeaderElement> iterator = ((Soap11Header) soapHeader).examineHeaderElementsToProcess(new String[]{"role1"});
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
assertTrue("header element iterator has no elements", iterator.hasNext());
|
||||
checkHeaderElement((SoapHeaderElement) iterator.next());
|
||||
@@ -63,6 +72,7 @@ public abstract class AbstractSoap11HeaderTestCase extends AbstractSoapHeaderTes
|
||||
assertFalse("header element iterator has too many elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineHeaderElementsToProcessNoActors() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName1", PREFIX);
|
||||
SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName);
|
||||
@@ -73,7 +83,7 @@ public abstract class AbstractSoap11HeaderTestCase extends AbstractSoapHeaderTes
|
||||
qName = new QName(NAMESPACE, "localName3", PREFIX);
|
||||
headerElement = soapHeader.addHeaderElement(qName);
|
||||
headerElement.setActorOrRole(SoapVersion.SOAP_11.getNextActorOrRoleUri());
|
||||
Iterator iterator = ((Soap11Header) soapHeader).examineHeaderElementsToProcess(new String[0]);
|
||||
Iterator<SoapHeaderElement> iterator = ((Soap11Header) soapHeader).examineHeaderElementsToProcess(new String[0]);
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
assertTrue("header element iterator has no elements", iterator.hasNext());
|
||||
checkHeaderElement((SoapHeaderElement) iterator.next());
|
||||
|
||||
@@ -29,8 +29,13 @@ import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.MockTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap11MessageFactoryTestCase extends AbstractSoapMessageFactoryTestCase {
|
||||
|
||||
@Test
|
||||
public void testCreateEmptySoap11Message() throws Exception {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage();
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
@@ -67,8 +72,8 @@ public abstract class AbstractSoap11MessageFactoryTestCase extends AbstractSoapM
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, soapMessage.getVersion());
|
||||
assertFalse("Message a XOP pacakge", soapMessage.isXopPackage());
|
||||
Iterator iter = soapMessage.getAttachments();
|
||||
assertFalse("Message a XOP package", soapMessage.isXopPackage());
|
||||
Iterator<Attachment> iter = soapMessage.getAttachments();
|
||||
assertTrue("No attachments read", iter.hasNext());
|
||||
Attachment attachment = soapMessage.getAttachment("interface21");
|
||||
assertNotNull("No attachment read", attachment);
|
||||
@@ -88,14 +93,15 @@ public abstract class AbstractSoap11MessageFactoryTestCase extends AbstractSoapM
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, soapMessage.getVersion());
|
||||
assertTrue("Message not a XOP pacakge", soapMessage.isXopPackage());
|
||||
Iterator iter = soapMessage.getAttachments();
|
||||
assertTrue("Message not a XOP package", soapMessage.isXopPackage());
|
||||
Iterator<Attachment> iter = soapMessage.getAttachments();
|
||||
assertTrue("No attachments read", iter.hasNext());
|
||||
|
||||
Attachment attachment = soapMessage.getAttachment("<1.urn:uuid:492264AB42E57108E01176731445504@apache.org>");
|
||||
assertNotNull("No attachment read", attachment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSoapMessageMtomWeirdStartInfo() throws Exception {
|
||||
InputStream is = AbstractSoap11MessageFactoryTestCase.class.getResourceAsStream("soap11-mtom.bin");
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
@@ -108,14 +114,15 @@ public abstract class AbstractSoap11MessageFactoryTestCase extends AbstractSoapM
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, soapMessage.getVersion());
|
||||
assertTrue("Message not a XOP pacakge", soapMessage.isXopPackage());
|
||||
Iterator iter = soapMessage.getAttachments();
|
||||
assertTrue("Message not a XOP package", soapMessage.isXopPackage());
|
||||
Iterator<Attachment> iter = soapMessage.getAttachments();
|
||||
assertTrue("No attachments read", iter.hasNext());
|
||||
|
||||
Attachment attachment = soapMessage.getAttachment("<1.urn:uuid:492264AB42E57108E01176731445504@apache.org>");
|
||||
assertNotNull("No attachment read", attachment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSoapMessageUtf8ByteOrderMark() throws Exception {
|
||||
InputStream is = AbstractSoap11MessageFactoryTestCase.class.getResourceAsStream("soap11-utf8-bom.xml");
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
@@ -126,6 +133,7 @@ public abstract class AbstractSoap11MessageFactoryTestCase extends AbstractSoapM
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, message.getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSoapMessageUtf16BigEndianByteOrderMark() throws Exception {
|
||||
InputStream is = AbstractSoap11MessageFactoryTestCase.class.getResourceAsStream("soap11-utf16-be-bom.xml");
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
@@ -136,6 +144,7 @@ public abstract class AbstractSoap11MessageFactoryTestCase extends AbstractSoapM
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_11, message.getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSoapMessageUtf16LittleEndianByteOrderMark() throws Exception {
|
||||
InputStream is = AbstractSoap11MessageFactoryTestCase.class.getResourceAsStream("soap11-utf16-le-bom.xml");
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,17 +28,25 @@ import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
assertTrue("Invalid type returned", soapBody instanceof Soap12Body);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals("Invalid qualified name", new QName(SoapVersion.SOAP_12.getEnvelopeNamespaceUri(), "Body"),
|
||||
soapBody.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(soapBody.getSource(), result);
|
||||
@@ -46,6 +54,7 @@ public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCas
|
||||
result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddMustUnderstandFault() throws Exception {
|
||||
SoapFault fault = soapBody.addMustUnderstandFault("SOAP Must Understand Error", Locale.ENGLISH);
|
||||
assertEquals("Invalid fault code", new QName("http://www.w3.org/2003/05/soap-envelope", "MustUnderstand"),
|
||||
@@ -60,6 +69,7 @@ public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"</soapenv:Reason></soapenv:Fault>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSenderFault() throws Exception {
|
||||
SoapFault fault = soapBody.addClientOrSenderFault("faultString", Locale.ENGLISH);
|
||||
assertEquals("Invalid fault code", new QName("http://www.w3.org/2003/05/soap-envelope", "Sender"),
|
||||
@@ -74,6 +84,7 @@ public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"</soapenv:Fault>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddReceiverFault() throws Exception {
|
||||
SoapFault fault = soapBody.addServerOrReceiverFault("faultString", Locale.ENGLISH);
|
||||
assertEquals("Invalid fault code", new QName("http://www.w3.org/2003/05/soap-envelope", "Receiver"),
|
||||
@@ -88,6 +99,7 @@ public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"</soapenv:Fault>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultWithDetail() throws Exception {
|
||||
SoapFault fault = soapBody.addServerOrReceiverFault("faultString", Locale.ENGLISH);
|
||||
SoapFaultDetail detail = fault.addFaultDetail();
|
||||
@@ -106,6 +118,7 @@ public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"</prefix:localPart></soapenv:Detail></soapenv:Fault>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultWithDetailResult() throws Exception {
|
||||
SoapFault fault = soapBody.addServerOrReceiverFault("faultString", Locale.ENGLISH);
|
||||
SoapFaultDetail detail = fault.addFaultDetail();
|
||||
@@ -122,13 +135,14 @@ public abstract class AbstractSoap12BodyTestCase extends AbstractSoapBodyTestCas
|
||||
"<detailContents xmlns='namespace'/>" + "</soapenv:Detail></soapenv:Fault>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultWithSubcode() throws Exception {
|
||||
Soap12Fault fault = (Soap12Fault) soapBody.addServerOrReceiverFault("faultString", Locale.ENGLISH);
|
||||
QName subcode1 = new QName("http://www.springframework.org", "Subcode1", "spring-ws");
|
||||
fault.addFaultSubcode(subcode1);
|
||||
QName subcode2 = new QName("http://www.springframework.org", "Subcode2", "spring-ws");
|
||||
fault.addFaultSubcode(subcode2);
|
||||
Iterator iterator = fault.getFaultSubcodes();
|
||||
Iterator<QName> iterator = fault.getFaultSubcodes();
|
||||
assertTrue("No subcode found", iterator.hasNext());
|
||||
assertEquals("Invalid subcode", subcode1, iterator.next());
|
||||
assertTrue("No subcode found", iterator.hasNext());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,13 +22,20 @@ import org.springframework.ws.soap.AbstractSoapEnvelopeTestCase;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class AbstractSoap12EnvelopeTestCase extends AbstractSoapEnvelopeTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals("Invalid qualified name", new QName(SoapVersion.SOAP_12.getEnvelopeNamespaceUri(), "Envelope"),
|
||||
soapEnvelope.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(soapEnvelope.getSource(), result);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,17 +24,25 @@ import org.springframework.ws.soap.SoapHeaderElement;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
assertTrue("Invalid type returned", soapHeader instanceof Soap12Header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals("Invalid qualified name", new QName(SoapVersion.SOAP_12.getEnvelopeNamespaceUri(), "Header"),
|
||||
soapHeader.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(soapHeader.getSource(), result);
|
||||
@@ -42,6 +50,7 @@ public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTes
|
||||
result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNotUnderstood() throws Exception {
|
||||
Soap12Header soap12Header = (Soap12Header) soapHeader;
|
||||
QName headerName = new QName("http://www.springframework.org", "NotUnderstood", "spring-ws");
|
||||
@@ -53,6 +62,7 @@ public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTes
|
||||
"</Header>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddUpgrade() throws Exception {
|
||||
String[] supportedUris =
|
||||
new String[]{"http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/2003/05/soap-envelope"};
|
||||
@@ -72,6 +82,7 @@ public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTes
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineHeaderElementsToProcessActors() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName1", PREFIX);
|
||||
SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName);
|
||||
@@ -82,7 +93,7 @@ public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTes
|
||||
qName = new QName(NAMESPACE, "localName3", PREFIX);
|
||||
headerElement = soapHeader.addHeaderElement(qName);
|
||||
headerElement.setActorOrRole(SoapVersion.SOAP_12.getNextActorOrRoleUri());
|
||||
Iterator iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[]{"role1"}, false);
|
||||
Iterator<SoapHeaderElement> iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[]{"role1"}, false);
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
assertTrue("header element iterator has no elements", iterator.hasNext());
|
||||
checkHeaderElement((SoapHeaderElement) iterator.next());
|
||||
@@ -91,6 +102,7 @@ public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTes
|
||||
assertFalse("header element iterator has too many elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineHeaderElementsToProcessNoActors() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName1", PREFIX);
|
||||
SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName);
|
||||
@@ -101,7 +113,7 @@ public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTes
|
||||
qName = new QName(NAMESPACE, "localName3", PREFIX);
|
||||
headerElement = soapHeader.addHeaderElement(qName);
|
||||
headerElement.setActorOrRole(SoapVersion.SOAP_12.getNextActorOrRoleUri());
|
||||
Iterator iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[0], false);
|
||||
Iterator<SoapHeaderElement> iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[0], false);
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
assertTrue("header element iterator has no elements", iterator.hasNext());
|
||||
checkHeaderElement((SoapHeaderElement) iterator.next());
|
||||
@@ -110,11 +122,12 @@ public abstract class AbstractSoap12HeaderTestCase extends AbstractSoapHeaderTes
|
||||
assertFalse("header element iterator has too many elements", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExamineHeaderElementsToProcessUltimateDestination() throws Exception {
|
||||
QName qName = new QName(NAMESPACE, "localName", PREFIX);
|
||||
SoapHeaderElement headerElement = soapHeader.addHeaderElement(qName);
|
||||
headerElement.setActorOrRole(SoapVersion.SOAP_12.getUltimateReceiverRoleUri());
|
||||
Iterator iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[]{"role"}, true);
|
||||
Iterator<SoapHeaderElement> iterator = ((Soap12Header) soapHeader).examineHeaderElementsToProcess(new String[]{"role"}, true);
|
||||
assertNotNull("header element iterator is null", iterator);
|
||||
headerElement = (SoapHeaderElement) iterator.next();
|
||||
assertEquals("Invalid name on header element", new QName(NAMESPACE, "localName", PREFIX),
|
||||
|
||||
@@ -30,6 +30,8 @@ import org.springframework.ws.transport.MockTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap12MessageFactoryTestCase extends AbstractSoapMessageFactoryTestCase {
|
||||
|
||||
@Override
|
||||
@@ -86,8 +88,8 @@ public abstract class AbstractSoap12MessageFactoryTestCase extends AbstractSoapM
|
||||
assertTrue("Not a SoapMessage", message instanceof SoapMessage);
|
||||
SoapMessage soapMessage = (SoapMessage) message;
|
||||
assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
|
||||
assertTrue("Message is not a XOP pacakge", soapMessage.isXopPackage());
|
||||
Iterator iter = soapMessage.getAttachments();
|
||||
assertTrue("Message is not a XOP package", soapMessage.isXopPackage());
|
||||
Iterator<Attachment> iter = soapMessage.getAttachments();
|
||||
assertTrue("No attachments read", iter.hasNext());
|
||||
|
||||
Attachment attachment = soapMessage.getAttachment("<1.urn:uuid:40864869929B855F971176851454452@apache.org>");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,56 +16,60 @@
|
||||
|
||||
package org.springframework.ws.soap.support;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SoapUtilsTest extends TestCase {
|
||||
public class SoapUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testExtractActionFromContentType() throws Exception {
|
||||
String soapAction = "http://springframework.org/spring-ws/Action";
|
||||
|
||||
String contentType = "application/soap+xml; action=" + soapAction;
|
||||
String result = SoapUtils.extractActionFromContentType(contentType);
|
||||
assertEquals("Invalid SOAP action", soapAction, result);
|
||||
Assert.assertEquals("Invalid SOAP action", soapAction, result);
|
||||
|
||||
contentType = "application/soap+xml; action = " + soapAction;
|
||||
result = SoapUtils.extractActionFromContentType(contentType);
|
||||
assertEquals("Invalid SOAP action", soapAction, result);
|
||||
Assert.assertEquals("Invalid SOAP action", soapAction, result);
|
||||
|
||||
contentType = "application/soap+xml; action=" + soapAction + " ; charset=UTF-8";
|
||||
result = SoapUtils.extractActionFromContentType(contentType);
|
||||
assertEquals("Invalid SOAP action", soapAction, result);
|
||||
Assert.assertEquals("Invalid SOAP action", soapAction, result);
|
||||
|
||||
contentType = "application/soap+xml; charset=UTF-8; action=" + soapAction;
|
||||
result = SoapUtils.extractActionFromContentType(contentType);
|
||||
assertEquals("Invalid SOAP action", soapAction, result);
|
||||
Assert.assertEquals("Invalid SOAP action", soapAction, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapeAction() throws Exception {
|
||||
String result = SoapUtils.escapeAction("action");
|
||||
assertEquals("Invalid SOAP action", "\"action\"", result);
|
||||
Assert.assertEquals("Invalid SOAP action", "\"action\"", result);
|
||||
|
||||
result = SoapUtils.escapeAction("\"action\"");
|
||||
assertEquals("Invalid SOAP action", "\"action\"", result);
|
||||
Assert.assertEquals("Invalid SOAP action", "\"action\"", result);
|
||||
|
||||
result = SoapUtils.escapeAction("");
|
||||
assertEquals("Invalid SOAP action", "\"\"", result);
|
||||
Assert.assertEquals("Invalid SOAP action", "\"\"", result);
|
||||
|
||||
result = SoapUtils.escapeAction(null);
|
||||
assertEquals("Invalid SOAP action", "\"\"", result);
|
||||
Assert.assertEquals("Invalid SOAP action", "\"\"", result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActionInContentType() throws Exception {
|
||||
String soapAction = "http://springframework.org/spring-ws/Action";
|
||||
String contentType = "application/soap+xml";
|
||||
|
||||
String result = SoapUtils.setActionInContentType(contentType, soapAction);
|
||||
assertEquals("Invalid SOAP action", soapAction, SoapUtils.extractActionFromContentType(result));
|
||||
Assert.assertEquals("Invalid SOAP action", soapAction, SoapUtils.extractActionFromContentType(result));
|
||||
|
||||
String anotherSoapAction = "http://springframework.org/spring-ws/AnotherAction";
|
||||
String contentTypeWithAction = "application/soap+xml; action=http://springframework.org/spring-ws/Action";
|
||||
result = SoapUtils.setActionInContentType(contentTypeWithAction, anotherSoapAction);
|
||||
assertEquals("Invalid SOAP action", anotherSoapAction, SoapUtils.extractActionFromContentType(result));
|
||||
Assert.assertEquals("Invalid SOAP action", anotherSoapAction, SoapUtils.extractActionFromContentType(result));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,10 +27,12 @@ import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DefaultStrategiesHelperTest extends TestCase {
|
||||
public class DefaultStrategiesHelperTest {
|
||||
|
||||
@Test
|
||||
public void testGetDefaultStrategies() throws Exception {
|
||||
|
||||
Properties strategies = new Properties();
|
||||
@@ -42,17 +44,18 @@ public class DefaultStrategiesHelperTest extends TestCase {
|
||||
applicationContext.registerSingleton("strategy1", StrategyImpl.class);
|
||||
applicationContext.registerSingleton("strategy2", ContextAwareStrategyImpl.class);
|
||||
|
||||
List result = helper.getDefaultStrategies(Strategy.class, applicationContext);
|
||||
assertNotNull("No result", result);
|
||||
assertEquals("Invalid amount of strategies", 2, result.size());
|
||||
assertTrue("Result not a Strategy implementation", result.get(0) instanceof Strategy);
|
||||
assertTrue("Result not a Strategy implementation", result.get(1) instanceof Strategy);
|
||||
assertTrue("Result not a StrategyImpl implementation", result.get(0) instanceof StrategyImpl);
|
||||
assertTrue("Result not a StrategyImpl implementation", result.get(1) instanceof ContextAwareStrategyImpl);
|
||||
List<Strategy> result = helper.getDefaultStrategies(Strategy.class, applicationContext);
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertEquals("Invalid amount of strategies", 2, result.size());
|
||||
Assert.assertTrue("Result not a Strategy implementation", result.get(0) != null);
|
||||
Assert.assertTrue("Result not a Strategy implementation", result.get(1) != null);
|
||||
Assert.assertTrue("Result not a StrategyImpl implementation", result.get(0) instanceof StrategyImpl);
|
||||
Assert.assertTrue("Result not a StrategyImpl implementation", result.get(1) instanceof ContextAwareStrategyImpl);
|
||||
ContextAwareStrategyImpl impl = (ContextAwareStrategyImpl) result.get(1);
|
||||
assertNotNull("No application context injected", impl.getApplicationContext());
|
||||
Assert.assertNotNull("No application context injected", impl.getApplicationContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultStrategy() throws Exception {
|
||||
Properties strategies = new Properties();
|
||||
strategies.put(Strategy.class.getName(), StrategyImpl.class.getName());
|
||||
@@ -63,11 +66,12 @@ public class DefaultStrategiesHelperTest extends TestCase {
|
||||
applicationContext.registerSingleton("strategy2", ContextAwareStrategyImpl.class);
|
||||
|
||||
Object result = helper.getDefaultStrategy(Strategy.class, applicationContext);
|
||||
assertNotNull("No result", result);
|
||||
assertTrue("Result not a Strategy implementation", result instanceof Strategy);
|
||||
assertTrue("Result not a StrategyImpl implementation", result instanceof StrategyImpl);
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertTrue("Result not a Strategy implementation", result instanceof Strategy);
|
||||
Assert.assertTrue("Result not a StrategyImpl implementation", result instanceof StrategyImpl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDefaultStrategyMoreThanOne() throws Exception {
|
||||
Properties strategies = new Properties();
|
||||
strategies.put(Strategy.class.getName(),
|
||||
@@ -80,13 +84,14 @@ public class DefaultStrategiesHelperTest extends TestCase {
|
||||
|
||||
try {
|
||||
helper.getDefaultStrategy(Strategy.class, applicationContext);
|
||||
fail("Expected BeanInitializationException");
|
||||
Assert.fail("Expected BeanInitializationException");
|
||||
}
|
||||
catch (BeanInitializationException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceConstructor() throws Exception {
|
||||
Resource resource = new ClassPathResource("strategies.properties", getClass());
|
||||
new DefaultStrategiesHelper(resource);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,10 +19,9 @@ package org.springframework.ws.support;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.oxm.mime.MimeMarshaller;
|
||||
import org.springframework.oxm.mime.MimeUnmarshaller;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
@@ -30,109 +29,96 @@ import org.springframework.ws.mime.MimeMessage;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public class MarshallingUtilsTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class MarshallingUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testUnmarshal() throws Exception {
|
||||
MockControl unmarshallerControl = MockControl.createControl(Unmarshaller.class);
|
||||
Unmarshaller unmarshallerMock = (Unmarshaller) unmarshallerControl.getMock();
|
||||
MockControl messageControl = MockControl.createControl(WebServiceMessage.class);
|
||||
WebServiceMessage messageMock = (WebServiceMessage) messageControl.getMock();
|
||||
Unmarshaller unmarshallerMock = createMock(Unmarshaller.class);
|
||||
WebServiceMessage messageMock = createMock(WebServiceMessage.class);
|
||||
|
||||
Source source = new StringSource("");
|
||||
Object unmarshalled = new Object();
|
||||
messageControl.expectAndReturn(messageMock.getPayloadSource(), source);
|
||||
unmarshallerControl.expectAndReturn(unmarshallerMock.unmarshal(source), unmarshalled);
|
||||
expect(messageMock.getPayloadSource()).andReturn(source);
|
||||
expect(unmarshallerMock.unmarshal(source)).andReturn(unmarshalled);
|
||||
|
||||
unmarshallerControl.replay();
|
||||
messageControl.replay();
|
||||
replay(unmarshallerMock, messageMock);
|
||||
|
||||
Object result = MarshallingUtils.unmarshal(unmarshallerMock, messageMock);
|
||||
assertEquals("Invalid unmarshalled object", unmarshalled, result);
|
||||
Assert.assertEquals("Invalid unmarshalled object", unmarshalled, result);
|
||||
|
||||
unmarshallerControl.verify();
|
||||
messageControl.verify();
|
||||
verify(unmarshallerMock, messageMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalMime() throws Exception {
|
||||
MockControl unmarshallerControl = MockControl.createControl(MimeUnmarshaller.class);
|
||||
MimeUnmarshaller unmarshallerMock = (MimeUnmarshaller) unmarshallerControl.getMock();
|
||||
MockControl messageControl = MockControl.createControl(MimeMessage.class);
|
||||
MimeMessage messageMock = (MimeMessage) messageControl.getMock();
|
||||
MimeUnmarshaller unmarshallerMock = createMock(MimeUnmarshaller.class);
|
||||
MimeMessage messageMock = createMock(MimeMessage.class);
|
||||
|
||||
Source source = new StringSource("");
|
||||
Object unmarshalled = new Object();
|
||||
messageControl.expectAndReturn(messageMock.getPayloadSource(), source);
|
||||
unmarshallerMock.unmarshal(source, null);
|
||||
unmarshallerControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
unmarshallerControl.setReturnValue(unmarshalled);
|
||||
expect(messageMock.getPayloadSource()).andReturn(source);
|
||||
expect(unmarshallerMock.unmarshal(eq(source), isA(MimeContainer.class))).andReturn(unmarshalled);
|
||||
|
||||
unmarshallerControl.replay();
|
||||
messageControl.replay();
|
||||
replay(unmarshallerMock, messageMock);
|
||||
|
||||
Object result = MarshallingUtils.unmarshal(unmarshallerMock, messageMock);
|
||||
assertEquals("Invalid unmarshalled object", unmarshalled, result);
|
||||
Assert.assertEquals("Invalid unmarshalled object", unmarshalled, result);
|
||||
|
||||
unmarshallerControl.verify();
|
||||
messageControl.verify();
|
||||
verify(unmarshallerMock, messageMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalNoPayload() throws Exception {
|
||||
MockControl unmarshallerControl = MockControl.createControl(MimeUnmarshaller.class);
|
||||
MimeUnmarshaller unmarshallerMock = (MimeUnmarshaller) unmarshallerControl.getMock();
|
||||
MockControl messageControl = MockControl.createControl(MimeMessage.class);
|
||||
MimeMessage messageMock = (MimeMessage) messageControl.getMock();
|
||||
Unmarshaller unmarshallerMock = createMock(Unmarshaller.class);
|
||||
MimeMessage messageMock = createMock(MimeMessage.class);
|
||||
|
||||
messageControl.expectAndReturn(messageMock.getPayloadSource(), null);
|
||||
expect(messageMock.getPayloadSource()).andReturn(null);
|
||||
|
||||
unmarshallerControl.replay();
|
||||
messageControl.replay();
|
||||
replay(unmarshallerMock, messageMock);
|
||||
|
||||
Object result = MarshallingUtils.unmarshal(unmarshallerMock, messageMock);
|
||||
assertNull("Invalid unmarshalled object", result);
|
||||
Assert.assertNull("Invalid unmarshalled object", result);
|
||||
|
||||
unmarshallerControl.verify();
|
||||
messageControl.verify();
|
||||
verify(unmarshallerMock, messageMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarshal() throws Exception {
|
||||
MockControl marshallerControl = MockControl.createControl(Marshaller.class);
|
||||
Marshaller marshallerMock = (Marshaller) marshallerControl.getMock();
|
||||
MockControl messageControl = MockControl.createControl(WebServiceMessage.class);
|
||||
WebServiceMessage messageMock = (WebServiceMessage) messageControl.getMock();
|
||||
Marshaller marshallerMock = createMock(Marshaller.class);
|
||||
WebServiceMessage messageMock = createMock(WebServiceMessage.class);
|
||||
|
||||
Result result = new StringResult();
|
||||
Object marshalled = new Object();
|
||||
messageControl.expectAndReturn(messageMock.getPayloadResult(), result);
|
||||
expect(messageMock.getPayloadResult()).andReturn(result);
|
||||
marshallerMock.marshal(marshalled, result);
|
||||
|
||||
marshallerControl.replay();
|
||||
messageControl.replay();
|
||||
replay(marshallerMock, messageMock);
|
||||
|
||||
MarshallingUtils.marshal(marshallerMock, marshalled, messageMock);
|
||||
|
||||
marshallerControl.verify();
|
||||
messageControl.verify();
|
||||
verify(marshallerMock, messageMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarshalMime() throws Exception {
|
||||
MockControl marshallerControl = MockControl.createControl(MimeMarshaller.class);
|
||||
MimeMarshaller marshallerMock = (MimeMarshaller) marshallerControl.getMock();
|
||||
MockControl messageControl = MockControl.createControl(MimeMessage.class);
|
||||
MimeMessage messageMock = (MimeMessage) messageControl.getMock();
|
||||
MimeMarshaller marshallerMock = createMock(MimeMarshaller.class);
|
||||
MimeMessage messageMock = createMock(MimeMessage.class);
|
||||
|
||||
Result result = new StringResult();
|
||||
Object marshalled = new Object();
|
||||
messageControl.expectAndReturn(messageMock.getPayloadResult(), result);
|
||||
marshallerMock.marshal(marshalled, result, null);
|
||||
marshallerControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
expect(messageMock.getPayloadResult()).andReturn(result);
|
||||
marshallerMock.marshal(eq(marshalled), eq(result), isA(MimeContainer.class));
|
||||
|
||||
marshallerControl.replay();
|
||||
messageControl.replay();
|
||||
replay(marshallerMock, messageMock);
|
||||
|
||||
MarshallingUtils.marshal(marshallerMock, marshalled, messageMock);
|
||||
|
||||
marshallerControl.verify();
|
||||
messageControl.verify();
|
||||
verify(marshallerMock, messageMock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,49 +16,51 @@
|
||||
|
||||
package org.springframework.ws.transport.http;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import org.springframework.ws.transport.http.LastModifiedHelper;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.transform.ResourceSource;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class LastModifiedHelperTest extends TestCase {
|
||||
public class LastModifiedHelperTest {
|
||||
|
||||
private Resource resource;
|
||||
|
||||
private long expected;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resource = new ClassPathResource("single.xsd", getClass());
|
||||
expected = resource.lastModified();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaxSource() throws Exception {
|
||||
long result = LastModifiedHelper.getLastModified(new ResourceSource(resource));
|
||||
assertEquals("Invalid last modified", expected, result);
|
||||
Assert.assertEquals("Invalid last modified", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomSource() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(resource.getFile());
|
||||
long result = LastModifiedHelper.getLastModified(new DOMSource(document));
|
||||
assertEquals("Invalid last modified", expected, result);
|
||||
Assert.assertEquals("Invalid last modified", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamSource() throws Exception {
|
||||
long result = LastModifiedHelper.getLastModified(new StreamSource(resource.getFile()));
|
||||
assertEquals("Invalid last modified", expected, result);
|
||||
Assert.assertEquals("Invalid last modified", expected, result);
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.springframework.ws.transport.http;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.ws.FaultAwareWebServiceMessage;
|
||||
@@ -29,7 +28,13 @@ import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.transport.WebServiceMessageReceiver;
|
||||
|
||||
public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class WebServiceMessageReceiverHandlerAdapterTest {
|
||||
|
||||
private static final String REQUEST = " <SOAP-ENV:Envelope\n" +
|
||||
" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
|
||||
@@ -43,29 +48,24 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
|
||||
|
||||
private MockHttpServletResponse httpResponse;
|
||||
|
||||
private MockControl factoryControl;
|
||||
|
||||
private WebServiceMessageFactory factoryMock;
|
||||
|
||||
private MockControl messageControl;
|
||||
|
||||
private FaultAwareWebServiceMessage responseMock;
|
||||
|
||||
private FaultAwareWebServiceMessage requestMock;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
adapter = new WebServiceMessageReceiverHandlerAdapter();
|
||||
httpRequest = new MockHttpServletRequest();
|
||||
httpResponse = new MockHttpServletResponse();
|
||||
factoryControl = MockControl.createControl(WebServiceMessageFactory.class);
|
||||
factoryMock = (WebServiceMessageFactory) factoryControl.getMock();
|
||||
factoryMock = createMock(WebServiceMessageFactory.class);
|
||||
adapter.setMessageFactory(factoryMock);
|
||||
messageControl = MockControl.createControl(FaultAwareWebServiceMessage.class);
|
||||
requestMock = (FaultAwareWebServiceMessage) messageControl.getMock();
|
||||
responseMock = (FaultAwareWebServiceMessage) messageControl.getMock();
|
||||
requestMock = createMock("request", FaultAwareWebServiceMessage.class);
|
||||
responseMock = createMock("response", FaultAwareWebServiceMessage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleNonPost() throws Exception {
|
||||
httpRequest.setMethod(HttpTransportConstants.METHOD_GET);
|
||||
replayMockControls();
|
||||
@@ -75,19 +75,18 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
|
||||
}
|
||||
};
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED,
|
||||
Assert.assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED,
|
||||
httpResponse.getStatus());
|
||||
verifyMockControls();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePostNoResponse() throws Exception {
|
||||
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
|
||||
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
factoryMock.createWebServiceMessage(null);
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(responseMock);
|
||||
expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(responseMock);
|
||||
|
||||
replayMockControls();
|
||||
WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() {
|
||||
@@ -98,23 +97,22 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
|
||||
assertEquals("Invalid status code on response", HttpServletResponse.SC_ACCEPTED, httpResponse.getStatus());
|
||||
assertEquals("Response written", 0, httpResponse.getContentAsString().length());
|
||||
Assert.assertEquals("Invalid status code on response", HttpServletResponse.SC_ACCEPTED,
|
||||
httpResponse.getStatus());
|
||||
Assert.assertEquals("Response written", 0, httpResponse.getContentAsString().length());
|
||||
verifyMockControls();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePostResponse() throws Exception {
|
||||
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
|
||||
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
factoryMock.createWebServiceMessage(null);
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(requestMock);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), responseMock);
|
||||
messageControl.expectAndReturn(responseMock.hasFault(), false);
|
||||
responseMock.writeTo(null);
|
||||
messageControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(requestMock);
|
||||
expect(factoryMock.createWebServiceMessage()).andReturn(responseMock);
|
||||
expect(responseMock.hasFault()).andReturn(false);
|
||||
responseMock.writeTo(isA(OutputStream.class));
|
||||
|
||||
replayMockControls();
|
||||
WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() {
|
||||
@@ -126,22 +124,20 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
|
||||
assertEquals("Invalid status code on response", HttpServletResponse.SC_OK, httpResponse.getStatus());
|
||||
Assert.assertEquals("Invalid status code on response", HttpServletResponse.SC_OK, httpResponse.getStatus());
|
||||
verifyMockControls();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePostFault() throws Exception {
|
||||
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
|
||||
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
factoryMock.createWebServiceMessage(null);
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(requestMock);
|
||||
factoryControl.expectAndReturn(factoryMock.createWebServiceMessage(), responseMock);
|
||||
messageControl.expectAndReturn(responseMock.hasFault(), true);
|
||||
responseMock.writeTo(null);
|
||||
messageControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(requestMock);
|
||||
expect(factoryMock.createWebServiceMessage()).andReturn(responseMock);
|
||||
expect(responseMock.hasFault()).andReturn(true);
|
||||
responseMock.writeTo(isA(OutputStream.class));
|
||||
|
||||
replayMockControls();
|
||||
WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() {
|
||||
@@ -153,19 +149,18 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
|
||||
assertEquals("Invalid status code on response", HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
Assert.assertEquals("Invalid status code on response", HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
httpResponse.getStatus());
|
||||
verifyMockControls();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleNotFound() throws Exception {
|
||||
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
|
||||
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
|
||||
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
|
||||
httpRequest.setCharacterEncoding("UTF-8");
|
||||
factoryMock.createWebServiceMessage(null);
|
||||
factoryControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
factoryControl.setReturnValue(requestMock);
|
||||
expect(factoryMock.createWebServiceMessage(isA(InputStream.class))).andReturn(requestMock);
|
||||
|
||||
replayMockControls();
|
||||
|
||||
@@ -177,20 +172,18 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
|
||||
};
|
||||
|
||||
adapter.handle(httpRequest, httpResponse, endpoint);
|
||||
assertEquals("No 404 returned", HttpServletResponse.SC_NOT_FOUND, httpResponse.getStatus());
|
||||
Assert.assertEquals("No 404 returned", HttpServletResponse.SC_NOT_FOUND, httpResponse.getStatus());
|
||||
|
||||
verifyMockControls();
|
||||
|
||||
}
|
||||
|
||||
private void replayMockControls() {
|
||||
factoryControl.replay();
|
||||
messageControl.replay();
|
||||
replay(factoryMock, requestMock, responseMock);
|
||||
}
|
||||
|
||||
private void verifyMockControls() {
|
||||
factoryControl.verify();
|
||||
messageControl.verify();
|
||||
verify(factoryMock, requestMock, responseMock);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,76 +18,77 @@ package org.springframework.ws.transport.support;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
import org.springframework.ws.MockWebServiceMessageFactory;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.transport.WebServiceConnection;
|
||||
import org.springframework.ws.transport.WebServiceMessageReceiver;
|
||||
|
||||
public class WebServiceMessageReceiverObjectSupportTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
public class WebServiceMessageReceiverObjectSupportTest {
|
||||
|
||||
private WebServiceMessageReceiverObjectSupport receiverSupport;
|
||||
|
||||
private MockControl connectionControl;
|
||||
|
||||
private WebServiceConnection connectionMock;
|
||||
|
||||
private MockWebServiceMessageFactory messageFactory;
|
||||
|
||||
private MockWebServiceMessage request;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
receiverSupport = new MyReceiverSupport();
|
||||
messageFactory = new MockWebServiceMessageFactory();
|
||||
receiverSupport.setMessageFactory(messageFactory);
|
||||
connectionControl = MockControl.createStrictControl(WebServiceConnection.class);
|
||||
connectionMock = (WebServiceConnection) connectionControl.getMock();
|
||||
connectionMock = createStrictMock(WebServiceConnection.class);
|
||||
request = new MockWebServiceMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleConnectionResponse() throws Exception {
|
||||
connectionControl.expectAndReturn(connectionMock.getUri(), new URI("http://example.com"));
|
||||
connectionControl.expectAndReturn(connectionMock.receive(messageFactory), request);
|
||||
connectionMock.send(new MockWebServiceMessage());
|
||||
connectionControl.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
expect(connectionMock.getUri()).andReturn(new URI("http://example.com"));
|
||||
expect(connectionMock.receive(messageFactory)).andReturn(request);
|
||||
connectionMock.send(isA(WebServiceMessage.class));
|
||||
connectionMock.close();
|
||||
|
||||
connectionControl.replay();
|
||||
replay(connectionMock);
|
||||
|
||||
WebServiceMessageReceiver receiver = new WebServiceMessageReceiver() {
|
||||
|
||||
public void receive(MessageContext messageContext) throws Exception {
|
||||
assertNotNull("No message context", messageContext);
|
||||
Assert.assertNotNull("No message context", messageContext);
|
||||
messageContext.getResponse();
|
||||
}
|
||||
};
|
||||
|
||||
receiverSupport.handleConnection(connectionMock, receiver);
|
||||
|
||||
connectionControl.verify();
|
||||
verify(connectionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleConnectionNoResponse() throws Exception {
|
||||
connectionControl.expectAndReturn(connectionMock.getUri(), new URI("http://example.com"));
|
||||
connectionControl.expectAndReturn(connectionMock.receive(messageFactory), request);
|
||||
expect(connectionMock.getUri()).andReturn(new URI("http://example.com"));
|
||||
expect(connectionMock.receive(messageFactory)).andReturn(request);
|
||||
connectionMock.close();
|
||||
|
||||
connectionControl.replay();
|
||||
replay(connectionMock);
|
||||
|
||||
WebServiceMessageReceiver receiver = new WebServiceMessageReceiver() {
|
||||
|
||||
public void receive(MessageContext messageContext) throws Exception {
|
||||
assertNotNull("No message context", messageContext);
|
||||
Assert.assertNotNull("No message context", messageContext);
|
||||
}
|
||||
};
|
||||
|
||||
receiverSupport.handleConnection(connectionMock, receiver);
|
||||
|
||||
connectionControl.verify();
|
||||
verify(connectionMock);
|
||||
}
|
||||
|
||||
private static class MyReceiverSupport extends WebServiceMessageReceiverObjectSupport {
|
||||
|
||||
@@ -16,21 +16,25 @@
|
||||
|
||||
package org.springframework.ws.wsdl.wsdl11;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public class SimpleWsdl11DefinitionTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SimpleWsdl11DefinitionTest {
|
||||
|
||||
private SimpleWsdl11Definition definition;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
definition = new SimpleWsdl11Definition();
|
||||
definition.setWsdl(new ClassPathResource("complete.wsdl", getClass()));
|
||||
definition.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
assertNotNull("No source returned", definition.getSource());
|
||||
Assert.assertNotNull("No source returned", definition.getSource());
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,16 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
|
||||
public class DefaultMessagesProviderTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class DefaultMessagesProviderTest {
|
||||
|
||||
private DefaultMessagesProvider provider;
|
||||
|
||||
@@ -41,8 +43,8 @@ public class DefaultMessagesProviderTest extends TestCase {
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
provider = new DefaultMessagesProvider();
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
@@ -51,6 +53,7 @@ public class DefaultMessagesProviderTest extends TestCase {
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddMessages() throws Exception {
|
||||
String definitionNamespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", definitionNamespace);
|
||||
@@ -69,24 +72,27 @@ public class DefaultMessagesProviderTest extends TestCase {
|
||||
|
||||
provider.addMessages(definition);
|
||||
|
||||
assertEquals("Invalid amount of messages created", 3, definition.getMessages().size());
|
||||
Assert.assertEquals("Invalid amount of messages created", 3, definition.getMessages().size());
|
||||
|
||||
Message message = definition.getMessage(new QName(definitionNamespace, "GetOrderRequest"));
|
||||
assertNotNull("Message not created", message);
|
||||
Assert.assertNotNull("Message not created", message);
|
||||
Part part = message.getPart("GetOrderRequest");
|
||||
assertNotNull("Part not created", part);
|
||||
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderRequest"), part.getElementName());
|
||||
Assert.assertNotNull("Part not created", part);
|
||||
Assert.assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderRequest"),
|
||||
part.getElementName());
|
||||
|
||||
message = definition.getMessage(new QName(definitionNamespace, "GetOrderResponse"));
|
||||
assertNotNull("Message not created", message);
|
||||
Assert.assertNotNull("Message not created", message);
|
||||
part = message.getPart("GetOrderResponse");
|
||||
assertNotNull("Part not created", part);
|
||||
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderResponse"), part.getElementName());
|
||||
Assert.assertNotNull("Part not created", part);
|
||||
Assert.assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderResponse"),
|
||||
part.getElementName());
|
||||
|
||||
message = definition.getMessage(new QName(definitionNamespace, "GetOrderFault"));
|
||||
assertNotNull("Message not created", message);
|
||||
Assert.assertNotNull("Message not created", message);
|
||||
part = message.getPart("GetOrderFault");
|
||||
assertNotNull("Part not created", part);
|
||||
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderFault"), part.getElementName());
|
||||
Assert.assertNotNull("Part not created", part);
|
||||
Assert.assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderFault"),
|
||||
part.getElementName());
|
||||
}
|
||||
}
|
||||
@@ -21,26 +21,29 @@ import javax.wsdl.Types;
|
||||
import javax.wsdl.extensions.schema.Schema;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
|
||||
|
||||
public class InliningXsdSchemaTypesProviderTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class InliningXsdSchemaTypesProviderTest {
|
||||
|
||||
private InliningXsdSchemaTypesProvider provider;
|
||||
|
||||
private Definition definition;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
provider = new InliningXsdSchemaTypesProvider();
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingle() throws Exception {
|
||||
String definitionNamespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", definitionNamespace);
|
||||
@@ -57,13 +60,14 @@ public class InliningXsdSchemaTypesProviderTest extends TestCase {
|
||||
provider.addTypes(definition);
|
||||
|
||||
Types types = definition.getTypes();
|
||||
assertNotNull("No types created", types);
|
||||
assertEquals("Invalid amount of schemas", 1, types.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No types created", types);
|
||||
Assert.assertEquals("Invalid amount of schemas", 1, types.getExtensibilityElements().size());
|
||||
|
||||
Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
|
||||
assertNotNull("No element defined", wsdlSchema.getElement());
|
||||
Assert.assertNotNull("No element defined", wsdlSchema.getElement());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplex() throws Exception {
|
||||
String definitionNamespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", definitionNamespace);
|
||||
@@ -81,13 +85,13 @@ public class InliningXsdSchemaTypesProviderTest extends TestCase {
|
||||
provider.addTypes(definition);
|
||||
|
||||
Types types = definition.getTypes();
|
||||
assertNotNull("No types created", types);
|
||||
assertEquals("Invalid amount of schemas", 2, types.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No types created", types);
|
||||
Assert.assertEquals("Invalid amount of schemas", 2, types.getExtensibilityElements().size());
|
||||
|
||||
Schema wsdlSchema = (Schema) types.getExtensibilityElements().get(0);
|
||||
assertNotNull("No element defined", wsdlSchema.getElement());
|
||||
Assert.assertNotNull("No element defined", wsdlSchema.getElement());
|
||||
|
||||
wsdlSchema = (Schema) types.getExtensibilityElements().get(1);
|
||||
assertNotNull("No element defined", wsdlSchema.getElement());
|
||||
Assert.assertNotNull("No element defined", wsdlSchema.getElement());
|
||||
}
|
||||
}
|
||||
@@ -39,21 +39,24 @@ import javax.wsdl.extensions.soap.SOAPOperation;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Soap11ProviderTest extends TestCase {
|
||||
public class Soap11ProviderTest {
|
||||
|
||||
private Soap11Provider provider;
|
||||
|
||||
private Definition definition;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
provider = new Soap11Provider();
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulateBinding() throws Exception {
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", namespace);
|
||||
@@ -91,52 +94,56 @@ public class Soap11ProviderTest extends TestCase {
|
||||
provider.addServices(definition);
|
||||
|
||||
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
|
||||
assertNotNull("No binding created", binding);
|
||||
assertEquals("Invalid port type", portType, binding.getPortType());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding created", binding);
|
||||
Assert.assertEquals("Invalid port type", portType, binding.getPortType());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
|
||||
|
||||
SOAPBinding soapBinding = (SOAPBinding) binding.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid style", "document", soapBinding.getStyle());
|
||||
assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
|
||||
Assert.assertEquals("Invalid style", "document", soapBinding.getStyle());
|
||||
Assert.assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
|
||||
|
||||
BindingOperation bindingOperation = binding.getBindingOperation("Operation", "Input", "Output");
|
||||
assertNotNull("No binding operation created", bindingOperation);
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingOperation.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding operation created", bindingOperation);
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingOperation.getExtensibilityElements().size());
|
||||
|
||||
SOAPOperation soapOperation = (SOAPOperation) bindingOperation.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
|
||||
Assert.assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
|
||||
|
||||
BindingInput bindingInput = bindingOperation.getBindingInput();
|
||||
assertNotNull("No binding input", bindingInput);
|
||||
assertEquals("Invalid name", "Input", bindingInput.getName());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingInput.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding input", bindingInput);
|
||||
Assert.assertEquals("Invalid name", "Input", bindingInput.getName());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingInput.getExtensibilityElements().size());
|
||||
SOAPBody soapBody = (SOAPBody) bindingInput.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
Assert.assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
|
||||
BindingOutput bindingOutput = bindingOperation.getBindingOutput();
|
||||
assertNotNull("No binding output", bindingOutput);
|
||||
assertEquals("Invalid name", "Output", bindingOutput.getName());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingOutput.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding output", bindingOutput);
|
||||
Assert.assertEquals("Invalid name", "Output", bindingOutput.getName());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingOutput.getExtensibilityElements().size());
|
||||
soapBody = (SOAPBody) bindingOutput.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
Assert.assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
|
||||
BindingFault bindingFault = bindingOperation.getBindingFault("Fault");
|
||||
assertNotNull("No binding fault", bindingFault);
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingFault.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding fault", bindingFault);
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingFault.getExtensibilityElements().size());
|
||||
SOAPFault soapFault = (SOAPFault) bindingFault.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
|
||||
Assert.assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
|
||||
|
||||
Service service = definition.getService(new QName(namespace, "Service"));
|
||||
assertNotNull("No Service created", service);
|
||||
assertEquals("Invalid amount of ports", 1, service.getPorts().size());
|
||||
Assert.assertNotNull("No Service created", service);
|
||||
Assert.assertEquals("Invalid amount of ports", 1, service.getPorts().size());
|
||||
|
||||
Port port = service.getPort("PortTypeSoap11");
|
||||
assertNotNull("No port created", port);
|
||||
assertEquals("Invalid binding", binding, port.getBinding());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No port created", port);
|
||||
Assert.assertEquals("Invalid binding", binding, port.getBinding());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
|
||||
|
||||
SOAPAddress soapAddress = (SOAPAddress) port.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
|
||||
Assert.assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,21 +39,24 @@ import javax.wsdl.extensions.soap12.SOAP12Operation;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Soap12ProviderTest extends TestCase {
|
||||
public class Soap12ProviderTest {
|
||||
|
||||
private Soap12Provider provider;
|
||||
|
||||
private Definition definition;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
provider = new Soap12Provider();
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulateBinding() throws Exception {
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", namespace);
|
||||
@@ -91,52 +94,56 @@ public class Soap12ProviderTest extends TestCase {
|
||||
provider.addServices(definition);
|
||||
|
||||
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap12"));
|
||||
assertNotNull("No binding created", binding);
|
||||
assertEquals("Invalid port type", portType, binding.getPortType());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding created", binding);
|
||||
Assert.assertEquals("Invalid port type", portType, binding.getPortType());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1, binding.getExtensibilityElements().size());
|
||||
|
||||
SOAP12Binding soapBinding = (SOAP12Binding) binding.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid style", "document", soapBinding.getStyle());
|
||||
assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
|
||||
Assert.assertEquals("Invalid style", "document", soapBinding.getStyle());
|
||||
Assert.assertEquals("Invalid amount of binding operations", 1, binding.getBindingOperations().size());
|
||||
|
||||
BindingOperation bindingOperation = binding.getBindingOperation("Operation", "Input", "Output");
|
||||
assertNotNull("No binding operation created", bindingOperation);
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingOperation.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding operation created", bindingOperation);
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingOperation.getExtensibilityElements().size());
|
||||
|
||||
SOAP12Operation soapOperation = (SOAP12Operation) bindingOperation.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
|
||||
Assert.assertEquals("Invalid SOAPAction", namespace + "/Action", soapOperation.getSoapActionURI());
|
||||
|
||||
BindingInput bindingInput = bindingOperation.getBindingInput();
|
||||
assertNotNull("No binding input", bindingInput);
|
||||
assertEquals("Invalid name", "Input", bindingInput.getName());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingInput.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding input", bindingInput);
|
||||
Assert.assertEquals("Invalid name", "Input", bindingInput.getName());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingInput.getExtensibilityElements().size());
|
||||
SOAP12Body soapBody = (SOAP12Body) bindingInput.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
Assert.assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
|
||||
BindingOutput bindingOutput = bindingOperation.getBindingOutput();
|
||||
assertNotNull("No binding output", bindingOutput);
|
||||
assertEquals("Invalid name", "Output", bindingOutput.getName());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingOutput.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding output", bindingOutput);
|
||||
Assert.assertEquals("Invalid name", "Output", bindingOutput.getName());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingOutput.getExtensibilityElements().size());
|
||||
soapBody = (SOAP12Body) bindingOutput.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
Assert.assertEquals("Invalid soap body use", "literal", soapBody.getUse());
|
||||
|
||||
BindingFault bindingFault = bindingOperation.getBindingFault("Fault");
|
||||
assertNotNull("No binding fault", bindingFault);
|
||||
assertEquals("Invalid amount of extensibility elements", 1, bindingFault.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No binding fault", bindingFault);
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1,
|
||||
bindingFault.getExtensibilityElements().size());
|
||||
SOAP12Fault soapFault = (SOAP12Fault) bindingFault.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
|
||||
Assert.assertEquals("Invalid soap fault use", "literal", soapFault.getUse());
|
||||
|
||||
Service service = definition.getService(new QName(namespace, "Service"));
|
||||
assertNotNull("No Service created", service);
|
||||
assertEquals("Invalid amount of ports", 1, service.getPorts().size());
|
||||
Assert.assertNotNull("No Service created", service);
|
||||
Assert.assertEquals("Invalid amount of ports", 1, service.getPorts().size());
|
||||
|
||||
Port port = service.getPort("PortTypeSoap12");
|
||||
assertNotNull("No port created", port);
|
||||
assertEquals("Invalid binding", binding, port.getBinding());
|
||||
assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
|
||||
Assert.assertNotNull("No port created", port);
|
||||
Assert.assertEquals("Invalid binding", binding, port.getBinding());
|
||||
Assert.assertEquals("Invalid amount of extensibility elements", 1, port.getExtensibilityElements().size());
|
||||
|
||||
SOAP12Address soapAddress = (SOAP12Address) port.getExtensibilityElements().get(0);
|
||||
assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
|
||||
Assert.assertEquals("Invalid soap address", locationUri, soapAddress.getLocationURI());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,21 +30,24 @@ import javax.wsdl.Service;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SoapProviderTest extends TestCase {
|
||||
public class SoapProviderTest {
|
||||
|
||||
private SoapProvider provider;
|
||||
|
||||
private Definition definition;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
provider = new SoapProvider();
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulateBinding() throws Exception {
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", namespace);
|
||||
@@ -85,18 +88,18 @@ public class SoapProviderTest extends TestCase {
|
||||
provider.addServices(definition);
|
||||
|
||||
Binding binding = definition.getBinding(new QName(namespace, "PortTypeSoap11"));
|
||||
assertNotNull("No SOAP 1.1 binding created", binding);
|
||||
Assert.assertNotNull("No SOAP 1.1 binding created", binding);
|
||||
binding = definition.getBinding(new QName(namespace, "PortTypeSoap12"));
|
||||
assertNotNull("No SOAP 1.2 binding created", binding);
|
||||
Assert.assertNotNull("No SOAP 1.2 binding created", binding);
|
||||
|
||||
Service service = definition.getService(new QName(namespace, "Service"));
|
||||
assertNotNull("No Service created", service);
|
||||
assertEquals("Invalid amount of ports", 2, service.getPorts().size());
|
||||
Assert.assertNotNull("No Service created", service);
|
||||
Assert.assertEquals("Invalid amount of ports", 2, service.getPorts().size());
|
||||
|
||||
Port port = service.getPort("PortTypeSoap11");
|
||||
assertNotNull("No SOAP 1.1 port created", port);
|
||||
Assert.assertNotNull("No SOAP 1.1 port created", port);
|
||||
port = service.getPort("PortTypeSoap12");
|
||||
assertNotNull("No SOAP 1.2 port created", port);
|
||||
Assert.assertNotNull("No SOAP 1.2 port created", port);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,14 +26,16 @@ import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
|
||||
public class SuffixBasedMessagesProviderTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class SuffixBasedMessagesProviderTest {
|
||||
|
||||
private SuffixBasedMessagesProvider provider;
|
||||
|
||||
@@ -41,8 +43,8 @@ public class SuffixBasedMessagesProviderTest extends TestCase {
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
provider = new SuffixBasedMessagesProvider();
|
||||
provider.setFaultSuffix("Foo");
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
@@ -52,6 +54,7 @@ public class SuffixBasedMessagesProviderTest extends TestCase {
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddMessages() throws Exception {
|
||||
String definitionNamespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", definitionNamespace);
|
||||
@@ -70,18 +73,20 @@ public class SuffixBasedMessagesProviderTest extends TestCase {
|
||||
|
||||
provider.addMessages(definition);
|
||||
|
||||
assertEquals("Invalid amount of messages created", 2, definition.getMessages().size());
|
||||
Assert.assertEquals("Invalid amount of messages created", 2, definition.getMessages().size());
|
||||
|
||||
Message message = definition.getMessage(new QName(definitionNamespace, "GetOrderRequest"));
|
||||
assertNotNull("Message not created", message);
|
||||
Assert.assertNotNull("Message not created", message);
|
||||
Part part = message.getPart("GetOrderRequest");
|
||||
assertNotNull("Part not created", part);
|
||||
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderRequest"), part.getElementName());
|
||||
Assert.assertNotNull("Part not created", part);
|
||||
Assert.assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderRequest"),
|
||||
part.getElementName());
|
||||
|
||||
message = definition.getMessage(new QName(definitionNamespace, "GetOrderResponse"));
|
||||
assertNotNull("Message not created", message);
|
||||
Assert.assertNotNull("Message not created", message);
|
||||
part = message.getPart("GetOrderResponse");
|
||||
assertNotNull("Part not created", part);
|
||||
assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderResponse"), part.getElementName());
|
||||
Assert.assertNotNull("Part not created", part);
|
||||
Assert.assertEquals("Invalid element on part", new QName(schemaNamespace, "GetOrderResponse"),
|
||||
part.getElementName());
|
||||
}
|
||||
}
|
||||
@@ -23,21 +23,24 @@ import javax.wsdl.PortType;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SuffixBasedPortTypesProviderTest extends TestCase {
|
||||
public class SuffixBasedPortTypesProviderTest {
|
||||
|
||||
private SuffixBasedPortTypesProvider provider;
|
||||
|
||||
private Definition definition;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
provider = new SuffixBasedPortTypesProvider();
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
definition = factory.newDefinition();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddPortTypes() throws Exception {
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
definition.addNamespace("tns", namespace);
|
||||
@@ -59,12 +62,12 @@ public class SuffixBasedPortTypesProviderTest extends TestCase {
|
||||
provider.addPortTypes(definition);
|
||||
|
||||
PortType portType = definition.getPortType(new QName(namespace, "PortType"));
|
||||
assertNotNull("No port type created", portType);
|
||||
Assert.assertNotNull("No port type created", portType);
|
||||
|
||||
Operation operation = portType.getOperation("Operation", "OperationRequest", "OperationResponse");
|
||||
assertNotNull("No operation created", operation);
|
||||
assertNotNull("No input created", operation.getInput());
|
||||
assertNotNull("No output created", operation.getOutput());
|
||||
assertFalse("No fault created", operation.getFaults().isEmpty());
|
||||
Assert.assertNotNull("No operation created", operation);
|
||||
Assert.assertNotNull("No input created", operation.getInput());
|
||||
Assert.assertNotNull("No output created", operation.getOutput());
|
||||
Assert.assertFalse("No fault created", operation.getFaults().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@ import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CallbackHandlerChainTest extends TestCase {
|
||||
public class CallbackHandlerChainTest {
|
||||
|
||||
private CallbackHandler supported = new CallbackHandler() {
|
||||
public void handle(Callback[] callbacks) {
|
||||
@@ -38,28 +38,21 @@ public class CallbackHandlerChainTest extends TestCase {
|
||||
private Callback callback = new Callback() {
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupported() throws Exception {
|
||||
CallbackHandlerChain chain = new CallbackHandlerChain(new CallbackHandler[]{supported});
|
||||
chain.handle(new Callback[]{callback});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedSupported() throws Exception {
|
||||
CallbackHandlerChain chain = new CallbackHandlerChain(new CallbackHandler[]{unsupported, supported});
|
||||
chain.handle(new Callback[]{callback});
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedCallbackException.class)
|
||||
public void testUnsupported() throws Exception {
|
||||
CallbackHandlerChain chain = new CallbackHandlerChain(new CallbackHandler[]{unsupported});
|
||||
try {
|
||||
chain.handle(new Callback[]{callback});
|
||||
fail("Expected UnsupportedCallbackException");
|
||||
}
|
||||
catch (UnsupportedCallbackException ex) {
|
||||
// expected behavior
|
||||
}
|
||||
chain.handle(new Callback[]{callback});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,11 +35,16 @@ import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SaajWss4jMessageInterceptorSignTest extends Wss4jMessageInterceptorSignTestCase {
|
||||
|
||||
private static final String PAYLOAD =
|
||||
"<tru:StockSymbol xmlns:tru=\"http://fabrikam123.com/payloads\">QQQ</tru:StockSymbol>";
|
||||
|
||||
@Test
|
||||
public void testSignAndValidate() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
interceptor.setSecurementActions("Signature");
|
||||
@@ -54,7 +59,7 @@ public class SaajWss4jMessageInterceptorSignTest extends Wss4jMessageInterceptor
|
||||
interceptor.secureMessage(message, messageContext);
|
||||
|
||||
SOAPHeader header = ((SaajSoapMessage) message).getSaajMessage().getSOAPHeader();
|
||||
Iterator iterator = header.getChildElements(new QName(
|
||||
Iterator<?> iterator = header.getChildElements(new QName(
|
||||
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security"));
|
||||
assertTrue("No security header", iterator.hasNext());
|
||||
SOAPHeaderElement securityHeader = (SOAPHeaderElement) iterator.next();
|
||||
|
||||
@@ -22,9 +22,15 @@ import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.WsSecuritySecurementException;
|
||||
import org.springframework.ws.soap.security.WsSecurityValidationException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public abstract class Wss4jInterceptorTestCase extends Wss4jTestCase {
|
||||
|
||||
public void testhandleRequest() throws Exception {
|
||||
@Test
|
||||
public void testHandleRequest() throws Exception {
|
||||
SoapMessage request = loadSoap11Message("empty-soap.xml");
|
||||
final Object requestMessage = getMessage(request);
|
||||
SoapMessage validatedRequest = loadSoap11Message("empty-soap.xml");
|
||||
@@ -48,7 +54,8 @@ public abstract class Wss4jInterceptorTestCase extends Wss4jTestCase {
|
||||
assertEquals("Invalid request", validatedRequestMessage, getMessage((SoapMessage) context.getRequest()));
|
||||
}
|
||||
|
||||
public void testhandleResponse() throws Exception {
|
||||
@Test
|
||||
public void testHandleResponse() throws Exception {
|
||||
SoapMessage securedResponse = loadSoap11Message("empty-soap.xml");
|
||||
final Object securedResponseMessage = getMessage(securedResponse);
|
||||
|
||||
|
||||
@@ -18,15 +18,16 @@ package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.ws.security.components.crypto.Crypto;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.KeyStoreCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean;
|
||||
|
||||
import org.apache.ws.security.components.crypto.Crypto;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorEncryptionTestCase extends Wss4jTestCase {
|
||||
|
||||
protected Wss4jSecurityInterceptor interceptor;
|
||||
@@ -61,6 +62,7 @@ public abstract class Wss4jMessageInterceptorEncryptionTestCase extends Wss4jTes
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptRequest() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("encrypted-soap.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getSoap11MessageFactory());
|
||||
@@ -72,6 +74,7 @@ public abstract class Wss4jMessageInterceptorEncryptionTestCase extends Wss4jTes
|
||||
getDocument(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptResponse() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("empty-soap.xml");
|
||||
MessageContext messageContext = getSoap11MessageContext(message);
|
||||
|
||||
@@ -28,6 +28,11 @@ import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.WsSecurityValidationException;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCase {
|
||||
|
||||
private Wss4jSecurityInterceptor interceptor;
|
||||
@@ -46,6 +51,7 @@ public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCas
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenPlainText() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("usernameTokenPlainTextWithHeaders-soap.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getSoap11MessageFactory());
|
||||
@@ -53,8 +59,8 @@ public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCas
|
||||
Object result = getMessage(message);
|
||||
assertNotNull("No result returned", result);
|
||||
|
||||
for (Iterator i = message.getEnvelope().getHeader().examineAllHeaderElements(); i.hasNext();) {
|
||||
SoapHeaderElement element = (SoapHeaderElement) i.next();
|
||||
for (Iterator<SoapHeaderElement> i = message.getEnvelope().getHeader().examineAllHeaderElements(); i.hasNext();) {
|
||||
SoapHeaderElement element = i.next();
|
||||
QName name = element.getName();
|
||||
if (name.getNamespaceURI()
|
||||
.equals("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")) {
|
||||
@@ -70,6 +76,7 @@ public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCas
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySecurityHeader() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("emptySecurityHeader-soap.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getSoap11MessageFactory());
|
||||
@@ -82,6 +89,7 @@ public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCas
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreserveCustomHeaders() throws Exception {
|
||||
interceptor.setSecurementActions("UsernameToken");
|
||||
interceptor.setSecurementUsername("Bert");
|
||||
|
||||
@@ -18,15 +18,17 @@ package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.ws.security.components.crypto.Crypto;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase {
|
||||
|
||||
protected Wss4jSecurityInterceptor interceptor;
|
||||
@@ -47,14 +49,15 @@ public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase
|
||||
cryptoFactoryBeanConfig.setProperty("org.apache.ws.security.crypto.merlin.file", "private.jks");
|
||||
cryptoFactoryBean.setConfiguration(cryptoFactoryBeanConfig);
|
||||
cryptoFactoryBean.afterPropertiesSet();
|
||||
interceptor.setValidationSignatureCrypto((Crypto) cryptoFactoryBean
|
||||
interceptor.setValidationSignatureCrypto(cryptoFactoryBean
|
||||
.getObject());
|
||||
interceptor.setSecurementSignatureCrypto((Crypto) cryptoFactoryBean
|
||||
interceptor.setSecurementSignatureCrypto(cryptoFactoryBean
|
||||
.getObject());
|
||||
interceptor.afterPropertiesSet();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCertificate() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("signed-soap.xml");
|
||||
|
||||
@@ -66,6 +69,7 @@ public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase
|
||||
getDocument(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCertificateWithSignatureConfirmation() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("signed-soap.xml");
|
||||
MessageContext messageContext = getSoap11MessageContext(message);
|
||||
@@ -79,6 +83,7 @@ public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase
|
||||
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse11:SignatureConfirmation", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignResponse() throws Exception {
|
||||
interceptor.setSecurementActions("Signature");
|
||||
interceptor.setEnableSignatureConfirmation(false);
|
||||
@@ -98,6 +103,7 @@ public abstract class Wss4jMessageInterceptorSignTestCase extends Wss4jTestCase
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignResponseWithSignatureUser() throws Exception {
|
||||
interceptor.setSecurementActions("Signature");
|
||||
interceptor.setEnableSignatureConfirmation(false);
|
||||
|
||||
@@ -18,13 +18,17 @@ package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.ws.security.WSConstants;
|
||||
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler;
|
||||
import org.springframework.ws.WebServiceMessageFactory;
|
||||
|
||||
import org.apache.ws.security.WSConstants;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorSoapActionTestCase extends Wss4jTestCase {
|
||||
|
||||
@@ -49,6 +53,7 @@ public abstract class Wss4jMessageInterceptorSoapActionTestCase extends Wss4jTes
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreserveSoapActionOnValidation() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("usernameTokenPlainText-soap.xml");
|
||||
message.setSoapAction(SOAP_ACTION);
|
||||
@@ -59,6 +64,7 @@ public abstract class Wss4jMessageInterceptorSoapActionTestCase extends Wss4jTes
|
||||
assertEquals("Soap Action is different from expected", SOAP_ACTION, message.getSoapAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreserveSoap12ActionOnValidation() throws Exception {
|
||||
SoapMessage message = loadSoap12Message("usernameTokenPlainText-soap12.xml");
|
||||
message.setSoapAction(SOAP_ACTION);
|
||||
@@ -70,6 +76,7 @@ public abstract class Wss4jMessageInterceptorSoapActionTestCase extends Wss4jTes
|
||||
assertEquals("Soap Action is different from expected", SOAP_ACTION, message.getSoapAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreserveSoapActionOnSecurement() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("empty-soap.xml");
|
||||
message.setSoapAction(SOAP_ACTION);
|
||||
@@ -83,6 +90,7 @@ public abstract class Wss4jMessageInterceptorSoapActionTestCase extends Wss4jTes
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreserveSoap12ActionOnSecurement() throws Exception {
|
||||
SoapMessage message = loadSoap12Message("empty-soap12.xml");
|
||||
message.setSoapAction(SOAP_ACTION);
|
||||
|
||||
@@ -18,9 +18,6 @@ package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.ws.security.WSConstants;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationManager;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
@@ -35,27 +32,33 @@ import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SpringDigestPasswordValidationCallbackHandler;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SpringPlainTextPasswordValidationCallbackHandler;
|
||||
|
||||
import org.apache.ws.security.WSConstants;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorSpringSecurityCallbackHandlerTestCase extends Wss4jTestCase {
|
||||
|
||||
private Properties users = new Properties();
|
||||
|
||||
private MockControl control;
|
||||
|
||||
private AuthenticationManager mock;
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
@Override
|
||||
protected void onSetup() throws Exception {
|
||||
control = MockControl.createControl(AuthenticationManager.class);
|
||||
mock = (AuthenticationManager) control.getMock();
|
||||
authenticationManager = createMock(AuthenticationManager.class);
|
||||
users.setProperty("Bert", "Ernie,ROLE_TEST");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
control.verify();
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
verify(authenticationManager);
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenPlainText() throws Exception {
|
||||
EndpointInterceptor interceptor = prepareInterceptor("UsernameToken", true, false);
|
||||
SoapMessage message = loadSoap11Message("usernameTokenPlainText-soap.xml");
|
||||
@@ -69,6 +72,7 @@ public abstract class Wss4jMessageInterceptorSpringSecurityCallbackHandlerTestCa
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenDigest() throws Exception {
|
||||
EndpointInterceptor interceptor = prepareInterceptor("UsernameToken", true, true);
|
||||
SoapMessage message = loadSoap11Message("usernameTokenDigest-soap.xml");
|
||||
@@ -114,15 +118,14 @@ public abstract class Wss4jMessageInterceptorSpringSecurityCallbackHandlerTestCa
|
||||
SpringPlainTextPasswordValidationCallbackHandler callbackHandler =
|
||||
new SpringPlainTextPasswordValidationCallbackHandler();
|
||||
Authentication authResult = new TestingAuthenticationToken("Bert", "Ernie", new GrantedAuthority[0]);
|
||||
control.expectAndReturn(mock.authenticate(new UsernamePasswordAuthenticationToken("Bert", "Ernie")),
|
||||
authResult);
|
||||
callbackHandler.setAuthenticationManager(mock);
|
||||
expect(authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("Bert", "Ernie"))).andReturn(authResult);
|
||||
callbackHandler.setAuthenticationManager(authenticationManager);
|
||||
callbackHandler.afterPropertiesSet();
|
||||
interceptor.setSecurementPasswordType(WSConstants.PW_TEXT);
|
||||
interceptor.setValidationCallbackHandler(callbackHandler);
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
control.replay();
|
||||
replay(authenticationManager);
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,15 +19,19 @@ package org.springframework.ws.soap.security.wss4j;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.WsSecurityValidationException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorTimestampTestCase extends Wss4jTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddTimestamp() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
|
||||
interceptor.setSecurementActions("Timestamp");
|
||||
@@ -40,6 +44,7 @@ public abstract class Wss4jMessageInterceptorTimestampTestCase extends Wss4jTest
|
||||
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsu:Timestamp", document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateTimestamp() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
|
||||
interceptor.setValidationActions("Timestamp");
|
||||
@@ -52,26 +57,23 @@ public abstract class Wss4jMessageInterceptorTimestampTestCase extends Wss4jTest
|
||||
getDocument(message));
|
||||
}
|
||||
|
||||
@Test(expected = WsSecurityValidationException.class)
|
||||
public void testValidateTimestampWithExpiredTtl() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
|
||||
interceptor.setValidationActions("Timestamp");
|
||||
interceptor.afterPropertiesSet();
|
||||
SoapMessage message = loadSoap11Message("expiredTimestamp-soap.xml");
|
||||
MessageContext context = new DefaultMessageContext(message, getSoap11MessageFactory());
|
||||
try {
|
||||
interceptor.validateMessage(message, context);
|
||||
fail();
|
||||
}
|
||||
catch (WsSecurityValidationException e) {
|
||||
// expected
|
||||
}
|
||||
interceptor.validateMessage(message, context);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSecureTimestampWithCustomTtl() throws Exception {
|
||||
int ttlInSeconds = 1;
|
||||
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
|
||||
interceptor.setSecurementActions("Timestamp");
|
||||
interceptor.setTimestampStrict(true);
|
||||
int ttlInSeconds = 1;
|
||||
interceptor.setSecurementTimeToLive(ttlInSeconds);
|
||||
interceptor.afterPropertiesSet();
|
||||
SoapMessage message = loadSoap11Message("empty-soap.xml");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
* Copyright 2005-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorUsernameTokenSignatureTestCase extends Wss4jTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddUsernameTokenSignature() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
|
||||
interceptor.setSecurementActions("UsernameTokenSignature");
|
||||
|
||||
@@ -18,14 +18,17 @@ package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.ws.security.WSConstants;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.callback.SimplePasswordValidationCallbackHandler;
|
||||
|
||||
import org.apache.ws.security.WSConstants;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4jTestCase {
|
||||
|
||||
private Properties users = new Properties();
|
||||
@@ -35,6 +38,7 @@ public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4j
|
||||
users.setProperty("Bert", "Ernie");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenPlainText() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = prepareInterceptor("UsernameToken", true, false);
|
||||
SoapMessage message = loadSoap11Message("usernameTokenPlainText-soap.xml");
|
||||
@@ -43,6 +47,7 @@ public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4j
|
||||
assertValidateUsernameToken(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenDigest() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = prepareInterceptor("UsernameToken", true, true);
|
||||
SoapMessage message = loadSoap11Message("usernameTokenDigest-soap.xml");
|
||||
@@ -51,6 +56,7 @@ public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4j
|
||||
assertValidateUsernameToken(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenWithQualifiedType() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = prepareInterceptor("UsernameToken", true, false);
|
||||
SoapMessage message = loadSoap11Message("usernameTokenPlainTextQualifiedType-soap.xml");
|
||||
@@ -59,6 +65,7 @@ public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4j
|
||||
assertValidateUsernameToken(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddUsernameTokenPlainText() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = prepareInterceptor("UsernameToken", false, false);
|
||||
interceptor.setSecurementUsername("Bert");
|
||||
@@ -71,6 +78,7 @@ public abstract class Wss4jMessageInterceptorUsernameTokenTestCase extends Wss4j
|
||||
assertAddUsernameTokenPlainText(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddUsernameTokenDigest() throws Exception {
|
||||
Wss4jSecurityInterceptor interceptor = prepareInterceptor("UsernameToken", false, true);
|
||||
interceptor.setSecurementUsername("Bert");
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
|
||||
package org.springframework.ws.soap.security.wss4j;
|
||||
|
||||
import org.apache.ws.security.components.crypto.Crypto;
|
||||
import org.apache.ws.security.components.crypto.Merlin;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean;
|
||||
|
||||
import org.apache.ws.security.components.crypto.Crypto;
|
||||
import org.apache.ws.security.components.crypto.Merlin;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public abstract class Wss4jMessageInterceptorX509TestCase extends Wss4jTestCase {
|
||||
|
||||
protected Wss4jSecurityInterceptor interceptor;
|
||||
@@ -49,6 +50,7 @@ public abstract class Wss4jMessageInterceptorX509TestCase extends Wss4jTestCase
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCertificate() throws Exception {
|
||||
|
||||
interceptor.setSecurementPassword("123456");
|
||||
@@ -64,7 +66,7 @@ public abstract class Wss4jMessageInterceptorX509TestCase extends Wss4jTestCase
|
||||
assertXpathExists("Absent BinarySecurityToken element",
|
||||
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:BinarySecurityToken", document);
|
||||
|
||||
// lets verfiy the signature that we've just generated
|
||||
// lets verify the signature that we've just generated
|
||||
interceptor.validateMessage(message, messageContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,15 +43,19 @@ import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.springframework.xml.xpath.Jaxp13XPathTemplate;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.axiom.soap.SOAP12Constants;
|
||||
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public abstract class Wss4jTestCase extends TestCase {
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class Wss4jTestCase {
|
||||
|
||||
protected MessageFactory saajSoap11MessageFactory;
|
||||
|
||||
protected MessageFactory saajSoap12MessageFactory;
|
||||
|
||||
protected final boolean axiomTest = this.getClass().getSimpleName().startsWith("Axiom");
|
||||
@@ -60,10 +64,10 @@ public abstract class Wss4jTestCase extends TestCase {
|
||||
|
||||
protected Jaxp13XPathTemplate xpathTemplate = new Jaxp13XPathTemplate();
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
if (!axiomTest && !saajTest) {
|
||||
throw new IllegalArgumentException("test class name must statrt with either Axiom or Saaj");
|
||||
throw new IllegalArgumentException("test class name must start with either Axiom or Saaj");
|
||||
}
|
||||
saajSoap11MessageFactory = MessageFactory.newInstance();
|
||||
saajSoap12MessageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
|
||||
@@ -87,7 +91,7 @@ public abstract class Wss4jTestCase extends TestCase {
|
||||
String xpathExpression,
|
||||
Document document) {
|
||||
String actualValue = xpathTemplate.evaluateAsString(xpathExpression, new DOMSource(document));
|
||||
assertEquals(message, expectedValue, actualValue);
|
||||
Assert.assertEquals(message, expectedValue, actualValue);
|
||||
}
|
||||
|
||||
protected void assertXpathEvaluatesTo(String message,
|
||||
@@ -95,22 +99,22 @@ public abstract class Wss4jTestCase extends TestCase {
|
||||
String xpathExpression,
|
||||
String document) {
|
||||
String actualValue = xpathTemplate.evaluateAsString(xpathExpression, new StringSource(document));
|
||||
assertEquals(message, expectedValue, actualValue);
|
||||
Assert.assertEquals(message, expectedValue, actualValue);
|
||||
}
|
||||
|
||||
protected void assertXpathExists(String message, String xpathExpression, Document document) {
|
||||
Node node = xpathTemplate.evaluateAsNode(xpathExpression, new DOMSource(document));
|
||||
assertNotNull(message, node);
|
||||
Assert.assertNotNull(message, node);
|
||||
}
|
||||
|
||||
protected void assertXpathNotExists(String message, String xpathExpression, Document document) {
|
||||
Node node = xpathTemplate.evaluateAsNode(xpathExpression, new DOMSource(document));
|
||||
assertNull(message, node);
|
||||
Assert.assertNull(message, node);
|
||||
}
|
||||
|
||||
protected void assertXpathNotExists(String message, String xpathExpression, String document) {
|
||||
Node node = xpathTemplate.evaluateAsNode(xpathExpression, new StringSource(document));
|
||||
assertNull(message, node);
|
||||
Assert.assertNull(message, node);
|
||||
}
|
||||
|
||||
protected SaajSoapMessage loadSaaj11Message(String fileName) throws Exception {
|
||||
@@ -160,6 +164,7 @@ public abstract class Wss4jTestCase extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("Since15")
|
||||
protected AxiomSoapMessage loadAxiom12Message(String fileName) throws Exception {
|
||||
Resource resource = new ClassPathResource(fileName, getClass());
|
||||
InputStream is = resource.getInputStream();
|
||||
|
||||
@@ -18,20 +18,22 @@ package org.springframework.ws.soap.security.wss4j.callback;
|
||||
|
||||
import java.security.KeyStore;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.ws.security.WSPasswordCallback;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.soap.security.support.KeyStoreFactoryBean;
|
||||
|
||||
public class KeyStoreCallbackHandlerTest extends TestCase {
|
||||
import org.apache.ws.security.WSPasswordCallback;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class KeyStoreCallbackHandlerTest {
|
||||
|
||||
private KeyStoreCallbackHandler callbackHandler;
|
||||
|
||||
private WSPasswordCallback callback;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
callbackHandler = new KeyStoreCallbackHandler();
|
||||
callback = new WSPasswordCallback("secretkey", WSPasswordCallback.KEY_NAME);
|
||||
|
||||
@@ -45,9 +47,10 @@ public class KeyStoreCallbackHandlerTest extends TestCase {
|
||||
callbackHandler.setSymmetricKeyPassword("123456");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleKeyName() throws Exception {
|
||||
callbackHandler.handleInternal(callback);
|
||||
assertNotNull("symmetric key must not be null", callback.getKey());
|
||||
Assert.assertNotNull("symmetric key must not be null", callback.getKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.ws.soap.security.wss4j.callback;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.ws.security.WSUsernameTokenPrincipal;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
@@ -29,50 +25,54 @@ import org.springframework.security.userdetails.User;
|
||||
import org.springframework.security.userdetails.UserDetails;
|
||||
import org.springframework.security.userdetails.UserDetailsService;
|
||||
|
||||
import org.apache.ws.security.WSUsernameTokenPrincipal;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
/** @author tareq */
|
||||
public class SpringDigestPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
public class SpringDigestPasswordValidationCallbackHandlerTest {
|
||||
|
||||
private SpringDigestPasswordValidationCallbackHandler callbackHandler;
|
||||
|
||||
private GrantedAuthorityImpl grantedAuthority;
|
||||
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
private MockControl control;
|
||||
|
||||
private WSUsernameTokenPrincipal principal;
|
||||
|
||||
private UsernameTokenPrincipalCallback callback;
|
||||
|
||||
private UserDetails user;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
callbackHandler = new SpringDigestPasswordValidationCallbackHandler();
|
||||
|
||||
grantedAuthority = new GrantedAuthorityImpl("ROLE_1");
|
||||
user = new User("Ernie", "Bert", true, true, true, true, new GrantedAuthority[]{grantedAuthority});
|
||||
|
||||
control = MockControl.createControl(UserDetailsService.class);
|
||||
userDetailsService = (UserDetailsService) control.getMock();
|
||||
userDetailsService.loadUserByUsername("Ernie");
|
||||
control.setDefaultReturnValue(user);
|
||||
control.replay();
|
||||
WSUsernameTokenPrincipal principal = new WSUsernameTokenPrincipal("Ernie", true);
|
||||
callback = new UsernameTokenPrincipalCallback(principal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleUsernameTokenPrincipal() throws Exception {
|
||||
UserDetailsService userDetailsService = createMock(UserDetailsService.class);
|
||||
callbackHandler.setUserDetailsService(userDetailsService);
|
||||
|
||||
principal = new WSUsernameTokenPrincipal("Ernie", true);
|
||||
callback = new UsernameTokenPrincipalCallback(principal);
|
||||
expect(userDetailsService.loadUserByUsername("Ernie")).andReturn(user).anyTimes();
|
||||
|
||||
}
|
||||
replay(userDetailsService);
|
||||
|
||||
public void testHandleUsernameTokenPrincipal() throws Exception {
|
||||
callbackHandler.handleUsernameTokenPrincipal(callback);
|
||||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
assertNotNull("SecurityContext must not be null", context);
|
||||
Assert.assertNotNull("SecurityContext must not be null", context);
|
||||
Authentication authentication = context.getAuthentication();
|
||||
assertNotNull("Authentication must not be null", authentication);
|
||||
Assert.assertNotNull("Authentication must not be null", authentication);
|
||||
GrantedAuthority[] authorities = authentication.getAuthorities();
|
||||
assertTrue("GrantedAuthority[] must not be null or empty", (authorities != null && authorities.length > 0));
|
||||
assertEquals("Unexpected authority", grantedAuthority, authorities[0]);
|
||||
Assert.assertTrue("GrantedAuthority[] must not be null or empty",
|
||||
(authorities != null && authorities.length > 0));
|
||||
Assert.assertEquals("Unexpected authority", grantedAuthority, authorities[0]);
|
||||
|
||||
verify(userDetailsService);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,21 +18,24 @@ package org.springframework.ws.soap.security.wss4j.support;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.ws.security.components.crypto.Merlin;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class CryptoFactoryBeanTest extends TestCase {
|
||||
import org.apache.ws.security.components.crypto.Merlin;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CryptoFactoryBeanTest {
|
||||
|
||||
private CryptoFactoryBean factoryBean;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factoryBean = new CryptoFactoryBean();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetConfiguration() throws Exception {
|
||||
Properties configuration = new Properties();
|
||||
configuration.setProperty("org.apache.ws.security.crypto.provider",
|
||||
@@ -46,10 +49,11 @@ public class CryptoFactoryBeanTest extends TestCase {
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
Object result = factoryBean.getObject();
|
||||
assertNotNull("No result", result);
|
||||
assertTrue("Not a Merlin instance", result instanceof Merlin);
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertTrue("Not a Merlin instance", result instanceof Merlin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperties() throws Exception {
|
||||
factoryBean.setKeyStoreType("jceks");
|
||||
factoryBean.setKeyStorePassword("123456");
|
||||
@@ -57,7 +61,7 @@ public class CryptoFactoryBeanTest extends TestCase {
|
||||
factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
|
||||
factoryBean.afterPropertiesSet();
|
||||
Object result = factoryBean.getObject();
|
||||
assertNotNull("No result", result);
|
||||
assertTrue("Not a Merlin instance", result instanceof Merlin);
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertTrue("Not a Merlin instance", result instanceof Merlin);
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,6 @@ package org.springframework.ws.soap.security.xwss;
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
@@ -28,16 +26,21 @@ import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.security.WsSecurityValidationException;
|
||||
|
||||
public class XwsSecurityInterceptorTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class XwsSecurityInterceptorTest {
|
||||
|
||||
private MessageFactory messageFactory;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
messageFactory = MessageFactory.newInstance();
|
||||
}
|
||||
|
||||
public void testhandleServerRequest() throws Exception {
|
||||
@Test
|
||||
public void testHandleServerRequest() throws Exception {
|
||||
final SOAPMessage request = messageFactory.createMessage();
|
||||
final SOAPMessage validatedRequest = messageFactory.createMessage();
|
||||
XwsSecurityInterceptor interceptor = new XwsSecurityInterceptor() {
|
||||
@@ -45,14 +48,14 @@ public class XwsSecurityInterceptorTest extends TestCase {
|
||||
@Override
|
||||
protected void secureMessage(SoapMessage soapMessage, MessageContext messageContext)
|
||||
throws XwsSecuritySecurementException {
|
||||
fail("secure not expected");
|
||||
Assert.fail("secure not expected");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateMessage(SoapMessage message, MessageContext messageContext)
|
||||
throws WsSecurityValidationException {
|
||||
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
|
||||
assertEquals("Invalid message", request, saajSoapMessage.getSaajMessage());
|
||||
Assert.assertEquals("Invalid message", request, saajSoapMessage.getSaajMessage());
|
||||
saajSoapMessage.setSaajMessage(validatedRequest);
|
||||
}
|
||||
|
||||
@@ -60,10 +63,12 @@ public class XwsSecurityInterceptorTest extends TestCase {
|
||||
MessageContext context =
|
||||
new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory));
|
||||
interceptor.handleRequest(context, null);
|
||||
assertEquals("Invalid request", validatedRequest, ((SaajSoapMessage) context.getRequest()).getSaajMessage());
|
||||
Assert.assertEquals("Invalid request", validatedRequest,
|
||||
((SaajSoapMessage) context.getRequest()).getSaajMessage());
|
||||
}
|
||||
|
||||
public void testhandleServerResponse() throws Exception {
|
||||
@Test
|
||||
public void testHandleServerResponse() throws Exception {
|
||||
final SOAPMessage securedResponse = messageFactory.createMessage();
|
||||
XwsSecurityInterceptor interceptor = new XwsSecurityInterceptor() {
|
||||
|
||||
@@ -77,7 +82,7 @@ public class XwsSecurityInterceptorTest extends TestCase {
|
||||
@Override
|
||||
protected void validateMessage(SoapMessage soapMessage, MessageContext messageContext)
|
||||
throws WsSecurityValidationException {
|
||||
fail("validate not expected");
|
||||
Assert.fail("validate not expected");
|
||||
}
|
||||
|
||||
};
|
||||
@@ -86,9 +91,11 @@ public class XwsSecurityInterceptorTest extends TestCase {
|
||||
new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory));
|
||||
context.getResponse();
|
||||
interceptor.handleResponse(context, null);
|
||||
assertEquals("Invalid response", securedResponse, ((SaajSoapMessage) context.getResponse()).getSaajMessage());
|
||||
Assert.assertEquals("Invalid response", securedResponse,
|
||||
((SaajSoapMessage) context.getResponse()).getSaajMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testhandleClientRequest() throws Exception {
|
||||
final SOAPMessage request = messageFactory.createMessage();
|
||||
final SOAPMessage securedRequest = messageFactory.createMessage();
|
||||
@@ -98,31 +105,33 @@ public class XwsSecurityInterceptorTest extends TestCase {
|
||||
protected void secureMessage(SoapMessage soapMessage, MessageContext messageContext)
|
||||
throws XwsSecuritySecurementException {
|
||||
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) soapMessage;
|
||||
assertEquals("Invalid message", request, saajSoapMessage.getSaajMessage());
|
||||
Assert.assertEquals("Invalid message", request, saajSoapMessage.getSaajMessage());
|
||||
saajSoapMessage.setSaajMessage(securedRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateMessage(SoapMessage message, MessageContext messageContext)
|
||||
throws WsSecurityValidationException {
|
||||
fail("validate not expected");
|
||||
Assert.fail("validate not expected");
|
||||
}
|
||||
|
||||
};
|
||||
MessageContext context =
|
||||
new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory));
|
||||
interceptor.handleRequest(context);
|
||||
assertEquals("Invalid request", securedRequest, ((SaajSoapMessage) context.getRequest()).getSaajMessage());
|
||||
Assert.assertEquals("Invalid request", securedRequest,
|
||||
((SaajSoapMessage) context.getRequest()).getSaajMessage());
|
||||
}
|
||||
|
||||
public void testhandleClientResponse() throws Exception {
|
||||
@Test
|
||||
public void testHandleClientResponse() throws Exception {
|
||||
final SOAPMessage validatedResponse = messageFactory.createMessage();
|
||||
XwsSecurityInterceptor interceptor = new XwsSecurityInterceptor() {
|
||||
|
||||
@Override
|
||||
protected void secureMessage(SoapMessage message, MessageContext messageContext)
|
||||
throws XwsSecuritySecurementException {
|
||||
fail("secure not expected");
|
||||
Assert.fail("secure not expected");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,7 +147,8 @@ public class XwsSecurityInterceptorTest extends TestCase {
|
||||
new DefaultMessageContext(new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory));
|
||||
context.getResponse();
|
||||
interceptor.handleResponse(context);
|
||||
assertEquals("Invalid response", validatedResponse, ((SaajSoapMessage) context.getResponse()).getSaajMessage());
|
||||
Assert.assertEquals("Invalid response", validatedResponse,
|
||||
((SaajSoapMessage) context.getResponse()).getSaajMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,23 +17,26 @@
|
||||
package org.springframework.ws.soap.security.xwss.callback;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.TimestampValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DefaultTimestampValidatorTest extends TestCase {
|
||||
public class DefaultTimestampValidatorTest {
|
||||
|
||||
private DefaultTimestampValidator validator;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
validator = new DefaultTimestampValidator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidate() throws Exception {
|
||||
TimestampValidationCallback.Request request = new TimestampValidationCallback.UTCTimestampRequest(
|
||||
"2006-09-25T20:42:50Z", "2107-09-25T20:42:50Z", 100, Long.MAX_VALUE);
|
||||
validator.validate(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateNoExpired() throws Exception {
|
||||
TimestampValidationCallback.Request request =
|
||||
new TimestampValidationCallback.UTCTimestampRequest("2006-09-25T20:42:50Z", null, 100, Long.MAX_VALUE);
|
||||
|
||||
@@ -16,17 +16,19 @@
|
||||
|
||||
package org.springframework.ws.soap.security.xwss.callback;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class KeyStoreCallbackHandlerTest extends TestCase {
|
||||
public class KeyStoreCallbackHandlerTest {
|
||||
|
||||
private KeyStoreCallbackHandler handler;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
handler = new KeyStoreCallbackHandler();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadDefaultTrustStore() throws Exception {
|
||||
System.setProperty("javax.net.ssl.trustStore",
|
||||
"/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/");
|
||||
|
||||
@@ -16,50 +16,56 @@
|
||||
|
||||
package org.springframework.ws.soap.security.xwss.callback;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class SimplePasswordValidationCallbackHandlerTest extends TestCase {
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SimplePasswordValidationCallbackHandlerTest {
|
||||
|
||||
private SimplePasswordValidationCallbackHandler handler;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
handler = new SimplePasswordValidationCallbackHandler();
|
||||
Properties users = new Properties();
|
||||
users.setProperty("Bert", "Ernie");
|
||||
handler.setUsers(users);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlainTextPasswordValid() throws Exception {
|
||||
PasswordValidationCallback.PlainTextPasswordRequest request =
|
||||
new PasswordValidationCallback.PlainTextPasswordRequest("Bert", "Ernie");
|
||||
PasswordValidationCallback callback = new PasswordValidationCallback(request);
|
||||
handler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
Assert.assertTrue("Not authenticated", authenticated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlainTextPasswordInvalid() throws Exception {
|
||||
PasswordValidationCallback.PlainTextPasswordRequest request =
|
||||
new PasswordValidationCallback.PlainTextPasswordRequest("Bert", "Big bird");
|
||||
PasswordValidationCallback callback = new PasswordValidationCallback(request);
|
||||
handler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlainTextPasswordNoSuchUser() throws Exception {
|
||||
PasswordValidationCallback.PlainTextPasswordRequest request =
|
||||
new PasswordValidationCallback.PlainTextPasswordRequest("Big bird", "Bert");
|
||||
PasswordValidationCallback callback = new PasswordValidationCallback(request);
|
||||
handler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDigestPasswordValid() throws Exception {
|
||||
String username = "Bert";
|
||||
String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
|
||||
@@ -70,10 +76,11 @@ public class SimplePasswordValidationCallbackHandlerTest extends TestCase {
|
||||
PasswordValidationCallback callback = new PasswordValidationCallback(request);
|
||||
handler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Authenticated", authenticated);
|
||||
Assert.assertTrue("Authenticated", authenticated);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDigestPasswordInvalid() throws Exception {
|
||||
String username = "Bert";
|
||||
String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
|
||||
@@ -84,7 +91,7 @@ public class SimplePasswordValidationCallbackHandlerTest extends TestCase {
|
||||
PasswordValidationCallback callback = new PasswordValidationCallback(request);
|
||||
handler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,28 +18,32 @@ package org.springframework.ws.soap.security.xwss.callback;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordCallback;
|
||||
import com.sun.xml.wss.impl.callback.UsernameCallback;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SimpleUsernamePasswordCallbackHandlerTest extends TestCase {
|
||||
public class SimpleUsernamePasswordCallbackHandlerTest {
|
||||
|
||||
private SimpleUsernamePasswordCallbackHandler handler;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
handler = new SimpleUsernamePasswordCallbackHandler();
|
||||
handler.setUsername("Bert");
|
||||
handler.setPassword("Ernie");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsernameCallback() throws Exception {
|
||||
UsernameCallback usernameCallback = new UsernameCallback();
|
||||
handler.handleInternal(usernameCallback);
|
||||
assertEquals("Invalid username", "Bert", usernameCallback.getUsername());
|
||||
Assert.assertEquals("Invalid username", "Bert", usernameCallback.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPasswordCallback() throws Exception {
|
||||
PasswordCallback passwordCallback = new PasswordCallback();
|
||||
handler.handleInternal(passwordCallback);
|
||||
assertEquals("Invalid username", "Ernie", passwordCallback.getPassword());
|
||||
Assert.assertEquals("Invalid username", "Ernie", passwordCallback.getPassword());
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,6 @@ import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.security.AuthenticationManager;
|
||||
import org.springframework.security.BadCredentialsException;
|
||||
@@ -33,24 +29,29 @@ import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
import org.springframework.security.providers.x509.X509AuthenticationToken;
|
||||
import org.springframework.ws.soap.security.callback.CleanupCallback;
|
||||
|
||||
public class SpringCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SpringCertificateValidationCallbackHandlerTest {
|
||||
|
||||
private SpringCertificateValidationCallbackHandler callbackHandler;
|
||||
|
||||
private MockControl control;
|
||||
|
||||
private AuthenticationManager mock;
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
private X509Certificate certificate;
|
||||
|
||||
private CertificateValidationCallback callback;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
callbackHandler = new SpringCertificateValidationCallbackHandler();
|
||||
control = MockControl.createControl(AuthenticationManager.class);
|
||||
mock = (AuthenticationManager) control.getMock();
|
||||
callbackHandler.setAuthenticationManager(mock);
|
||||
authenticationManager = createMock(AuthenticationManager.class);
|
||||
callbackHandler.setAuthenticationManager(authenticationManager);
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
InputStream is = null;
|
||||
try {
|
||||
@@ -66,35 +67,42 @@ public class SpringCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
callback = new CertificateValidationCallback(certificate);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCertificateValid() throws Exception {
|
||||
mock.authenticate(new X509AuthenticationToken(certificate));
|
||||
control.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
control.setReturnValue(new TestingAuthenticationToken(certificate, null, new GrantedAuthority[0]));
|
||||
control.replay();
|
||||
expect(authenticationManager.authenticate(isA(X509AuthenticationToken.class)))
|
||||
.andReturn(new TestingAuthenticationToken(certificate, null, new GrantedAuthority[0]));
|
||||
|
||||
replay(authenticationManager);
|
||||
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
Assert.assertTrue("Not authenticated", authenticated);
|
||||
Assert.assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
|
||||
verify(authenticationManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCertificateInvalid() throws Exception {
|
||||
mock.authenticate(new X509AuthenticationToken(certificate));
|
||||
control.setMatcher(MockControl.ALWAYS_MATCHER);
|
||||
control.setThrowable(new BadCredentialsException(""));
|
||||
control.replay();
|
||||
expect(authenticationManager.authenticate(isA(X509AuthenticationToken.class)))
|
||||
.andThrow(new BadCredentialsException(""));
|
||||
|
||||
replay(authenticationManager);
|
||||
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
Assert.assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
|
||||
verify(authenticationManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCleanUp() throws Exception {
|
||||
TestingAuthenticationToken authentication =
|
||||
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
|
||||
@@ -102,7 +110,7 @@ public class SpringCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
|
||||
CleanupCallback cleanupCallback = new CleanupCallback();
|
||||
callbackHandler.handleInternal(cleanupCallback);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
Assert.assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,12 +16,8 @@
|
||||
|
||||
package org.springframework.ws.soap.security.xwss.callback;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.DisabledException;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
import org.springframework.security.userdetails.User;
|
||||
@@ -29,13 +25,19 @@ import org.springframework.security.userdetails.UserDetailsService;
|
||||
import org.springframework.security.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.ws.soap.security.callback.CleanupCallback;
|
||||
|
||||
public class SpringDigestPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SpringDigestPasswordValidationCallbackHandlerTest {
|
||||
|
||||
private SpringDigestPasswordValidationCallbackHandler callbackHandler;
|
||||
|
||||
private MockControl control;
|
||||
|
||||
private UserDetailsService mock;
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
private String username;
|
||||
|
||||
@@ -43,12 +45,11 @@ public class SpringDigestPasswordValidationCallbackHandlerTest extends TestCase
|
||||
|
||||
private PasswordValidationCallback callback;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
callbackHandler = new SpringDigestPasswordValidationCallbackHandler();
|
||||
control = MockControl.createControl(UserDetailsService.class);
|
||||
mock = (UserDetailsService) control.getMock();
|
||||
callbackHandler.setUserDetailsService(mock);
|
||||
userDetailsService = createMock(UserDetailsService.class);
|
||||
callbackHandler.setUserDetailsService(userDetailsService);
|
||||
username = "Bert";
|
||||
password = "Ernie";
|
||||
String nonce = "9mdsYDCrjjYRur0rxzYt2oD7";
|
||||
@@ -59,55 +60,72 @@ public class SpringDigestPasswordValidationCallbackHandlerTest extends TestCase
|
||||
callback = new PasswordValidationCallback(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserDigestUserNotFound() throws Exception {
|
||||
control.expectAndThrow(mock.loadUserByUsername(username), new UsernameNotFoundException(username));
|
||||
control.replay();
|
||||
expect(userDetailsService.loadUserByUsername(username)).andThrow(new UsernameNotFoundException(username));
|
||||
|
||||
replay(userDetailsService);
|
||||
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
Assert.assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
|
||||
verify(userDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserDigestValid() throws Exception {
|
||||
User user = new User(username, password, true, true, true, true, new GrantedAuthority[0]);
|
||||
control.expectAndReturn(mock.loadUserByUsername(username), user);
|
||||
control.replay();
|
||||
expect(userDetailsService.loadUserByUsername(username)).andReturn(user);
|
||||
|
||||
replay(userDetailsService);
|
||||
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
Assert.assertTrue("Not authenticated", authenticated);
|
||||
Assert.assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
|
||||
verify(userDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserDigestValidInvalid() throws Exception {
|
||||
User user = new User(username, "Big bird", true, true, true, true, new GrantedAuthority[0]);
|
||||
control.expectAndReturn(mock.loadUserByUsername(username), user);
|
||||
control.replay();
|
||||
expect(userDetailsService.loadUserByUsername(username)).andReturn(user);
|
||||
|
||||
replay(userDetailsService);
|
||||
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
Assert.assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
|
||||
verify(userDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserDigestDisbaled() throws Exception {
|
||||
User user = new User(username, "Ernie", false, true, true, true, new GrantedAuthority[0]);
|
||||
control.expectAndReturn(mock.loadUserByUsername(username), user);
|
||||
control.replay();
|
||||
expect(userDetailsService.loadUserByUsername(username)).andReturn(user);
|
||||
|
||||
replay(userDetailsService);
|
||||
|
||||
try {
|
||||
callbackHandler.handleInternal(callback);
|
||||
fail("disabled user authenticated");
|
||||
} catch (
|
||||
DisabledException expected) {
|
||||
Assert.fail("disabled user authenticated");
|
||||
} catch (DisabledException expected) {
|
||||
// expected
|
||||
}
|
||||
verify(userDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCleanUp() throws Exception {
|
||||
TestingAuthenticationToken authentication =
|
||||
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
|
||||
@@ -115,7 +133,7 @@ public class SpringDigestPasswordValidationCallbackHandlerTest extends TestCase
|
||||
|
||||
CleanupCallback cleanupCallback = new CleanupCallback();
|
||||
callbackHandler.handleInternal(cleanupCallback);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
Assert.assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.ws.soap.security.xwss.callback;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationManager;
|
||||
import org.springframework.security.BadCredentialsException;
|
||||
@@ -29,13 +25,19 @@ import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.ws.soap.security.callback.CleanupCallback;
|
||||
|
||||
public class SpringPlainTextPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class SpringPlainTextPasswordValidationCallbackHandlerTest {
|
||||
|
||||
private SpringPlainTextPasswordValidationCallbackHandler callbackHandler;
|
||||
|
||||
private MockControl control;
|
||||
|
||||
private AuthenticationManager mock;
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
private PasswordValidationCallback callback;
|
||||
|
||||
@@ -43,12 +45,11 @@ public class SpringPlainTextPasswordValidationCallbackHandlerTest extends TestCa
|
||||
|
||||
private String password;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
callbackHandler = new SpringPlainTextPasswordValidationCallbackHandler();
|
||||
control = MockControl.createControl(AuthenticationManager.class);
|
||||
mock = (AuthenticationManager) control.getMock();
|
||||
callbackHandler.setAuthenticationManager(mock);
|
||||
authenticationManager = createMock(AuthenticationManager.class);
|
||||
callbackHandler.setAuthenticationManager(authenticationManager);
|
||||
username = "Bert";
|
||||
password = "Ernie";
|
||||
PasswordValidationCallback.PlainTextPasswordRequest request =
|
||||
@@ -56,34 +57,41 @@ public class SpringPlainTextPasswordValidationCallbackHandlerTest extends TestCa
|
||||
callback = new PasswordValidationCallback(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserPlainTextValid() throws Exception {
|
||||
Authentication authResult = new TestingAuthenticationToken(username, password, new GrantedAuthority[0]);
|
||||
control.expectAndReturn(mock.authenticate(new UsernamePasswordAuthenticationToken(username, password)),
|
||||
authResult);
|
||||
control.replay();
|
||||
expect(authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password))).andReturn(authResult);
|
||||
|
||||
replay(authenticationManager);
|
||||
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
Assert.assertTrue("Not authenticated", authenticated);
|
||||
Assert.assertNotNull("No Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
|
||||
verify(authenticationManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserPlainTextInvalid() throws Exception {
|
||||
control.expectAndThrow(mock.authenticate(new UsernamePasswordAuthenticationToken(username, password)),
|
||||
new BadCredentialsException(""));
|
||||
control.replay();
|
||||
expect(authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password))).andThrow(new BadCredentialsException(""));
|
||||
|
||||
replay(authenticationManager);
|
||||
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
control.verify();
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
Assert.assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
|
||||
verify(authenticationManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCleanUp() throws Exception {
|
||||
TestingAuthenticationToken authentication =
|
||||
new TestingAuthenticationToken(new Object(), new Object(), new GrantedAuthority[0]);
|
||||
@@ -91,7 +99,7 @@ public class SpringPlainTextPasswordValidationCallbackHandlerTest extends TestCa
|
||||
|
||||
CleanupCallback cleanupCallback = new CleanupCallback();
|
||||
callbackHandler.handleInternal(cleanupCallback);
|
||||
assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
Assert.assertNull("Authentication created", SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,39 +16,44 @@
|
||||
|
||||
package org.springframework.ws.soap.security.xwss.callback;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordCallback;
|
||||
import com.sun.xml.wss.impl.callback.UsernameCallback;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
||||
public class SpringUsernamePasswordCallbackHandlerTest extends TestCase {
|
||||
import com.sun.xml.wss.impl.callback.PasswordCallback;
|
||||
import com.sun.xml.wss.impl.callback.UsernameCallback;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SpringUsernamePasswordCallbackHandlerTest {
|
||||
|
||||
private SpringUsernamePasswordCallbackHandler handler;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
handler = new SpringUsernamePasswordCallbackHandler();
|
||||
Authentication authentication = new UsernamePasswordAuthenticationToken("Bert", "Ernie");
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsernameCallback() throws Exception {
|
||||
UsernameCallback usernameCallback = new UsernameCallback();
|
||||
handler.handleInternal(usernameCallback);
|
||||
assertEquals("Invalid username", "Bert", usernameCallback.getUsername());
|
||||
Assert.assertEquals("Invalid username", "Bert", usernameCallback.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPasswordCallback() throws Exception {
|
||||
PasswordCallback passwordCallback = new PasswordCallback();
|
||||
handler.handleInternal(passwordCallback);
|
||||
assertEquals("Invalid username", "Ernie", passwordCallback.getPassword());
|
||||
Assert.assertEquals("Invalid username", "Ernie", passwordCallback.getPassword());
|
||||
}
|
||||
}
|
||||
@@ -20,19 +20,21 @@ import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public class JaasCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JaasCertificateValidationCallbackHandlerTest {
|
||||
|
||||
private JaasCertificateValidationCallbackHandler callbackHandler;
|
||||
|
||||
private CertificateValidationCallback callback;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty("java.security.auth.login.config", getClass().getResource("jaas.config").toString());
|
||||
callbackHandler = new JaasCertificateValidationCallbackHandler();
|
||||
callbackHandler.setLoginContextName("Certificate");
|
||||
@@ -51,10 +53,11 @@ public class JaasCertificateValidationCallbackHandlerTest extends TestCase {
|
||||
callback = new CertificateValidationCallback(certificate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCertificateValid() throws Exception {
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
Assert.assertTrue("Not authenticated", authenticated);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,35 +17,39 @@
|
||||
package org.springframework.ws.soap.security.xwss.callback.jaas;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JaasPlainTextPasswordValidationCallbackHandlerTest extends TestCase {
|
||||
public class JaasPlainTextPasswordValidationCallbackHandlerTest {
|
||||
|
||||
private JaasPlainTextPasswordValidationCallbackHandler callbackHandler;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty("java.security.auth.login.config", getClass().getResource("jaas.config").toString());
|
||||
callbackHandler = new JaasPlainTextPasswordValidationCallbackHandler();
|
||||
callbackHandler.setLoginContextName("PlainText");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserPlainTextValid() throws Exception {
|
||||
PasswordValidationCallback.PlainTextPasswordRequest request =
|
||||
new PasswordValidationCallback.PlainTextPasswordRequest("Bert", "Ernie");
|
||||
PasswordValidationCallback callback = new PasswordValidationCallback(request);
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertTrue("Not authenticated", authenticated);
|
||||
Assert.assertTrue("Not authenticated", authenticated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticateUserPlainTextInvalid() throws Exception {
|
||||
PasswordValidationCallback.PlainTextPasswordRequest request =
|
||||
new PasswordValidationCallback.PlainTextPasswordRequest("Bert", "Big bird");
|
||||
PasswordValidationCallback callback = new PasswordValidationCallback(request);
|
||||
callbackHandler.handleInternal(callback);
|
||||
boolean authenticated = callback.getResult();
|
||||
assertFalse("Authenticated", authenticated);
|
||||
Assert.assertFalse("Authenticated", authenticated);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,31 +25,34 @@ import javax.xml.transform.TransformerFactory;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
@SuppressWarnings("Since15")
|
||||
public class XmlEventStreamReaderTest extends TestCase {
|
||||
public class XmlEventStreamReaderTest {
|
||||
|
||||
private static final String XML =
|
||||
"<?pi content?><root xmlns='namespace'><prefix:child xmlns:prefix='namespace2'>content</prefix:child></root>";
|
||||
|
||||
private XmlEventStreamReader streamReader;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(XML));
|
||||
streamReader = new XmlEventStreamReader(eventReader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAll() throws Exception {
|
||||
while (streamReader.hasNext()) {
|
||||
streamReader.next();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadCorrect() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
StaxSource source = new StaxSource(streamReader);
|
||||
|
||||
Reference in New Issue
Block a user