01: // ========================================================================
02: // $Id: TestMailSessionReference.java 842 2006-08-28 15:03:35Z janb $
03: // Copyright 1999-2004 Mort Bay Consulting Pty. Ltd.
04: // ------------------------------------------------------------------------
05: // Licensed under the Apache License, Version 2.0 (the "License");
06: // you may not use this file except in compliance with the License.
07: // You may obtain a copy of the License at
08: // http://www.apache.org/licenses/LICENSE-2.0
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14: // ========================================================================
15:
16: package org.mortbay.naming.factories;
17:
18: import java.util.Properties;
19:
20: import javax.mail.Session;
21: import javax.naming.Context;
22: import javax.naming.InitialContext;
23: import javax.naming.LinkRef;
24: import javax.naming.Name;
25: import javax.naming.NameParser;
26:
27: import org.mortbay.naming.NamingUtil;
28:
29: import junit.framework.TestCase;
30:
31: /**
32: * TestMailSessionReference
33: *
34: *
35: */
36: public class TestMailSessionReference extends TestCase {
37: public void testMailSessionReference() throws Exception {
38: InitialContext icontext = new InitialContext();
39: MailSessionReference sref = new MailSessionReference();
40: sref.setUser("janb");
41: sref.setPassword("OBF:1xmk1w261z0f1w1c1xmq");
42: Properties props = new Properties();
43: props.put("mail.smtp.host", "xxx");
44: props.put("mail.debug", "true");
45: sref.setProperties(props);
46: NamingUtil.bind(icontext, "mail/Session", sref);
47: Object x = icontext.lookup("mail/Session");
48: assertNotNull(x);
49: assertTrue(x instanceof javax.mail.Session);
50: javax.mail.Session session = (javax.mail.Session) x;
51: Properties sessionProps = session.getProperties();
52: assertEquals(props, sessionProps);
53: assertTrue(session.getDebug());
54:
55: Context foo = icontext.createSubcontext("foo");
56: NameParser parser = icontext.getNameParser("");
57: Name objectNameInNamespace = parser.parse(icontext
58: .getNameInNamespace());
59: objectNameInNamespace.addAll(parser.parse("mail/Session"));
60:
61: NamingUtil.bind(foo, "mail/Session", new LinkRef(
62: objectNameInNamespace.toString()));
63:
64: Object o = foo.lookup("mail/Session");
65: assertNotNull(o);
66: Session fooSession = (Session) o;
67: assertEquals(props, fooSession.getProperties());
68: assertTrue(fooSession.getDebug());
69: }
70: }
|