blob: 3863f375ca1fb4b082406df3576456410a08fe83 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.directory.server.core.jndi;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.integ.CiRunner;
import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.message.AttributesImpl;
import org.junit.Test;import static org.junit.Assert.assertNotNull;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertTrue;
import org.junit.runner.RunWith;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
/**
* Tests the use of extensible objects.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
@RunWith ( CiRunner.class )
public class ExtensibleObjectIT
{
public static DirectoryService service;
@Test
public void testExtensibleObjectModify() throws Exception
{
LdapContext sysRoot = getSystemContext( service );
Attributes attributes = new AttributesImpl( true );
Attribute attribute = new AttributeImpl( "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 AttributesImpl( true );
Attribute freeform = new AttributeImpl( "cn" );
freeform.add( "testing" );
newattribs.put( freeform );
Attribute objectClass = new AttributeImpl( "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( "cn" );
assertTrue( attribute.contains( "testing" ) );
}
@Test
public void testExtensibleObjectAdd() throws Exception
{
LdapContext sysRoot = getSystemContext( service );
Attributes attributes = new AttributesImpl( true );
Attribute attribute = new AttributeImpl( "objectClass" );
attribute.add( "top" );
attribute.add( "extensibleObject" );
attribute.add( "organizationalUnit" );
attributes.put( attribute );
attributes.put( "ou", "testing00" );
// WARNING: extensible objects cannot accept any arbitrary
// attribute. The attribute must be defined by the schema
// at a bare minimum or the addition will be rejected
// here's an attribute that is not on the MAY or MUST list for
// an organizationalUnit - it's our test for extensible objects
attributes.put( "employeeType", "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( "employeeType" );
assertTrue( attribute.contains( "testing" ) );
}
}