Updated testcase archetype for ApacheDS 1.5.5, added basic usage examples
authorStefan Seelmann <seelmann@apache.org>
Thu, 12 Nov 2009 06:15:34 +0000 (06:15 +0000)
committerStefan Seelmann <seelmann@apache.org>
Thu, 12 Nov 2009 06:15:34 +0000 (06:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/directory/samples/trunk@835252 13f79535-47bb-0310-9956-ffa450edef68

testcase-archetype/apacheds-testcase-archetype.sh
testcase-archetype/pom.xml
testcase-archetype/src/main/resources/META-INF/archetype.xml
testcase-archetype/src/main/resources/archetype-resources/pom.xml
testcase-archetype/src/main/resources/archetype-resources/src/main/java/Dummy.java
testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java [new file with mode: 0644]
testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java [new file with mode: 0644]
testcase-archetype/src/main/resources/archetype-resources/src/test/java/ApacheDSITest.java [deleted file]
testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java [new file with mode: 0644]
testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif [new file with mode: 0644]
testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif [new file with mode: 0644]

index 1f2f91f..5488206 100755 (executable)
@@ -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
 
index 4c61c30..bd73e7d 100644 (file)
@@ -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>
index fe5b0a3..2be244b 100644 (file)
@@ -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>
index b580da0..9fc640f 100644 (file)
@@ -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>
index 92b6baa..4b4d5f1 100644 (file)
@@ -21,8 +21,8 @@ package ${groupId};
 
 
 /**
- * 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
 {
 }
diff --git a/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java b/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTest.java
new file mode 100644 (file)
index 0000000..4db547a
--- /dev/null
@@ -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() );
+    }
+
+}
diff --git a/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java b/testcase-archetype/src/main/resources/archetype-resources/src/test/java/AdvancedTestApacheDsFactory.java
new file mode 100644 (file)
index 0000000..c539955
--- /dev/null
@@ -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;
+    }
+
+}
diff --git a/testcase-archetype/src/main/resources/archetype-resources/src/test/java/ApacheDSITest.java b/testcase-archetype/src/main/resources/archetype-resources/src/test/java/ApacheDSITest.java
deleted file mode 100644 (file)
index 12ac457..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *  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.Hashtable;
-
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-
-import org.apache.directory.server.unit.AbstractServerTest;
-
-
-
-/**
- * An example ApacheDS integration test.  
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
- */
-public class ApacheDSITest extends AbstractServerTest
-{
-    private DirContext ctx = null;
-
-
-    /**
-     * Get a connection to the embedded server using the SUN JNDI LDAP provider
-     * over the wire.
-     */
-    public void setUp() throws Exception
-    {
-        // Starts up the embedded ApacheDS instance.
-        super.setUp();
-
-        // -------------------------------------------------------------------
-        // Get a connection (JNDI context) to the LDAP server       
-        // -------------------------------------------------------------------
-
-        Hashtable env = new Hashtable();
-        env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
-        env.put( "java.naming.provider.url", "ldap://localhost:" + port + "/ou=system" );
-        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
-        env.put( "java.naming.security.credentials", "secret" );
-        env.put( "java.naming.security.authentication", "simple" );
-        ctx = new InitialDirContext( env );
-    }
-
-
-    /**
-     * Closes our context before shuting down the server.
-     */
-    public void tearDown() throws Exception
-    {
-        ctx.close();
-        super.tearDown();
-    }
-
-
-    /**
-     * An example test reads and assert an attribute value in the ou=system
-     * context.
-     */
-    public void testExample() throws NamingException
-    {
-        Attributes system = ctx.getAttributes( "" );
-        assertNotNull( system );
-        assertEquals( "system", system.get( "ou" ).get() );
-    }
-}
diff --git a/testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java b/testcase-archetype/src/main/resources/archetype-resources/src/test/java/MinimalTest.java
new file mode 100644 (file)
index 0000000..6232e2c
--- /dev/null
@@ -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();
+    }
+
+}
diff --git a/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif b/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_data.ldif
new file mode 100644 (file)
index 0000000..945c74b
--- /dev/null
@@ -0,0 +1,236 @@
+# Sample LDIF data for the ApacheDS v1.0 Basic User's Guide\r
+#\r
+# Some sailors and their ships\r
+# userpassword for all persons is "pass"\r
+#\r
+version: 1\r
+\r
+dn: o=sevenSeas\r
+objectClass: organization\r
+objectClass: top\r
+o: sevenSeas\r
+\r
+dn: ou=people,o=sevenSeas\r
+objectClass: organizationalUnit\r
+objectClass: top\r
+description: Contains entries which describe persons (seamen)\r
+ou: people\r
+\r
+dn: ou=groups,o=sevenSeas\r
+objectClass: organizationalUnit\r
+objectClass: top\r
+description: Contains entries which describe groups (crews, for instance)\r
+ou: groups\r
+\r
+dn: ou=crews,ou=groups,o=sevenSeas\r
+objectClass: organizationalUnit\r
+objectClass: top\r
+description: Contains entries which describe ship crews\r
+ou: crews\r
+\r
+dn: ou=ranks,ou=groups,o=sevenSeas\r
+objectClass: organizationalUnit\r
+objectClass: top\r
+description: Contains entries which describe naval ranks (e.g. captain)\r
+ou: ranks\r
+\r
+dn: ou=ships,o=sevenSeas\r
+objectClass: organizationalUnit\r
+objectClass: top\r
+description: Contains entries which describe ships\r
+ou: ships\r
+\r
+# HMS Lydia Crew\r
+# --------------\r
+\r
+dn: cn=Horatio Hornblower,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: Horatio Hornblower\r
+description: Capt. Horatio Hornblower, R.N\r
+givenName: Horatio\r
+sn: Hornblower\r
+uid: hhornblo\r
+mail: hhornblo@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=William Bush,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: William Bush\r
+description: Lt. William Bush\r
+givenName: William\r
+manager: cn=Horatio Hornblower,ou=people,o=sevenSeas\r
+sn: Bush\r
+uid: wbush\r
+mail: wbush@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=Thomas Quist,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: Thomas Quist\r
+description: Seaman Quist\r
+givenName: Thomas\r
+manager: cn=Horatio Hornblower,ou=people,o=sevenSeas\r
+sn: Quist\r
+uid: tquist\r
+mail: tquist@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=Moultrie Crystal,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: Moultrie Crystal\r
+description: Lt. Crystal\r
+givenName: Moultrie\r
+manager: cn=Horatio Hornblower,ou=people,o=sevenSeas\r
+sn: Crystal\r
+uid: mchrysta\r
+mail: mchrysta@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=HMS Lydia,ou=crews,ou=groups,o=sevenSeas\r
+objectClass: groupOfUniqueNames\r
+objectClass: top\r
+cn: HMS Lydia\r
+uniqueMember: cn=Horatio Hornblower,ou=people,o=sevenSeas\r
+uniqueMember: cn=William Bush,ou=people,o=sevenSeas\r
+uniqueMember: cn=Thomas Quist,ou=people,o=sevenSeas\r
+uniqueMember: cn=Moultrie Crystal,ou=people,o=sevenSeas\r
+\r
+# HMS Victory Crew\r
+# ----------------\r
+\r
+dn: cn=Horatio Nelson,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: Horatio Nelson\r
+description: Lord Horatio Nelson\r
+givenName: Horatio\r
+sn: Nelson\r
+uid: hnelson\r
+mail: hnelson@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=Thomas Masterman Hardy,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: Thomas Masterman Hardy\r
+description: Sir Thomas Masterman Hardy\r
+givenName: Thomas\r
+manager: cn=Horatio Nelson,ou=people,o=sevenSeas\r
+sn: Hardy\r
+uid: thardy\r
+mail: thardy@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=Cornelius Buckley,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: Cornelius Buckley\r
+description: LM Cornelius Buckley\r
+givenName: Cornelius\r
+manager: cn=Horatio Nelson,ou=people,o=sevenSeas\r
+sn: Buckley\r
+uid: cbuckley\r
+mail: cbuckley@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=HMS Victory,ou=crews,ou=groups,o=sevenSeas\r
+objectClass: groupOfUniqueNames\r
+objectClass: top\r
+cn: HMS Victory\r
+uniqueMember: cn=Horatio Nelson,ou=people,o=sevenSeas\r
+uniqueMember: cn=Thomas Masterman Hardy,ou=people,o=sevenSeas\r
+uniqueMember: cn=Cornelius Buckley,ou=people,o=sevenSeas\r
+\r
+dn: cn=HMS Victory,ou=ships,o=sevenSeas\r
+objectClass: top\r
+objectClass: ship\r
+cn: HMS Victory\r
+numberOfGuns: 104\r
+description: a ship of the line of the Royal Navy\r
+description: built between 1759 and 1765\r
+\r
+# HMS Bounty Crew\r
+# ---------------\r
+\r
+dn: cn=William Bligh,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: William Bligh\r
+description: Captain William Bligh\r
+givenName: William\r
+sn: Bligh\r
+uid: wbligh\r
+mail: wbligh@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=Fletcher Christian,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: Fletcher Christian\r
+description: Lieutenant Fletcher Christian\r
+givenName: Fletcher\r
+manager: cn=William Bligh,ou=people,o=sevenSeas\r
+sn: Christian\r
+uid: fchristi\r
+mail: fchristi@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=John Fryer,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: John Fryer\r
+description: Master John Fryer\r
+givenName: John\r
+manager: cn=William Bligh,ou=people,o=sevenSeas\r
+sn: Fryer\r
+uid: jfryer\r
+mail: jfryer@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=John Hallett,ou=people,o=sevenSeas\r
+objectClass: person\r
+objectClass: organizationalPerson\r
+objectClass: inetOrgPerson\r
+objectClass: top\r
+cn: John Hallett\r
+description: Midshipman John Hallett\r
+givenName: John\r
+manager: cn=William Bligh,ou=people,o=sevenSeas\r
+sn: Hallett\r
+uid: jhallett\r
+mail: jhallett@royalnavy.mod.uk\r
+userPassword: {SHA}nU4eI71bcnBGqeO0t9tXvY1u5oQ=\r
+\r
+dn: cn=HMS Bounty,ou=crews,ou=groups,o=sevenSeas\r
+objectClass: groupOfUniqueNames\r
+objectClass: top\r
+cn: HMS Bounty\r
+uniqueMember: cn=William Bligh,ou=people,o=sevenSeas\r
+uniqueMember: cn=Fletcher Christian,ou=people,o=sevenSeas\r
+uniqueMember: cn=John Fryer,ou=people,o=sevenSeas\r
+uniqueMember: cn=John Hallett,ou=people,o=sevenSeas\r
+\r
diff --git a/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif b/testcase-archetype/src/main/resources/archetype-resources/src/test/resources/sevenSeas_schema.ldif
new file mode 100644 (file)
index 0000000..b1826a7
--- /dev/null
@@ -0,0 +1,88 @@
+# sevenSeas\r
+# Generated by LDAP Studio on 27. April 2007 14:59:52\r
+\r
+dn: cn=sevenSeas, ou=schema\r
+objectclass: metaSchema\r
+objectclass: top\r
+cn: sevenSeas\r
+\r
+dn: ou=attributeTypes, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: attributetypes\r
+\r
+dn: m-oid=1.3.6.1.4.1.18060.0.4.3.2.1, ou=attributeTypes, cn=sevenSeas, ou=schem\r
+ a\r
+objectclass: metaAttributeType\r
+objectclass: metaTop\r
+objectclass: top\r
+m-oid: 1.3.6.1.4.1.18060.0.4.3.2.1\r
+m-name: numberOfGuns\r
+m-description: Number of guns of a ship\r
+m-equality: integerMatch\r
+m-syntax: 1.3.6.1.4.1.1466.115.121.1.27\r
+m-singleValue: TRUE\r
+\r
+dn: ou=comparators, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: comparators\r
+\r
+dn: ou=ditContentRules, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: ditcontentrules\r
+\r
+dn: ou=ditStructureRules, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: ditstructurerules\r
+\r
+dn: ou=matchingRules, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: matchingrules\r
+\r
+dn: ou=matchingRuleUse, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: matchingruleuse\r
+\r
+dn: ou=nameForms, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: nameforms\r
+\r
+dn: ou=normalizers, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: normalizers\r
+\r
+dn: ou=objectClasses, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: objectClasses\r
+\r
+dn: m-oid=1.3.6.1.4.1.18060.0.4.3.3.1, ou=objectClasses, cn=sevenSeas, ou=schema\r
\r
+objectclass: metaObjectclass\r
+objectclass: metaTop\r
+objectclass: top\r
+m-oid: 1.3.6.1.4.1.18060.0.4.3.3.1\r
+m-name: ship\r
+m-description: An entry which represents a ship\r
+m-supObjectClass: top\r
+m-must: cn\r
+m-may: numberOfGuns\r
+m-may: description\r
+\r
+dn: ou=syntaxCheckers, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: syntaxcheckers\r
+\r
+dn: ou=syntaxes, cn=sevenSeas, ou=schema\r
+objectclass: organizationalUnit\r
+objectclass: top\r
+ou: syntaxes\r
+\r