aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJevica Arianne B. Zurbano <jzurbano@apache.org>2009-09-10 13:50:40 +0000
committerJevica Arianne B. Zurbano <jzurbano@apache.org>2009-09-10 13:50:40 +0000
commitd20cce3a52f5a983ced1ab9da36fa91999f8a6f5 (patch)
treee5b50f70ec934b8abb6ab18df52e398919a36374
parent9471a08db3407bb12da9349911f527a5eddf70ed (diff)
downloadarchiva-d20cce3a52f5a983ced1ab9da36fa91999f8a6f5.tar.gz
archiva-d20cce3a52f5a983ced1ab9da36fa91999f8a6f5.zip
[MRM-1240] - NPE when updating consumers (not setting any of the checkboxes) of Unprocessed Artifacts and Artifact Cleanup Scanning in Database
- added null checks - added unit test for DatabaseAction Submitted by: Gwen Harold Autencio git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@813439 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java40
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/database/DatabaseActionTest.java184
2 files changed, 220 insertions, 4 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java
index 9c7d1b518..7515fc2aa 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java
@@ -110,8 +110,15 @@ public class DatabaseAction
archivaConfiguration.getConfiguration().getDatabaseScanning().setUnprocessedConsumers(
enabledUnprocessedConsumers );
- filterAddedConsumers( oldConsumers, enabledUnprocessedConsumers );
- filterRemovedConsumers( oldConsumers, enabledUnprocessedConsumers );
+ if ( enabledUnprocessedConsumers != null )
+ {
+ filterAddedConsumers( oldConsumers, enabledUnprocessedConsumers );
+ filterRemovedConsumers( oldConsumers, enabledUnprocessedConsumers );
+ }
+ else
+ {
+ disableAllEnabledConsumers( oldConsumers );
+ }
return saveConfiguration();
}
@@ -122,8 +129,15 @@ public class DatabaseAction
archivaConfiguration.getConfiguration().getDatabaseScanning().setCleanupConsumers( enabledCleanupConsumers );
- filterAddedConsumers( oldConsumers, enabledCleanupConsumers );
- filterRemovedConsumers( oldConsumers, enabledCleanupConsumers );
+ if ( enabledCleanupConsumers != null )
+ {
+ filterAddedConsumers( oldConsumers, enabledCleanupConsumers );
+ filterRemovedConsumers( oldConsumers, enabledCleanupConsumers );
+ }
+ else
+ {
+ disableAllEnabledConsumers( oldConsumers );
+ }
return saveConfiguration();
}
@@ -215,6 +229,16 @@ public class DatabaseAction
this.enabledCleanupConsumers = enabledCleanupConsumers;
}
+ public ArchivaConfiguration getArchivaConfiguration()
+ {
+ return archivaConfiguration;
+ }
+
+ public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
+ {
+ this.archivaConfiguration = archivaConfiguration;
+ }
+
private void filterAddedConsumers( List<String> oldList, List<String> newList )
{
for ( String consumer : newList )
@@ -236,4 +260,12 @@ public class DatabaseAction
}
}
}
+
+ private void disableAllEnabledConsumers( List<String> enabledConsumers )
+ {
+ for( String consumer : enabledConsumers )
+ {
+ triggerAuditEvent( consumer, AuditEvent.DISABLE_DB_CONSUMER );
+ }
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/database/DatabaseActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/database/DatabaseActionTest.java
new file mode 100644
index 000000000..a47535ea5
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/database/DatabaseActionTest.java
@@ -0,0 +1,184 @@
+package org.apache.maven.archiva.web.action.admin.database;
+
+/*
+ * 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.
+ */
+
+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.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
+
+/**
+ * DatabaseActionTest
+ */
+public class DatabaseActionTest
+ extends PlexusInSpringTestCase
+{
+ private DatabaseAction 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 DatabaseAction();
+
+ config = new Configuration();
+
+ DatabaseScanningConfiguration databaseScanningConfig = new DatabaseScanningConfiguration();
+
+ List<String> cleanUpConsumers = new ArrayList<String>();
+ cleanUpConsumers.add( "not-present-remove-db-artifact" );
+ cleanUpConsumers.add( "not-present-remove-db-project" );
+ cleanUpConsumers.add( "not-present-remove-indexed" );
+
+ List<String> unprocessedConsumers = new ArrayList<String>();
+ unprocessedConsumers.add( "update-db-bytecode-stats" );
+ unprocessedConsumers.add( "update-db-project" );
+ unprocessedConsumers.add( "validate-repository-metadata" );
+
+ databaseScanningConfig.setCleanupConsumers( cleanUpConsumers );
+ databaseScanningConfig.setUnprocessedConsumers( unprocessedConsumers );
+
+ config.setDatabaseScanning( databaseScanningConfig );
+
+ setUpEnabledUnproccessedConsumers();
+ setUpEnabledCleanupConsumers();
+
+ action.setArchivaConfiguration( archivaConfig );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void testUpdateUnprocessedConsumers()
+ throws Exception
+ {
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfig.save( config );
+ archivaConfigControl.replay();
+
+ String returnString = action.updateUnprocessedConsumers();
+
+ List<String> results = config.getDatabaseScanning().getUnprocessedConsumers();
+
+ assertEquals( action.SUCCESS, returnString );
+ assertEquals( 3, results.size() );
+ }
+
+ public void testUpdateCleanUpConsumers()
+ throws Exception
+ {
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfig.save( config );
+ archivaConfigControl.replay();
+
+ String returnString = action.updateCleanupConsumers();
+
+ List<String> results = config.getDatabaseScanning().getCleanupConsumers();
+
+ assertEquals( action.SUCCESS, returnString );
+ assertEquals( 3, results.size() );
+ }
+
+ public void testDisableAllUnprocessedConsumers( )
+ throws Exception
+ {
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfig.save( config );
+ archivaConfigControl.replay();
+
+ action.setEnabledUnprocessedConsumers( null );
+
+ String returnString = action.updateUnprocessedConsumers();
+
+ List<String> results = config.getDatabaseScanning().getUnprocessedConsumers();
+
+ assertEquals( action.SUCCESS, returnString );
+ assertEquals( 0, results.size() );
+ }
+
+ public void testDisableAllCleanupConsumers( )
+ throws Exception
+ {
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfig.save( config );
+ archivaConfigControl.replay();
+
+ action.setEnabledCleanupConsumers( null );
+
+ String returnString = action.updateCleanupConsumers();
+
+ List<String> results = config.getDatabaseScanning().getCleanupConsumers();
+
+ assertEquals( action.SUCCESS, returnString );
+ assertEquals( 0, results.size() );
+ }
+
+ private void setUpEnabledUnproccessedConsumers( )
+ {
+ List<String> enabledUnprocessedConsumer = new ArrayList<String>();
+
+ enabledUnprocessedConsumer.add( "update-db-bytecode-stats" );
+ enabledUnprocessedConsumer.add( "update-db-project" );
+ enabledUnprocessedConsumer.add( "validate-repository-metadata" );
+
+ action.setEnabledUnprocessedConsumers( enabledUnprocessedConsumer );
+ }
+
+ private void setUpEnabledCleanupConsumers( )
+ {
+ List<String> enabledCleanupConsumers = new ArrayList<String>();
+
+ enabledCleanupConsumers.add( "not-present-remove-db-artifact" );
+ enabledCleanupConsumers.add( "not-present-remove-db-project" );
+ enabledCleanupConsumers.add( "not-present-remove-indexed" );
+
+ action.setEnabledCleanupConsumers( enabledCleanupConsumers );
+ }
+
+}