1 package org.apache.maven.archiva.web.action.admin.scanning;
3 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
4 import org.apache.maven.archiva.configuration.Configuration;
5 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
6 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
7 import org.easymock.MockControl;
9 import java.util.ArrayList;
10 import java.util.List;
13 * Licensed to the Apache Software Foundation (ASF) under one
14 * or more contributor license agreements. See the NOTICE file
15 * distributed with this work for additional information
16 * regarding copyright ownership. The ASF licenses this file
17 * to you under the Apache License, Version 2.0 (the
18 * "License"); you may not use this file except in compliance
19 * with the License. You may obtain a copy of the License at
21 * http://www.apache.org/licenses/LICENSE-2.0
23 * Unless required by applicable law or agreed to in writing,
24 * software distributed under the License is distributed on an
25 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26 * KIND, either express or implied. See the License for the
27 * specific language governing permissions and limitations
31 public class RepositoryScanningActionTest
32 extends AbstractActionTestCase
34 private RepositoryScanningAction action;
36 private MockControl archivaConfigControl;
38 private ArchivaConfiguration archivaConfig;
40 private Configuration config;
42 protected void setUp()
48 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
49 archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
51 action = new RepositoryScanningAction();
53 config = new Configuration();
55 RepositoryScanningConfiguration repositoryScanningConfig = new RepositoryScanningConfiguration( );
57 repositoryScanningConfig.setKnownContentConsumers( createKnownContentConsumersList() );
59 config.setRepositoryScanning( repositoryScanningConfig );
61 action.setArchivaConfiguration( archivaConfig );
64 public void testUpdateKnownConsumers()
67 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
68 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
69 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
71 archivaConfig.save( config );
72 archivaConfigControl.replay();
74 setEnabledKnownContentConsumers();
76 String returnString = action.updateKnownConsumers();
78 List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
80 assertEquals( action.SUCCESS, returnString );
81 assertEquals( 8, results.size() );
84 public void testDisableAllKnownConsumers()
87 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
88 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
89 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
91 archivaConfig.save( config );
92 archivaConfigControl.replay();
94 action.setEnabledKnownContentConsumers( null );
96 String returnString = action.updateKnownConsumers();
98 List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
100 assertEquals( action.SUCCESS, returnString );
101 assertEquals( 0, results.size() );
104 private void setEnabledKnownContentConsumers()
106 action.setEnabledKnownContentConsumers( createKnownContentConsumersList() );
109 private List<String> createKnownContentConsumersList( )
111 List<String> knownContentConsumers = new ArrayList<String>();
112 knownContentConsumers.add( "auto-remove" );
113 knownContentConsumers.add( "auto-rename" );
114 knownContentConsumers.add( "create-missing-checksums" );
115 knownContentConsumers.add( "index-content" );
116 knownContentConsumers.add( "metadata-updater" );
117 knownContentConsumers.add( "repository-purge" );
118 knownContentConsumers.add( "update-db-artifact" );
119 knownContentConsumers.add( "validate-checksums" );
121 return knownContentConsumers;