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 assertTrue( ui.isAppletFindEnabled() );
121 assertTrue( ui.isShowFindArtifacts() );
123 ui.setAppletFindEnabled( false );
124 ui.setShowFindArtifacts( false );
125 ui.setDisableEasterEggs( true );
127 getArchivaAdministrationService().setUiConfiguration( ui );
129 ui = getArchivaAdministrationService().getUiConfiguration();
131 assertTrue( ui.isDisableEasterEggs() );
132 assertFalse( ui.isAppletFindEnabled() );
133 assertFalse( ui.isShowFindArtifacts() );
137 public void getKnownContentAdminRepositoryConsumer()
140 List<AdminRepositoryConsumer> consumers =
141 getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers();
142 assertFalse( consumers.isEmpty() );
146 public void getInvalidContentAdminRepositoryConsumer()
149 List<AdminRepositoryConsumer> consumers =
150 getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
151 assertFalse( consumers.isEmpty() );
152 assertAllDisabled( consumers );
154 getArchivaAdministrationService().addInvalidContentConsumer( "foo" );
156 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
157 assertFalse( consumers.isEmpty() );
158 assertAllEnabled( consumers );
161 getArchivaAdministrationService().removeInvalidContentConsumer( "foo" );
163 consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
165 assertAllDisabled( consumers );
167 assertFalse( consumers.isEmpty() );
170 private void assertAllEnabled( List<AdminRepositoryConsumer> consumers )
172 for ( AdminRepositoryConsumer consumer : consumers )
174 assertTrue( consumer.isEnabled() );
178 private void assertAllDisabled( List<AdminRepositoryConsumer> consumers )
180 for ( AdminRepositoryConsumer consumer : consumers )
182 assertFalse( consumer.isEnabled() );