You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2009/11/12 07:15:35 UTC

svn commit: r835252 - in /directory/samples/trunk/testcase-archetype: ./ src/main/resources/META-INF/ src/main/resources/archetype-resources/ src/main/resources/archetype-resources/src/main/java/ src/main/resources/archetype-resources/src/test/java/ sr...

Author: seelmann
Date: Thu Nov 12 06:15:34 2009
New Revision: 835252

URL: http://svn.apache.org/viewvc?rev=835252&view=rev
Log:
Updated testcase archetype for ApacheDS 1.5.5, added basic usage examples

Added:
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif
Removed:
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/ApacheDSITest.java
Modified:
    directory/samples/trunk/testcase-archetype/apacheds-testcase-archetype.sh
    directory/samples/trunk/testcase-archetype/pom.xml
    directory/samples/trunk/testcase-archetype/src/main/resources/META-INF/archetype.xml
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/pom.xml
    directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/main/java/Dummy.java

Modified: directory/samples/trunk/testcase-archetype/apacheds-testcase-archetype.sh
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/apacheds-testcase-archetype.sh?rev=835252&r1=835251&r2=835252&view=diff
==============================================================================
--- directory/samples/trunk/testcase-archetype/apacheds-testcase-archetype.sh (original)
+++ directory/samples/trunk/testcase-archetype/apacheds-testcase-archetype.sh Thu Nov 12 06:15:34 2009
@@ -1,4 +1,4 @@
 #!/bin/sh
 
-mvn archetype:create -DarchetypeGroupId=org.apache.directory.server -DarchetypeArtifactId=apacheds-testcase-archetype -DarchetypeVersion=1.0.2 -DgroupId=$1 -DartifactId=$2
+mvn archetype:generate -DarchetypeGroupId=org.apache.directory.server -DarchetypeArtifactId=apacheds-testcase-archetype -DarchetypeVersion=1.5.5-SNAPSHOT -DgroupId=$1 -DartifactId=$2 -Dversion=1.0-SNAPSHOT
 

Modified: directory/samples/trunk/testcase-archetype/pom.xml
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/pom.xml?rev=835252&r1=835251&r2=835252&view=diff
==============================================================================
--- directory/samples/trunk/testcase-archetype/pom.xml (original)
+++ directory/samples/trunk/testcase-archetype/pom.xml Thu Nov 12 06:15:34 2009
@@ -1,12 +1,13 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
     <groupId>org.apache.directory.server</groupId>
-    <artifactId>build</artifactId>
-    <version>1.0.2</version>
+    <artifactId>apacheds-parent</artifactId>
+    <version>1.5.5</version>
   </parent>
 
   <modelVersion>4.0.0</modelVersion>
   <artifactId>apacheds-testcase-archetype</artifactId>
-  <packaging>maven-plugin</packaging>
+  <packaging>jar</packaging>
   <name>ApacheDS Testcase Archetype</name>
+  <version>1.5.5-SNAPSHOT</version>
 </project>

Modified: directory/samples/trunk/testcase-archetype/src/main/resources/META-INF/archetype.xml
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/META-INF/archetype.xml?rev=835252&r1=835251&r2=835252&view=diff
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/META-INF/archetype.xml (original)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/META-INF/archetype.xml Thu Nov 12 06:15:34 2009
@@ -4,9 +4,13 @@
     <source>src/main/java/Dummy.java</source>
   </sources>
   <testSources>
-    <source>src/test/java/ApacheDSITest.java</source>
+    <source>src/test/java/AdvancedTest.java</source>
+    <source>src/test/java/AdvancedTestApacheDsFactory.java</source>
+    <source>src/test/java/MinimalTest.java</source>
   </testSources>
   <resources>
     <resource>src/test/resources/log4j.properties</resource>
+    <resource>src/test/resources/sevenSeas_data.ldif</resource>
+    <resource>src/test/resources/sevenSeas_schema.ldif</resource>
   </resources>
 </archetype>

Modified: directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/pom.xml
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/pom.xml?rev=835252&r1=835251&r2=835252&view=diff
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/pom.xml (original)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/pom.xml Thu Nov 12 06:15:34 2009
@@ -5,27 +5,39 @@
   <artifactId>${artifactId}</artifactId>
   <packaging>jar</packaging>
   <version>${version}</version>
-  <name>Schema Project</name>
+  <name>Test Project</name>
   <url>http://directory.apache.org/</url>
 
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
   <dependencies>
     <dependency>
       <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-server-unit</artifactId>
