Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

UTs fixed

  • Loading branch information...
commit 1b0863323ffb2485ed38c8d212693a1d74e5471a 1 parent dd10bc4
@cstamas cstamas authored
View
91 nexus/nexus-core/src/test/java/org/sonatype/nexus/proxy/RemoteStorageSettingsInheritanceTest.java
@@ -18,7 +18,10 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.junit.Test;
import org.sonatype.configuration.ConfigurationException;
+import org.sonatype.nexus.Nexus;
+import org.sonatype.nexus.NexusAppTestSupport;
import org.sonatype.nexus.configuration.application.ApplicationConfiguration;
+import org.sonatype.nexus.configuration.application.NexusConfiguration;
import org.sonatype.nexus.configuration.model.CLocalStorage;
import org.sonatype.nexus.configuration.model.CRemoteStorage;
import org.sonatype.nexus.configuration.model.CRepository;
@@ -39,8 +42,9 @@
* @author cstamas
*/
public class RemoteStorageSettingsInheritanceTest
- extends AbstractProxyTestEnvironment
+ extends NexusAppTestSupport
{
+
protected ApplicationConfiguration applicationConfiguration;
protected ProxyRepository aProxyRepository;
@@ -48,68 +52,14 @@
public void setUp()
throws Exception
{
+ // loads up config, defaults
+ lookup( Nexus.class );
+
super.setUp();
applicationConfiguration = lookup( ApplicationConfiguration.class );
-
- aProxyRepository = lookup( RepositoryRegistry.class ).getRepositoryWithFacet( "central", ProxyRepository.class );
- }
-
- @Override
- protected EnvironmentBuilder getEnvironmentBuilder()
- throws Exception
- {
- return new EnvironmentBuilder()
- {
- public void stopService()
- throws Exception
- {
- // nothing
- }
-
- public void startService()
- throws Exception
- {
- // nothing
- }
-
- public void buildEnvironment( AbstractProxyTestEnvironment abstractProxyTestEnvironment )
- throws ConfigurationException, IOException, ComponentLookupException
- {
- // building a "mock" proxy repo we will not use at all
- M2Repository repo = (M2Repository) getContainer().lookup( Repository.class, "maven2" );
-
- CRepository repoConf = new DefaultCRepository();
-
- repoConf.setProviderRole( Repository.class.getName() );
- repoConf.setProviderHint( "maven2" );
- repoConf.setId( "central" );
- repoConf.setName( "Fake Central" );
-
- repoConf.setLocalStorage( new CLocalStorage() );
- repoConf.getLocalStorage().setProvider( "file" );
- repoConf.getLocalStorage().setUrl(
- abstractProxyTestEnvironment.getApplicationConfiguration().getWorkingDirectory(
- "proxy/store/central" ).toURI().toURL().toString() );
-
- Xpp3Dom ex = new Xpp3Dom( "externalConfiguration" );
- repoConf.setExternalConfiguration( ex );
- M2RepositoryConfiguration exConf = new M2RepositoryConfiguration( ex );
- exConf.setRepositoryPolicy( RepositoryPolicy.RELEASE );
- exConf.setChecksumPolicy( ChecksumPolicy.STRICT_IF_EXISTS );
-
- repoConf.setRemoteStorage( new CRemoteStorage() );
- repoConf.getRemoteStorage().setProvider( abstractProxyTestEnvironment.getRemoteProviderHintFactory().getDefaultHttpRoleHint() );
- repoConf.getRemoteStorage().setUrl( "http://whatever.server/foo/but/be/a/valid/url" );
-
- repo.configure( repoConf );
-
- abstractProxyTestEnvironment.getApplicationConfiguration().getConfigurationModel().addRepository(
- repoConf );
-
- abstractProxyTestEnvironment.getRepositoryRegistry().addRepository( repo );
- }
- };
+ aProxyRepository =
+ lookup( RepositoryRegistry.class ).getRepositoryWithFacet( "central", ProxyRepository.class );
}
@Test
@@ -119,21 +69,16 @@ public void testNEXUS3064PerRepo()
int rscChange = aProxyRepository.getRemoteStorageContext().getGeneration();
RemoteProxySettings proxy = aProxyRepository.getRemoteProxySettings();
-
assertFalse( "Should no proxy be set!", proxy.isEnabled() );
-
proxy.setHostname( "192.168.1.1" );
-
proxy.setPort( 1234 );
-
// TODO: this is the spurious part!!! Make it not needed! Config framework DOES know it changed!
// If you remove this, test will fail
- // aProxyRepository.setRemoteProxySettings( proxy );
-
+ aProxyRepository.setRemoteProxySettings( proxy );
applicationConfiguration.saveConfiguration();
assertTrue( "The change should be detected",
- aProxyRepository.getRemoteStorageContext().getGeneration() > rscChange );
+ aProxyRepository.getRemoteStorageContext().getGeneration() > rscChange );
}
@Test
@@ -145,21 +90,17 @@ public void testNEXUS3064Global()
// and the problem now
// change the global proxy
RemoteProxySettings proxy =
- getApplicationConfiguration().getGlobalRemoteStorageContext().getRemoteProxySettings();
-
+ applicationConfiguration.getGlobalRemoteStorageContext().getRemoteProxySettings();
proxy.setHostname( "192.168.1.1" );
-
proxy.setPort( 1234 );
-
- applicationConfiguration.saveConfiguration();
-
// TODO: this is the spurious part!!! Make it not needed! Config framework DOES know it changed!
// If you remove this, test will fail
applicationConfiguration.getGlobalRemoteStorageContext().setRemoteProxySettings( proxy );
+ applicationConfiguration.saveConfiguration();
+
assertTrue( "The change should be detected",
- aProxyRepository.getRemoteStorageContext().getGeneration() > rscChange );
+ aProxyRepository.getRemoteStorageContext().getGeneration() > rscChange );
}
-
}
View
31 nexus/nexus-core/src/test/java/org/sonatype/nexus/proxy/repository/AccessTest.java
@@ -14,7 +14,10 @@
import java.io.File;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;
@@ -24,7 +27,9 @@
import org.apache.shiro.util.ThreadContext;
import org.codehaus.plexus.util.FileUtils;
import org.sonatype.jettytestsuite.ServletServer;
+import org.sonatype.nexus.Nexus;
import org.sonatype.nexus.configuration.application.ApplicationConfiguration;
+import org.sonatype.nexus.configuration.application.NexusConfiguration;
import org.sonatype.nexus.proxy.AbstractProxyTestEnvironment;
import org.sonatype.nexus.proxy.AccessDeniedException;
import org.sonatype.nexus.proxy.EnvironmentBuilder;
@@ -44,32 +49,38 @@
{
private M2TestsuiteEnvironmentBuilder jettyTestsuiteEnvironmentBuilder;
- protected ApplicationConfiguration applicationConfiguration;
-
@Override
public void setUp()
throws Exception
{
- applicationConfiguration = this.lookup( ApplicationConfiguration.class );
- applicationConfiguration.saveConfiguration();
+ // loads up config, defaults
+ lookup( Nexus.class );
super.setUp();
- //String resource = this.getClass().getName().replaceAll( "\\.", "\\/" ) + "-security-configuration.xml";
- //URL url = Thread.currentThread().getContextClassLoader().getResource( resource );
- //FileUtils.copyURLToFile( url, new File( getConfHomeDir(), "security-configuration.xml" ) );
+ final TargetRegistry targetRegistry = this.lookup( TargetRegistry.class );
- TargetRegistry targetRegistry = this.lookup( TargetRegistry.class );
+ // shave off defaults
+ final Collection<Target> targets = new ArrayList<Target>( targetRegistry.getRepositoryTargets() );
+ for ( Target t : targets )
+ {
+ targetRegistry.removeRepositoryTarget( t.getId() );
+ }
+ // add target
Target t1 =
new Target( "maven2-all", "All (Maven2)", new Maven2ContentClass(), Arrays.asList( new String[] { ".*" } ) );
targetRegistry.addRepositoryTarget( t1 );
- applicationConfiguration.saveConfiguration();
+ getApplicationConfiguration().saveConfiguration();
// setup security
- this.lookup( SecuritySystem.class ).start(); // need to call start to clear caches
+ // setup security
+ final SecuritySystem securitySystem = this.lookup( SecuritySystem.class );
+ securitySystem.setRealms( Collections.singletonList( "default" ) );
+ securitySystem.setSecurityEnabled( true );
+ securitySystem.start();
}
@Override
View
24 nexus/nexus-core/src/test/java/org/sonatype/nexus/proxy/router/DefaultRepositoryRouterTest.java
@@ -16,6 +16,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -30,6 +31,7 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.sonatype.nexus.NexusAppTestSupport;
import org.sonatype.nexus.configuration.application.ApplicationConfiguration;
+import org.sonatype.nexus.configuration.application.NexusConfiguration;
import org.sonatype.nexus.configuration.model.CRepository;
import org.sonatype.nexus.configuration.model.DefaultCRepository;
import org.sonatype.nexus.proxy.NexusProxyTestSupport;
@@ -69,6 +71,11 @@ protected void setUp()
{
super.setUp();
+ // loads up config, defaults
+ nexusConfiguration = this.lookup( NexusConfiguration.class );
+ nexusConfiguration.loadConfiguration( false );
+ nexusConfiguration.saveConfiguration();
+
applicationConfiguration = this.lookup( ApplicationConfiguration.class );
applicationConfiguration.saveConfiguration();
@@ -92,8 +99,16 @@ protected void setUp()
// URL url = Thread.currentThread().getContextClassLoader().getResource( resource );
// FileUtils.copyURLToFile( url, new File( getConfHomeDir(), "security-configuration.xml" ) );
- // create a target
TargetRegistry targetRegistry = this.lookup( TargetRegistry.class );
+
+ // shave off defaults
+ final Collection<Target> targets = new ArrayList<Target>( targetRegistry.getRepositoryTargets() );
+ for ( Target t : targets )
+ {
+ targetRegistry.removeRepositoryTarget( t.getId() );
+ }
+
+ // create a target
Target t1 =
new Target( "maven2-all", "All (Maven2)", new Maven2ContentClass(), Arrays.asList( new String[] { ".*" } ) );
targetRegistry.addRepositoryTarget( t1 );
@@ -104,9 +119,7 @@ protected void setUp()
// setup security
this.securitySystem = this.lookup( SecuritySystem.class );
this.securitySystem.setRealms( Collections.singletonList( "default" ) );
- this.securitySystem.setAnonymousAccessEnabled( false );
this.securitySystem.start();
-
}
@Override
@@ -123,6 +136,11 @@ public void tearDown()
}
}
+ protected boolean loadConfigurationAtSetUp()
+ {
+ return false;
+ }
+
@Test
public void testRouterWithViewAccess()
throws Exception
Please sign in to comment.
Something went wrong with that request. Please try again.