Author: lcorneliussen
Date: Tue Apr  5 14:44:18 2011
New Revision: 1089064

URL: http://svn.apache.org/viewvc?rev=1089064&view=rev
Log:
[NPANDAY-366] Tests and some refactorings for "The input line is too long"

Modified:
    
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
    
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java
    
incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java

Modified: 
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java?rev=1089064&r1=1089063&r2=1089064&view=diff
==============================================================================
--- 
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
 (original)
+++ 
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
 Tue Apr  5 14:44:18 2011
@@ -294,12 +294,12 @@ public interface CommandExecutor
                         public String toString()
                         {
                             StringBuffer strBuff = new StringBuffer("");
-                            for(String command : getShellCommandline())
+                            for(String command : getEscapedShellCommandline())
                             {
                                 strBuff.append(" ");
-                                strBuff.append(escapeCmdParams(command));
+                                strBuff.append(command);
                             }
-                            return strBuff.toString().trim();
+                            return strBuff.toString();
                         }
 
                         public String[] getEscapedShellCommandline()

Modified: 
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java?rev=1089064&r1=1089063&r2=1089064&view=diff
==============================================================================
--- 
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java
 (original)
+++ 
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java
 Tue Apr  5 14:44:18 2011
@@ -98,14 +98,16 @@ public class DefaultRepositoryNetExecuta
         catch ( ExecutionException e )
         {
             throw new ExecutionException( "NPANDAY-063-000: Execution Path = " 
+
-                ( ( getExecutionPath() != null ) ? 
getExecutionPath().getAbsolutePath() : "unknown" ) + ", Command = " +
+                ( ( getExecutionPath() != null ) ? 
getExecutionPath().getAbsolutePath() : "unknown" ) + ", Executable = " + 
getExecutable() + ", Args = " +
                 commands, e );
         }
         if ( commandExecutor.getStandardOut().contains( "error" )
           && !commandExecutor.getStandardOut().contains( "exit code = 0" ) )   
     
         {
             throw new ExecutionException(
-                "NPANDAY-063-001: Executable = " + getExecutable() + ",Command 
= " + commands );
+                "NPANDAY-063-001: Execution Path = " +
+                ( ( getExecutionPath() != null ) ? 
getExecutionPath().getAbsolutePath() : "unknown" ) + ", Executable = " + 
getExecutable() + ", Args = " +
+                commands );
         }
     }
 

Modified: 
incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java?rev=1089064&r1=1089063&r2=1089064&view=diff
==============================================================================
--- 
incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java
 (original)
+++ 
incubator/npanday/trunk/components/dotnet-executable/src/test/java/npanday/executable/CommandExecutorTest.java
 Tue Apr  5 14:44:18 2011
@@ -18,72 +18,158 @@
  */
 package npanday.executable;
 
+import org.codehaus.plexus.logging.console.ConsoleLogger;
 import org.junit.Test;
+
 import static org.junit.Assert.*;
+
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
-import java.util.Arrays;
-
-import npanday.executable.CommandExecutor;
 
 
 public class CommandExecutorTest
