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.apache.maven.wagon.providers.http.HttpWagon;
31 import org.junit.Test;
33 import javax.inject.Inject;
34 import java.lang.reflect.Field;
35 import java.util.Arrays;
38 * @author Olivier Lamy
40 public class ArchivaAdministrationTest
41 extends AbstractRepositoryAdminTest
44 ArchivaAdministration archivaAdministration;
48 public void getAllLegacyPaths()
51 assertNotNull( archivaAdministration.getLegacyArtifactPaths() );
52 assertFalse( archivaAdministration.getLegacyArtifactPaths().isEmpty() );
53 assertEquals( 1, archivaAdministration.getLegacyArtifactPaths().size() );
54 log.info( "all legacy paths {}", archivaAdministration.getLegacyArtifactPaths() );
57 public void addAndDeleteLegacyPath()
60 int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
62 LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath( "foo", "bar" );
63 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getFakeAuditInformation() );
65 assertTrue( archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
66 assertEquals( initialSize + 1, archivaAdministration.getLegacyArtifactPaths().size() );
68 archivaAdministration.deleteLegacyArtifactPath( legacyArtifactPath.getPath(), getFakeAuditInformation() );
71 archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
72 assertEquals( initialSize, archivaAdministration.getLegacyArtifactPaths().size() );
73 mockAuditListener.clearEvents();
77 public void addAndUpdateAndDeleteFileType()
78 throws RepositoryAdminException
80 int initialSize = archivaAdministration.getFileTypes().size();
82 FileType fileType = new FileType();
83 fileType.setId( "foo" );
84 fileType.setPatterns( Arrays.asList( "bar", "toto" ) );
86 archivaAdministration.addFileType( fileType, getFakeAuditInformation() );
88 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
90 archivaAdministration.addFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
92 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
94 assertEquals( 3, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
96 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
97 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
98 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
100 archivaAdministration.removeFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
102 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
104 assertEquals( 2, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
106 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
107 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
108 assertFalse( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
110 archivaAdministration.removeFileType( "foo", getFakeAuditInformation() );
112 assertEquals( initialSize, archivaAdministration.getFileTypes().size() );
113 assertNull( archivaAdministration.getFileType( "foo" ) );
114 mockAuditListener.clearEvents();
117 @Test(expected = RepositoryAdminException.class)
118 public void addFileTypePatternAgain()
119 throws RepositoryAdminException
123 archivaAdministration.addFileTypePattern( "artifacts", "**/*.jar", getFakeAuditInformation() );
125 catch ( RepositoryAdminException e )
128 assertEquals( "File type [artifacts] already contains pattern [**/*.jar]", e.getMessage() );
134 public void knownContentConsumersTest()
137 int initialSize = archivaAdministration.getKnownContentConsumers().size();
139 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
141 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
142 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
144 // ensure we don't add it twice as it's an ArrayList as storage
145 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
147 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
148 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
150 archivaAdministration.removeKnownContentConsumer( "foo", getFakeAuditInformation() );
152 assertEquals( initialSize, archivaAdministration.getKnownContentConsumers().size() );
153 assertFalse( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
155 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
156 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
157 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
159 mockAuditListener.clearEvents();
164 public void invalidContentConsumersTest()
167 int initialSize = archivaAdministration.getInvalidContentConsumers().size();
169 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
171 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
172 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
174 // ensure we don't add it twice as it's an ArrayList as storage
175 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
177 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
178 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
180 archivaAdministration.removeInvalidContentConsumer( "foo", getFakeAuditInformation() );
182 assertEquals( initialSize, archivaAdministration.getInvalidContentConsumers().size() );
183 assertFalse( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
185 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
186 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
187 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
189 mockAuditListener.clearEvents();
194 public void organisationInfoUpdate()
197 OrganisationInformation organisationInformation = archivaAdministration.getOrganisationInformation();
198 assertNotNull( organisationInformation );
199 assertNull( organisationInformation.getLogoLocation() );
200 assertNull( organisationInformation.getName() );
201 assertNull( organisationInformation.getUrl() );
203 organisationInformation = new OrganisationInformation();
204 organisationInformation.setLogoLocation( "http://foo.com/bar.png" );
205 organisationInformation.setName( "foo org" );
206 organisationInformation.setUrl( "http://foo.com" );
208 archivaAdministration.setOrganisationInformation( organisationInformation );
210 organisationInformation = archivaAdministration.getOrganisationInformation();
211 assertNotNull( organisationInformation );
212 assertEquals( "http://foo.com/bar.png", organisationInformation.getLogoLocation() );
213 assertEquals( "foo org", organisationInformation.getName() );
214 assertEquals( "http://foo.com", organisationInformation.getUrl() );
219 public void uiConfiguration()
222 UiConfiguration ui = archivaAdministration.getUiConfiguration();
224 // assert default values
225 assertFalse( ui.isDisableEasterEggs() );
226 assertTrue( ui.isAppletFindEnabled() );
227 assertTrue( ui.isShowFindArtifacts() );
229 ui.setAppletFindEnabled( false );
230 ui.setShowFindArtifacts( false );
231 ui.setDisableEasterEggs( true );
233 archivaAdministration.updateUiConfiguration( ui );
235 ui = archivaAdministration.getUiConfiguration();
237 assertTrue( ui.isDisableEasterEggs() );
238 assertFalse( ui.isAppletFindEnabled() );
239 assertFalse( ui.isShowFindArtifacts() );
243 public void networkConfiguration()
246 NetworkConfiguration networkConfiguration = archivaAdministration.getNetworkConfiguration();
247 assertNotNull( networkConfiguration );
249 assertTrue( networkConfiguration.isUsePooling() );
250 assertEquals( 30, networkConfiguration.getMaxTotal() );
251 assertEquals( 30, networkConfiguration.getMaxTotalPerHost() );