]> source.dussan.org Git - archiva.git/blob
ac4be6f5311cc05e17b3a53e240bf929939d1089
[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 import org.junit.Before;
13 import org.junit.Test;
14
15 /*
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
23  *
24  *  http://www.apache.org/licenses/LICENSE-2.0
25  *
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
31  * under the License.
32  */
33
34 public class RepositoryScanningActionTest
35     extends AbstractActionTestCase
36 {
37     private RepositoryScanningAction action;
38
39     private MockControl archivaConfigControl;
40
41     private ArchivaConfiguration archivaConfig;
42
43     private Configuration config;
44
45     @Override
46     @Before
47     public void setUp()
48         throws Exception
49     {
50
51         super.setUp();
52
53         archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
54         archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock();
55
56         action = new RepositoryScanningAction();
57
58         config = new Configuration();
59
60         RepositoryScanningConfiguration repositoryScanningConfig = new RepositoryScanningConfiguration();
61
62         repositoryScanningConfig.setKnownContentConsumers( createKnownContentConsumersList() );
63
64         config.setRepositoryScanning( repositoryScanningConfig );
65
66         DefaultArchivaAdministration archivaAdministration = new DefaultArchivaAdministration();
67         archivaAdministration.setArchivaConfiguration( archivaConfig );
68         action.setArchivaAdministration( archivaAdministration );
69
70     }
71
72     @Test
73     public void testUpdateKnownConsumers()
74         throws Exception
75     {
76         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
77
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();
87
88         setEnabledKnownContentConsumers();
89
90         String returnString = action.updateKnownConsumers();
91
92         List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
93
94         assertEquals( action.SUCCESS, returnString );
95         assertEquals( "results " + results, 8, results.size() );
96     }
97
98     @Test
99     public void testDisableAllKnownConsumers()
100         throws Exception
101     {
102         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 10 );
103
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();
113
114         action.setEnabledKnownContentConsumers( null );
115
116         String returnString = action.updateKnownConsumers();
117
118         List<String> results = config.getRepositoryScanning().getKnownContentConsumers();
119
120         assertEquals( action.SUCCESS, returnString );
121         assertEquals( 0, results.size() );
122     }
123
124     private void setEnabledKnownContentConsumers()
125     {
126         action.setEnabledKnownContentConsumers( createKnownContentConsumersList() );
127     }
128
129     private List<String> createKnownContentConsumersList()
130     {
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" );
140
141         return knownContentConsumers;
142     }
143 }