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.provider.ldap;
018:
019: import java.util.Hashtable;
020:
021: import javax.naming.CompositeName;
022: import javax.naming.Name;
023: import javax.naming.NamingException;
024: import javax.naming.OperationNotSupportedException;
025: import javax.naming.directory.BasicAttributes;
026: import javax.naming.directory.ModificationItem;
027: import javax.naming.directory.SchemaViolationException;
028:
029: import junit.framework.TestCase;
030:
031: public class LdapSchemaContextImplTest extends TestCase {
032: public LdapSchemaContextImpl context;
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036: LdapContextImpl impl = new LdapContextImpl(
037: new MockLdapClient(), null, "");
038: CompositeName name = new CompositeName("ou=mock");
039: context = new LdapSchemaContextImpl(impl,
040: new Hashtable<Object, Object>(), name);
041: LdapSchemaContextImpl.schemaTree = new Hashtable<String, Hashtable<String, Hashtable<String, Object>>>();
042: LdapSchemaContextImpl.schemaTree.put(
043: LdapSchemaContextImpl.ATTRIBUTE_TYPES,
044: new Hashtable<String, Hashtable<String, Object>>());
045: LdapSchemaContextImpl.schemaTree.put(
046: LdapSchemaContextImpl.OBJECT_CLASSES,
047: new Hashtable<String, Hashtable<String, Object>>());
048: LdapSchemaContextImpl.schemaTree.put(
049: LdapSchemaContextImpl.LDAP_SYNTAXES,
050: new Hashtable<String, Hashtable<String, Object>>());
051: LdapSchemaContextImpl.schemaTree.put(
052: LdapSchemaContextImpl.MATCHING_RULES,
053: new Hashtable<String, Hashtable<String, Object>>());
054: context = new LdapSchemaContextImpl(context,
055: new Hashtable<Object, Object>(), name);
056: }
057:
058: protected void tearDown() throws Exception {
059: super .tearDown();
060:
061: }
062:
063: public void test_CreateSubcontext_LName_LAttributes()
064: throws NamingException {
065: try {
066: context
067: .createSubcontext((Name) null,
068: new BasicAttributes());
069: fail("Should throw NPE");
070: } catch (NullPointerException e) {
071: // expected
072: }
073:
074: try {
075: context.createSubcontext(new CompositeName(""), null);
076: fail("Should throw ArrayIndexOutOfBoundsException");
077: } catch (ArrayIndexOutOfBoundsException e) {
078: // expected
079: }
080: try {
081: context.createSubcontext(new CompositeName("test"), null);
082: fail("Should throw SchemaViolationException");
083: } catch (SchemaViolationException e) {
084: // expected
085: }
086: try {
087: context.createSubcontext(new CompositeName("test"),
088: new BasicAttributes());
089: fail("Should throw SchemaViolationException");
090: } catch (SchemaViolationException e) {
091: // expected
092: }
093:
094: // Specify attributes for the schema object
095: }
096:
097: public void test_modifyAttributes_LString_LModificationItem()
098: throws NamingException {
099: try {
100: context.modifyAttributes((String) null,
101: new ModificationItem[] {});
102: fail("Should throw NPE");
103: } catch (NullPointerException e) {
104: // expected
105: }
106:
107: try {
108: context.modifyAttributes("AttributeDefinition/cn", null);
109: fail("Should throw NPE");
110: } catch (NullPointerException e) {
111: // expected
112: }
113: }
114:
115: public void test_search_LString_LAttributes_LString()
116: throws NamingException {
117: try {
118: context.search((String) null, new BasicAttributes(),
119: new String[] {});
120: fail("Should throw NPE");
121: } catch (NullPointerException e) {
122: // expected
123: }
124: }
125:
126: public void testDestroySubcontextString() throws NamingException {
127: try {
128: context.destroySubcontext((String) null);
129: fail("Should throw NPE");
130: } catch (NullPointerException e) {
131: // expected
132: }
133: }
134:
135: public void test_getNameInNamespace() throws NamingException {
136: try {
137: context.getNameInNamespace();
138: fail("Should throw OperationNotSupportedException");
139: } catch (OperationNotSupportedException e) {
140: // expected
141: }
142: }
143:
144: public void test_getSchemaClassDefinition() throws NamingException {
145: try {
146: context.getSchemaClassDefinition(new CompositeName(""));
147: fail("Should throw OperationNotSupportedException");
148: } catch (OperationNotSupportedException e) {
149: // expected
150: }
151: }
152:
153: }
|