1 package org.apache.maven.archiva.proxy;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.ConfigurationListener;
25 import org.apache.maven.archiva.configuration.FileType;
26 import org.apache.maven.archiva.configuration.FileTypes;
27 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
28 import org.codehaus.plexus.registry.Registry;
29 import org.codehaus.plexus.registry.RegistryException;
30 import org.codehaus.plexus.registry.RegistryListener;
31 import org.easymock.MockControl;
32 import org.springframework.stereotype.Service;
34 import java.util.Collections;
35 import java.util.HashSet;
36 import java.util.List;
38 import javax.annotation.PostConstruct;
45 * plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration"
48 @Service( "archivaConfiguration#mock" )
49 public class MockConfiguration
50 implements ArchivaConfiguration
53 private Configuration configuration = new Configuration();
55 private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
57 private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
59 private MockControl registryControl;
61 private Registry registryMock;
63 public MockConfiguration()
65 registryControl = MockControl.createNiceControl( Registry.class );
66 registryMock = (Registry) registryControl.getMock();
70 public void initialize()
74 configuration.setRepositoryScanning( new RepositoryScanningConfiguration()
77 public List<FileType> getFileTypes()
79 FileType fileType = new FileType();
80 fileType.setId( FileTypes.ARTIFACTS );
81 fileType.setPatterns( Collections.singletonList( "**/*" ) );
82 return Collections.singletonList( fileType );
87 public void addChangeListener( RegistryListener listener )
89 registryListeners.add( listener );
92 public Configuration getConfiguration()
97 public void save( Configuration configuration )
98 throws RegistryException
103 public void triggerChange( String name, String value )
105 for ( RegistryListener listener : registryListeners )
109 listener.afterConfigurationChange( registryMock, name, value );
111 catch ( Exception e )
118 public void addListener( ConfigurationListener listener )
120 configListeners.add( listener );
123 public void removeListener( ConfigurationListener listener )
125 configListeners.remove( listener );
128 public boolean isDefaulted()