Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java?rev=730924&r1=730923&r2=730924&view=diff ============================================================================== --- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java (original) +++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java Fri Jan 2 22:33:39 2009 @@ -48,18 +48,24 @@ // * Only use a small set of message types for the other setups. suite.addExclude("(!(|(&(broker=qpid)(singleCF=false)(cfOnSender=false)(!(|(destType=topic)(replyDestType=topic))))" + "(&(test=AsyncXML)(messageType=SOAP11)(data=ASCII))" + - "(&(test=EchoXML)(messageType=POX)(data=ASCII))))"); + "(&(test=EchoXML)(messageType=POX)(data=ASCII))" + + "(test=MinConcurrency)))"); // SYNAPSE-436: suite.addExclude("(&(test=EchoXML)(replyDestType=topic)(endpoint=axis))"); - + + // Example to run a few use cases.. please leave these commented out - asankha + //suite.addExclude("(|(test=AsyncXML)(test=MinConcurrency)(destType=topic)(broker=qpid)(destType=topic)(replyDestType=topic)(client=jms)(endpoint=mock)(cfOnSender=true))"); + //suite.addExclude("(|(test=EchoXML)(destType=queue)(broker=qpid)(cfOnSender=true)(singleCF=false)(destType=queue)(client=jms)(endpoint=mock))"); + //suite.addExclude("(|(test=EchoXML)(test=AsyncXML)(test=AsyncSwA)(test=AsyncTextPlain)(test=AsyncBinary)(test=AsyncSOAPLarge)(broker=qpid))"); + TransportTestSuiteBuilder builder = new TransportTestSuiteBuilder(suite); JMSTestEnvironment[] environments = new JMSTestEnvironment[] { new QpidTestEnvironment(), new ActiveMQTestEnvironment() }; for (boolean singleCF : new boolean[] { false, true }) { for (boolean cfOnSender : new boolean[] { false, true }) { for (JMSTestEnvironment env : environments) { - builder.addEnvironment(env, new JMSTransportDescriptionFactory(singleCF, cfOnSender)); + builder.addEnvironment(env, new JMSTransportDescriptionFactory(singleCF, cfOnSender, 1)); } } } @@ -72,6 +78,7 @@ builder.addAxisAsyncTestClient(new AxisAsyncTestClient(), new JMSAxisTestClientConfigurator(JMSConstants.JMS_TEXT_MESSAGE)); builder.addByteArrayAsyncTestClient(new JMSAsyncClient<byte[]>(JMSBytesMessageFactory.INSTANCE)); builder.addStringAsyncTestClient(new JMSAsyncClient<String>(JMSTextMessageFactory.INSTANCE)); + builder.addMapAsyncTestClient(new JMSAsyncClient<Map>(JMSMapMessageFactory.INSTANCE), new JMSAxisTestClientConfigurator(JMSConstants.JMS_MAP_MESSAGE)); builder.addAxisAsyncEndpoint(new AxisAsyncEndpoint()); @@ -88,15 +95,15 @@ builder.addAxisRequestResponseTestClient(new AxisRequestResponseTestClient(), timeoutConfigurator); builder.addStringRequestResponseTestClient(new JMSRequestResponseClient<String>(JMSTextMessageFactory.INSTANCE)); builder.addMapRequestResponseTestClient(new JMSRequestResponseClient<Map>(JMSMapMessageFactory.INSTANCE)); - + builder.addEchoEndpoint(new MockEchoEndpoint()); builder.addEchoEndpoint(new AxisEchoEndpoint()); - + for (JMSTestEnvironment env : new JMSTestEnvironment[] { new QpidTestEnvironment(), new ActiveMQTestEnvironment() }) { suite.addTest(new MinConcurrencyTest(new AsyncChannel[] { new JMSAsyncChannel("endpoint1", JMSConstants.DESTINATION_TYPE_QUEUE, ContentTypeMode.TRANSPORT), new JMSAsyncChannel("endpoint2", JMSConstants.DESTINATION_TYPE_QUEUE, ContentTypeMode.TRANSPORT) }, - 2, false, env, new JMSTransportDescriptionFactory(false, false))); + 2, false, env, new JMSTransportDescriptionFactory(false, false, 2))); }
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JNDIEnvironment.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JNDIEnvironment.java?rev=730924&r1=730923&r2=730924&view=diff ============================================================================== --- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JNDIEnvironment.java (original) +++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JNDIEnvironment.java Fri Jan 2 22:33:39 2009 @@ -1,45 +1,45 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.axis2.transport.jms; - -import javax.naming.Context; -import javax.naming.InitialContext; - -import org.apache.axis2.transport.testkit.tests.Setup; -import org.apache.axis2.transport.testkit.tests.Transient; -import org.mockejb.jndi.MockContextFactory; - -public class JNDIEnvironment { - public static final JNDIEnvironment INSTANCE = new JNDIEnvironment(); - - private @Transient Context context; - - private JNDIEnvironment() {} - - @Setup @SuppressWarnings("unused") - private void setUp() throws Exception { - MockContextFactory.setAsInitial(); - context = new InitialContext(); - } - - public Context getContext() { - return context; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.jms; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.apache.axis2.transport.testkit.tests.Setup; +import org.apache.axis2.transport.testkit.tests.Transient; +import org.mockejb.jndi.MockContextFactory; + +public class JNDIEnvironment { + public static final JNDIEnvironment INSTANCE = new JNDIEnvironment(); + + private @Transient Context context; + + private JNDIEnvironment() {} + + @Setup @SuppressWarnings("unused") + private void setUp() throws Exception { + MockContextFactory.setAsInitial(); + context = new InitialContext(); + } + + public Context getContext() { + return context; + } +} Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java?rev=730924&r1=730923&r2=730924&view=diff ============================================================================== --- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java (original) +++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java Fri Jan 2 22:33:39 2009 @@ -1,111 +1,111 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.axis2.transport.jms; - -import java.util.Enumeration; - -import javax.jms.BytesMessage; -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.MapMessage; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.axis2.transport.base.BaseConstants; -import org.apache.axis2.transport.testkit.endpoint.InOutEndpoint; -import org.apache.axis2.transport.testkit.endpoint.InOutEndpointSupport; -import org.apache.axis2.transport.testkit.name.Name; -import org.apache.axis2.transport.testkit.tests.Setup; -import org.apache.axis2.transport.testkit.tests.TearDown; -import org.apache.axis2.transport.testkit.tests.Transient; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -...@name("mock") -public class MockEchoEndpoint extends InOutEndpointSupport implements InOutEndpoint, ExceptionListener { - static Log log = LogFactory.getLog(MockEchoEndpoint.class); - - private @Transient Connection connection; - private @Transient Connection replyConnection; - - @Setup @SuppressWarnings("unused") - private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception { - Destination destination = channel.getDestination(); - Destination replyDestination = channel.getReplyDestination(); - connection = env.getConnectionFactory().createConnection(); - connection.setExceptionListener(this); - connection.start(); - replyConnection = env.getConnectionFactory().createConnection(); - replyConnection.setExceptionListener(this); - final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final MessageProducer producer = replySession.createProducer(replyDestination); - MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(destination); - consumer.setMessageListener(new MessageListener() { - public void onMessage(Message message) { - try { - log.info("Message received: ID = " + message.getJMSMessageID()); - Message reply; - if (message instanceof BytesMessage) { - reply = replySession.createBytesMessage(); - IOUtils.copy(new BytesMessageInputStream((BytesMessage)message), new BytesMessageOutputStream((BytesMessage)reply)); - } else if (message instanceof TextMessage) { - reply = replySession.createTextMessage(); - ((TextMessage)reply).setText(((TextMessage)message).getText()); - } else if (message instanceof MapMessage) { - reply = replySession.createMapMessage(); - MapMessage mapMessage = (MapMessage)message; - for (Enumeration e = mapMessage.getMapNames() ; e.hasMoreElements() ;) { - String key = (String) e.nextElement(); - Object value = mapMessage.getObject(key); - ((MapMessage)reply).setObject(key, value); - } - } else { - // TODO - throw new UnsupportedOperationException("Unsupported message type"); - } - reply.setJMSCorrelationID(message.getJMSMessageID()); - reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE)); - producer.send(reply); - log.info("Message sent: ID = " + reply.getJMSMessageID()); - } catch (Throwable ex) { - fireEndpointError(ex); - } - } - }); - } - - @TearDown @SuppressWarnings("unused") - private void tearDown() throws Exception { - connection.close(); - replyConnection.close(); - } - - public void onException(JMSException ex) { - log.error("Exception received by JMS exception listener", ex); - fireEndpointError(ex); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.jms; + +import java.util.Enumeration; + +import javax.jms.BytesMessage; +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.MapMessage; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.axis2.transport.base.BaseConstants; +import org.apache.axis2.transport.testkit.endpoint.InOutEndpoint; +import org.apache.axis2.transport.testkit.endpoint.InOutEndpointSupport; +import org.apache.axis2.transport.testkit.name.Name; +import org.apache.axis2.transport.testkit.tests.Setup; +import org.apache.axis2.transport.testkit.tests.TearDown; +import org.apache.axis2.transport.testkit.tests.Transient; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +...@name("mock") +public class MockEchoEndpoint extends InOutEndpointSupport implements InOutEndpoint, ExceptionListener { + static Log log = LogFactory.getLog(MockEchoEndpoint.class); + + private @Transient Connection connection; + private @Transient Connection replyConnection; + + @Setup @SuppressWarnings("unused") + private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception { + Destination destination = channel.getDestination(); + Destination replyDestination = channel.getReplyDestination(); + connection = env.getConnectionFactory().createConnection(); + connection.setExceptionListener(this); + connection.start(); + replyConnection = env.getConnectionFactory().createConnection(); + replyConnection.setExceptionListener(this); + final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = replySession.createProducer(replyDestination); + MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(destination); + consumer.setMessageListener(new MessageListener() { + public void onMessage(Message message) { + try { + log.info("Message received: ID = " + message.getJMSMessageID()); + Message reply; + if (message instanceof BytesMessage) { + reply = replySession.createBytesMessage(); + IOUtils.copy(new BytesMessageInputStream((BytesMessage)message), new BytesMessageOutputStream((BytesMessage)reply)); + } else if (message instanceof TextMessage) { + reply = replySession.createTextMessage(); + ((TextMessage)reply).setText(((TextMessage)message).getText()); + } else if (message instanceof MapMessage) { + reply = replySession.createMapMessage(); + MapMessage mapMessage = (MapMessage)message; + for (Enumeration e = mapMessage.getMapNames() ; e.hasMoreElements() ;) { + String key = (String) e.nextElement(); + Object value = mapMessage.getObject(key); + ((MapMessage)reply).setObject(key, value); + } + } else { + // TODO + throw new UnsupportedOperationException("Unsupported message type"); + } + reply.setJMSCorrelationID(message.getJMSMessageID()); + reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE)); + producer.send(reply); + log.info("Message sent: ID = " + reply.getJMSMessageID()); + } catch (Throwable ex) { + fireEndpointError(ex); + } + } + }); + } + + @TearDown @SuppressWarnings("unused") + private void tearDown() throws Exception { + connection.close(); + replyConnection.close(); + } + + public void onException(JMSException ex) { + log.error("Exception received by JMS exception listener", ex); + fireEndpointError(ex); + } +} Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/QpidTestEnvironment.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/QpidTestEnvironment.java?rev=730924&r1=730923&r2=730924&view=diff ============================================================================== --- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/QpidTestEnvironment.java (original) +++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/QpidTestEnvironment.java Fri Jan 2 22:33:39 2009 @@ -1,77 +1,77 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.axis2.transport.jms; - -import javax.jms.Destination; -import javax.jms.Queue; -import javax.jms.Topic; - -import org.apache.axis2.transport.testkit.name.Name; -import org.apache.axis2.transport.testkit.tests.Setup; -import org.apache.axis2.transport.testkit.tests.TearDown; -import org.apache.qpid.AMQException; -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.client.AMQDestination; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.AMQTopic; -import org.apache.qpid.client.transport.TransportConnection; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.virtualhost.VirtualHost; - -...@name("qpid") -public class QpidTestEnvironment extends JMSTestEnvironment { - private VirtualHost virtualHost; - - @Setup @SuppressWarnings("unused") - private void setUp() throws Exception { - TransportConnection.createVMBroker(1); - // null means the default virtual host - virtualHost = ApplicationRegistry.getInstance(1).getVirtualHostRegistry().getVirtualHost(null); - } - - @TearDown @SuppressWarnings("unused") - private void tearDown() throws Exception { - TransportConnection.killVMBroker(1); - } - - @Override - protected AMQConnectionFactory createConnectionFactory() throws Exception { - return new AMQConnectionFactory("vm://:1", "guest", "guest", "fred", "test"); - } - - @Override - public Queue createQueue(String name) throws AMQException { - QpidUtil.createQueue(virtualHost, ExchangeDefaults.DIRECT_EXCHANGE_NAME, name); - return new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, name); - } - - @Override - public Topic createTopic(String name) throws AMQException { - QpidUtil.createQueue(virtualHost, ExchangeDefaults.TOPIC_EXCHANGE_NAME, name); - return new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_NAME, name); - } - - @Override - public void deleteDestination(Destination destination) throws Exception { - QpidUtil.deleteQueue(virtualHost, ((AMQDestination)destination).getDestinationName().asString()); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.jms; + +import javax.jms.Destination; +import javax.jms.Queue; +import javax.jms.Topic; + +import org.apache.axis2.transport.testkit.name.Name; +import org.apache.axis2.transport.testkit.tests.Setup; +import org.apache.axis2.transport.testkit.tests.TearDown; +import org.apache.qpid.AMQException; +import org.apache.qpid.client.AMQConnectionFactory; +import org.apache.qpid.client.AMQDestination; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.AMQTopic; +import org.apache.qpid.client.transport.TransportConnection; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.virtualhost.VirtualHost; + +...@name("qpid") +public class QpidTestEnvironment extends JMSTestEnvironment { + private VirtualHost virtualHost; + + @Setup @SuppressWarnings("unused") + private void setUp() throws Exception { + TransportConnection.createVMBroker(1); + // null means the default virtual host + virtualHost = ApplicationRegistry.getInstance(1).getVirtualHostRegistry().getVirtualHost(null); + } + + @TearDown @SuppressWarnings("unused") + private void tearDown() throws Exception { + TransportConnection.killVMBroker(1); + } + + @Override + protected AMQConnectionFactory createConnectionFactory() throws Exception { + return new AMQConnectionFactory("vm://:1", "guest", "guest", "fred", "test"); + } + + @Override + public Queue createQueue(String name) throws AMQException { + QpidUtil.createQueue(virtualHost, ExchangeDefaults.DIRECT_EXCHANGE_NAME, name); + return new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, name); + } + + @Override + public Topic createTopic(String name) throws AMQException { + QpidUtil.createQueue(virtualHost, ExchangeDefaults.TOPIC_EXCHANGE_NAME, name); + return new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_NAME, name); + } + + @Override + public void deleteDestination(Destination destination) throws Exception { + QpidUtil.deleteQueue(virtualHost, ((AMQDestination)destination).getDestinationName().asString()); + } +} Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/GreenMailTestEnvironment.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/GreenMailTestEnvironment.java?rev=730924&r1=730923&r2=730924&view=diff ============================================================================== --- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/GreenMailTestEnvironment.java (original) +++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/GreenMailTestEnvironment.java Fri Jan 2 22:33:39 2009 @@ -1,154 +1,146 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.axis2.transport.mail; - -import java.io.OutputStream; -import java.net.InetSocketAddress; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.mail.Flags; - -import org.apache.axis2.transport.testkit.name.Key; -import org.apache.axis2.transport.testkit.name.Name; -import org.apache.axis2.transport.testkit.tests.Setup; -import org.apache.axis2.transport.testkit.tests.TearDown; -import org.apache.axis2.transport.testkit.tests.Transient; -import org.apache.axis2.transport.testkit.util.LogManager; -import org.apache.axis2.transport.testkit.util.ServerUtil; -import org.apache.axis2.transport.testkit.util.tcpmon.Tunnel; - -import com.icegreen.greenmail.store.FolderListener; -import com.icegreen.greenmail.store.MailFolder; -import com.icegreen.greenmail.store.StoredMessage; -import com.icegreen.greenmail.user.GreenMailUser; -import com.icegreen.greenmail.util.GreenMail; -import com.icegreen.greenmail.util.ServerSetup; - -...@name("greenmail") -public class GreenMailTestEnvironment extends MailTestEnvironment { - private static final ServerSetup SMTP = - new ServerSetup(7025, "127.0.0.1", ServerSetup.PROTOCOL_SMTP); - - private static final ServerSetup POP3 = - new ServerSetup(7110, "127.0.0.1", ServerSetup.PROTOCOL_POP3); - - private static final ServerSetup IMAP = - new ServerSetup(7143, "127.0.0.1", ServerSetup.PROTOCOL_IMAP); - - private final String protocol; - private final ServerSetup storeServerSetup; - private @Transient LogManager logManager; - private @Transient GreenMail greenMail; - private @Transient Tunnel smtpTunnel; - private int accountNumber; - private @Transient List<Account> unallocatedAccounts; - - public GreenMailTestEnvironment(String protocol) { - this.protocol = protocol; - if (protocol.equals("pop3")) { - storeServerSetup = POP3; - } else if (protocol.equals("imap")) { - storeServerSetup = IMAP; - } else { - throw new IllegalArgumentException(); - } - } - - @Setup @SuppressWarnings("unused") - private void setUp(LogManager logManager) throws Exception { - this.logManager = logManager; - greenMail = new GreenMail(new ServerSetup[] { SMTP, storeServerSetup }); - greenMail.start(); - smtpTunnel = new Tunnel(new InetSocketAddress("127.0.0.1", 7025)); - smtpTunnel.start(); - unallocatedAccounts = new LinkedList<Account>(); - ServerUtil.waitForServer(SMTP.getPort()); - ServerUtil.waitForServer(storeServerSetup.getPort()); - } - - @TearDown @SuppressWarnings("unused") - private void tearDown() throws Exception { - greenMail.stop(); - accountNumber = 1; - } - - @Override - @Key("protocol") - public String getProtocol() { - return protocol; - } - - @Override - public Account allocateAccount() throws Exception { - if (unallocatedAccounts.isEmpty()) { - String login = "test" + accountNumber++; - GreenMailUser user = greenMail.setUser(login + "@localhost", login, "password"); - final MailFolder inbox = greenMail.getManagers().getImapHostManager().getInbox(user); - inbox.addListener(new FolderListener() { - public void added(int msn) { - StoredMessage storedMessage = (StoredMessage)inbox.getMessages().get(msn-1); - try { - OutputStream out = logManager.createLog("greenmail"); - try { - storedMessage.getMimeMessage().writeTo(out); - } finally { - out.close(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void expunged(int msn) {} - public void flagsUpdated(int msn, Flags flags, Long uid) {} - public void mailboxDeleted() {} - }); - return new Account(user.getEmail(), user.getLogin(), user.getPassword()); - } else { - return unallocatedAccounts.remove(0); - } - } - - @Override - public void freeAccount(Account account) { - unallocatedAccounts.add(account); - } - - @Override - public Map<String,String> getInProperties(Account account) { - Map<String,String> props = new HashMap<String,String>(); - props.put("mail." + protocol + ".host", "localhost"); - props.put("mail." + protocol + ".port", String.valueOf(storeServerSetup.getPort())); - props.put("mail." + protocol + ".user", account.getLogin()); - props.put("mail." + protocol + ".password", account.getPassword()); - return props; - } - - @Override - public Map<String,String> getOutProperties() { - Map<String,String> props = new HashMap<String,String>(); - props.put("mail.smtp.host", "localhost"); - props.put("mail.smtp.port", String.valueOf(smtpTunnel.getPort())); - return props; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.mail; + +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.mail.Flags; + +import org.apache.axis2.transport.testkit.name.Key; +import org.apache.axis2.transport.testkit.name.Name; +import org.apache.axis2.transport.testkit.tests.Setup; +import org.apache.axis2.transport.testkit.tests.TearDown; +import org.apache.axis2.transport.testkit.tests.Transient; +import org.apache.axis2.transport.testkit.util.LogManager; +import org.apache.axis2.transport.testkit.util.PortAllocator; +import org.apache.axis2.transport.testkit.util.ServerUtil; +import org.apache.axis2.transport.testkit.util.tcpmon.Tunnel; + +import com.icegreen.greenmail.store.FolderListener; +import com.icegreen.greenmail.store.MailFolder; +import com.icegreen.greenmail.store.StoredMessage; +import com.icegreen.greenmail.user.GreenMailUser; +import com.icegreen.greenmail.util.GreenMail; +import com.icegreen.greenmail.util.ServerSetup; + +...@name("greenmail") +public class GreenMailTestEnvironment extends MailTestEnvironment { + private final String protocol; + private @Transient PortAllocator portAllocator; + private @Transient ServerSetup smtpServerSetup; + private @Transient ServerSetup storeServerSetup; + private @Transient LogManager logManager; + private @Transient GreenMail greenMail; + private @Transient Tunnel smtpTunnel; + private int accountNumber; + private @Transient List<Account> unallocatedAccounts; + + public GreenMailTestEnvironment(String protocol) { + this.protocol = protocol; + } + + @Setup @SuppressWarnings("unused") + private void setUp(LogManager logManager, PortAllocator portAllocator) throws Exception { + this.logManager = logManager; + this.portAllocator = portAllocator; + smtpServerSetup = new ServerSetup(portAllocator.allocatePort(), "127.0.0.1", ServerSetup.PROTOCOL_SMTP); + storeServerSetup = new ServerSetup(portAllocator.allocatePort(), "127.0.0.1", protocol); + greenMail = new GreenMail(new ServerSetup[] { smtpServerSetup, storeServerSetup }); + greenMail.start(); + smtpTunnel = new Tunnel(new InetSocketAddress("127.0.0.1", smtpServerSetup.getPort())); + smtpTunnel.start(); + unallocatedAccounts = new LinkedList<Account>(); + ServerUtil.waitForServer(smtpServerSetup.getPort()); + ServerUtil.waitForServer(storeServerSetup.getPort()); + } + + @TearDown @SuppressWarnings("unused") + private void tearDown() throws Exception { + greenMail.stop(); + accountNumber = 1; + portAllocator.releasePort(smtpServerSetup.getPort()); + portAllocator.releasePort(storeServerSetup.getPort()); + } + + @Override + @Key("protocol") + public String getProtocol() { + return protocol; + } + + @Override + public Account allocateAccount() throws Exception { + if (unallocatedAccounts.isEmpty()) { + String login = "test" + accountNumber++; + GreenMailUser user = greenMail.setUser(login + "@localhost", login, "password"); + final MailFolder inbox = greenMail.getManagers().getImapHostManager().getInbox(user); + inbox.addListener(new FolderListener() { + public void added(int msn) { + StoredMessage storedMessage = (StoredMessage)inbox.getMessages().get(msn-1); + try { + OutputStream out = logManager.createLog("greenmail"); + try { + storedMessage.getMimeMessage().writeTo(out); + } finally { + out.close(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void expunged(int msn) {} + public void flagsUpdated(int msn, Flags flags, Long uid) {} + public void mailboxDeleted() {} + }); + return new Account(user.getEmail(), user.getLogin(), user.getPassword()); + } else { + return unallocatedAccounts.remove(0); + } + } + + @Override + public void freeAccount(Account account) { + unallocatedAccounts.add(account); + } + + @Override + public Map<String,String> getInProperties(Account account) { + Map<String,String> props = new HashMap<String,String>(); + props.put("mail." + protocol + ".host", "localhost"); + props.put("mail." + protocol + ".port", String.valueOf(storeServerSetup.getPort())); + props.put("mail." + protocol + ".user", account.getLogin()); + props.put("mail." + protocol + ".password", account.getPassword()); + return props; + } + + @Override + public Map<String,String> getOutProperties() { + Map<String,String> props = new HashMap<String,String>(); + props.put("mail.smtp.host", "localhost"); + props.put("mail.smtp.port", String.valueOf(smtpTunnel.getPort())); + return props; + } +} Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/MailAxisTestClientConfigurator.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/MailAxisTestClientConfigurator.java?rev=730924&r1=730923&r2=730924&view=diff ============================================================================== --- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/MailAxisTestClientConfigurator.java (original) +++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/mail/MailAxisTestClientConfigurator.java Fri Jan 2 22:33:39 2009 @@ -1,42 +1,42 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.axis2.transport.mail; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.transport.testkit.axis2.client.AxisTestClientConfigurator; -import org.apache.axis2.transport.testkit.name.Key; - -public class MailAxisTestClientConfigurator implements AxisTestClientConfigurator { - private final String transportFormat; - - public MailAxisTestClientConfigurator(String transportFormat) { - this.transportFormat = transportFormat; - } - - @Key("layout") - public String getTransportFormat() { - return MailConstants.TRANSPORT_FORMAT_MP.equals(transportFormat) ? "multipart" : "flat"; - } - - public void setupRequestMessageContext(MessageContext msgContext) throws AxisFault { - msgContext.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT, transportFormat); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.transport.mail; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.testkit.axis2.client.AxisTestClientConfigurator; +import org.apache.axis2.transport.testkit.name.Key; + +public class MailAxisTestClientConfigurator implements AxisTestClientConfigurator { + private final String transportFormat; + + public MailAxisTestClientConfigurator(String transportFormat) { + this.transportFormat = transportFormat; + } + + @Key("layout") + public String getTransportFormat() { + return MailConstants.TRANSPORT_FORMAT_MP.equals(transportFormat) ? "multipart" : "flat"; + } + + public void setupRequestMessageContext(MessageContext msgContext) throws AxisFault { + msgContext.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT, transportFormat); + } +}