-      <version>1.0.2</version>
+      <artifactId>apacheds-server-integ</artifactId>
+      <version>1.5.5</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.1</version>
+      <version>4.5</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
-      <artifactId>nlog4j</artifactId>
-      <version>1.2.25</version>
-      <scope>test</scope>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.3.1</version>
     </dependency>
   </dependencies>
 </project>

Modified: directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/main/java/Dummy.java
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/main/java/Dummy.java?rev=835252&r1=835251&r2=835252&view=diff
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/main/java/Dummy.java (original)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/main/java/Dummy.java Thu Nov 12 06:15:34 2009
@@ -21,8 +21,8 @@
 
 
 /**
- * This class does nothing.  Makes sure maven builds and the archetype works.
+ * This class does nothing. Makes sure maven builds and the archetype works.
  */
-public class Dummy 
+public class Dummy
 {
 }

Added: directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java?rev=835252&view=auto
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java (added)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java Thu Nov 12 06:15:34 2009
@@ -0,0 +1,144 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package ${groupId};
+
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifFiles;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.core.integ.annotations.Factory;
+import org.apache.directory.server.integ.SiRunner;
+import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.client.ClientModification;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.DummySSLSocketFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * This is an advanced test template.
+ * It shows how to configure the embedded ApacheDS:
+ * <ul>
+ * <li>Create a partition 'o=sevenSeas'</li>
+ * <li>Enable LDAP and LDAPS protocol</li>
+ * <li>Enable the 'nis' schema</li>
+ * <li>Inject a new custom schema from an LDIF file</li>
+ * <li>Inject test data from an LDIF file</li>
+ * <li>Restart the embedded ApacheDS after each test method</li>
+ * <li></li>
+ * </ul>  
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(SiRunner.class)
+@CleanupLevel(Level.METHOD)
+@Factory(AdvancedTestApacheDsFactory.class)
+@ApplyLdifFiles(
+    { "/sevenSeas_schema.ldif", "/sevenSeas_data.ldif" })
+public class AdvancedTest
+{
+    // the LdapServer is injected on test startup
+    public static LdapServer ldapServer;
+
+
+    @Before
+    public void enableNisSchema() throws Exception
+    {
+        List<Modification> mod = new ArrayList<Modification>();
+        mod.add( new ClientModification( ModificationOperation.REMOVE_ATTRIBUTE, new DefaultClientAttribute(
+            "m-disabled" ) ) );
+        ldapServer.getDirectoryService().getAdminSession().modify( new LdapDN( "cn=nis,ou=schema" ), mod );
+    }
+
+
+    /**
+     * Test that partition 'o=sevenSeas' exists.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testCustomPartitionExists() throws Exception
+    {
+        assertTrue( ldapServer.getDirectoryService().getAdminSession().exists( new LdapDN( "o=sevenSeas" ) ) );
+    }
+
+
+    /**
+     * Test that LDAPS works. Use JNDI as the request must go over the wire.
+     * Use a dummy SSL factory that accepts the self-signed server certificate.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void testLdaps() throws Exception
+    {
+        Hashtable<String, String> env = new Hashtable<String, String>();
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( Context.PROVIDER_URL, "ldaps://localhost:" + ldapServer.getPortSSL() );
+        env.put( Context.SECURITY_PRINCIPAL, ServerDNConstants.ADMIN_SYSTEM_DN );
+        env.put( Context.SECURITY_CREDENTIALS, "secret" );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        env.put( "java.naming.ldap.factory.socket", DummySSLSocketFactory.class.getName() );
+        LdapContext ctx = new InitialLdapContext( env, null );
+
+        assertNotNull( ctx.lookup( "ou=users,ou=system" ) );
+    }
+
+
+    /**
+     * Test that the custom schema and the data was injected.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testCustomSchemaAndData() throws Exception
+    {
+        // use the helper method to create a JNDI context from the LdapServer
+        LdapContext ctx = getWiredContext( ldapServer );
+
+        Attributes attributes = ctx.getAttributes( "cn=HMS Victory,ou=ships,o=sevenSeas" );
+        assertNotNull( attributes );
+        assertNotNull( attributes.get( "objectClass" ) );
+        assertTrue( attributes.get( "objectClass" ).contains( "ship" ) );
+        assertNotNull( attributes.get( "numberOfGuns" ) );
+        assertEquals( "104", attributes.get( "numberOfGuns" ).get() );
+    }
+
+}

Added: directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java?rev=835252&view=auto
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java (added)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java Thu Nov 12 06:15:34 2009
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package ${groupId};
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.integ.LdapServerFactory;
+import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.protocol.shared.transport.TcpTransport;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.mina.util.AvailablePortFinder;
+
+
+/**
+ * A LdapServerFactory for AdvancedTest.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AdvancedTestApacheDsFactory implements LdapServerFactory
+{
+    public LdapServer newInstance() throws Exception
+    {
+        // default configuration
+        DirectoryService service = new DefaultDirectoryService();
+        IntegrationUtils.doDelete( service.getWorkingDirectory() );
+        service.getChangeLog().setEnabled( true );
+        service.setAllowAnonymousAccess( true );
+        service.setShutdownHookEnabled( false );
+
+        // create a new partition "o=sevenSeas" with some indices
+        JdbmPartition example = new JdbmPartition();
+        example.setCacheSize( 500 );
+        example.setSuffix( "o=sevenSeas" );
+        example.setId( "sevenSeas" );
+        Set<Index<?, ServerEntry>> indexedAttrs = new HashSet<Index<?, ServerEntry>>();
+        indexedAttrs.add( new JdbmIndex<String, ServerEntry>( "cn" ) );
+        indexedAttrs.add( new JdbmIndex<String, ServerEntry>( "ou" ) );
+        indexedAttrs.add( new JdbmIndex<String, ServerEntry>( "dc" ) );
+        indexedAttrs.add( new JdbmIndex<String, ServerEntry>( "objectClass" ) );
+        example.setIndexedAttributes( indexedAttrs );
+        service.addPartition( example );
+
+        // create the LDAP Server, create a transport for LDAP and LDAPS
+        LdapServer ldapServer = new LdapServer();
+        ldapServer.setDirectoryService( service );
+        int ldapPort = AvailablePortFinder.getNextAvailable( 1024 );
+        TcpTransport ldapTransport = new TcpTransport( ldapPort );
+        int ldapsPort = AvailablePortFinder.getNextAvailable( ldapPort + 1 );
+        TcpTransport ldapsTransport = new TcpTransport( ldapsPort );
+        ldapsTransport.setEnableSSL( true );
+        ldapServer.setTransports( ldapTransport, ldapsTransport );
+        ldapServer.setAllowAnonymousAccess( true );
+
+        return ldapServer;
+    }
+
+}

Added: directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java?rev=835252&view=auto
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java (added)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java Thu Nov 12 06:15:34 2009
@@ -0,0 +1,219 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package ${groupId};
+
+
+import static junit.framework.Assert.assertNotNull;
+import static org.apache.directory.server.integ.ServerIntegrationUtils.getWiredContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.filtering.EntryFilteringCursor;
+import org.apache.directory.server.integ.SiRunner;
+import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.client.ClientModification;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.filter.EqualityNode;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * This is a minimal test template.
+ * It just starts up an embedded ApacheDS with default configuration:
+ * <ul>
+ * <li>Only system partion 'ou=system' and schema partition 'ou=schema' exist.</li>
+ * <li>Only LDAP protocol (no LDAPS) is enabled, listening on port 1024.</li>
+ * <li>The directory data can also be accessed directly via the core API.</li>
+ * <li></li>
+ * </ul>
+ * 
+ * The two tests methods demonstrate how to use the core API and JNDI 
+ * to access the embedded ApacheDS within the JVM or over the wire.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(SiRunner.class)
+public class MinimalTest
+{
+    // the LdapServer is injected on test startup
+    public static LdapServer ldapServer;
+
+
+    /**
+     * Demonstrates how to use the core API.
+     * Note that those requests don't go over the wire but access
+     * the ApacheDS within the same JVM.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void demonstrateCoreAPI() throws Exception
+    {
+        // get the admin session which has unlimited access rights to the directory
+        CoreSession session = ldapServer.getDirectoryService().getAdminSession();
+        Registries registries = ldapServer.getDirectoryService().getRegistries();
+
+        // this entry should exist
+        assertTrue( session.exists( new LdapDN( "ou=users,ou=system" ) ) );
+
+        // this entry should not exist
+        assertFalse( session.exists( new LdapDN( "uid=foo.bar,ou=users,ou=system" ) ) );
+
+        // create an entry
+        ServerEntry newEntry = new DefaultServerEntry( registries, new LdapDN( "uid=foo.bar,ou=users,ou=system" ) );
+        newEntry.add( "objectClass", "top", "person", "organizationalPerson", "inetOrgPerson" );
+        newEntry.add( "uid", "foo.bar" );
+        newEntry.add( "cn", "Foo Bar" );
+        newEntry.add( "sn", "Bar" );
+        newEntry.add( "givenName", "Foo" );
+        session.add( newEntry );
+
+        // lookup entry
+        ServerEntry entry = session.lookup( new LdapDN( "uid=foo.bar,ou=users,ou=system" ) );
+        assertTrue( entry.hasObjectClass( "inetOrgPerson" ) );
+        assertNotNull( entry.get( "cn" ) );
+        assertEquals( "Foo Bar", entry.get( "cn" ).get().getString() );
+
+        // modify entry
+        List<Modification> modifications = new ArrayList<Modification>();
+        modifications.add( new ClientModification( ModificationOperation.ADD_ATTRIBUTE, new DefaultClientAttribute(
+            "mail", "bar@example.com", "foo.bar@example.com" ) ) );
+        modifications.add( new ClientModification( ModificationOperation.REMOVE_ATTRIBUTE, new DefaultClientAttribute(
+            "givenName" ) ) );
+        modifications.add( new ClientModification( ModificationOperation.REPLACE_ATTRIBUTE, new DefaultClientAttribute(
+            "description", "This is Foo Bar." ) ) );
+        session.modify( new LdapDN( "uid=foo.bar,ou=users,ou=system" ), modifications );
+
+        // search
+        EntryFilteringCursor cursor = session.search( new LdapDN( "ou=users,ou=system" ), SearchScope.ONELEVEL,
+            new EqualityNode<String>( "uid", new ClientStringValue( "foo.bar" ) ), AliasDerefMode.DEREF_ALWAYS, null );
+        cursor.beforeFirst();
+        assertTrue( cursor.next() );
+        assertNotNull( cursor.get() );
+        assertEquals( "uid=foo.bar,ou=users,ou=system", cursor.get().getDn().getUpName() );
+        assertFalse( cursor.next() );
+        cursor.close();
+
+        // delete entry
+        session.delete( new LdapDN( "uid=foo.bar,ou=users,ou=system" ) );
+    }
+
+
+    /**
+     * Demonstrates how to use the JNDI API to access the embedded
+     * ApacheDS over the wire.
+     * 
+     * @throws Exception
+     */
+    @Test
+    public void demonstrateJndiAPI() throws Exception
+    {
+        // use the helper method to create a JNDI context from the LdapServer
+        LdapContext ctx = getWiredContext( ldapServer );
+
+        // this entry should exist
+        assertNotNull( ctx.lookup( "ou=users,ou=system" ) );
+
+        // this entry should not exist
+        try
+        {
+            ctx.lookup( "uid=foo.bar,ou=users,ou=system" );
+            fail( "uid=foo.bar,ou=users,ou=system doesn't exist." );
+        }
+        catch ( NameNotFoundException e )
+        {
+            // expected
+        }
+
+        // create an entry
+        Attributes newAttributes = new BasicAttributes();
+        Attribute newOcAttribute = new BasicAttribute( "objectClass" );
+        newOcAttribute.add( "top" );
+        newOcAttribute.add( "person" );
+        newOcAttribute.add( "organizationalPerson" );
+        newOcAttribute.add( "inetOrgPerson" );
+        newAttributes.put( newOcAttribute );
+        newAttributes.put( "uid", "foo.bar" );
+        newAttributes.put( "cn", "Foo Bar" );
+        newAttributes.put( "sn", "Bar" );
+        newAttributes.put( "givenName", "Foo" );
+        ctx.bind( "uid=foo.bar,ou=users,ou=system", null, newAttributes );
+
+        // lookup entry
+        Attributes attributes = ctx.getAttributes( "uid=foo.bar,ou=users,ou=system" );
+        assertNotNull( attributes.get( "objectClass" ) );
+        assertTrue( attributes.get( "objectClass" ).contains( "inetOrgPerson" ) );
+        assertNotNull( attributes.get( "cn" ) );
+        assertEquals( "Foo Bar", attributes.get( "cn" ).get() );
+
+        // modify entry
+        ModificationItem[] modificatons = new ModificationItem[3];
+        modificatons[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute( "mail",
+            "foo.bar@example.com" ) );
+        modificatons[1] = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( "givenName" ) );
+        modificatons[2] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, new BasicAttribute( "description",
+            "This is Foo Bar." ) );
+        ctx.modifyAttributes( "uid=foo.bar,ou=users,ou=system", modificatons );
+
+        // search
+        SearchControls searchControls = new SearchControls();
+        NamingEnumeration<SearchResult> results = ctx.search( "ou=users,ou=system", "(uid=foo.bar)", searchControls );
+        assertTrue( results.hasMore() );
+        SearchResult next = results.next();
+        assertNotNull( next );
+        assertEquals( "uid=foo.bar,ou=users,ou=system", next.getNameInNamespace() );
+        assertFalse( results.hasMore() );
+        results.close();
+
+        // delete entry
+        ctx.unbind( "uid=foo.bar,ou=users,ou=system" );
+
+        ctx.close();
+    }
+
+}

