mirror of https://github.com/apache/archiva.git
isolate a testMethod unable to run solely. alphabetical order in class name is important.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1376884 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
18f535b8da
commit
8c5f6a8c07
|
@ -0,0 +1,136 @@
|
||||||
|
package org.apache.archiva.configuration;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.archiva.common.utils.FileUtil;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the configuration store.
|
||||||
|
*/
|
||||||
|
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
|
||||||
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
|
||||||
|
public class ArchivaConfigurationMRM789Test
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FileTypes filetypes;
|
||||||
|
|
||||||
|
public static File getTestFile( String path )
|
||||||
|
{
|
||||||
|
return new File( FileUtil.getBasedir(), path );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> T lookup( Class<T> clazz, String hint )
|
||||||
|
{
|
||||||
|
return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
// test for [MRM-789]
|
||||||
|
@Test
|
||||||
|
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
File repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_snapshots" );
|
||||||
|
repo.mkdirs();
|
||||||
|
|
||||||
|
repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_internal" );
|
||||||
|
repo.mkdirs();
|
||||||
|
|
||||||
|
String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
|
||||||
|
getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ) );
|
||||||
|
existingTestDefaultArchivaConfigFile =
|
||||||
|
StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
|
||||||
|
|
||||||
|
File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir(),
|
||||||
|
"target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
|
||||||
|
|
||||||
|
FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
|
||||||
|
null );
|
||||||
|
|
||||||
|
ArchivaConfiguration archivaConfiguration =
|
||||||
|
lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
assertConfiguration( configuration, 2, 1, 1 );
|
||||||
|
|
||||||
|
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
|
||||||
|
assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
|
||||||
|
|
||||||
|
generatedTestDefaultArchivaConfigFile.delete();
|
||||||
|
assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the provided configuration matches the details present in the archiva-default.xml file.
|
||||||
|
*/
|
||||||
|
private void assertConfiguration( Configuration configuration, int managedExpected, int remoteExpected,
|
||||||
|
int proxyConnectorExpected )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
assertEquals( "check managed repositories: " + configuration.getManagedRepositories(), managedExpected,
|
||||||
|
configuration.getManagedRepositories().size() );
|
||||||
|
assertEquals( "check remote repositories: " + configuration.getRemoteRepositories(), remoteExpected,
|
||||||
|
configuration.getRemoteRepositories().size() );
|
||||||
|
assertEquals( "check proxy connectors:" + configuration.getProxyConnectors(), proxyConnectorExpected,
|
||||||
|
configuration.getProxyConnectors().size() );
|
||||||
|
|
||||||
|
RepositoryScanningConfiguration repoScanning = configuration.getRepositoryScanning();
|
||||||
|
assertNotNull( "check repository scanning", repoScanning );
|
||||||
|
assertEquals( "check file types", 4, repoScanning.getFileTypes().size() );
|
||||||
|
assertEquals( "check known consumers", 9, repoScanning.getKnownContentConsumers().size() );
|
||||||
|
assertEquals( "check invalid consumers", 1, repoScanning.getInvalidContentConsumers().size() );
|
||||||
|
|
||||||
|
List<String> patterns = filetypes.getFileTypePatterns( "artifacts" );
|
||||||
|
assertNotNull( "check 'artifacts' file type", patterns );
|
||||||
|
assertEquals( "check 'artifacts' patterns", 13, patterns.size() );
|
||||||
|
|
||||||
|
WebappConfiguration webapp = configuration.getWebapp();
|
||||||
|
assertNotNull( "check webapp", webapp );
|
||||||
|
|
||||||
|
UserInterfaceOptions ui = webapp.getUi();
|
||||||
|
assertNotNull( "check webapp ui", ui );
|
||||||
|
assertTrue( "check showFindArtifacts", ui.isShowFindArtifacts() );
|
||||||
|
assertTrue( "check appletFindEnabled", ui.isAppletFindEnabled() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -67,13 +67,31 @@ public class ArchivaConfigurationTest
|
||||||
return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class );
|
return (T) applicationContext.getBean( "archivaConfiguration#" + hint, ArchivaConfiguration.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetConfigurationFromDefaults()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-defaults" );
|
||||||
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
|
|
||||||
|
assertConfiguration( configuration, 2, 1, 1 );
|
||||||
|
assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
|
||||||
|
|
||||||
|
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
|
||||||
|
|
||||||
|
assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
|
||||||
|
repository.getLocation() );
|
||||||
|
assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
|
||||||
|
assertEquals( "check managed repositories", "internal", repository.getId() );
|
||||||
|
assertEquals( "check managed repositories", "default", repository.getLayout() );
|
||||||
|
assertTrue( "check managed repositories", repository.isScanned() );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
|
public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
|
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
|
||||||
|
|
||||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||||
assertConfiguration( configuration, 2, 2, 2 );
|
assertConfiguration( configuration, 2, 2, 2 );
|
||||||
assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
|
assertEquals( "check network proxies", 1, configuration.getNetworkProxies().size() );
|
||||||
|
@ -88,62 +106,6 @@ public class ArchivaConfigurationTest
|
||||||
assertTrue( "check managed repositories", repository.isScanned() );
|
assertTrue( "check managed repositories", repository.isScanned() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetConfigurationFromDefaults()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-defaults" );
|
|
||||||
|
|
||||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
|
||||||
assertConfiguration( configuration, 2, 1, 1 );
|
|
||||||
assertEquals( "check network proxies", 0, configuration.getNetworkProxies().size() );
|
|
||||||
|
|
||||||
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
|
|
||||||
|
|
||||||
assertEquals( "check managed repositories", "${appserver.base}/data/repositories/internal",
|
|
||||||
repository.getLocation() );
|
|
||||||
assertEquals( "check managed repositories", "Archiva Managed Internal Repository", repository.getName() );
|
|
||||||
assertEquals( "check managed repositories", "internal", repository.getId() );
|
|
||||||
assertEquals( "check managed repositories", "default", repository.getLayout() );
|
|
||||||
assertTrue( "check managed repositories", repository.isScanned() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// test for [MRM-789]
|
|
||||||
@Test
|
|
||||||
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
File repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_snapshots" );
|
|
||||||
repo.mkdirs();
|
|
||||||
|
|
||||||
repo = new File( FileUtil.getBasedir(), "/target/test-classes/existing_internal" );
|
|
||||||
repo.mkdirs();
|
|
||||||
|
|
||||||
String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(
|
|
||||||
getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ) );
|
|
||||||
existingTestDefaultArchivaConfigFile =
|
|
||||||
StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() );
|
|
||||||
|
|
||||||
File generatedTestDefaultArchivaConfigFile = new File( FileUtil.getBasedir(),
|
|
||||||
"target/test-classes/org/apache/archiva/configuration/default-archiva.xml" );
|
|
||||||
|
|
||||||
FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile,
|
|
||||||
null );
|
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration =
|
|
||||||
lookup( ArchivaConfiguration.class, "test-defaults-default-repo-location-exists" );
|
|
||||||
|
|
||||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
|
||||||
assertConfiguration( configuration, 2, 1, 1 );
|
|
||||||
|
|
||||||
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get( 0 );
|
|
||||||
assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) );
|
|
||||||
|
|
||||||
generatedTestDefaultArchivaConfigFile.delete();
|
|
||||||
assertFalse( generatedTestDefaultArchivaConfigFile.exists() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the provided configuration matches the details present in the archiva-default.xml file.
|
* Ensures that the provided configuration matches the details present in the archiva-default.xml file.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue