DirContext ctx = ( DirContext ) exampleCtx.lookup( "ou=testing00" );
assertNotNull( ctx );
Attributes attributes = ctx.getAttributes( "" );
assertNotNull( attributes );
assertEquals( "testing00", attributes.get( "ou" ).get() );
Attribute attribute = attributes.get( "objectClass" );
assertNotNull( attribute );
assertTrue( attribute.contains( "top" ) );
assertTrue( attribute.contains( "organizationalUnit" ) );
/*
* check ou=testing01,dc=example,dc=com
*/
ctx = ( DirContext ) exampleCtx.lookup( "ou=testing01" );
assertNotNull( ctx );
attributes = ctx.getAttributes( "" );
assertNotNull( attributes );
assertEquals( "testing01", attributes.get( "ou" ).get() );
attribute = attributes.get( "objectClass" );
assertNotNull( attribute );
assertTrue( attribute.contains( "top" ) );
assertTrue( attribute.contains( "organizationalUnit" ) );
/*
* Check ou=testing02,dc=example,dc=com
*/
ctx = ( DirContext ) exampleCtx.lookup( "ou=testing02" );
assertNotNull( ctx );
attributes = ctx.getAttributes( "" );
assertNotNull( attributes );
assertEquals( "testing02", attributes.get( "ou" ).get() );
attribute = attributes.get( "objectClass" );
assertNotNull( attribute );
assertTrue( attribute.contains( "top" ) );
assertTrue( attribute.contains( "organizationalUnit" ) );
/*
* Check ou=subtest,ou=testing01,dc=example,dc=com
*/
ctx = ( DirContext ) exampleCtx.lookup( "ou=subtest,ou=testing01" );
assertNotNull( ctx );
attributes = ctx.getAttributes( "" );
assertNotNull( attributes );
assertEquals( "subtest", attributes.get( "ou" ).get() );
attribute = attributes.get( "objectClass" );
assertNotNull( attribute );
assertTrue( attribute.contains( "top" ) );
assertTrue( attribute.contains( "organizationalUnit" ) );
/*
* Check entry cn=Heather Nova, dc=example,dc=com
*/
ctx = ( DirContext ) exampleCtx.lookup( RDN_HEATHER_NOVA );
assertNotNull( ctx );
// -------------------------------------------------------------------
// Enable the nis schema
// -------------------------------------------------------------------
// check if nis is disabled
LdapContext schemaRoot = getSchemaContext( getService() );
Attributes nisAttrs = schemaRoot.getAttributes( "cn=nis" );
boolean isNisDisabled = false;
if ( nisAttrs.get( "m-disabled" ) != null )
{
isNisDisabled = ( ( String ) nisAttrs.get( "m-disabled" ).get() ).equalsIgnoreCase( "TRUE" );
}
// if nis is disabled then enable it
if ( isNisDisabled )
{
Attribute disabled = new BasicAttribute( "m-disabled" );
ModificationItem[] mods = new ModificationItem[]
{
new ModificationItem( DirContext.REMOVE_ATTRIBUTE, disabled ) };
schemaRoot.modifyAttributes( "cn=nis", mods );
}
// -------------------------------------------------------------------
// Add a bunch of nis groups
// -------------------------------------------------------------------
addNisPosixGroup( "testGroup0", 0 );
addNisPosixGroup( "testGroup1", 1 );
addNisPosixGroup( "testGroup2", 2 );
addNisPosixGroup( "testGroup4", 4 );
addNisPosixGroup( "testGroup5", 5 );
// Create a test account
Attributes test = new BasicAttributes( true );
Attribute oc = new BasicAttribute( "ObjectClass" );
oc.add( "top" );
oc.add( "account" );
oc.add( "posixAccount" );
test.put( oc );
test.put( "cn", "test" );
test.put( "uid", "1" );
test.put( "uidNumber", "1" );