| /* |
| * Copyright 2004 The Apache Software Foundation |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| */ |
| package org.apache.ldap.server.jndi; |
| |
| |
| import org.apache.ldap.server.AbstractAdminTestCase; |
| |
| import javax.naming.directory.*; |
| |
| |
| /** |
| * Tests the use of extensible objects. |
| * |
| * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> |
| * @version $Rev$ |
| */ |
| public class ExtensibleObjectTest extends AbstractAdminTestCase |
| { |
| public void testExtensibleObjectModify() throws Exception |
| { |
| Attributes attributes = new BasicAttributes( true ); |
| Attribute attribute = new BasicAttribute( "objectClass" ); |
| attribute.add( "top" ); |
| attribute.add( "organizationalUnit" ); |
| attributes.put( attribute ); |
| attributes.put( "ou", "testing00" ); |
| DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes ); |
| assertNotNull( ctx ); |
| |
| ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" ); |
| assertNotNull( ctx ); |
| |
| attributes = ctx.getAttributes( "" ); |
| assertNotNull( attributes ); |
| assertEquals( "testing00", attributes.get( "ou" ).get() ); |
| attribute = attributes.get( "objectClass" ); |
| assertNotNull( attribute ); |
| assertTrue( attribute.contains( "top" ) ); |
| assertTrue( attribute.contains( "organizationalUnit" ) ); |
| |
| Attributes newattribs = new BasicAttributes( true ); |
| Attribute freeform = new BasicAttribute( "freeform" ); |
| freeform.add( "testing" ); |
| newattribs.put( freeform ); |
| Attribute objectClass = new BasicAttribute( "objectClass" ); |
| objectClass.add( "top" ); |
| objectClass.add( "extensibleObject" ); |
| objectClass.add( "organizationalUnit" ); |
| newattribs.put( objectClass ); |
| ctx.modifyAttributes( "", DirContext.REPLACE_ATTRIBUTE, newattribs ); |
| |
| attributes = ctx.getAttributes( "" ); |
| assertNotNull( attributes ); |
| assertEquals( "testing00", attributes.get( "ou" ).get() ); |
| attribute = attributes.get( "objectClass" ); |
| assertNotNull( attribute ); |
| assertTrue( attribute.contains( "top" ) ); |
| assertTrue( attribute.contains( "organizationalUnit" ) ); |
| assertTrue( attribute.contains( "extensibleObject" ) ); |
| attribute = attributes.get( "freeform" ); |
| assertTrue( attribute.contains( "testing" ) ); |
| } |
| |
| public void testExtensibleObjectAdd() throws Exception |
| { |
| Attributes attributes = new BasicAttributes( true ); |
| Attribute attribute = new BasicAttribute( "objectClass" ); |
| attribute.add( "top" ); |
| attribute.add( "extensibleObject" ); |
| attribute.add( "organizationalUnit" ); |
| attributes.put( attribute ); |
| attributes.put( "ou", "testing00" ); |
| attributes.put( "freeform", "testing" ); |
| DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes ); |
| assertNotNull( ctx ); |
| |
| ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" ); |
| assertNotNull( ctx ); |
| |
| attributes = ctx.getAttributes( "" ); |
| assertNotNull( attributes ); |
| assertEquals( "testing00", attributes.get( "ou" ).get() ); |
| attribute = attributes.get( "objectClass" ); |
| assertNotNull( attribute ); |
| assertTrue( attribute.contains( "top" ) ); |
| assertTrue( attribute.contains( "extensibleObject" ) ); |
| assertTrue( attribute.contains( "organizationalUnit" ) ); |
| attribute = attributes.get( "freeform" ); |
| assertTrue( attribute.contains( "testing" ) ); |
| } |
| } |