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: */
017:
018: package org.apache.harmony.jndi.tests.javax.naming;
019:
020: import java.util.Properties;
021:
022: import javax.naming.CompositeName;
023: import javax.naming.CompoundName;
024: import javax.naming.InvalidNameException;
025: import javax.naming.LinkException;
026: import javax.naming.Name;
027:
028: import junit.framework.TestCase;
029:
030: public class LinkExceptionTest extends TestCase {
031:
032: /*
033: * -------------------------------------------------------------------
034: * Constants
035: * -------------------------------------------------------------------
036: */
037:
038: /**
039: * Constructor for TestLinkException.
040: *
041: * @param arg0
042: */
043: public LinkExceptionTest(String arg0) {
044: super (arg0);
045: }
046:
047: /*
048: * -------------------------------------------------------------------
049: * Methods
050: * -------------------------------------------------------------------
051: */
052:
053: public void testConstructor() {
054: LinkException ex = new LinkException();
055: assertNull(ex.getMessage());
056: }
057:
058: public void testConstructorAndGetterSetter()
059: throws InvalidNameException {
060: LinkException ex = new LinkException("msg");
061: ex.setLinkExplanation("link msg");
062: CompositeName n = new CompositeName("");
063: ex.setLinkRemainingName(n);
064: ex.setLinkResolvedName(n);
065: ex.setLinkResolvedObj("resolved obj sample");
066:
067: assertEquals("msg", ex.getMessage());
068: assertEquals("link msg", ex.getLinkExplanation());
069: n.add("changed");
070: assertFalse(n.equals(ex.getLinkRemainingName()));
071: assertFalse(n.equals(ex.getLinkResolvedName()));
072: assertEquals("resolved obj sample", ex.getLinkResolvedObj());
073: }
074:
075: public void testToString() throws InvalidNameException {
076: LinkException ex = new LinkException("msg");
077: ex.setLinkRemainingName(new CompositeName("a/b/c"));
078: ex.setLinkResolvedObj("resolved obj sample");
079:
080: String str = ex.toString();
081: assertTrue(str.indexOf("msg") >= 0);
082: assertTrue(str.indexOf("a/b/c") >= 0);
083: assertFalse(str.indexOf("resolved obj sample") >= 0);
084:
085: str = ex.toString(false);
086: assertTrue(str.indexOf("msg") >= 0);
087: assertTrue(str.indexOf("a/b/c") >= 0);
088: assertFalse(str.indexOf("resolved obj sample") >= 0);
089:
090: str = ex.toString(true);
091: assertTrue(str.indexOf("msg") >= 0);
092: assertTrue(str.indexOf("a/b/c") >= 0);
093: assertTrue(str.indexOf("resolved obj sample") >= 0);
094: }
095:
096: public void testSetLinkResolvedName() throws InvalidNameException {
097: LinkException ex = new LinkException("Test");
098: Properties env = new Properties();
099: env.put("jndi.syntax.direction", "flat");
100: Name name = new CompoundName("Test", env);
101: ex.setLinkResolvedName(name);
102: ex.setLinkResolvedName(null);
103: assertNull(ex.getLinkResolvedName());
104: }
105:
106: public void testSetLinkRemainingName() throws InvalidNameException {
107: LinkException ex = new LinkException("Test");
108: Properties env = new Properties();
109: env.put("jndi.syntax.direction", "flat");
110: Name name = new CompoundName("Test", env);
111: ex.setLinkRemainingName(name);
112: ex.setLinkRemainingName(null);
113: assertNull(ex.getLinkRemainingName());
114: }
115:
116: public void testLinkException() {
117: /*
118: * Create instance of LinkException, call the setLinkResolvedObj method
119: * with null value passed and check for toString(true) method's return
120: * value. The toString(true) returns, the resolved object is - 'null'
121: * and this message is not required for null object and this causes the
122: * Test Failure.
123: */
124: LinkException ex = new LinkException("testLinkException");
125: ex.setLinkResolvedObj(null);
126: // System.out.println(ex.toString(true));
127: }
128: }
|