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 getKnownContentAdminRepositoryConsumer()
147 List<AdminRepositoryConsumer> consumers =
148 getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers();
149 assertFalse( consumers.isEmpty() );
153 public void getInvalidContentAdminRepositoryConsumer()
156 List<AdminRepositoryConsumer> consumers =
157 getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
158 assertFalse( consumers.isEmpty() );
159 assertAllDisabled( consumers );
161 getArchivaAdministrationService().enabledInvalidContentConsumer( "foo" );
163 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
164 assertFalse( consumers.isEmpty() );
165 assertAllEnabled( consumers );
167 getArchivaAdministrationService().disabledInvalidContentConsumer( "foo" );
169 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
171 assertAllDisabled( consumers );
173 assertFalse( consumers.isEmpty() );
176 private void assertAllEnabled( List<AdminRepositoryConsumer> consumers )
178 for ( AdminRepositoryConsumer consumer : consumers )
180 assertTrue( consumer.isEnabled() );
184 private void assertAllDisabled( List<AdminRepositoryConsumer> consumers )
186 for ( AdminRepositoryConsumer consumer : consumers )
188 assertFalse( consumer.isEnabled() );