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();
118 public void knownContentConsumersTest()
121 int initialSize = archivaAdministration.getKnownContentConsumers().size();
123 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
125 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
126 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
128 // ensure we don't add it twice as it's an ArrayList as storage
129 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
131 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
132 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
134 archivaAdministration.removeKnownContentConsumer( "foo", getFakeAuditInformation() );
136 assertEquals( initialSize, archivaAdministration.getKnownContentConsumers().size() );
137 assertFalse( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
139 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
140 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
141 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
143 mockAuditListener.clearEvents();
148 public void invalidContentConsumersTest()
151 int initialSize = archivaAdministration.getInvalidContentConsumers().size();
153 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
155 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
156 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
158 // ensure we don't add it twice as it's an ArrayList as storage
159 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
161 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
162 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
164 archivaAdministration.removeInvalidContentConsumer( "foo", getFakeAuditInformation() );
166 assertEquals( initialSize, archivaAdministration.getInvalidContentConsumers().size() );
167 assertFalse( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
169 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
170 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
171 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
173 mockAuditListener.clearEvents();
178 public void organisationInfoUpdate()
181 OrganisationInformation organisationInformation = archivaAdministration.getOrganisationInformation();
182 assertNotNull( organisationInformation );
183 assertNull( organisationInformation.getLogoLocation() );
184 assertNull( organisationInformation.getName() );
185 assertNull( organisationInformation.getUrl() );
187 organisationInformation = new OrganisationInformation();
188 organisationInformation.setLogoLocation( "http://foo.com/bar.png" );
189 organisationInformation.setName( "foo org" );
190 organisationInformation.setUrl( "http://foo.com" );
192 archivaAdministration.setOrganisationInformation( organisationInformation );
194 organisationInformation = archivaAdministration.getOrganisationInformation();
195 assertNotNull( organisationInformation );
196 assertEquals( "http://foo.com/bar.png", organisationInformation.getLogoLocation() );
197 assertEquals( "foo org", organisationInformation.getName() );
198 assertEquals( "http://foo.com", organisationInformation.getUrl() );
203 public void uiConfiguration()
206 UiConfiguration ui = archivaAdministration.getUiConfiguration();
208 // assert default values
209 assertFalse( ui.isDisableEasterEggs() );
210 assertTrue( ui.isAppletFindEnabled() );
211 assertTrue( ui.isShowFindArtifacts() );
213 ui.setAppletFindEnabled( false );
214 ui.setShowFindArtifacts( false );
215 ui.setDisableEasterEggs( true );
217 archivaAdministration.updateUiConfiguration( ui );
219 ui = archivaAdministration.getUiConfiguration();
221 assertTrue( ui.isDisableEasterEggs() );
222 assertFalse( ui.isAppletFindEnabled() );
223 assertFalse( ui.isShowFindArtifacts() );
227 public void networkConfiguration()
230 NetworkConfiguration networkConfiguration = archivaAdministration.getNetworkConfiguration();
231 assertNotNull( networkConfiguration );
233 assertTrue( networkConfiguration.isUsePooling() );
234 assertEquals( 30, networkConfiguration.getMaxTotal() );
235 assertEquals( 30, networkConfiguration.getMaxTotalPerHost() );