directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r426483 [4/5] - in /directory/trunks/apacheds/server-tools/src: main/java/org/apache/directory/server/tools/ main/java/org/apache/directory/server/tools/commands/ main/java/org/apache/directory/server/tools/commands/diagnosticcmd/ main/java...
Date Fri, 28 Jul 2006 11:50:43 GMT
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/ExceptionListener.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/ExceptionListener.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/ExceptionListener.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/ExceptionListener.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,38 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.listeners;
+
+
+import java.io.Serializable;
+
+import org.apache.directory.server.tools.ToolCommandListener;
+
+
+public class ExceptionListener implements ToolCommandListener
+{
+
+    public void notify( Serializable o )
+    {
+        if ( o instanceof Exception )
+        {
+            Exception e = ( Exception ) o;
+            System.err.println( "An error has occurred. Apache DS Tools must quit." + "\n"
+ e.getMessage() );
+            System.exit( 1 );
+        }
+    }
+
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysErrListener.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysErrListener.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysErrListener.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysErrListener.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,42 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.listeners;
+
+
+import java.io.Serializable;
+
+import org.apache.directory.server.tools.ToolCommandListener;
+
+
+public class SysErrListener implements ToolCommandListener
+{
+
+    public void notify( Serializable o )
+    {
+        if ( o instanceof String )
+        {
+            String msg = ( String ) o;
+            System.err.println( msg );
+        }
+        else if ( o instanceof Character )
+        {
+            Character c = ( Character ) o;
+            System.err.print( c.charValue() );
+        }
+    }
+
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysOutListener.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysOutListener.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysOutListener.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysOutListener.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,42 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.listeners;
+
+
+import java.io.Serializable;
+
+import org.apache.directory.server.tools.ToolCommandListener;
+
+
+public class SysOutListener implements ToolCommandListener
+{
+
+    public void notify( Serializable o )
+    {
+        if ( o instanceof String )
+        {
+            String msg = ( String ) o;
+            System.out.println( msg );
+        }
+        else if ( o instanceof Character )
+        {
+            Character c = ( Character ) o;
+            System.out.print( c.charValue() );
+        }
+    }
+
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandCL.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandCL.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandCL.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandCL.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,66 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.request;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.directory.server.tools.BaseToolCommand;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+/**
+ * Abstract class that must extended by every command that want
+ * to be used via Command Line
+ *
+ */
+public abstract class BaseToolCommandCL extends BaseToolCommand implements ToolCommandCL
+{
+    /** The List of parameters that will be filled when parsing the command line */
+    protected List parameters;
+
+
+    /**
+     * Defalut contructor
+     * @param name the name of the command
+     */
+    public BaseToolCommandCL( String name )
+    {
+        super( name );
+
+        parameters = new ArrayList();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.safehaus.ldapstudio.server.tools.request.ToolCommandCL#execute(org.apache.commons.cli.CommandLine,
org.safehaus.ldapstudio.server.tools.util.ListenerParameter[])
+     */
+    public void execute( CommandLine cmd, ListenerParameter[] listeners ) throws Exception
+    {
+        assert ( parameters != null );
+        assert ( parameters.size() != 0 );
+
+        processOptions( cmd );
+
+        ToolCommandExecutorStub toolCommandExecutorStub = getStub();
+        toolCommandExecutorStub.execute( ( Parameter[] ) parameters.toArray( new Parameter[0]
), listeners );
+    }
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandGui.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandGui.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandGui.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandGui.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,57 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.request;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.server.tools.BaseToolCommand;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+/**
+ * Abstract class that must extended by every command that want
+ * to be used in a program with a user interface
+ *
+ */
+public abstract class BaseToolCommandGui extends BaseToolCommand implements ToolCommandGui
+{
+    protected List parameters;
+
+
+    public BaseToolCommandGui( String name )
+    {
+        super( name );
+
+        parameters = new ArrayList();
+    }
+
+
+    public void execute( Parameter[] params, ListenerParameter[] listeners ) throws Exception
+    {
+        assert ( parameters != null );
+        assert ( parameters.size() != 0 );
+
+        processParams( params );
+
+        ToolCommandExecutorStub toolCommandExecutorStub = getStub();
+        toolCommandExecutorStub.execute( ( Parameter[] ) parameters.toArray( new Parameter[0]
), listeners );
+    }
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandCL.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandCL.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandCL.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandCL.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,64 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.request;
+
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.directory.server.tools.ToolCommand;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.util.ListenerParameter;
+
+
+/**
+ * Interface that defines the operations available for Command Line commands
+ *
+ */
+public interface ToolCommandCL extends ToolCommand
+{
+    /**
+     * Returns the available options for the command
+     * @return available options for the command
+     */
+    public Options getOptions();
+
+
+    /**
+     * Executes the command.
+     * @param cmd the command line from the user
+     * @param listeners the listeners
+     * @throws Exception
+     */
+    public void execute( CommandLine cmd, ListenerParameter[] listeners ) throws Exception;
+
+
+    /**
+     * Processes the options given by the user.
+     * Checks and verifies the data entered by the user.
+     * Converts the Options given by the user into Parameters and stores the result in the
"params" List
+     * @param cmd the command line from the user
+     * @throws Exception
+     */
+    public void processOptions( CommandLine cmd ) throws Exception;
+
+
+    /**
+     * Returns the ToolCommandExecutorStub of the command
+     * @return the ToolCommandExecutorStub
+     */
+    public ToolCommandExecutorStub getStub();
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandGui.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandGui.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandGui.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandGui.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,56 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.request;
+
+
+import org.apache.directory.server.tools.ToolCommand;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+/**
+ * Interface that defines the operations available for commands
+ * that want to be used in program with a user interface
+ *
+ */
+public interface ToolCommandGui extends ToolCommand
+{
+    /**
+     * Executes the command
+     * @param params the parameters of the command
+     * @param listeners the listeners of the command
+     * @throws Exception
+     */
+    public void execute( Parameter[] params, ListenerParameter[] listeners ) throws Exception;
+
+
+    /**
+     * Processes the parameters given.
+     * Checks and verifies the data entered by the user.
+     * @param params the params
+     * @throws Exception
+     */
+    public void processParams( Parameter[] params ) throws Exception;
+
+
+    /**
+     * Returns the ToolCommandExecutorStub of the command
+     * @return the ToolCommandExecutorStub
+     */
+    public ToolCommandExecutorStub getStub();
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ListenerParameter.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ListenerParameter.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ListenerParameter.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ListenerParameter.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,52 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.util;
+
+
+import org.apache.directory.server.tools.ToolCommandListener;
+
+
+/**
+ * This Class defines a ListenerParameter used in the command call to pass
+ * arguments to the Command Executor.
+ * 
+ * 
+ */
+public class ListenerParameter
+{
+    private String name;
+    private ToolCommandListener listener;
+
+
+    public ListenerParameter( String name, ToolCommandListener listener )
+    {
+        this.name = name;
+        this.listener = listener;
+    }
+
+
+    public ToolCommandListener getListener()
+    {
+        return listener;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/Parameter.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/Parameter.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/Parameter.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/Parameter.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,60 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.util;
+
+
+/**
+ * This Class defines a Parameter used in the command call to pass
+ * arguments to the Command Executor
+ * 
+ */
+public class Parameter
+{
+    private String name;
+    private Object value;
+
+
+    public Parameter( String name, Object value )
+    {
+        this.name = name;
+        this.value = value;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+
+    public Object getValue()
+    {
+        return value;
+    }
+
+
+    public void setValue( Object value )
+    {
+        this.value = value;
+    }
+}

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ToolCommandException.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ToolCommandException.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ToolCommandException.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ToolCommandException.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,30 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.util;
+
+
+public class ToolCommandException extends Exception
+{
+
+    private static final long serialVersionUID = -6879708530721655642L;
+
+
+    public ToolCommandException( String string )
+    {
+        super( string );
+    }
+}

Added: directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/AbstractTestCase.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/AbstractTestCase.java
(added)
+++ directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/AbstractTestCase.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,135 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.commands;
+
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Abstract Class to extends to test the commands
+ */
+public class AbstractTestCase extends TestCase
+{
+    /** Flag to check if the server has been launched */
+    protected boolean bindSuccessful;
+
+    // General server settings
+    protected final static String host = "localhost";
+    protected final static int port = 10389;
+    protected final static String user = "uid=admin,ou=system";
+    protected final static String password = "secret";
+
+    protected DirContext ctx;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        bindSuccessful = false;
+
+        // Set up the environment for creating the initial context
+        Hashtable env = new Hashtable();
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( Context.PROVIDER_URL, "ldap://" + host + ":" + port );
+
+        // Authenticate as Admin
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        env.put( Context.SECURITY_PRINCIPAL, user );
+        env.put( Context.SECURITY_CREDENTIALS, password );
+
+        // Create the initial context
+        try
+        {
+            ctx = new InitialDirContext( env );
+        }
+        catch ( NamingException ne )
+        {
+            bindSuccessful = false;
+            return;
+        }
+
+        bindSuccessful = true;
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+
+        if ( bindSuccessful )
+        {
+            try
+            {
+                deleteLDAPSubtree( "o=neworganization,dc=example,dc=com" );
+                deleteLDAPSubtree( "ou=Product Development, dc=example, dc=com" );
+                deleteLDAPSubtree( "ou=Product Testing, dc=example, dc=com" );
+                deleteLDAPSubtree( "ou=Accounting, dc=example, dc=com " );
+            }
+            catch ( NamingException e )
+            {
+
+            }
+        }
+    }
+
+
+    /**
+     * Deletes recursively the LDAP subtree of the given DN
+     * @param dn the root dn to delete from
+     * @throws NamingException 
+     * 
+     */
+    protected void deleteLDAPSubtree( String dn ) throws NamingException
+    {
+        boolean searchSuccessful = true;
+
+        SearchControls ctls = new SearchControls();
+        ctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+
+        NamingEnumeration entries = null;
+        try
+        {
+            entries = ctx.search( dn, "(objectClass=*)", ctls );
+        }
+        catch ( NamingException e )
+        {
+            searchSuccessful = false;
+        }
+
+        if ( searchSuccessful )
+        {
+            while ( entries.hasMoreElements() )
+            {
+                SearchResult sr = ( SearchResult ) entries.nextElement();
+                deleteLDAPSubtree( sr.getNameInNamespace() );
+            }
+            ctx.destroySubcontext( dn );
+        }
+    }
+}

Added: directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandTest.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandTest.java
(added)
+++ directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandTest.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,294 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.commands.exportcmd;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.tools.ToolCommandListener;
+import org.apache.directory.server.tools.commands.AbstractTestCase;
+import org.apache.directory.server.tools.commands.exportcmd.ExportCommandExecutor;
+import org.apache.directory.server.tools.commands.importcmd.ImportCommandExecutor;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+/**
+ * Test Class for the Export Command Executor
+ */
+public class ExportCommandTest extends AbstractTestCase
+{
+    public void testExportCommand()
+    {
+        // Checking if server had been launched
+        if ( !bindSuccessful )
+        {
+            // The server hasn't been lauched, so we don't execute the test and return 
+            // a successful test, so Maven can is Ok when executing tests.
+            assertTrue( true );
+        }
+        else
+        {
+            // We are going to import a LDIF file, export the corresponding part of the newly
+            // imported entries, then delete these entries and import again the entries
+            // with the newly created LDIF file (from the export).
+            // IMPORT -> EXPORT -> DELETE -> IMPORT | => TEST
+            File importFile = null;
+            try
+            {
+                // Getting the import file
+                importFile = new File( ( ExportCommandTest.class.getResource( "10_entries.ldif"
) ).toURI() );
+            }
+            catch ( URISyntaxException e )
+            {
+                fail();
+            }
+            // Preparing the call to the Import Command
+            ImportCommandExecutor importCommandExecutor = new ImportCommandExecutor();
+            Parameter hostParam = new Parameter( ImportCommandExecutor.HOST_PARAMETER, host
);
+            Parameter portParam = new Parameter( ImportCommandExecutor.PORT_PARAMETER, new
Integer( port ) );
+            Parameter userParam = new Parameter( ImportCommandExecutor.USER_PARAMETER, user
);
+            Parameter passwordParam = new Parameter( ImportCommandExecutor.PASSWORD_PARAMETER,
password );
+            Parameter authParam = new Parameter( ImportCommandExecutor.AUTH_PARAMETER, "simple"
);
+            Parameter fileParam = new Parameter( ImportCommandExecutor.FILE_PARAMETER, importFile
);
+            Parameter ignoreErrorsParam = new Parameter( ImportCommandExecutor.IGNOREERRORS_PARAMETER,
new Boolean(
+                false ) );
+            Parameter debugParam = new Parameter( ImportCommandExecutor.DEBUG_PARAMETER,
new Boolean( false ) );
+            Parameter verboseParam = new Parameter( ImportCommandExecutor.VERBOSE_PARAMETER,
new Boolean( false ) );
+            Parameter quietParam = new Parameter( ImportCommandExecutor.QUIET_PARAMETER,
new Boolean( false ) );
+
+            ToolCommandListener errorListener = new ToolCommandListener()
+            {
+                public void notify( Serializable o )
+                {
+                    fail();
+                }
+            };
+            ListenerParameter errorListenerParam = new ListenerParameter(
+                ImportCommandExecutor.ERRORLISTENER_PARAMETER, errorListener );
+
+            // Calling the import command
+            importCommandExecutor.execute( new Parameter[]
+                { hostParam, portParam, userParam, passwordParam, authParam, fileParam, ignoreErrorsParam,
debugParam,
+                    verboseParam, quietParam }, new ListenerParameter[]
+                { errorListenerParam } );
+
+            // Creating a temporary file for the export
+            File exportedFile = null;
+            try
+            {
+                exportedFile = File.createTempFile( "exportedFile", ".ldif" );
+            }
+            catch ( IOException e1 )
+            {
+                fail();
+            }
+
+            // Preparing the call to the Export Command
+            ExportCommandExecutor exportCommandExecutor = new ExportCommandExecutor();
+            hostParam = new Parameter( ExportCommandExecutor.HOST_PARAMETER, host );
+            portParam = new Parameter( ExportCommandExecutor.PORT_PARAMETER, new Integer(
port ) );
+            userParam = new Parameter( ExportCommandExecutor.USER_PARAMETER, user );
+            passwordParam = new Parameter( ExportCommandExecutor.PASSWORD_PARAMETER, password
);
+            authParam = new Parameter( ExportCommandExecutor.AUTH_PARAMETER, "simple" );
+            Parameter baseDNParam = new Parameter( ExportCommandExecutor.BASEDN_PARAMETER,
"" );
+            Parameter exportPointParam = new Parameter( ExportCommandExecutor.EXPORTPOINT_PARAMETER,
+                "o=neworganization, dc=example,dc=com" );
+            Parameter scopeParam = new Parameter( ExportCommandExecutor.SCOPE_PARAMETER,
+                ExportCommandExecutor.SCOPE_SUBTREE );
+            fileParam = new Parameter( ExportCommandExecutor.FILE_PARAMETER, exportedFile.getAbsolutePath()
);
+            debugParam = new Parameter( ExportCommandExecutor.DEBUG_PARAMETER, new Boolean(
false ) );
+            verboseParam = new Parameter( ExportCommandExecutor.VERBOSE_PARAMETER, new Boolean(
false ) );
+            quietParam = new Parameter( ExportCommandExecutor.QUIET_PARAMETER, new Boolean(
false ) );
+
+            // Calling the export command
+            exportCommandExecutor.execute( new Parameter[]
+                { hostParam, portParam, userParam, passwordParam, authParam, baseDNParam,
exportPointParam, fileParam,
+                    scopeParam, debugParam, verboseParam, quietParam }, new ListenerParameter[0]
);
+
+            // Deleting the entries previously added
+            try
+            {
+                deleteLDAPSubtree( "o=neworganization,dc=example,dc=com" );
+            }
+            catch ( NamingException e )
+            {
+                fail();
+            }
+
+            // Preparing the call to the Import Command
+            importCommandExecutor = new ImportCommandExecutor();
+            hostParam = new Parameter( ImportCommandExecutor.HOST_PARAMETER, host );
+            portParam = new Parameter( ImportCommandExecutor.PORT_PARAMETER, new Integer(
port ) );
+            userParam = new Parameter( ImportCommandExecutor.USER_PARAMETER, user );
+            passwordParam = new Parameter( ImportCommandExecutor.PASSWORD_PARAMETER, password
);
+            authParam = new Parameter( ImportCommandExecutor.AUTH_PARAMETER, "simple" );
+            fileParam = new Parameter( ImportCommandExecutor.FILE_PARAMETER, new File( exportedFile.getAbsolutePath()
) );
+            ignoreErrorsParam = new Parameter( ImportCommandExecutor.IGNOREERRORS_PARAMETER,
new Boolean( false ) );
+            debugParam = new Parameter( ImportCommandExecutor.DEBUG_PARAMETER, new Boolean(
false ) );
+            verboseParam = new Parameter( ImportCommandExecutor.VERBOSE_PARAMETER, new Boolean(
false ) );
+            quietParam = new Parameter( ImportCommandExecutor.QUIET_PARAMETER, new Boolean(
false ) );
+
+            // Calling the import command, this time on the newly created file from the export
+            importCommandExecutor.execute( new Parameter[]
+                { hostParam, portParam, userParam, passwordParam, authParam, fileParam, ignoreErrorsParam,
debugParam,
+                    verboseParam, quietParam }, new ListenerParameter[]
+                { errorListenerParam } );
+
+            // Now we are able to test if all is successful
+
+            // Testing if the number of entries is correct
+            SearchControls ctls = new SearchControls();
+            ctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+            try
+            {
+                NamingEnumeration entries = ctx.search( "o=neworganization,dc=example,dc=com",
"(objectClass=*)", ctls );
+
+                int counter = 0;
+                while ( entries.hasMore() )
+                {
+                    counter++;
+                    entries.next();
+                }
+
+                // Testing the number of entries added
+                assertEquals( 9, counter );
+            }
+            catch ( NamingException e )
+            {
+                fail();
+            }
+
+            // Testing an entry and its attributes
+            try
+            {
+                ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
+                NamingEnumeration entries = ctx.search( "cn=newperson1,o=neworganization,dc=example,dc=com",
+                    "(objectClass=*)", ctls );
+
+                if ( entries.hasMore() )
+                {
+                    SearchResult sr = ( SearchResult ) entries.nextElement();
+
+                    assertEquals( "cn=newperson1,o=neworganization,dc=example,dc=com", sr.getNameInNamespace()
);
+
+                    Attributes attributes = sr.getAttributes();
+
+                    Attribute attr = attributes.get( "objectclass" );
+                    assertTrue( attr.contains( "top" ) );
+                    assertTrue( attr.contains( "person" ) );
+
+                    attr = attributes.get( "cn" );
+                    assertTrue( attr.contains( "newperson1" ) );
+
+                    attr = attributes.get( "telephoneNumber" );
+                    assertTrue( attr.contains( "0101010101" ) );
+                }
+                else
+                {
+                    fail();
+                }
+            }
+            catch ( NamingException e )
+            {
+                fail();
+            }
+
+            // Testing another entry and its attributes
+            try
+            {
+                ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
+                NamingEnumeration entries = ctx.search( "cn=newperson4,o=neworganization,dc=example,dc=com",
+                    "(objectClass=*)", ctls );
+
+                if ( entries.hasMore() )
+                {
+                    SearchResult sr = ( SearchResult ) entries.nextElement();
+
+                    assertEquals( "cn=newperson4,o=neworganization,dc=example,dc=com", sr.getNameInNamespace()
);
+
+                    Attributes attributes = sr.getAttributes();
+
+                    Attribute attr = attributes.get( "objectclass" );
+                    assertTrue( attr.contains( "top" ) );
+                    assertTrue( attr.contains( "person" ) );
+
+                    attr = attributes.get( "cn" );
+                    assertTrue( attr.contains( "newperson4" ) );
+
+                    attr = attributes.get( "telephoneNumber" );
+                    assertTrue( attr.contains( "0404040404" ) );
+                }
+                else
+                {
+                    fail();
+                }
+            }
+            catch ( NamingException e )
+            {
+                fail();
+            }
+
+            // Testing a thirf entry and its attributes
+            try
+            {
+                ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
+                NamingEnumeration entries = ctx.search( "cn=newperson9,o=neworganization,dc=example,dc=com",
+                    "(objectClass=*)", ctls );
+
+                if ( entries.hasMore() )
+                {
+                    SearchResult sr = ( SearchResult ) entries.nextElement();
+
+                    assertEquals( "cn=newperson9,o=neworganization,dc=example,dc=com", sr.getNameInNamespace()
);
+
+                    Attributes attributes = sr.getAttributes();
+
+                    Attribute attr = attributes.get( "objectclass" );
+                    assertTrue( attr.contains( "top" ) );
+                    assertTrue( attr.contains( "person" ) );
+
+                    attr = attributes.get( "cn" );
+                    assertTrue( attr.contains( "newperson9" ) );
+
+                    attr = attributes.get( "telephoneNumber" );
+                    assertTrue( attr.contains( "0909090909" ) );
+                }
+                else
+                {
+                    fail();
+                }
+            }
+            catch ( NamingException e )
+            {
+                fail();
+            }
+            // This file will be deleted when the JVM will exit.
+            exportedFile.deleteOnExit();
+        }
+    }
+}

Added: directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandTest.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandTest.java
(added)
+++ directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandTest.java
Fri Jul 28 04:50:40 2006
@@ -0,0 +1,106 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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 org.apache.directory.server.tools.commands.gracefulshutdowncmd;
+
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+
+import org.apache.directory.server.tools.commands.AbstractTestCase;
+import org.apache.directory.server.tools.commands.gracefulshutdowncmd.GracefulShutdownCommandExecutor;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+/**
+ * Test Class for the Graceful Shutdown Command Executor
+ */
+public class GracefulShutdownCommandTest extends AbstractTestCase
+{
+    /**
+     * Tests if the server shuts down correctly after the execution of the command
+     */
+    public void testOneEntryImport()
+    {
+        // Checking if server had been launched
+        if ( !bindSuccessful )
+        {
+            // The server hasn't been lauched, so we don't execute the test and return 
+            // a successful test, so Maven can is Ok when executing tests.
+            assertTrue( true );
+        }
+        else
+        {
+            // Preparing the call to the Import Command
+            GracefulShutdownCommandExecutor executor = new GracefulShutdownCommandExecutor();
+            Parameter hostParam = new Parameter( GracefulShutdownCommandExecutor.HOST_PARAMETER,
host );
+            Parameter portParam = new Parameter( GracefulShutdownCommandExecutor.PORT_PARAMETER,
new Integer( port ) );
+            Parameter passwordParam = new Parameter( GracefulShutdownCommandExecutor.PASSWORD_PARAMETER,
password );
+            Parameter timeOfflineParam = new Parameter( GracefulShutdownCommandExecutor.TIMEOFFLINE_PARAMETER,
+                new Integer( 0 ) );
+            Parameter delayParam = new Parameter( GracefulShutdownCommandExecutor.DELAY_PARAMETER,
new Integer( 0 ) );
+            Parameter debugParam = new Parameter( GracefulShutdownCommandExecutor.DEBUG_PARAMETER,
new Boolean( false ) );
+            Parameter verboseParam = new Parameter( GracefulShutdownCommandExecutor.VERBOSE_PARAMETER,
new Boolean(
+                false ) );
+            Parameter quietParam = new Parameter( GracefulShutdownCommandExecutor.QUIET_PARAMETER,
new Boolean( false ) );
+
+            // Calling the import command
+            executor.execute( new Parameter[]
+                { hostParam, portParam, passwordParam, timeOfflineParam, delayParam, debugParam,
verboseParam,
+                    quietParam }, new ListenerParameter[0] );
+
+            // Let's give the server some time to complete the shutdown
+            try
+            {
+                Thread.sleep( 2000 );
+            }
+            catch ( InterruptedException e )
+            {
+                e.printStackTrace();
+            }
+
+            // Checking if the server is down with a simple bind
+
+            // Set up the environment for creating the initial context
+            Hashtable env = new Hashtable();
+            env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"
);
+            env.put( Context.PROVIDER_URL, "ldap://" + host + ":" + port );
+
+            // Authenticate as Admin
+            env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+            env.put( Context.SECURITY_PRINCIPAL, user );
+            env.put( Context.SECURITY_CREDENTIALS, password );
+
+            // Create the initial context
+            try
+            {
+                ctx = new InitialDirContext( env );
+            }
+            catch ( NamingException ne )
+            {
+                assertTrue( true );
+                return;
+            }
+
+            // If the bind request is successful, the ShutdownCommand has failed
+            fail();
+        }
+    }
+}



Mime
View raw message