1 package org.apache.archiva.rest.services;
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.beans.FileType;
22 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
23 import org.apache.archiva.admin.model.beans.OrganisationInformation;
24 import org.apache.archiva.admin.model.beans.UiConfiguration;
25 import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
26 import org.apache.commons.lang.StringUtils;
27 import org.junit.Test;
29 import java.util.Arrays;
30 import java.util.List;
33 * @author Olivier Lamy
35 public class ArchivaAdministrationServiceTest
36 extends AbstractArchivaRestTest
39 public void getAllLegacyPaths()
42 assertNotNull( getArchivaAdministrationService().getLegacyArtifactPaths() );
43 assertFalse( getArchivaAdministrationService().getLegacyArtifactPaths().isEmpty() );
47 public void addAndDeleteLegacyPath()
50 //Path jaxen/jars/jaxen-1.0-FCS-full.jar
51 //Artifact jaxen:jaxen:1.0-FCS:full:jar
52 int initialSize = getArchivaAdministrationService().getLegacyArtifactPaths().size();
53 LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath();
54 legacyArtifactPath.setArtifact( "wine:bordeaux:2006:GREAT:jar" );
55 legacyArtifactPath.setPath( "wine/jars/bordeaux-2006-GREAT.jar" );
56 getArchivaAdministrationService().addLegacyArtifactPath( legacyArtifactPath );
57 assertEquals( initialSize + 1, getArchivaAdministrationService().getLegacyArtifactPaths().size() );
59 getArchivaAdministrationService().deleteLegacyArtifactPath( "wine/jars/bordeaux-2006-GREAT.jar" );
60 assertEquals( initialSize, getArchivaAdministrationService().getLegacyArtifactPaths().size() );
64 public void addAndDeleteFileType()
67 int initialSize = getArchivaAdministrationService().getFileTypes().size();
68 FileType fileType = new FileType();
69 fileType.setId( "footwo" );
70 fileType.setPatterns( Arrays.asList( "foo", "bar" ) );
71 getArchivaAdministrationService().addFileType( fileType );
72 assertEquals( initialSize + 1, getArchivaAdministrationService().getFileTypes().size() );
74 assertNotNull( getArchivaAdministrationService().getFileType( "footwo" ) );
75 assertEquals( Arrays.asList( "foo", "bar" ),
76 getArchivaAdministrationService().getFileType( "footwo" ).getPatterns() );
78 getArchivaAdministrationService().removeFileType( "footwo" );
80 assertEquals( initialSize, getArchivaAdministrationService().getFileTypes().size() );
82 assertNull( getArchivaAdministrationService().getFileType( "footwo" ) );
86 public void organisationInformationUpdate()
89 OrganisationInformation organisationInformation =
90 getArchivaAdministrationService().getOrganisationInformation();
92 // rest return an empty bean
93 assertNotNull( organisationInformation );
94 assertTrue( StringUtils.isBlank( organisationInformation.getLogoLocation() ) );
95 assertTrue( StringUtils.isBlank( organisationInformation.getName() ) );
96 assertTrue( StringUtils.isBlank( organisationInformation.getUrl() ) );
98 organisationInformation = new OrganisationInformation();
99 organisationInformation.setLogoLocation( "http://foo.com/bar.png" );
100 organisationInformation.setName( "foo org" );
101 organisationInformation.setUrl( "http://foo.com" );
103 getArchivaAdministrationService().setOrganisationInformation( organisationInformation );
105 organisationInformation = getArchivaAdministrationService().getOrganisationInformation();
106 assertNotNull( organisationInformation );
107 assertEquals( "http://foo.com/bar.png", organisationInformation.getLogoLocation() );
108 assertEquals( "foo org", organisationInformation.getName() );
109 assertEquals( "http://foo.com", organisationInformation.getUrl() );
113 public void uiConfigurationReadUpdate()
116 UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration();
118 // assert default values
119 assertFalse( ui.isDisableEasterEggs() );
120 assertFalse( ui.isDisableRegistration() );
121 assertTrue( ui.isAppletFindEnabled() );
122 assertTrue( ui.isShowFindArtifacts() );
123 assertNull( ui.getApplicationUrl() );
125 ui.setAppletFindEnabled( false );
126 ui.setShowFindArtifacts( false );
127 ui.setDisableEasterEggs( true );
128 ui.setDisableRegistration( true );
129 String url = "http://foo.fr/bar";
130 ui.setApplicationUrl( url );
132 getArchivaAdministrationService().setUiConfiguration( ui );
134 ui = getArchivaAdministrationService().getUiConfiguration();
136 assertTrue( ui.isDisableEasterEggs() );
137 assertTrue( ui.isDisableRegistration() );
138 assertFalse( ui.isAppletFindEnabled() );
139 assertFalse( ui.isShowFindArtifacts() );
140 assertEquals( url, ui.getApplicationUrl() );
144 public void uiConfigurationUpdate_ApplicationUrlHasTrailingSlash()
147 UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration();
149 assertNull( ui.getApplicationUrl() );
151 String url = "http://foo.fr/bar/";
152 ui.setApplicationUrl( url );
154 getArchivaAdministrationService().setUiConfiguration( ui );
156 ui = getArchivaAdministrationService().getUiConfiguration();
158 assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() );
160 // test if multiple '/' is trailing
161 url = "http://foo.fr/bar//";
163 ui.setApplicationUrl(url);
165 getArchivaAdministrationService().setUiConfiguration(ui);
167 ui = getArchivaAdministrationService().getUiConfiguration();
169 assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() );
173 public void getKnownContentAdminRepositoryConsumer()
176 List<AdminRepositoryConsumer> consumers =
177 getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers();
178 assertFalse( consumers.isEmpty() );
182 public void getInvalidContentAdminRepositoryConsumer()
185 List<AdminRepositoryConsumer> consumers =
186 getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
187 assertFalse( consumers.isEmpty() );
188 assertAllDisabled( consumers );
190 getArchivaAdministrationService().enabledInvalidContentConsumer( "foo" );
192 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
193 assertFalse( consumers.isEmpty() );
194 assertAllEnabled( consumers );
196 getArchivaAdministrationService().disabledInvalidContentConsumer( "foo" );
198 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
200 assertAllDisabled( consumers );
202 assertFalse( consumers.isEmpty() );
205 private void assertAllEnabled( List<AdminRepositoryConsumer> consumers )
207 for ( AdminRepositoryConsumer consumer : consumers )
209 assertTrue( consumer.isEnabled() );
213 private void assertAllDisabled( List<AdminRepositoryConsumer> consumers )
215 for ( AdminRepositoryConsumer consumer : consumers )
217 assertFalse( consumer.isEnabled() );