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.OrganisationInformation;
23 import org.apache.archiva.admin.model.beans.UiConfiguration;
24 import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
25 import org.apache.commons.lang.StringUtils;
26 import org.junit.Test;
28 import java.util.Arrays;
29 import java.util.List;
32 * @author Olivier Lamy
34 public class ArchivaAdministrationServiceTest
35 extends AbstractArchivaRestTest
38 public void getAllLegacyPaths()
41 assertNotNull( getArchivaAdministrationService().getLegacyArtifactPaths() );
42 assertFalse( getArchivaAdministrationService().getLegacyArtifactPaths().isEmpty() );
46 public void addAndDeleteFileType()
49 int initialSize = getArchivaAdministrationService().getFileTypes().size();
50 FileType fileType = new FileType();
51 fileType.setId( "footwo" );
52 fileType.setPatterns( Arrays.asList( "foo", "bar" ) );
53 getArchivaAdministrationService().addFileType( fileType );
54 assertEquals( initialSize + 1, getArchivaAdministrationService().getFileTypes().size() );
56 assertNotNull( getArchivaAdministrationService().getFileType( "footwo" ) );
57 assertEquals( Arrays.asList( "foo", "bar" ),
58 getArchivaAdministrationService().getFileType( "footwo" ).getPatterns() );
60 getArchivaAdministrationService().removeFileType( "footwo" );
62 assertEquals( initialSize, getArchivaAdministrationService().getFileTypes().size() );
64 assertNull( getArchivaAdministrationService().getFileType( "footwo" ) );
68 public void organisationInformationUpdate()
71 OrganisationInformation organisationInformation =
72 getArchivaAdministrationService().getOrganisationInformation();
74 // rest return an empty bean
75 assertNotNull( organisationInformation );
76 assertTrue( StringUtils.isBlank( organisationInformation.getLogoLocation() ) );
77 assertTrue( StringUtils.isBlank( organisationInformation.getName() ) );
78 assertTrue( StringUtils.isBlank( organisationInformation.getUrl() ) );
80 organisationInformation = new OrganisationInformation();
81 organisationInformation.setLogoLocation( "http://foo.com/bar.png" );
82 organisationInformation.setName( "foo org" );
83 organisationInformation.setUrl( "http://foo.com" );
85 getArchivaAdministrationService().setOrganisationInformation( organisationInformation );
87 organisationInformation = getArchivaAdministrationService().getOrganisationInformation();
88 assertNotNull( organisationInformation );
89 assertEquals( "http://foo.com/bar.png", organisationInformation.getLogoLocation() );
90 assertEquals( "foo org", organisationInformation.getName() );
91 assertEquals( "http://foo.com", organisationInformation.getUrl() );
95 public void uiConfigurationReadUpdate()
98 UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration();
100 // assert default values
101 assertFalse( ui.isDisableEasterEggs() );
102 assertFalse( ui.isDisableRegistration() );
103 assertTrue( ui.isAppletFindEnabled() );
104 assertTrue( ui.isShowFindArtifacts() );
105 assertNull( ui.getApplicationUrl() );
107 ui.setAppletFindEnabled( false );
108 ui.setShowFindArtifacts( false );
109 ui.setDisableEasterEggs( true );
110 ui.setDisableRegistration( true );
111 String url = "http://foo.fr/bar";
112 ui.setApplicationUrl( url );
114 getArchivaAdministrationService().setUiConfiguration( ui );
116 ui = getArchivaAdministrationService().getUiConfiguration();
118 assertTrue( ui.isDisableEasterEggs() );
119 assertTrue( ui.isDisableRegistration() );
120 assertFalse( ui.isAppletFindEnabled() );
121 assertFalse( ui.isShowFindArtifacts() );
122 assertEquals( url, ui.getApplicationUrl() );
126 public void uiConfigurationUpdate_ApplicationUrlHasTrailingSlash()
129 UiConfiguration ui = getArchivaAdministrationService().getUiConfiguration();
131 assertNull( ui.getApplicationUrl() );
133 String url = "http://foo.fr/bar/";
134 ui.setApplicationUrl( url );
136 getArchivaAdministrationService().setUiConfiguration( ui );
138 ui = getArchivaAdministrationService().getUiConfiguration();
140 assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() );
142 // test if multiple '/' is trailing
143 url = "http://foo.fr/bar//";
145 ui.setApplicationUrl(url);
147 getArchivaAdministrationService().setUiConfiguration(ui);
149 ui = getArchivaAdministrationService().getUiConfiguration();
151 assertEquals( "http://foo.fr/bar", ui.getApplicationUrl() );
155 public void getKnownContentAdminRepositoryConsumer()
158 List<AdminRepositoryConsumer> consumers =
159 getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers();
160 assertFalse( consumers.isEmpty() );
164 public void getInvalidContentAdminRepositoryConsumer()
167 List<AdminRepositoryConsumer> consumers =
168 getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
169 assertFalse( consumers.isEmpty() );
170 assertAllDisabled( consumers );
172 getArchivaAdministrationService().enabledInvalidContentConsumer( "foo" );
174 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
175 assertFalse( consumers.isEmpty() );
176 assertAllEnabled( consumers );
178 getArchivaAdministrationService().disabledInvalidContentConsumer( "foo" );
180 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
182 assertAllDisabled( consumers );
184 assertFalse( consumers.isEmpty() );
187 private void assertAllEnabled( List<AdminRepositoryConsumer> consumers )
189 for ( AdminRepositoryConsumer consumer : consumers )
191 assertTrue( consumer.isEnabled() );
195 private void assertAllDisabled( List<AdminRepositoryConsumer> consumers )
197 for ( AdminRepositoryConsumer consumer : consumers )
199 assertFalse( consumer.isEnabled() );