1 package org.apache.archiva.web.action.admin.scanning;
3 import org.apache.archiva.admin.repository.admin.DefaultArchivaAdministration;
4 import org.apache.archiva.configuration.ArchivaConfiguration;
5 import org.apache.archiva.configuration.Configuration;
6 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
7 import org.apache.archiva.web.action.AbstractActionTestCase;
8 import org.easymock.MockControl;
10 import java.util.ArrayList;
11 import java.util.List;
14 * Licensed to the Apache Software Foundation (ASF) under one
15 * or more contributor license agreements. See the NOTICE file
16 * distributed with this work for additional information
17 * regarding copyright ownership. The ASF licenses this file
18 * to you under the Apache License, Version 2.0 (the
19 * "License"); you may not use this file except in compliance
20 * with the License. You may obtain a copy of the License at
22 * http://www.apache.org/licenses/LICENSE-2.0
24 * Unless required by applicable law or agreed to in writing,
25 * software distributed under the License is distributed on an
26 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27 * KIND, either express or implied. See the License for the
28 * specific language governing permissions and limitations
32 public class RepositoryScanningActionTest
33 extends AbstractActionTestCase
35 private RepositoryScanningAction action;
37 private MockControl archivaConfigControl;
39 private ArchivaConfiguration archivaConfig;
41 private Configuration config;
43 protected void setUp()
49 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
50 archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
52 action = new RepositoryScanningAction();
54 config = new Configuration();
56 RepositoryScanningConfiguration repositoryScanningConfig = new RepositoryScanningConfiguration();
58 repositoryScanningConfig.setKnownContentConsumers( createKnownContentConsumersList() );
60 config.setRepositoryScanning( repositoryScanningConfig );
62 DefaultArchivaAdministration archivaAdministration = new DefaultArchivaAdministration();
63 archivaAdministration.setArchivaConfiguration( archivaConfig );
64 action.setArchivaAdministration( archivaAdministration );
68 public void testUpdateKnownConsumers()
71 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
73 archivaConfig.save( config );
74 archivaConfig.save( config );
75 archivaConfig.save( config );
76 archivaConfig.save( config );
77 archivaConfig.save( config );
78 archivaConfig.save( config );
79 archivaConfig.save( config );
80 archivaConfig.save( config );
81 archivaConfigControl.replay();
83 setEnabledKnownContentConsumers();
85 String returnString = action.updateKnownConsumers();
87 List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
89 assertEquals( action.SUCCESS, returnString );
90 assertEquals( "results " + results, 8, results.size() );
93 public void testDisableAllKnownConsumers()
96 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
98 archivaConfig.save( config );
99 archivaConfig.save( config );
100 archivaConfig.save( config );
101 archivaConfig.save( config );
102 archivaConfig.save( config );
103 archivaConfig.save( config );
104 archivaConfig.save( config );
105 archivaConfig.save( config );
106 archivaConfigControl.replay();
108 action.setEnabledKnownContentConsumers( null );
110 String returnString = action.updateKnownConsumers();
112 List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
114 assertEquals( action.SUCCESS, returnString );
115 assertEquals( 0, results.size() );
118 private void setEnabledKnownContentConsumers()
120 action.setEnabledKnownContentConsumers( createKnownContentConsumersList() );
123 private List<String> createKnownContentConsumersList()
125 List<String> knownContentConsumers = new ArrayList<String>();
126 knownContentConsumers.add( "auto-remove" );
127 knownContentConsumers.add( "auto-rename" );
128 knownContentConsumers.add( "create-missing-checksums" );
129 knownContentConsumers.add( "index-content" );
130 knownContentConsumers.add( "metadata-updater" );
131 knownContentConsumers.add( "repository-purge" );
132 knownContentConsumers.add( "update-db-artifact" );
133 knownContentConsumers.add( "validate-checksums" );
135 return knownContentConsumers;