Added: directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif?rev=835252&view=auto
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif (added)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif Thu Nov 12 06:15:34 2009
@@ -0,0 +1,236 @@
+# Sample LDIF data for the ApacheDS v1.0 Basic User's Guide
+#
+# Some sailors and their ships
+# userpassword for all persons is "pass"
+#
+version: 1
+
+dn: o=sevenSeas
+objectClass: organization
+objectClass: top
+o: sevenSeas
+
+dn: ou=people,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+description: Contains entries which describe persons (seamen)
+ou: people
+
+dn: ou=groups,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+description: Contains entries which describe groups (crews, for instance)
+ou: groups
+
+dn: ou=crews,ou=groups,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+description: Contains entries which describe ship crews
+ou: crews
+
+dn: ou=ranks,ou=groups,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+description: Contains entries which describe naval ranks (e.g. captain)
+ou: ranks
+
+dn: ou=ships,o=sevenSeas
+objectClass: organizationalUnit
+objectClass: top
+description: Contains entries which describe ships
+ou: ships
+
+# HMS Lydia Crew
+# --------------
+
+dn: cn=Horatio Hornblower,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: Horatio Hornblower
+description: Capt. Horatio Hornblower, R.N
+givenName: Horatio
+sn: Hornblower
+uid: hhornblo
+mail: hhornblo@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=William Bush,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: William Bush
+description: Lt. William Bush
+givenName: William
+manager: cn=Horatio Hornblower,ou=people,o=sevenSeas
+sn: Bush
+uid: wbush
+mail: wbush@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=Thomas Quist,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: Thomas Quist
+description: Seaman Quist
+givenName: Thomas
+manager: cn=Horatio Hornblower,ou=people,o=sevenSeas
+sn: Quist
+uid: tquist
+mail: tquist@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=Moultrie Crystal,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: Moultrie Crystal
+description: Lt. Crystal
+givenName: Moultrie
+manager: cn=Horatio Hornblower,ou=people,o=sevenSeas
+sn: Crystal
+uid: mchrysta
+mail: mchrysta@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=HMS Lydia,ou=crews,ou=groups,o=sevenSeas
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: HMS Lydia
+uniqueMember: cn=Horatio Hornblower,ou=people,o=sevenSeas
+uniqueMember: cn=William Bush,ou=people,o=sevenSeas
+uniqueMember: cn=Thomas Quist,ou=people,o=sevenSeas
+uniqueMember: cn=Moultrie Crystal,ou=people,o=sevenSeas
+
+# HMS Victory Crew
+# ----------------
+
+dn: cn=Horatio Nelson,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: Horatio Nelson
+description: Lord Horatio Nelson
+givenName: Horatio
+sn: Nelson
+uid: hnelson
+mail: hnelson@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=Thomas Masterman Hardy,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: Thomas Masterman Hardy
+description: Sir Thomas Masterman Hardy
+givenName: Thomas
+manager: cn=Horatio Nelson,ou=people,o=sevenSeas
+sn: Hardy
+uid: thardy
+mail: thardy@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=Cornelius Buckley,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: Cornelius Buckley
+description: LM Cornelius Buckley
+givenName: Cornelius
+manager: cn=Horatio Nelson,ou=people,o=sevenSeas
+sn: Buckley
+uid: cbuckley
+mail: cbuckley@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=HMS Victory,ou=crews,ou=groups,o=sevenSeas
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: HMS Victory
+uniqueMember: cn=Horatio Nelson,ou=people,o=sevenSeas
+uniqueMember: cn=Thomas Masterman Hardy,ou=people,o=sevenSeas
+uniqueMember: cn=Cornelius Buckley,ou=people,o=sevenSeas
+
+dn: cn=HMS Victory,ou=ships,o=sevenSeas
+objectClass: top
+objectClass: ship
+cn: HMS Victory
+numberOfGuns: 104
+description: a ship of the line of the Royal Navy
+description: built between 1759 and 1765
+
+# HMS Bounty Crew
+# ---------------
+
+dn: cn=William Bligh,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: William Bligh
+description: Captain William Bligh
+givenName: William
+sn: Bligh
+uid: wbligh
+mail: wbligh@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=Fletcher Christian,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: Fletcher Christian
+description: Lieutenant Fletcher Christian
+givenName: Fletcher
+manager: cn=William Bligh,ou=people,o=sevenSeas
+sn: Christian
+uid: fchristi
+mail: fchristi@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=John Fryer,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: John Fryer
+description: Master John Fryer
+givenName: John
+manager: cn=William Bligh,ou=people,o=sevenSeas
+sn: Fryer
+uid: jfryer
+mail: jfryer@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=John Hallett,ou=people,o=sevenSeas
+objectClass: person
+objectClass: organizationalPerson
+objectClass: inetOrgPerson
+objectClass: top
+cn: John Hallett
+description: Midshipman John Hallett
+givenName: John
+manager: cn=William Bligh,ou=people,o=sevenSeas
+sn: Hallett
+uid: jhallett
+mail: jhallett@royalnavy.mod.uk
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=
+
+dn: cn=HMS Bounty,ou=crews,ou=groups,o=sevenSeas
+objectClass: groupOfUniqueNames
+objectClass: top
+cn: HMS Bounty
+uniqueMember: cn=William Bligh,ou=people,o=sevenSeas
+uniqueMember: cn=Fletcher Christian,ou=people,o=sevenSeas
+uniqueMember: cn=John Fryer,ou=people,o=sevenSeas
+uniqueMember: cn=John Hallett,ou=people,o=sevenSeas
+

