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.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.getFileTypes().size() );
82 archivaAdministration.addFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
84 assertEquals( initialSize + 1, archivaAdministration.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.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.getFileTypes().size() );
105 assertNull( archivaAdministration.getFileType( "foo" ) );
106 mockAuditListener.clearEvents();
110 public void knownContentConsumersTest()
113 int initialSize = archivaAdministration.getKnownContentConsumers().size();
115 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
117 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
118 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
120 // ensure we don't add it twice as it's an ArrayList as storage
121 archivaAdministration.addKnownContentConsumer( "foo", getFakeAuditInformation() );
123 assertEquals( initialSize + 1, archivaAdministration.getKnownContentConsumers().size() );
124 assertTrue( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
126 archivaAdministration.removeKnownContentConsumer( "foo", getFakeAuditInformation() );
128 assertEquals( initialSize, archivaAdministration.getKnownContentConsumers().size() );
129 assertFalse( archivaAdministration.getKnownContentConsumers().contains( "foo" ) );
131 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
132 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
133 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
135 mockAuditListener.clearEvents();
140 public void invalidContentConsumersTest()
143 int initialSize = archivaAdministration.getInvalidContentConsumers().size();
145 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
147 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
148 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
150 // ensure we don't add it twice as it's an ArrayList as storage
151 archivaAdministration.addInvalidContentConsumer( "foo", getFakeAuditInformation() );
153 assertEquals( initialSize + 1, archivaAdministration.getInvalidContentConsumers().size() );
154 assertTrue( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
156 archivaAdministration.removeInvalidContentConsumer( "foo", getFakeAuditInformation() );
158 assertEquals( initialSize, archivaAdministration.getInvalidContentConsumers().size() );
159 assertFalse( archivaAdministration.getInvalidContentConsumers().contains( "foo" ) );
161 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
162 assertEquals( AuditEvent.ENABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
163 assertEquals( AuditEvent.DISABLE_REPO_CONSUMER, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
165 mockAuditListener.clearEvents();