KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jndi > JndiTemplateEditorTests


1
2 /*
3  * Copyright 2002-2005 the original author or authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.springframework.jndi;
19
20 import junit.framework.TestCase;
21
22 /**
23  * @author Rod Johnson
24  */

25 public class JndiTemplateEditorTests extends TestCase {
26
27     public void testNullIsIllegalArgument() {
28         try {
29             new JndiTemplateEditor().setAsText(null);
30             fail("Null is illegal");
31         }
32         catch (IllegalArgumentException JavaDoc ex) {
33             // OK
34
}
35     }
36     
37     public void testEmptyStringMeansNullEnvironment() {
38         JndiTemplateEditor je = new JndiTemplateEditor();
39         je.setAsText("");
40         JndiTemplate jt = (JndiTemplate) je.getValue();
41         assertTrue(jt.getEnvironment() == null);
42     }
43     
44     public void testCustomEnvironment() {
45         JndiTemplateEditor je = new JndiTemplateEditor();
46         // These properties are meaningless for JNDI, but we don't worry about that:
47
// the underlying JNDI implementation will throw exceptions when the user tries
48
// to look anything up
49
je.setAsText("jndiInitialSomethingOrOther=org.springframework.myjndi.CompleteRubbish\nfoo=bar");
50         JndiTemplate jt = (JndiTemplate) je.getValue();
51         assertTrue(jt.getEnvironment().size() == 2);
52         assertTrue(jt.getEnvironment().getProperty("jndiInitialSomethingOrOther").equals("org.springframework.myjndi.CompleteRubbish"));
53         assertTrue(jt.getEnvironment().getProperty("foo").equals("bar"));
54     }
55
56 }
57
Popular Tags