+{
+    private static final String MKDIR = "mkdir";
+
+    private String parentPath;
+
+    private List<String> params = new ArrayList<String>();
+
+    private CommandExecutor cmdExecutor;
+
+    public CommandExecutorTest()
     {
-        private static final String MKDIR = "mkdir";
-        private String parentPath;
-        private List<String> params = new ArrayList<String>();
-        private CommandExecutor cmdExecutor;
+        File f = new File( "test" );
+        parentPath = System.getProperty( "user.dir" ) + File.separator + 
"target" + File.separator + "test-resources";
 
-        public CommandExecutorTest()
+        File parentPathFile = new File( parentPath );
+        if ( !parentPathFile.exists() )
         {
-            File f = new File( "test" );
-            parentPath = System.getProperty( "user.dir" ) + File.separator + 
"target" + File.separator + "test-resources";
+            parentPathFile.mkdir();
+        }
+
+        cmdExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor();
+    }
 
-            File parentPathFile = new File(parentPath);
-            if (!parentPathFile.exists())
-                parentPathFile.mkdir();
+    @Test
+    public void testParamWithNoSpaces()
+        throws ExecutionException
+    {
+        String path = parentPath + File.separator + "sampledirectory";
+
+        params.clear();
+        params.add( path );
+
+        cmdExecutor.executeCommand( MKDIR, params );
+        File dir = new File( path );
 
-            cmdExecutor = 
CommandExecutor.Factory.createDefaultCommmandExecutor();
+        assertTrue( dir.exists() );
+
+        if ( dir.exists() )
+        {
+            dir.delete();
         }
+    }
+
+    @Test
+    public void testParamWithSpaces()
+        throws ExecutionException
+    {
+        String path = parentPath + File.separator + "sample directory";
+
+        params.clear();
+        params.add( path );
+
+        cmdExecutor.executeCommand( MKDIR, params );
+        File dir = new File( path );
 
-        @Test
-        public void testParamWithNoSpaces()
-            throws ExecutionException
+        assertTrue( dir.exists() );
+
+        if ( dir.exists() )
         {
-            String path = parentPath + File.separator + "sampledirectory";
+            dir.delete();
+        }
+    }
 
-            params.clear();
-            params.add(path);
+    @Test
+    /**
+     test is related to NPANDAY-366
+     */
+    public void testTooLongCommandName()
+        throws ExecutionException
+    {
+        params.clear();
 
-            cmdExecutor.executeCommand( MKDIR, params );
-            File dir = new File( path );
+        cmdExecutor.setLogger( new ConsoleLogger( 0, null ) );
 
-            assertTrue( dir.exists() );
+        try
+        {
+            cmdExecutor.executeCommand( repeat( 'x', 260 ), params, null, 
false );
+            fail( "Expected the command to fail!" );
+        }
+        catch ( ExecutionException e )
+        {
+            System.out.println( cmdExecutor.toString() );
+            // the message is language-specific, but better to ensure an error 
than
+            // ignoring the test
+            // assertEquals( "The input line is too long.", 
cmdExecutor.getStandardError() );
+            assertEquals( 1, cmdExecutor.getResult() );
+        }
+    }
+
+    @Test
+    /**
+     test is related to NPANDAY-366
+     */
+    public void testTooLongCommandName_withSpace()
+        throws ExecutionException
+    {
+        params.clear();
 
-            if (dir.exists())
-                dir.delete();
+        cmdExecutor.setLogger( new ConsoleLogger( 0, null ) );
+
+        try
+        {
+            cmdExecutor.executeCommand( "echo " + repeat( 'x', 255 ), params, 
null, false );
+            fail( "Expected the command to fail!" );
+        }
+        catch ( ExecutionException e )
+        {
+            System.out.println( cmdExecutor.toString() );
+            // the message is language-specific, but better to ensure an error 
than
+            // ignoring the test
+            // assertEquals( "The input line is too long.", 
cmdExecutor.getStandardError() );
+            assertEquals( 1, cmdExecutor.getResult() );
         }
+    }
 
-        @Test
-        public void testParamWithSpaces()
-            throws ExecutionException
-        { 
-            String path = parentPath + File.separator + "sample directory";
 
-            params.clear(); 
-            params.add(path);
+    @Test
+    /**
+     test is related to NPANDAY-366
+     */
+    public void testLongCommand()
+        throws ExecutionException
+    {
+        params.clear();
 
-            cmdExecutor.executeCommand( MKDIR, params );
-            File dir = new File( path );
+        cmdExecutor.setLogger( new ConsoleLogger( 0, null ) );
+        params.add( repeat( 'a', 260 ) );
 
-            assertTrue( dir.exists() );
+        cmdExecutor.executeCommand( "echo", params, null, false );
+        System.out.println( cmdExecutor.toString() );
 
-            if (dir.exists())
-                dir.delete();
-         }
+        assertEquals( repeat( 'a', 260 ), cmdExecutor.getStandardOut() );
+    }
 
-    }
\ No newline at end of file
+    private static String repeat( char c, int i )
+    {
+        String tst = "";
+        for ( int j = 0; j < i; j++ )
+        {
+            tst = tst + c;
+        }
+        return tst;
+    }
+}
\ No newline at end of file


Reply via email to