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 static org.junit.Assert.*; 21 22 import org.junit.Test; 23 24 /** 25 * @author Rod Johnson 26 * @author Chris Beams 27 */ 28 public class JndiTemplateEditorTests { 29 30 @Test testNullIsIllegalArgument()31 public void testNullIsIllegalArgument() { 32 try { 33 new JndiTemplateEditor().setAsText(null); 34 fail("Null is illegal"); 35 } 36 catch (IllegalArgumentException ex) { 37 // OK 38 } 39 } 40 41 @Test testEmptyStringMeansNullEnvironment()42 public void testEmptyStringMeansNullEnvironment() { 43 JndiTemplateEditor je = new JndiTemplateEditor(); 44 je.setAsText(""); 45 JndiTemplate jt = (JndiTemplate) je.getValue(); 46 assertTrue(jt.getEnvironment() == null); 47 } 48 49 @Test testCustomEnvironment()50 public void testCustomEnvironment() { 51 JndiTemplateEditor je = new JndiTemplateEditor(); 52 // These properties are meaningless for JNDI, but we don't worry about that: 53 // the underlying JNDI implementation will throw exceptions when the user tries 54 // to look anything up 55 je.setAsText("jndiInitialSomethingOrOther=org.springframework.myjndi.CompleteRubbish\nfoo=bar"); 56 JndiTemplate jt = (JndiTemplate) je.getValue(); 57 assertTrue(jt.getEnvironment().size() == 2); 58 assertTrue(jt.getEnvironment().getProperty("jndiInitialSomethingOrOther").equals("org.springframework.myjndi.CompleteRubbish")); 59 assertTrue(jt.getEnvironment().getProperty("foo").equals("bar")); 60 } 61 62 } 63