1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.operational;
18
19
20 import javax.naming.NamingException;
21 import javax.naming.directory.Attribute;
22 import javax.naming.directory.Attributes;
23 import javax.naming.directory.BasicAttributes;
24 import javax.naming.directory.DirContext;
25
26 import org.apache.ldap.server.AbstractAdminTestCase;
27
28
29 /***
30 * Tests to see that the binary property filtering in the schema service's
31 * filter class {@link org.apache.ldap.server.schema.SchemaService} is working
32 * properly.
33 *
34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35 * @version $Rev: 264732 $
36 */
37 public class BinaryAttributeFilterTest extends AbstractAdminTestCase
38 {
39 private static final String BINARY_KEY = "java.naming.ldap.attributes.binary";
40
41
42 public void testBinaryExtension() throws NamingException
43 {
44 Attributes attributes = new BasicAttributes( true );
45 attributes.put( "objectClass", "top" );
46 attributes.put( "objectClass", "organizationalUnit" );
47 attributes.put( "objectClass", "extensibleObject" );
48 attributes.put( "ou", "testing" );
49 sysRoot.createSubcontext( "ou=test", attributes );
50
51
52 DirContext ctx = ( DirContext ) sysRoot.lookup( "ou=test" ) ;
53 Attribute ou = ctx.getAttributes( "" ).get( "ou" );
54 Object value = ou.get();
55 assertTrue( value instanceof String );
56
57
58 sysRoot.addToEnvironment( BINARY_KEY, "ou" );
59 ctx = ( DirContext ) sysRoot.lookup( "ou=test" ) ;
60 ou = ctx.getAttributes( "" ).get( "ou" );
61 value = ou.get();
62 assertTrue( value instanceof byte[] );
63
64
65 byte[] keyValue = new byte[] { 0x45, 0x23, 0x7d, 0x7f };
66 attributes.put( "jpegPhoto", keyValue );
67 sysRoot.createSubcontext( "ou=anothertest", attributes );
68 ctx = ( DirContext ) sysRoot.lookup( "ou=anothertest" ) ;
69 ou = ctx.getAttributes( "" ).get( "ou" );
70 value = ou.get();
71 assertTrue( value instanceof byte[] );
72 Attribute jpegPhoto = ctx.getAttributes( "" ).get( "jpegPhoto" );
73 value = jpegPhoto.get();
74 assertTrue( value instanceof byte[] );
75
76
77
78 attributes.remove( "jpegPhoto" );
79 attributes.put( "jpegPhoto", "testing a string" );
80 sysRoot.createSubcontext( "ou=yetanothertest", attributes );
81 ctx = ( DirContext ) sysRoot.lookup( "ou=yetanothertest" ) ;
82 ou = ctx.getAttributes( "" ).get( "ou" );
83 value = ou.get();
84 assertTrue( value instanceof byte[] );
85 jpegPhoto = ctx.getAttributes( "" ).get( "jpegPhoto" );
86 value = jpegPhoto.get();
87 assertTrue( value instanceof byte[] );
88 }
89 }