Added: directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif
URL: http://svn.apache.org/viewvc/directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif?rev=835252&view=auto
==============================================================================
--- directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif (added)
+++ directory/samples/trunk/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif Thu Nov 12 06:15:34 2009
@@ -0,0 +1,88 @@
+# sevenSeas
+# Generated by LDAP Studio on 27. April 2007 14:59:52
+
+dn: cn=sevenSeas, ou=schema
+objectclass: metaSchema
+objectclass: top
+cn: sevenSeas
+
+dn: ou=attributeTypes, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: attributetypes
+
+dn: m-oid=1.3.6.1.4.1.18060.0.4.3.2.1, ou=attributeTypes, cn=sevenSeas, ou=schem
+ a
+objectclass: metaAttributeType
+objectclass: metaTop
+objectclass: top
+m-oid: 1.3.6.1.4.1.18060.0.4.3.2.1
+m-name: numberOfGuns
+m-description: Number of guns of a ship
+m-equality: integerMatch
+m-syntax: 1.3.6.1.4.1.1466.115.121.1.27
+m-singleValue: TRUE
+
+dn: ou=comparators, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: comparators
+
+dn: ou=ditContentRules, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: ditcontentrules
+
+dn: ou=ditStructureRules, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: ditstructurerules
+
+dn: ou=matchingRules, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: matchingrules
+
+dn: ou=matchingRuleUse, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: matchingruleuse
+
+dn: ou=nameForms, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: nameforms
+
+dn: ou=normalizers, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: normalizers
+
+dn: ou=objectClasses, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: objectClasses
+
+dn: m-oid=1.3.6.1.4.1.18060.0.4.3.3.1, ou=objectClasses, cn=sevenSeas, ou=schema
+ 
+objectclass: metaObjectclass
+objectclass: metaTop
+objectclass: top
+m-oid: 1.3.6.1.4.1.18060.0.4.3.3.1
+m-name: ship
+m-description: An entry which represents a ship
+m-supObjectClass: top
+m-must: cn
+m-may: numberOfGuns
+m-may: description
+
+dn: ou=syntaxCheckers, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: syntaxcheckers
+
+dn: ou=syntaxes, cn=sevenSeas, ou=schema
+objectclass: organizationalUnit
+objectclass: top
+ou: syntaxes
+