001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.mail;
017:
018: import java.util.Collections;
019: import java.util.Properties;
020:
021: import javax.mail.Session;
022: import javax.mail.Store;
023: import javax.mail.Transport;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * @version $Rev: 525003 $ $Date: 2007-04-02 19:25:49 -0700 (Mon, 02 Apr 2007) $
029: */
030: public class MailGBeanTest extends TestCase {
031: public void testNotheing() {
032: }
033:
034: public void XtestProperties() throws Exception {
035: Properties properties = new Properties();
036: properties.put("mail.store.protocol", "testStore");
037: properties.put("mail.transport.protocol", "testTransport");
038:
039: MailGBean mail = new MailGBean("test:name=mail", null,
040: Boolean.TRUE, properties, null, null, null, null, null,
041: null, null);
042: mail.doStart();
043: Object proxy = mail.$getResource();
044:
045: assertNotNull(proxy);
046: assertTrue(proxy instanceof Session);
047:
048: Store store = ((Session) proxy).getStore();
049: assertNotNull(store);
050: assertTrue(store instanceof TestStore);
051:
052: Transport transport = ((Session) proxy).getTransport();
053: assertNotNull(transport);
054: assertTrue(transport instanceof TestTransport);
055:
056: }
057:
058: public void XtestDefaultOverrides() throws Exception {
059: Properties properties = new Properties();
060: properties.put("mail.store.protocol", "POOKIE");
061: properties.put("mail.transport.protocol", "BEAR");
062:
063: MailGBean mail = new MailGBean("test:name=mail", null,
064: Boolean.TRUE, properties, null, "test", "test", null,
065: null, null, null);
066: mail.doStart();
067: Object proxy = mail.$getResource();
068:
069: assertNotNull(proxy);
070: assertTrue(proxy instanceof Session);
071:
072: Store store = ((Session) proxy).getStore();
073: assertNotNull(store);
074: assertTrue(store instanceof TestStore);
075:
076: Transport transport = ((Session) proxy).getTransport();
077: assertNotNull(transport);
078: assertTrue(transport instanceof TestTransport);
079:
080: }
081:
082: public void XtestSMTPOverrides() throws Exception {
083: // these are defaults, all to be overridden
084: Properties properties = new Properties();
085: properties.put("mail.store.protocol", "POOKIE");
086: properties.put("mail.transport.protocol", "BEAR");
087: properties.put("mail.smtp.ehlo", "false");
088:
089: // this is done in the property bundle for the transport.
090: Properties bundle = new Properties();
091: bundle.put("mail.smtp.ehlo", "true");
092: bundle.put("mail.smtp.quitwait", "true");
093:
094: SMTPTransportGBean protocol = new SMTPTransportGBean(
095: "test:name=smtp", null, null, null, null, null, null,
096: null, null, null, null, null, null, null, null, null,
097: null, null, null, null, null, null, null, null, null,
098: null);
099: protocol.doStart();
100:
101: MailGBean mail = new MailGBean("test:name=mail", Collections
102: .singleton(protocol), Boolean.TRUE, properties, null,
103: "test", "test", null, null, null, null);
104: mail.doStart();
105: Object proxy = mail.$getResource();
106:
107: assertNotNull(proxy);
108: assertTrue(proxy instanceof Session);
109:
110: Store store = ((Session) proxy).getStore();
111: assertNotNull(store);
112: assertTrue(store instanceof TestStore);
113:
114: Transport transport = ((Session) proxy).getTransport();
115: assertNotNull(transport);
116: assertTrue(transport instanceof TestTransport);
117:
118: TestTransport testTransport = (TestTransport) transport;
119: assertFalse(testTransport.isEHLO());
120:
121: }
122:
123: public void XtestPOP3Overrides() throws Exception {
124: Properties properties = new Properties();
125: properties.put("mail.store.protocol", "POOKIE");
126: properties.put("mail.transport.protocol", "BEAR");
127: properties.put("mail.pop3.ehlo", "true");
128:
129: POP3StoreGBean protocol = new POP3StoreGBean("test:name=pop3",
130: null, null, null, null, null, null, null, null, null,
131: null, null, null, null, null);
132: protocol.doStart();
133:
134: MailGBean mail = new MailGBean("test:name=mail", Collections
135: .singleton(protocol), Boolean.TRUE, properties, null,
136: "test", "test", null, null, null, null);
137: mail.doStart();
138: Object proxy = mail.$getResource();
139:
140: assertNotNull(proxy);
141: assertTrue(proxy instanceof Session);
142:
143: Store store = ((Session) proxy).getStore();
144: assertNotNull(store);
145: assertTrue(store instanceof TestStore);
146:
147: Transport transport = ((Session) proxy).getTransport();
148: assertNotNull(transport);
149: assertTrue(transport instanceof TestTransport);
150:
151: }
152:
153: public void XtestIMAPOverrides() throws Exception {
154: Properties properties = new Properties();
155: properties.put("mail.store.protocol", "POOKIE");
156: properties.put("mail.transport.protocol", "BEAR");
157: properties.put("mail.imap.ehlo", "true");
158:
159: IMAPStoreGBean protocol = new IMAPStoreGBean("test:name=imap",
160: null, null, null, null, null, null, null, null, null,
161: null, null, null, null, null, null, null, null, null,
162: null, null, null, null, null, null, null);
163: protocol.doStart();
164:
165: MailGBean mail = new MailGBean("test:name=mail", Collections
166: .singleton(protocol), Boolean.TRUE, properties, null,
167: "test", "test", null, null, null, null);
168: mail.doStart();
169: Object proxy = mail.$getResource();
170:
171: assertNotNull(proxy);
172: assertTrue(proxy instanceof Session);
173:
174: Store store = ((Session) proxy).getStore();
175: assertNotNull(store);
176: assertTrue(store instanceof TestStore);
177:
178: Transport transport = ((Session) proxy).getTransport();
179: assertNotNull(transport);
180: assertTrue(transport instanceof TestTransport);
181:
182: }
183:
184: }
|