mirror of https://github.com/apache/archiva.git
[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
This commit is contained in:
parent
d20cce3a52
commit
0ce636965d
|
@ -251,8 +251,15 @@ public class RepositoryScanningAction
|
|||
archivaConfiguration.getConfiguration().getRepositoryScanning().setInvalidContentConsumers(
|
||||
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 );
|
||||
|
||||
if ( enabledKnownContentConsumers != null )
|
||||
{
|
||||
filterAddedConsumers( oldConsumers, enabledKnownContentConsumers );
|
||||
filterRemovedConsumers( oldConsumers, enabledKnownContentConsumers );
|
||||
}
|
||||
else
|
||||
{
|
||||
disableAllEnabledConsumers( oldConsumers );
|
||||
}
|
||||
|
||||
return saveConfiguration();
|
||||
}
|
||||
|
@ -336,6 +350,14 @@ public class RepositoryScanningAction
|
|||
}
|
||||
}
|
||||
|
||||
private void disableAllEnabledConsumers( List<String> consumers )
|
||||
{
|
||||
for ( String consumer : consumers )
|
||||
{
|
||||
triggerAuditEvent( AuditEvent.DISABLE_REPO_CONSUMER + " " + consumer );
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getEnabledInvalidContentConsumers()
|
||||
{
|
||||
return enabledInvalidContentConsumers;
|
||||
|
@ -355,4 +377,14 @@ public class RepositoryScanningAction
|
|||
{
|
||||
this.enabledKnownContentConsumers = enabledKnownContentConsumers;
|
||||
}
|
||||
|
||||
public ArchivaConfiguration getArchivaConfiguration()
|
||||
{
|
||||
return archivaConfiguration;
|
||||
}
|
||||
|
||||
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
|
||||
{
|
||||
this.archivaConfiguration = archivaConfiguration;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue