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.OrganisationInformation;
26 import org.apache.archiva.admin.model.beans.UiConfiguration;
27 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
28 import org.apache.archiva.audit.AuditEvent;
29 import org.junit.Test;
31 import javax.inject.Inject;
32 import java.util.Arrays;
35 * @author Olivier Lamy
37 public class ArchivaAdministrationTest
38 extends AbstractRepositoryAdminTest
41 ArchivaAdministration archivaAdministration;
45 public void getAllLegacyPaths()
48 assertNotNull( archivaAdministration.getLegacyArtifactPaths() );
49 assertFalse( archivaAdministration.getLegacyArtifactPaths().isEmpty() );
50 assertEquals( 1, archivaAdministration.getLegacyArtifactPaths().size() );
51 log.info( "all legacy paths {}", archivaAdministration.getLegacyArtifactPaths() );
54 public void addAndDeleteLegacyPath()
57 int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
59 LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath( "foo", "bar" );
60 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getFakeAuditInformation() );
62 assertTrue( archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
63 assertEquals( initialSize + 1, archivaAdministration.getLegacyArtifactPaths().size() );
65 archivaAdministration.deleteLegacyArtifactPath( legacyArtifactPath.getPath(), getFakeAuditInformation() );
68 archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
69 assertEquals( initialSize, archivaAdministration.getLegacyArtifactPaths().size() );
70 mockAuditListener.clearEvents();
74 public void addAndUpdateAndDeleteFileType()
75 throws RepositoryAdminException
77 int initialSize = archivaAdministration.getFileTypes().size();
79 FileType fileType = new FileType();
80 fileType.setId( "foo" );
81 fileType.setPatterns( Arrays.asList( "bar", "toto" ) );
83 archivaAdministration.addFileType( fileType, getFakeAuditInformation() );
85 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
87 archivaAdministration.addFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
89 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
91 assertEquals( 3, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
93 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
94 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
95 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
97 archivaAdministration.removeFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
99 assertEquals( initialSize + 1, archivaAdministration.getFileTypes().size() );
101 assertEquals( 2, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
103 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
104 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
105 assertFalse( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
107 archivaAdministration.removeFileType( "foo", getFakeAuditInformation() );
109 assertEquals( initialSize, archivaAdministration.getFileTypes().size() );
110 assertNull( archivaAdministration.getFileType( "foo" ) );
111 mockAuditListener.clearEvents();
115 public void knownContentConsumersTest()
118 int initialSize = archivaAdministration.getKnownContentConsumers().size();
120 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
122 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
123 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
125 // ensure we don't add it twice as it's an ArrayList as storage
126 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
128 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
129 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
131 archivaAdministration.removeKnownContentConsumer( "foo", getFakeAuditInformation() );
133 assertEquals( initialSize, archivaAdministration.getKnownContentConsumers().size() );
134 assertFalse( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
136 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
137 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
138 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
140 mockAuditListener.clearEvents();
145 public void invalidContentConsumersTest()
148 int initialSize = archivaAdministration.getInvalidContentConsumers().size();
150 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
152 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
153 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
155 // ensure we don't add it twice as it's an ArrayList as storage
156 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
158 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
159 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
161 archivaAdministration.removeInvalidContentConsumer( "foo", getFakeAuditInformation() );
163 assertEquals( initialSize, archivaAdministration.getInvalidContentConsumers().size() );
164 assertFalse( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
166 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
167 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
168 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
170 mockAuditListener.clearEvents();
175 public void organisationInfoUpdate()
178 OrganisationInformation organisationInformation = archivaAdministration.getOrganisationInformation();
179 assertNotNull( organisationInformation );
180 assertNull( organisationInformation.getLogoLocation() );
181 assertNull( organisationInformation.getName() );
182 assertNull( organisationInformation.getUrl() );
184 organisationInformation = new OrganisationInformation();
185 organisationInformation.setLogoLocation( "http://foo.com/bar.png" );
186 organisationInformation.setName( "foo org" );
187 organisationInformation.setUrl( "http://foo.com" );
189 archivaAdministration.setOrganisationInformation( organisationInformation );
191 organisationInformation = archivaAdministration.getOrganisationInformation();
192 assertNotNull( organisationInformation );
193 assertEquals( "http://foo.com/bar.png", organisationInformation.getLogoLocation() );
194 assertEquals( "foo org", organisationInformation.getName() );
195 assertEquals( "http://foo.com", organisationInformation.getUrl() );
200 public void uiConfiguration()
203 UiConfiguration ui = archivaAdministration.getUiConfiguration();
205 // assert default values
206 assertFalse( ui.isDisableEasterEggs() );
207 assertTrue( ui.isAppletFindEnabled() );
208 assertTrue( ui.isShowFindArtifacts() );
210 ui.setAppletFindEnabled( false );
211 ui.setShowFindArtifacts( false );
212 ui.setDisableEasterEggs( true );
214 archivaAdministration.updateUiConfiguration( ui );
216 ui = archivaAdministration.getUiConfiguration();
218 assertTrue( ui.isDisableEasterEggs() );
219 assertFalse( ui.isAppletFindEnabled() );
220 assertFalse( ui.isShowFindArtifacts() );