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: package org.apache.harmony.jndi.tests.javax.naming;
018:
019: import java.lang.reflect.Modifier;
020:
021: import javax.naming.NamingException;
022:
023: import org.apache.harmony.jndi.tests.javax.naming.util.Log;
024: import junit.framework.TestCase;
025:
026: public class NamingExceptionsTest extends TestCase {
027:
028: private static final Log log = new Log(NamingExceptionsTest.class);
029:
030: private static final Class nexClasses[] = {
031: javax.naming.directory.SchemaViolationException.class,
032: javax.naming.directory.AttributeInUseException.class,
033: javax.naming.directory.AttributeModificationException.class,
034: javax.naming.directory.InvalidSearchFilterException.class,
035: javax.naming.directory.InvalidAttributeIdentifierException.class,
036: javax.naming.directory.InvalidAttributeValueException.class,
037: javax.naming.directory.NoSuchAttributeException.class,
038: javax.naming.directory.InvalidAttributesException.class,
039: javax.naming.directory.InvalidSearchControlsException.class,
040: javax.naming.NamingException.class,
041: javax.naming.InvalidNameException.class,
042: javax.naming.ldap.LdapReferralException.class,
043: javax.naming.NameAlreadyBoundException.class,
044: javax.naming.NameNotFoundException.class,
045: javax.naming.NotContextException.class,
046: javax.naming.OperationNotSupportedException.class,
047: javax.naming.NoInitialContextException.class,
048: javax.naming.ConfigurationException.class,
049: javax.naming.MalformedLinkException.class,
050: javax.naming.AuthenticationException.class,
051: javax.naming.AuthenticationNotSupportedException.class,
052: javax.naming.CannotProceedException.class,
053: javax.naming.CommunicationException.class,
054: javax.naming.ContextNotEmptyException.class,
055: javax.naming.InsufficientResourcesException.class,
056: javax.naming.InterruptedNamingException.class,
057: javax.naming.LimitExceededException.class,
058: javax.naming.LinkException.class,
059: javax.naming.LinkLoopException.class,
060: javax.naming.NamingSecurityException.class,
061: javax.naming.NoPermissionException.class,
062: javax.naming.PartialResultException.class,
063: javax.naming.ReferralException.class,
064: javax.naming.ServiceUnavailableException.class,
065: javax.naming.SizeLimitExceededException.class,
066: javax.naming.TimeLimitExceededException.class, };
067:
068: /**
069: * Constructor for NamingExceptionsTest.
070: *
071: * @param arg0
072: */
073: public NamingExceptionsTest(String arg0) {
074: super (arg0);
075: }
076:
077: public void testDefaultConstructor() {
078: log.setMethod("testDefaultConstructor()");
079:
080: for (Class<?> element : nexClasses) {
081: try {
082: if (Modifier.isAbstract(element.getModifiers())) {
083: continue;
084: }
085: NamingException nex = (NamingException) element
086: .newInstance();
087: assertNull(nex.getMessage());
088: } catch (Throwable e) {
089: log.log("Failed at " + element);
090: log.log(e);
091: }
092: }
093: }
094:
095: public void testStringConstructor() {
096: log.setMethod("testStringConstructor()");
097:
098: for (Class<?> element : nexClasses) {
099: try {
100: if (Modifier.isAbstract(element.getModifiers())) {
101: continue;
102: }
103: NamingException nex = (NamingException) element
104: .getConstructor(new Class[] { String.class })
105: .newInstance(new Object[] { "sample text" });
106: assertEquals("sample text", nex.getMessage());
107: } catch (Throwable e) {
108: log.log("Failed at " + element);
109: log.log(e);
110: }
111: }
112: }
113:
114: }
|