View Javadoc
1   package org.apache.archiva.metadata.repository.storage.maven2.conf;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.apache.archiva.configuration.ArchivaConfiguration;
23  import org.apache.archiva.configuration.Configuration;
24  import org.apache.archiva.configuration.ConfigurationListener;
25  import org.apache.archiva.redback.components.registry.Registry;
26  import org.apache.archiva.redback.components.registry.RegistryException;
27  import org.apache.archiva.redback.components.registry.RegistryListener;
28  import org.easymock.IMocksControl;
29  import org.springframework.stereotype.Service;
30  
31  import java.util.HashSet;
32  import java.util.Set;
33  
34  import static org.easymock.EasyMock.createNiceControl;
35  
36  /**
37   * MockConfiguration 
38   *
39   *
40   */
41  @Service("archivaConfiguration#mock")
42  public class MockConfiguration
43      implements ArchivaConfiguration
44  {
45  
46      private Configuration configuration = new Configuration();
47  
48      private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
49      private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
50  
51      private IMocksControl registryControl;
52  
53      private Registry registryMock;
54  
55      public MockConfiguration()
56      {
57          registryControl = createNiceControl();
58          registryMock = registryControl.createMock( Registry.class );
59      }
60  
61      @Override
62      public void addChangeListener( RegistryListener listener )
63      {
64          registryListeners.add( listener );
65      }
66  
67      @Override
68      public void removeChangeListener( RegistryListener listener )
69      {
70          registryListeners.remove( listener );
71      }
72  
73      @Override
74      public Configuration getConfiguration()
75      {
76          return configuration;
77      }
78  
79      @Override
80      public void save( Configuration configuration )
81          throws RegistryException
82      {
83          /* do nothing */
84      }
85  
86      public void triggerChange( String name, String value )
87      {
88          for(RegistryListener listener: registryListeners)
89          {
90              try
91              {
92                  listener.afterConfigurationChange( registryMock, name, value );
93              }
94              catch ( Exception e )
95              {
96                  e.printStackTrace();
97              }
98          }
99      }
100 
101     @Override
102     public void addListener( ConfigurationListener listener )
103     {
104         configListeners.add(listener);
105     }
106 
107     @Override
108     public void removeListener( ConfigurationListener listener )
109     {
110         configListeners.remove( listener );
111     }
112     
113     @Override
114     public boolean isDefaulted()
115     {
116         return false;
117     }
118 
119     @Override
120     public void reload()
121     {
122         // no op
123     }
124 }