Upgraded tests.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.ws.transport.jms;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
@@ -47,10 +48,10 @@ public class WebServiceMessageListenerIntegrationTest {
|
||||
@Autowired
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private Queue responseQueue;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private Queue requestQueue;
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -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.
|
||||
@@ -20,86 +20,94 @@ import java.net.URI;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.Message;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.ws.transport.jms.JmsTransportConstants;
|
||||
|
||||
public class JmsTransportUtilsTest extends TestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JmsTransportUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetDestinationName() throws Exception {
|
||||
URI uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
|
||||
String destinationName = JmsTransportUtils.getDestinationName(uri);
|
||||
assertEquals("Invalid destination", "RequestQueue", destinationName);
|
||||
Assert.assertEquals("Invalid destination", "RequestQueue", destinationName);
|
||||
|
||||
uri = new URI("jms:RequestQueue");
|
||||
destinationName = JmsTransportUtils.getDestinationName(uri);
|
||||
assertEquals("Invalid destination", "RequestQueue", destinationName);
|
||||
Assert.assertEquals("Invalid destination", "RequestQueue", destinationName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeliveryMode() throws Exception {
|
||||
URI uri = new URI("jms:RequestQueue?deliveryMode=NON_PERSISTENT");
|
||||
int deliveryMode = JmsTransportUtils.getDeliveryMode(uri);
|
||||
assertEquals("Invalid deliveryMode", DeliveryMode.NON_PERSISTENT, deliveryMode);
|
||||
Assert.assertEquals("Invalid deliveryMode", DeliveryMode.NON_PERSISTENT, deliveryMode);
|
||||
|
||||
uri = new URI("jms:RequestQueue?deliveryMode=PERSISTENT");
|
||||
deliveryMode = JmsTransportUtils.getDeliveryMode(uri);
|
||||
assertEquals("Invalid deliveryMode", DeliveryMode.PERSISTENT, deliveryMode);
|
||||
Assert.assertEquals("Invalid deliveryMode", DeliveryMode.PERSISTENT, deliveryMode);
|
||||
|
||||
uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
|
||||
deliveryMode = JmsTransportUtils.getDeliveryMode(uri);
|
||||
assertEquals("Invalid deliveryMode", Message.DEFAULT_DELIVERY_MODE, deliveryMode);
|
||||
Assert.assertEquals("Invalid deliveryMode", Message.DEFAULT_DELIVERY_MODE, deliveryMode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMessageType() throws Exception {
|
||||
URI uri = new URI("jms:RequestQueue?messageType=BYTESMESSAGE");
|
||||
int messageType = JmsTransportUtils.getMessageType(uri);
|
||||
assertEquals("Invalid messageType", JmsTransportConstants.BYTES_MESSAGE_TYPE, messageType);
|
||||
Assert.assertEquals("Invalid messageType", JmsTransportConstants.BYTES_MESSAGE_TYPE, messageType);
|
||||
|
||||
uri = new URI("jms:RequestQueue?messageType=TEXT_MESSAGE");
|
||||
messageType = JmsTransportUtils.getMessageType(uri);
|
||||
assertEquals("Invalid messageType", JmsTransportConstants.TEXT_MESSAGE_TYPE, messageType);
|
||||
Assert.assertEquals("Invalid messageType", JmsTransportConstants.TEXT_MESSAGE_TYPE, messageType);
|
||||
|
||||
uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
|
||||
messageType = JmsTransportUtils.getMessageType(uri);
|
||||
assertEquals("Invalid messageType", JmsTransportConstants.BYTES_MESSAGE_TYPE, messageType);
|
||||
Assert.assertEquals("Invalid messageType", JmsTransportConstants.BYTES_MESSAGE_TYPE, messageType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTimeToLive() throws Exception {
|
||||
URI uri = new URI("jms:RequestQueue?timeToLive=100");
|
||||
long timeToLive = JmsTransportUtils.getTimeToLive(uri);
|
||||
assertEquals("Invalid timeToLive", 100, timeToLive);
|
||||
Assert.assertEquals("Invalid timeToLive", 100, timeToLive);
|
||||
|
||||
uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
|
||||
timeToLive = JmsTransportUtils.getTimeToLive(uri);
|
||||
assertEquals("Invalid timeToLive", Message.DEFAULT_TIME_TO_LIVE, timeToLive);
|
||||
Assert.assertEquals("Invalid timeToLive", Message.DEFAULT_TIME_TO_LIVE, timeToLive);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPriority() throws Exception {
|
||||
URI uri = new URI("jms:RequestQueue?priority=5");
|
||||
int priority = JmsTransportUtils.getPriority(uri);
|
||||
assertEquals("Invalid priority", 5, priority);
|
||||
Assert.assertEquals("Invalid priority", 5, priority);
|
||||
|
||||
uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
|
||||
priority = JmsTransportUtils.getPriority(uri);
|
||||
assertEquals("Invalid priority", Message.DEFAULT_PRIORITY, priority);
|
||||
Assert.assertEquals("Invalid priority", Message.DEFAULT_PRIORITY, priority);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReplyToName() throws Exception {
|
||||
URI uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
|
||||
String replyToName = JmsTransportUtils.getReplyToName(uri);
|
||||
assertEquals("Invalid replyToName", "RESP_QUEUE", replyToName);
|
||||
Assert.assertEquals("Invalid replyToName", "RESP_QUEUE", replyToName);
|
||||
|
||||
uri = new URI("jms:RequestQueue?priority=5");
|
||||
replyToName = JmsTransportUtils.getReplyToName(uri);
|
||||
assertNull("Invalid replyToName", replyToName);
|
||||
Assert.assertNull("Invalid replyToName", replyToName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJndi() throws Exception {
|
||||
URI uri = new URI("jms:jms/REQUEST_QUEUE?replyToName=jms/REPLY_QUEUE");
|
||||
String destination = JmsTransportUtils.getDestinationName(uri);
|
||||
assertEquals("Invalid destination name", "jms/REQUEST_QUEUE", destination);
|
||||
Assert.assertEquals("Invalid destination name", "jms/REQUEST_QUEUE", destination);
|
||||
|
||||
String replyTo = JmsTransportUtils.getReplyToName(uri);
|
||||
assertEquals("Invalid reply to name", "jms/REPLY_QUEUE", replyTo);
|
||||
Assert.assertEquals("Invalid reply to name", "jms/REPLY_QUEUE", replyTo);
|
||||
}
|
||||
}
|
||||
@@ -16,31 +16,39 @@
|
||||
|
||||
package org.springframework.ws.transport.mail;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.jvnet.mock_javamail.Mailbox;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public class MailIntegrationTest extends AbstractDependencyInjectionSpringContextTests {
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jvnet.mock_javamail.Mailbox;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("mail-applicationContext.xml")
|
||||
public class MailIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private WebServiceTemplate webServiceTemplate;
|
||||
|
||||
@Override
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[]{"classpath:org/springframework/ws/transport/mail/mail-applicationContext.xml"};
|
||||
}
|
||||
@Autowired
|
||||
private GenericApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
protected void onTearDown() throws Exception {
|
||||
@After
|
||||
public void clearMailbox() throws Exception {
|
||||
Mailbox.clearAll();
|
||||
}
|
||||
|
||||
public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) {
|
||||
this.webServiceTemplate = webServiceTemplate;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMailTransport() throws Exception {
|
||||
String content = "<root xmlns='http://springframework.org/spring-ws'><child/></root>";
|
||||
StringResult result = new StringResult();
|
||||
|
||||
@@ -22,13 +22,17 @@ import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jvnet.mock_javamail.Mailbox;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.transport.WebServiceConnection;
|
||||
|
||||
public class MailMessageSenderIntegrationTest extends TestCase {
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.mock_javamail.Mailbox;
|
||||
|
||||
public class MailMessageSenderIntegrationTest {
|
||||
|
||||
private MailMessageSender messageSender;
|
||||
|
||||
@@ -36,8 +40,8 @@ public class MailMessageSenderIntegrationTest extends TestCase {
|
||||
|
||||
private static final String SOAP_ACTION = "http://springframework.org/DoIt";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
messageSender = new MailMessageSender();
|
||||
messageSender.setFrom("Spring-WS SOAP Client <client@example.com>");
|
||||
messageSender.setTransportUri("smtp://smtp.example.com");
|
||||
@@ -46,22 +50,23 @@ public class MailMessageSenderIntegrationTest extends TestCase {
|
||||
messageSender.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
Mailbox.clearAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveQueueNoResponse() throws Exception {
|
||||
URI mailTo = new URI("mailto:server@example.com?subject=SOAP%20Test");
|
||||
WebServiceConnection connection = null;
|
||||
try {
|
||||
URI mailTo = new URI("mailto:server@example.com?subject=SOAP%20Test");
|
||||
connection = messageSender.createConnection(mailTo);
|
||||
SOAPMessage saajMessage = messageFactory.createMessage();
|
||||
saajMessage.getSOAPBody().addBodyElement(new QName("http://springframework.org", "test"));
|
||||
SoapMessage soapRequest = new SaajSoapMessage(saajMessage);
|
||||
soapRequest.setSoapAction(SOAP_ACTION);
|
||||
connection.send(soapRequest);
|
||||
assertEquals("No mail message sent", 1, Mailbox.get("server@example.com").size());
|
||||
Assert.assertEquals("No mail message sent", 1, Mailbox.get("server@example.com").size());
|
||||
}
|
||||
finally {
|
||||
if (connection != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright ${YEAR} 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.
|
||||
@@ -20,33 +20,37 @@ import java.net.URI;
|
||||
import javax.mail.URLName;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MailTransportUtilsTest extends TestCase {
|
||||
public class MailTransportUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testToPasswordProtectedString() throws Exception {
|
||||
URLName name = new URLName("imap://john:secret@imap.example.com/INBOX");
|
||||
String result = MailTransportUtils.toPasswordProtectedString(name);
|
||||
assertEquals("Password found in string", -1, result.indexOf("secret"));
|
||||
Assert.assertEquals("Password found in string", -1, result.indexOf("secret"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTo() throws Exception {
|
||||
URI uri = new URI("mailto:infobot@example.com?subject=current-issue");
|
||||
InternetAddress to = MailTransportUtils.getTo(uri);
|
||||
assertEquals("Invalid destination", new InternetAddress("infobot@example.com"), to);
|
||||
Assert.assertEquals("Invalid destination", new InternetAddress("infobot@example.com"), to);
|
||||
|
||||
uri = new URI("mailto:infobot@example.com");
|
||||
to = MailTransportUtils.getTo(uri);
|
||||
assertEquals("Invalid destination", new InternetAddress("infobot@example.com"), to);
|
||||
Assert.assertEquals("Invalid destination", new InternetAddress("infobot@example.com"), to);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubject() throws Exception {
|
||||
URI uri = new URI("mailto:infobot@example.com?subject=current-issue");
|
||||
String subject = MailTransportUtils.getSubject(uri);
|
||||
assertEquals("Invalid destination", "current-issue", subject);
|
||||
Assert.assertEquals("Invalid destination", "current-issue", subject);
|
||||
|
||||
uri = new URI("mailto:infobot@example.com");
|
||||
subject = MailTransportUtils.getSubject(uri);
|
||||
assertNull("Invalid destination", subject);
|
||||
Assert.assertNull("Invalid destination", subject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user