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" ) );
127 mockAuditListener.clearEvents();
132 public void invalidContentConsumersTest()
135 int initialSize = archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().size();
137 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
139 assertEquals( initialSize + 1,
140 archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().size() );
141 assertTrue( archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().contains( "foo" ) );
143 // ensure we don't add it twice as it's an ArrayList as storage
144 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
146 assertEquals( initialSize + 1,
147 archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().size() );
148 assertTrue( archivaAdministration.getRepositoryScanning().getInvalidContentConsumers().contains( "foo" ) );
150 assertEquals( 1, mockAuditListener.getAuditEvents().size() );
151 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
153 mockAuditListener.clearEvents();