1 17 package org.apache.ldap.server.operational; 18 19 20 import org.apache.ldap.server.AbstractCoreTest; 21 22 import javax.naming.NamingException ; 23 import javax.naming.directory.Attribute ; 24 import javax.naming.directory.Attributes ; 25 import javax.naming.directory.BasicAttributes ; 26 import javax.naming.directory.DirContext ; 27 28 29 37 public class BinaryAttributeFilterTest extends AbstractCoreTest 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 (); 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 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 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 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 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 } 90 | Popular Tags |