You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MockConfiguration.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package org.apache.archiva.proxy;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.configuration.ArchivaConfiguration;
  21. import org.apache.archiva.configuration.Configuration;
  22. import org.apache.archiva.configuration.ConfigurationListener;
  23. import org.apache.archiva.configuration.FileType;
  24. import org.apache.archiva.configuration.FileTypes;
  25. import org.apache.archiva.configuration.RepositoryScanningConfiguration;
  26. import org.apache.archiva.redback.components.registry.Registry;
  27. import org.apache.archiva.redback.components.registry.RegistryException;
  28. import org.apache.archiva.redback.components.registry.RegistryListener;
  29. import org.easymock.MockControl;
  30. import org.springframework.stereotype.Service;
  31. import java.util.Collections;
  32. import java.util.HashSet;
  33. import java.util.List;
  34. import java.util.Set;
  35. import javax.annotation.PostConstruct;
  36. /**
  37. * MockConfiguration
  38. *
  39. *
  40. */
  41. @Service( "archivaConfiguration#mock" )
  42. public class MockConfiguration
  43. implements ArchivaConfiguration
  44. {
  45. private Configuration configuration = new Configuration();
  46. private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
  47. private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
  48. private MockControl registryControl;
  49. private Registry registryMock;
  50. public MockConfiguration()
  51. {
  52. registryControl = MockControl.createNiceControl( org.apache.archiva.redback.components.registry.Registry.class );
  53. registryMock = (org.apache.archiva.redback.components.registry.Registry) registryControl.getMock();
  54. }
  55. @PostConstruct
  56. public void initialize()
  57. throws Exception
  58. {
  59. configuration.setRepositoryScanning( new RepositoryScanningConfiguration()
  60. {
  61. @Override
  62. public List<FileType> getFileTypes()
  63. {
  64. FileType fileType = new FileType();
  65. fileType.setId( FileTypes.ARTIFACTS );
  66. fileType.setPatterns( Collections.singletonList( "**/*" ) );
  67. return Collections.singletonList( fileType );
  68. }
  69. } );
  70. }
  71. public void addChangeListener( org.apache.archiva.redback.components.registry.RegistryListener listener )
  72. {
  73. registryListeners.add( listener );
  74. }
  75. public Configuration getConfiguration()
  76. {
  77. return configuration;
  78. }
  79. public void save( Configuration configuration )
  80. throws RegistryException
  81. {
  82. /* do nothing */
  83. }
  84. public void triggerChange( String name, String value )
  85. {
  86. for ( org.apache.archiva.redback.components.registry.RegistryListener listener : registryListeners )
  87. {
  88. try
  89. {
  90. listener.afterConfigurationChange( registryMock, name, value );
  91. }
  92. catch ( Exception e )
  93. {
  94. e.printStackTrace();
  95. }
  96. }
  97. }
  98. public void addListener( ConfigurationListener listener )
  99. {
  100. configListeners.add( listener );
  101. }
  102. public void removeListener( ConfigurationListener listener )
  103. {
  104. configListeners.remove( listener );
  105. }
  106. public boolean isDefaulted()
  107. {
  108. return false;
  109. }
  110. public void reload()
  111. {
  112. // no op
  113. }
  114. }