continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1332041 - in /continuum/trunk: continuum-commons/src/main/java/org/apache/maven/continuum/configuration/ continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ continuum-webapp/src/main/java/org/apache/continuum/web/acti...
Date Mon, 30 Apr 2012 02:03:17 GMT
Author: ctan
Date: Mon Apr 30 02:03:16 2012
New Revision: 1332041

URL: http://svn.apache.org/viewvc?rev=1332041&view=rev
Log:
[CONTINUUM-2443] trim trailing space in build agent url

Submitted By: Garry Baal 
- with modifications

Modified:
    continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
    continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java

Modified: continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java?rev=1332041&r1=1332040&r2=1332041&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
(original)
+++ continuum/trunk/continuum-commons/src/main/java/org/apache/maven/continuum/configuration/DefaultConfigurationService.java
Mon Apr 30 02:03:16 2012
@@ -299,6 +299,9 @@ public class DefaultConfigurationService
     public void addBuildAgent( BuildAgentConfiguration buildAgent )
         throws ConfigurationException
     {
+        // trim trailing space
+        buildAgent.setUrl( buildAgent.getUrl().trim() );
+        
         List<BuildAgentConfiguration> buildAgents = generalConfiguration.getBuildAgents();
         if ( buildAgents == null )
         {
@@ -307,7 +310,7 @@ public class DefaultConfigurationService
 
         for ( BuildAgentConfiguration agent : buildAgents )
         {
-            if ( agent.getUrl().equals( buildAgent.getUrl() ) )
+            if ( agent.getUrl().trim().equals( buildAgent.getUrl() ) )
             {
                 throw new ConfigurationException( "Unable to add build agent: build agent
already exist" );
             }
@@ -336,15 +339,19 @@ public class DefaultConfigurationService
 
     public void updateBuildAgent( BuildAgentConfiguration buildAgent )
     {
+        // trim trailing space
+        buildAgent.setUrl( buildAgent.getUrl().trim() );
+
         List<BuildAgentConfiguration> buildAgents = getBuildAgents();
         if ( buildAgents != null )
         {
             for ( BuildAgentConfiguration agent : buildAgents )
             {
-                if ( agent.getUrl().equals( buildAgent.getUrl() ) )
+                if ( agent.getUrl().trim().equals( buildAgent.getUrl() ) )
                 {
                     agent.setDescription( buildAgent.getDescription() );
                     agent.setEnabled( buildAgent.isEnabled() );
+                    agent.setUrl( buildAgent.getUrl() );
 
                     return;
                 }

Modified: continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java?rev=1332041&r1=1332040&r2=1332041&view=diff
==============================================================================
--- continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
(original)
+++ continuum/trunk/continuum-commons/src/test/java/org/apache/maven/continuum/configuration/ConfigurationServiceTest.java
Mon Apr 30 02:03:16 2012
@@ -163,4 +163,35 @@ public class ConfigurationServiceTest
 
         assertEquals( "password", service.getSharedSecretPassword() );
     }
+
+    public void testAddDuplicateBuildAgentUrl()
+        throws Exception
+    {
+        ConfigurationService service = (ConfigurationService) lookup( "configurationService"
);
+
+        assertNotNull( service );
+
+        BuildAgentConfiguration buildAgent = new BuildAgentConfiguration( "http://agent1/xmlrpc
", "windows", false );
+        service.addBuildAgent( buildAgent );
+        service.store();
+        service.reload();
+
+        assertEquals( "check # build agents", 2, service.getBuildAgents().size() );
+        assertNotNull( service.getBuildAgent( "http://agent1/xmlrpc" ) );
+
+        BuildAgentConfiguration buildAgent2 = new BuildAgentConfiguration( "http://agent1/xmlrpc",
"windows", false );
+
+        try
+        {
+            service.addBuildAgent( buildAgent2 );
+            fail( "Should have thrown an exception because of duplicate agent url" );
+        }
+        catch ( ConfigurationException e )
+        {
+            assertEquals( "Unable to add build agent: build agent already exist", e.getMessage()
);
+        }
+
+        service.removeBuildAgent( buildAgent );
+        service.store();
+    }
 }

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java?rev=1332041&r1=1332040&r2=1332041&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/admin/BuildAgentAction.java
Mon Apr 30 02:03:16 2012
@@ -176,11 +176,18 @@ public class BuildAgentAction
             {
                 if ( agent.getUrl().equals( buildAgent.getUrl() ) )
                 {
-                    agent.setDescription( buildAgent.getDescription() );
-                    agent.setEnabled( buildAgent.isEnabled() );
-
-                    configuration.updateBuildAgent( agent );
-                    configuration.store();
+                    if ( type.equals( "new" ) )
+                    {
+                        addActionError( getResourceBundle().getString( "buildAgent.error.duplicate"
) );
+                        return INPUT;
+                    }
+                    else
+                    {
+                        agent.setDescription( buildAgent.getDescription() );
+                        agent.setEnabled( buildAgent.isEnabled() );
+                        configuration.updateBuildAgent( agent );
+                        configuration.store();
+                    }
                     found = true;
                 }
             }
@@ -196,14 +203,6 @@ public class BuildAgentAction
             configuration.store();
             event.setAction( AuditLogConstants.ADD_BUILD_AGENT );
         }
-        else
-        {
-            if ( type.equals( "new" ) )
-            {
-                addActionError( getResourceBundle().getString( "buildAgent.error.duplicate"
) );
-                return INPUT;
-            }
-        }
 
         try
         {



Mime
View raw message