1 17 package org.apache.ldap.server.operational; 18 19 20 import org.apache.ldap.common.message.DerefAliasesEnum; 21 import org.apache.ldap.server.AbstractCoreTest; 22 23 import javax.naming.NamingEnumeration ; 24 import javax.naming.NamingException ; 25 import javax.naming.directory.*; 26 27 28 35 public class OperationalAttributeServiceTest extends AbstractCoreTest 36 { 37 private static final String CREATORS_NAME = "creatorsName"; 38 private static final String CREATE_TIMESTAMP = "createTimestamp"; 39 40 41 public void testModifyOperationalOpAttrs() throws NamingException 42 { 43 46 Attributes attributes = new BasicAttributes(); 47 Attribute attribute = new BasicAttribute( "objectClass" ); 48 attribute.add( "top" ); 49 attribute.add( "organizationalUnit" ); 50 attributes.put( attribute ); 51 attributes.put( "ou", "testing00" ); 52 DirContext ctx = sysRoot.createSubcontext( "ou=testing00", attributes ); 53 assertNotNull( ctx ); 54 55 ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" ); 56 assertNotNull( ctx ); 57 58 attributes = ctx.getAttributes( "" ); 59 assertNotNull( attributes ); 60 assertEquals( "testing00", attributes.get( "ou" ).get() ); 61 attribute = attributes.get( "objectClass" ); 62 assertNotNull( attribute ); 63 assertTrue( attribute.contains( "top" ) ); 64 assertTrue( attribute.contains( "organizationalUnit" ) ); 65 assertNull( attributes.get( CREATE_TIMESTAMP ) ); 66 assertNull( attributes.get( CREATORS_NAME ) ); 67 68 SearchControls ctls = new SearchControls(); 69 ctls.setReturningAttributes( new String [] 70 { "ou", "createTimestamp", "creatorsName" } ); 71 72 sysRoot.addToEnvironment( DerefAliasesEnum.JNDI_PROP, 73 DerefAliasesEnum.NEVERDEREFALIASES_NAME ); 74 NamingEnumeration list; 75 list = sysRoot.search( "", "(ou=testing00)", ctls ); 76 SearchResult result = ( SearchResult ) list.next(); 77 list.close(); 78 79 System.out.println( result ); 80 81 assertNotNull( result.getAttributes().get( "ou" ) ); 82 assertNotNull( result.getAttributes().get( CREATORS_NAME ) ); 83 assertNotNull( result.getAttributes().get( CREATE_TIMESTAMP ) ); 84 } 85 86 87 98 public void testSystemContextRoot() throws NamingException 99 { 100 SearchControls controls = new SearchControls(); 101 controls.setSearchScope( SearchControls.OBJECT_SCOPE ); 102 NamingEnumeration list; 103 list = sysRoot.search( "", "(objectClass=*)", controls ); 104 SearchResult result = ( SearchResult ) list.next(); 105 106 Attributes attributes = result.getAttributes(); 108 assertNull( attributes.get( "creatorsName" ) ); 109 assertNull( attributes.get( "createTimestamp" ) ); 110 111 String [] ids = new String [] { "creatorsName", "createTimestamp" }; 113 controls.setReturningAttributes( ids ); 114 list = sysRoot.search( "", "(objectClass=*)", controls ); 115 result = ( SearchResult ) list.next(); 116 attributes = result.getAttributes(); 117 assertNotNull( attributes.get( "creatorsName" ) ); 118 assertNotNull( attributes.get( "createTimestamp" ) ); 119 } 120 121 122 133 public void testConfirmNonAdminUserDnIsCreatorsName() throws NamingException 134 { 135 Attributes attributes = sysRoot.getAttributes( "uid=akarasulu,ou=users", new String [] { "creatorsName" } ); 136 137 assertFalse( "uid=akarasulu,ou=users,ou=system".equals( attributes.get( "creatorsName" ).get() ) ); 138 } 139 } 140 | Popular Tags |