View Javadoc

1   package org.apache.maven.archiva.proxy;
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.maven.archiva.configuration.ArchivaConfiguration;
23  import org.apache.maven.archiva.configuration.Configuration;
24  import org.apache.maven.archiva.configuration.ConfigurationListener;
25  import org.codehaus.plexus.registry.Registry;
26  import org.codehaus.plexus.registry.RegistryException;
27  import org.codehaus.plexus.registry.RegistryListener;
28  import org.easymock.MockControl;
29  
30  import java.util.HashSet;
31  import java.util.Set;
32  
33  /**
34   * MockConfiguration 
35   *
36   * @version $Id: MockConfiguration.java 718864 2008-11-19 06:33:35Z brett $
37   * 
38   * @plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration"
39   *                   role-hint="mock"
40   */
41  public class MockConfiguration
42      implements ArchivaConfiguration
43  {
44      private Configuration configuration = new Configuration();
45  
46      private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
47      private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
48  
49      private MockControl registryControl;
50  
51      private Registry registryMock;
52  
53      public MockConfiguration()
54      {
55          registryControl = MockControl.createNiceControl( Registry.class );
56          registryMock = (Registry) registryControl.getMock();
57      }
58  
59      public void addChangeListener( RegistryListener listener )
60      {
61          registryListeners.add( listener );
62      }
63  
64      public Configuration getConfiguration()
65      {
66          return configuration;
67      }
68  
69      public void save( Configuration configuration )
70          throws RegistryException
71      {
72          /* do nothing */
73      }
74  
75      public void triggerChange( String name, String value )
76      {
77          for(RegistryListener listener: registryListeners)
78          {
79              try
80              {
81                  listener.afterConfigurationChange( registryMock, name, value );
82              }
83              catch ( Exception e )
84              {
85                  e.printStackTrace();
86              }
87          }
88      }
89  
90      public void addListener( ConfigurationListener listener )
91      {
92          configListeners.add(listener);
93      }
94  
95      public void removeListener( ConfigurationListener listener )
96      {
97          configListeners.remove( listener );
98      }
99  
100     public boolean isDefaulted()
101     {
102         return false;
103     }
104 }