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.repository.AbstractRepositoryAdminTest;
22 import org.apache.archiva.admin.repository.RepositoryAdminException;
23 import org.apache.archiva.audit.AuditEvent;
24 import org.junit.Test;
26 import javax.inject.Inject;
27 import java.util.Arrays;
30 * @author Olivier Lamy
32 public class ArchivaAdministrationTest
33 extends AbstractRepositoryAdminTest
36 ArchivaAdministration archivaAdministration;
40 public void getAllLegacyPaths()
43 assertNotNull( archivaAdministration.getLegacyArtifactPaths() );
44 assertFalse( archivaAdministration.getLegacyArtifactPaths().isEmpty() );
45 assertEquals( 1, archivaAdministration.getLegacyArtifactPaths().size() );
46 log.info( "all legacy paths {}", archivaAdministration.getLegacyArtifactPaths() );
49 public void addAndDeleteLegacyPath()
52 int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
54 LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath( "foo", "bar" );
55 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getFakeAuditInformation() );
57 assertTrue( archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
58 assertEquals( initialSize + 1, archivaAdministration.getLegacyArtifactPaths().size() );
60 archivaAdministration.deleteLegacyArtifactPath( legacyArtifactPath.getPath(), getFakeAuditInformation() );
63 archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
64 assertEquals( initialSize, archivaAdministration.getLegacyArtifactPaths().size() );
65 mockAuditListener.clearEvents();
69 public void addAndUpdateAndDeleteFileType()
70 throws RepositoryAdminException
72 int initialSize = archivaAdministration.getRepositoryScanning().getFileTypes().size();
74 FileType fileType = new FileType();
75 fileType.setId( "foo" );
76 fileType.setPatterns( Arrays.asList( "bar", "toto" ) );
78 archivaAdministration.addFileType( fileType, getFakeAuditInformation() );
80 assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
82 archivaAdministration.addFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
84 assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
86 assertEquals( 3, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
88 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
89 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
90 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
92 archivaAdministration.removeFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
94 assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
96 assertEquals( 2, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
98 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
99 assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
100 assertFalse( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
102 archivaAdministration.removeFileType( "foo", getFakeAuditInformation() );
104 assertEquals( initialSize, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
105 assertNull( archivaAdministration.getFileType( "foo" ) );
106 mockAuditListener.clearEvents();
110 public void knownContentConsumersTest()
113 int initialSize = archivaAdministration.getRepositoryScanning().getKnownContentConsumers().size();
115 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
117 assertEquals( initialSize + 1,
118 archivaAdministration.getRepositoryScanning().getKnownContentConsumers().size() );
119 assertTrue( archivaAdministration.getRepositoryScanning().getKnownContentConsumers().contains( "foo" ) );
121 // ensure we don't add it twice as it's an ArrayList as storage
122 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
124 assertEquals( initialSize + 1,
125 archivaAdministration.getRepositoryScanning().getKnownContentConsumers().size() );
126 assertTrue( archivaAdministration.getRepositoryScanning().getKnownContentConsumers().contains( "foo" ) );
128 archivaAdministration.removeKnownContentConsumer( "foo", getFakeAuditInformation() );
131 assertEquals( initialSize ,
132 archivaAdministration.getRepositoryScanning().getKnownContentConsumers().size() );
133 assertFalse( archivaAdministration.getRepositoryScanning().getKnownContentConsumers().contains( "foo" ) );
135 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
136 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
137 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
139 mockAuditListener.clearEvents();
144 public void invalidContentConsumersTest()
147 int initialSize = archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().size();
149 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
151 assertEquals( initialSize + 1,
152 archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().size() );
153 assertTrue( archivaAdministration.getRepositoryScanning().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,
159 archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().size() );
160 assertTrue( archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().contains( "foo" ) );
162 archivaAdministration.removeInvalidContentConsumer( "foo", getFakeAuditInformation() );
164 assertEquals( initialSize, archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().size() );
165 assertFalse( archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().contains( "foo" ) );
167 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
168 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
169 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
171 mockAuditListener.clearEvents();