]> source.dussan.org Git - archiva.git/blob
ce97851c15a4ceac6e62d049c61fbfed3649fded
[archiva.git] /
1 package org.apache.archiva.web.action.admin.scanning;
2
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;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 /*
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
21  *
22  *  http://www.apache.org/licenses/LICENSE-2.0
23  *
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
29  * under the License.
30  */
31
32 public class RepositoryScanningActionTest
33     extends AbstractActionTestCase
34 {
35     private RepositoryScanningAction action;
36
37     private MockControl archivaConfigControl;
38
39     private ArchivaConfiguration archivaConfig;
40
41     private Configuration config;
42
43     protected void setUp()
44         throws Exception
45     {
46
47         super.setUp();
48
49         archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
50         archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
51
52         action = new RepositoryScanningAction();
53
54         config = new Configuration();
55
56         RepositoryScanningConfiguration repositoryScanningConfig = new RepositoryScanningConfiguration();
57
58         repositoryScanningConfig.setKnownContentConsumers( createKnownContentConsumersList() );
59
60         config.setRepositoryScanning( repositoryScanningConfig );
61
62         DefaultArchivaAdministration archivaAdministration = new DefaultArchivaAdministration();
63         archivaAdministration.setArchivaConfiguration( archivaConfig );
64         action.setArchivaAdministration( archivaAdministration );
65
66     }
67
68     public void testUpdateKnownConsumers()
69         throws Exception
70     {
71         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
72
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();
82
83         setEnabledKnownContentConsumers();
84
85         String returnString = action.updateKnownConsumers();
86
87         List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
88
89         assertEquals( action.SUCCESS, returnString );
90         assertEquals( "results " + results, 8, results.size() );
91     }
92
93     public void testDisableAllKnownConsumers()
94         throws Exception
95     {
96         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
97
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();
107
108         action.setEnabledKnownContentConsumers( null );
109
110         String returnString = action.updateKnownConsumers();
111
112         List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
113
114         assertEquals( action.SUCCESS, returnString );
115         assertEquals( 0, results.size() );
116     }
117
118     private void setEnabledKnownContentConsumers()
119     {
120         action.setEnabledKnownContentConsumers( createKnownContentConsumersList() );
121     }
122
123     private List<String> createKnownContentConsumersList()
124     {
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" );
134
135         return knownContentConsumers;
136     }
137 }