summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web
diff options
context:
space:
mode:
authorJevica Arianne B. Zurbano <jzurbano@apache.org>2009-09-10 15:14:48 +0000
committerJevica Arianne B. Zurbano <jzurbano@apache.org>2009-09-10 15:14:48 +0000
commit0ce636965d677a9b3664dbd7ab15ea3ac1f11bcd (patch)
treef11403cad2af0e5673957f896e12324b95e2b322 /archiva-modules/archiva-web
parentd20cce3a52f5a983ced1ab9da36fa91999f8a6f5 (diff)
downloadarchiva-0ce636965d677a9b3664dbd7ab15ea3ac1f11bcd.tar.gz
archiva-0ce636965d677a9b3664dbd7ab15ea3ac1f11bcd.zip
[MRM-1238] - NPE when updating consumers of known content without setting any of the checkboxes (enabled)
- added null checks - added unit tests Submitted by: Gwen Harold Autencio git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@813473 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web')
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java40
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningActionTest.java125
2 files changed, 161 insertions, 4 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java
index ca68e7c69..38a7df399 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java
@@ -251,8 +251,15 @@ public class RepositoryScanningAction
archivaConfiguration.getConfiguration().getRepositoryScanning().setInvalidContentConsumers(
enabledInvalidContentConsumers );
- filterAddedConsumers( oldConsumers, enabledInvalidContentConsumers );
- filterRemovedConsumers( oldConsumers, enabledInvalidContentConsumers );
+ if ( enabledInvalidContentConsumers != null )
+ {
+ filterAddedConsumers( oldConsumers, enabledInvalidContentConsumers );
+ filterRemovedConsumers( oldConsumers, enabledInvalidContentConsumers );
+ }
+ else
+ {
+ disableAllEnabledConsumers( oldConsumers );
+ }
return saveConfiguration();
}
@@ -266,8 +273,15 @@ public class RepositoryScanningAction
archivaConfiguration.getConfiguration().getRepositoryScanning().setKnownContentConsumers(
enabledKnownContentConsumers );
- filterAddedConsumers( oldConsumers, enabledKnownContentConsumers );
- filterRemovedConsumers( oldConsumers, enabledKnownContentConsumers );
+ if ( enabledKnownContentConsumers != null )
+ {
+ filterAddedConsumers( oldConsumers, enabledKnownContentConsumers );
+ filterRemovedConsumers( oldConsumers, enabledKnownContentConsumers );
+ }
+ else
+ {
+ disableAllEnabledConsumers( oldConsumers );
+ }
return saveConfiguration();
}
@@ -335,6 +349,14 @@ public class RepositoryScanningAction
}
}
}
+
+ private void disableAllEnabledConsumers( List<String> consumers )
+ {
+ for ( String consumer : consumers )
+ {
+ triggerAuditEvent( AuditEvent.DISABLE_REPO_CONSUMER + " " + consumer );
+ }
+ }
public List<String> getEnabledInvalidContentConsumers()
{
@@ -355,4 +377,14 @@ public class RepositoryScanningAction
{
this.enabledKnownContentConsumers = enabledKnownContentConsumers;
}
+
+ public ArchivaConfiguration getArchivaConfiguration()
+ {
+ return archivaConfiguration;
+ }
+
+ public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
+ {
+ this.archivaConfiguration = archivaConfiguration;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningActionTest.java
new file mode 100644
index 000000000..e31759a8b
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningActionTest.java
@@ -0,0 +1,125 @@
+package org.apache.maven.archiva.web.action.admin.scanning;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
+import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
+import org.apache.maven.archiva.web.action.admin.scanning.RepositoryScanningAction;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
+
+/*
+ * 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.
+ */
+
+public class RepositoryScanningActionTest
+ extends PlexusInSpringTestCase
+{
+ private RepositoryScanningAction action;
+
+ private MockControl archivaConfigControl;
+
+ private ArchivaConfiguration archivaConfig;
+
+ private Configuration config;
+
+ protected void setUp()
+ throws Exception
+ {
+
+ super.setUp();
+
+ archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
+ archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
+
+ action = new RepositoryScanningAction();
+
+ config = new Configuration();
+
+ RepositoryScanningConfiguration repositoryScanningConfig = new RepositoryScanningConfiguration( );
+
+ repositoryScanningConfig.setKnownContentConsumers( createKnownContentConsumersList() );
+
+ config.setRepositoryScanning( repositoryScanningConfig );
+
+ action.setArchivaConfiguration( archivaConfig );
+ }
+
+ public void testUpdateKnownConsumers()
+ throws Exception
+ {
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfig.save( config );
+ archivaConfigControl.replay();
+
+ setEnabledKnownContentConsumers();
+
+ String returnString = action.updateKnownConsumers();
+
+ List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
+
+ assertEquals( action.SUCCESS, returnString );
+ assertEquals( 8, results.size() );
+ }
+
+ public void testDisableAllKnownConsumers()
+ throws Exception
+ {
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfig.save( config );
+ archivaConfigControl.replay();
+
+ action.setEnabledKnownContentConsumers( null );
+
+ String returnString = action.updateKnownConsumers();
+
+ List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
+
+ assertEquals( action.SUCCESS, returnString );
+ assertEquals( 0, results.size() );
+ }
+
+ private void setEnabledKnownContentConsumers()
+ {
+ action.setEnabledKnownContentConsumers( createKnownContentConsumersList() );
+ }
+
+ private List<String> createKnownContentConsumersList( )
+ {
+ List<String> knownContentConsumers = new ArrayList<String>();
+ knownContentConsumers.add( "auto-remove" );
+ knownContentConsumers.add( "auto-rename" );
+ knownContentConsumers.add( "create-missing-checksums" );
+ knownContentConsumers.add( "index-content" );
+ knownContentConsumers.add( "metadata-updater" );
+ knownContentConsumers.add( "repository-purge" );
+ knownContentConsumers.add( "update-db-artifact" );
+ knownContentConsumers.add( "validate-checksums" );
+
+ return knownContentConsumers;
+ }
+}