1 package org.apache.archiva.admin.repository.admin;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
23 import org.apache.archiva.admin.model.beans.FileType;
24 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
25 import org.apache.archiva.admin.model.beans.NetworkConfiguration;
26 import org.apache.archiva.admin.model.beans.OrganisationInformation;
27 import org.apache.archiva.admin.model.beans.UiConfiguration;
28 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
29 import org.apache.archiva.audit.AuditEvent;
30 import org.junit.Test;
32 import javax.inject.Inject;
33 import java.util.Arrays;
36 * @author Olivier Lamy
38 public class ArchivaAdministrationTest
39 extends AbstractRepositoryAdminTest
42 ArchivaAdministration archivaAdministration;
46 public void getAllLegacyPaths()
49 assertNotNull( archivaAdministration.getLegacyArtifactPaths() );
50 assertFalse( archivaAdministration.getLegacyArtifactPaths().isEmpty() );
51 assertEquals( 1, archivaAdministration.getLegacyArtifactPaths().size() );
52 log.info( "all legacy paths {}", archivaAdministration.getLegacyArtifactPaths() );
55 public void addAndDeleteLegacyPath()
58 int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
60 LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath( "foo", "bar" );
61 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getFakeAuditInformation() );
63 assertTrue( archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
64 assertEquals( initialSize + 1, archivaAdministration.getLegacyArtifactPaths().size() );
66 archivaAdministration.deleteLegacyArtifactPath( legacyArtifactPath.getPath(), getFakeAuditInformation() );
69 archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
70 assertEquals( initialSize, archivaAdministration.getLegacyArtifactPaths().size() );
71 mockAuditListener.clearEvents();
75 public void addAndUpdateAndDeleteFileType()
76 throws RepositoryAdminException
78 int initialSize = archivaAdministration.getFileTypes().size();
80 FileType fileType = new FileType();
81 fileType.setId( "foo" );
82 fileType.setPatterns( Arrays.asList( "bar", "toto" ) );
84 archivaAdministration.addFileType( fileType, getFakeAuditInformation() );
86 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
88 archivaAdministration.addFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
90 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
92 assertEquals( 3, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
94 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
95 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
96 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
98 archivaAdministration.removeFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
100 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
102 assertEquals( 2, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
104 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
105 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
106 assertFalse( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
108 archivaAdministration.removeFileType( "foo", getFakeAuditInformation() );
110 assertEquals( initialSize, archivaAdministration.getFileTypes().size() );
111 assertNull( archivaAdministration.getFileType( "foo" ) );
112 mockAuditListener.clearEvents();
115 @Test(expected = RepositoryAdminException.class)
116 public void addFileTypePatternAgain()
117 throws RepositoryAdminException
121 archivaAdministration.addFileTypePattern( "artifacts", "**/*.jar", getFakeAuditInformation() );
123 catch ( RepositoryAdminException e )
126 assertEquals( "File type [artifacts] already contains pattern [**/*.jar]", e.getMessage() );
132 public void knownContentConsumersTest()
135 int initialSize = archivaAdministration.getKnownContentConsumers().size();
137 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
139 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
140 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
142 // ensure we don't add it twice as it's an ArrayList as storage
143 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
145 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
146 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
148 archivaAdministration.removeKnownContentConsumer( "foo", getFakeAuditInformation() );
150 assertEquals( initialSize, archivaAdministration.getKnownContentConsumers().size() );
151 assertFalse( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
153 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
154 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
155 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
157 mockAuditListener.clearEvents();
162 public void invalidContentConsumersTest()
165 int initialSize = archivaAdministration.getInvalidContentConsumers().size();
167 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
169 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
170 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
172 // ensure we don't add it twice as it's an ArrayList as storage
173 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
175 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
176 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
178 archivaAdministration.removeInvalidContentConsumer( "foo", getFakeAuditInformation() );
180 assertEquals( initialSize, archivaAdministration.getInvalidContentConsumers().size() );
181 assertFalse( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
183 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
184 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
185 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
187 mockAuditListener.clearEvents();
192 public void organisationInfoUpdate()
195 OrganisationInformation oldOrganisationInformation = archivaAdministration.getOrganisationInformation();
196 assertNotNull( oldOrganisationInformation );
197 assertNull( oldOrganisationInformation.getLogoLocation() );
198 assertNull( oldOrganisationInformation.getName() );
199 assertNull( oldOrganisationInformation.getUrl() );
201 OrganisationInformation newOrganisationInformation = new OrganisationInformation();
202 newOrganisationInformation.setLogoLocation( "http://foo.com/bar.png" );
203 newOrganisationInformation.setName( "foo org" );
204 newOrganisationInformation.setUrl( "http://foo.com" );
206 archivaAdministration.setOrganisationInformation( newOrganisationInformation );
208 newOrganisationInformation = archivaAdministration.getOrganisationInformation();
209 assertNotNull( newOrganisationInformation );
210 assertEquals( "http://foo.com/bar.png", newOrganisationInformation.getLogoLocation() );
211 assertEquals( "foo org", newOrganisationInformation.getName() );
212 assertEquals( "http://foo.com", newOrganisationInformation.getUrl() );
214 // back to initial OrganisationInformation //MRM-1638
215 archivaAdministration.setOrganisationInformation( oldOrganisationInformation );
220 public void uiConfiguration()
223 UiConfiguration oldUi = archivaAdministration.getUiConfiguration();
224 assertNotNull( oldUi );
225 // assert default values
226 assertFalse( oldUi.isDisableEasterEggs() );
227 assertTrue( oldUi.isAppletFindEnabled() );
228 assertTrue( oldUi.isShowFindArtifacts() );
229 assertFalse( oldUi.isDisableRegistration() );
231 UiConfiguration ui = archivaAdministration.getUiConfiguration();
232 ui.setAppletFindEnabled( false );
233 ui.setShowFindArtifacts( false );
234 ui.setDisableEasterEggs( true );
235 ui.setDisableRegistration( true );
237 archivaAdministration.updateUiConfiguration( ui );
239 ui = archivaAdministration.getUiConfiguration();
241 assertTrue( ui.isDisableEasterEggs() );
242 assertFalse( ui.isAppletFindEnabled() );
243 assertFalse( ui.isShowFindArtifacts() );
244 assertTrue( ui.isDisableRegistration() );
246 archivaAdministration.updateUiConfiguration( oldUi );
250 public void networkConfiguration()
253 NetworkConfiguration networkConfiguration = archivaAdministration.getNetworkConfiguration();
254 assertNotNull( networkConfiguration );
256 assertTrue( networkConfiguration.isUsePooling() );
257 assertEquals( 30, networkConfiguration.getMaxTotal() );
258 assertEquals( 30, networkConfiguration.getMaxTotalPerHost() );