* Test the put( SA... ) method
*/
@Test public void tesPutServerAttributeElipsis() throws Exception
{
DN dn = new DN( "cn=test" );
DefaultServerEntry entry = new DefaultServerEntry( schemaManager, dn );
// first test a null SA addition. It should be allowed.
try
{
entry.put( (EntryAttribute)null );
fail();
}
catch ( IllegalArgumentException iae )
{
assertTrue( true );
}
// Adding some serverAttributes
//AttributeType atCo = registries.lookupAttributeTypeRegistry( "countryName" );
AttributeType atGN = schemaManager.lookupAttributeTypeRegistry( "givenname" );
AttributeType atStreet = schemaManager.lookupAttributeTypeRegistry( "2.5.4.9" );
EntryAttribute sa = new DefaultServerAttribute( atL, "france" );
entry.put( sa );
assertEquals( 1, entry.size() );
assertNotNull( entry.get( "l" ) );
assertEquals( "france", entry.get( "l" ).get().getString() );
EntryAttribute sb = new DefaultServerAttribute( atC, "countryTest" );
EntryAttribute sc = new DefaultServerAttribute( atGN, "test" );
EntryAttribute sd = new DefaultServerAttribute( atStreet, "testStreet" );
entry.put( sb, sc, sd );
assertEquals( 4, entry.size() );
assertNotNull( entry.get( atC ) );
assertEquals( "countryTest", entry.get( atC ).get().getString() );
assertNotNull( entry.get( atGN ) );
assertEquals( "test", entry.get( atGN ).get().getString() );
assertNotNull( entry.get( atStreet) );
assertEquals( "testStreet", entry.get( atStreet ).get().getString() );
// Test a replacement
EntryAttribute sbb = new DefaultServerAttribute( atC, "countryTestTest" );
EntryAttribute scc = new DefaultServerAttribute( atGN, "testtest" );
List<EntryAttribute> result = entry.put( sbb, scc );
assertEquals( 2, result.size() );
assertEquals( "countryTest", result.get(0).get().getString() );
assertEquals( "test", result.get(1).get().getString() );
assertEquals( 4, entry.size() );
assertNotNull( entry.get( atC ) );
assertEquals( "countryTestTest", entry.get( atC ).get().getString() );
assertNotNull( entry.get( atGN ) );
assertEquals( "testtest", entry.get( atGN ).get().getString() );
assertNotNull( entry.get( atStreet) );
assertEquals( "testStreet", entry.get( atStreet ).get().getString() );
// test an ObjectClass replacement
AttributeType OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
EntryAttribute oc = new DefaultServerAttribute( "OBJECTCLASS", OBJECT_CLASS_AT, "person", "inetorgperson" );
List<EntryAttribute> oldOc = entry.put( oc );
assertNotNull( oldOc );
assertEquals( 0, oldOc.size() );
assertNotNull( entry.get( "objectClass" ) );
EntryAttribute newOc = entry.get( "objectClass" );
assertNotNull( newOc );
assertEquals( OBJECT_CLASS_AT, newOc.getAttributeType() );
assertEquals( 2, newOc.size() );
assertEquals( "OBJECTCLASS", newOc.getUpId() );