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;
12 import org.junit.Before;
13 import org.junit.Test;
16 * Licensed to the Apache Software Foundation (ASF) under one
17 * or more contributor license agreements. See the NOTICE file
18 * distributed with this work for additional information
19 * regarding copyright ownership. The ASF licenses this file
20 * to you under the Apache License, Version 2.0 (the
21 * "License"); you may not use this file except in compliance
22 * with the License. You may obtain a copy of the License at
24 * http://www.apache.org/licenses/LICENSE-2.0
26 * Unless required by applicable law or agreed to in writing,
27 * software distributed under the License is distributed on an
28 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
29 * KIND, either express or implied. See the License for the
30 * specific language governing permissions and limitations
34 public class RepositoryScanningActionTest
35 extends AbstractActionTestCase
37 private RepositoryScanningAction action;
39 private MockControl archivaConfigControl;
41 private ArchivaConfiguration archivaConfig;
43 private Configuration config;
53 archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
54 archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
56 action = new RepositoryScanningAction();
58 config = new Configuration();
60 RepositoryScanningConfiguration repositoryScanningConfig = new RepositoryScanningConfiguration();
62 repositoryScanningConfig.setKnownContentConsumers( createKnownContentConsumersList() );
64 config.setRepositoryScanning( repositoryScanningConfig );
66 DefaultArchivaAdministration archivaAdministration = new DefaultArchivaAdministration();
67 archivaAdministration.setArchivaConfiguration( archivaConfig );
68 action.setArchivaAdministration( archivaAdministration );
73 public void testUpdateKnownConsumers()
76 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
78 archivaConfig.save( config );
79 archivaConfig.save( config );
80 archivaConfig.save( config );
81 archivaConfig.save( config );
82 archivaConfig.save( config );
83 archivaConfig.save( config );
84 archivaConfig.save( config );
85 archivaConfig.save( config );
86 archivaConfigControl.replay();
88 setEnabledKnownContentConsumers();
90 String returnString = action.updateKnownConsumers();
92 List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
94 assertEquals( action.SUCCESS, returnString );
95 assertEquals( "results " + results, 8, results.size() );
99 public void testDisableAllKnownConsumers()
102 archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
104 archivaConfig.save( config );
105 archivaConfig.save( config );
106 archivaConfig.save( config );
107 archivaConfig.save( config );
108 archivaConfig.save( config );
109 archivaConfig.save( config );
110 archivaConfig.save( config );
111 archivaConfig.save( config );
112 archivaConfigControl.replay();
114 action.setEnabledKnownContentConsumers( null );
116 String returnString = action.updateKnownConsumers();
118 List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
120 assertEquals( action.SUCCESS, returnString );
121 assertEquals( 0, results.size() );
124 private void setEnabledKnownContentConsumers()
126 action.setEnabledKnownContentConsumers( createKnownContentConsumersList() );
129 private List<String> createKnownContentConsumersList()
131 List<String> knownContentConsumers = new ArrayList<String>();
132 knownContentConsumers.add( "auto-remove" );
133 knownContentConsumers.add( "auto-rename" );
134 knownContentConsumers.add( "create-missing-checksums" );
135 knownContentConsumers.add( "index-content" );
136 knownContentConsumers.add( "metadata-updater" );
137 knownContentConsumers.add( "repository-purge" );
138 knownContentConsumers.add( "update-db-artifact" );
139 knownContentConsumers.add( "validate-checksums" );
141 return knownContentConsumers;