1 package org.apache.archiva.configuration;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.apache.archiva.common.utils.FileUtil;
24 import org.apache.commons.io.FileUtils;
25 import org.apache.commons.lang.StringUtils;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.test.context.ContextConfiguration;
34 import javax.inject.Inject;
36 import java.util.List;
37 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
40 * Test the configuration store.
42 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
43 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
44 public class ArchivaConfigurationMRM789Test
48 private Logger log = LoggerFactory.getLogger( getClass() );
51 protected ApplicationContext applicationContext;
56 public static File getTestFile( String path )
58 return new File( FileUtil.getBasedir(), path );
61 protected <T> T lookup( Class<T> clazz, String hint )
63 return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class );
68 public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
71 File repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_snapshots" );
74 repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_internal" );
77 String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
78 getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ) );
79 existingTestDefaultArchivaConfigFile =
80 StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
82 File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir(),
83 "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
85 FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
88 ArchivaConfiguration archivaConfiguration =
89 lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
90 Configuration configuration = archivaConfiguration.getConfiguration();
91 assertConfiguration( configuration, 2, 1, 1 );
93 ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
94 assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
96 generatedTestDefaultArchivaConfigFile.delete();
97 assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
102 * Ensures that the provided configuration matches the details present in the archiva-default.xml file.
104 private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected,
105 int proxyConnectorExpected )
109 assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
110 configuration.getManagedRepositories().size() );
111 assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected,
112 configuration.getRemoteRepositories().size() );
113 assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected,
114 configuration.getProxyConnectors().size() );
116 RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
117 assertNotNull( "check repository scanning", repoScanning );
118 assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
119 assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
120 assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
122 List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
123 assertNotNull( "check 'artifacts' file type", patterns );
124 assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
126 WebappConfiguration webapp = configuration.getWebapp();
127 assertNotNull( "check webapp", webapp );
129 UserInterfaceOptions ui = webapp.getUi();
130 assertNotNull( "check webapp ui", ui );
131 assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
132 assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );