Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
NEXUS-421: fixed IT
Browse files Browse the repository at this point in the history
git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/trunk/nexus@6264 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information
cstamas committed Apr 2, 2010
1 parent 04b3bda commit a36296f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 30 deletions.
Expand Up @@ -65,7 +65,7 @@ public RepositoryMessageUtil( XStream xstream, MediaType mediaType, RepositoryTy
this.mediaType = mediaType;
this.repositoryTypeRegistry = registry;
}

public RepositoryBaseResource createRepository( RepositoryBaseResource repo )
throws IOException
{
Expand Down Expand Up @@ -130,15 +130,15 @@ public void validateResourceResponse( RepositoryBaseResource repo, RepositoryBas
if ( actual.getDefaultLocalStorageUrl().endsWith( "/" ) )
{
Assert.assertTrue( "Unexpected defaultLocalStorage: <expected to end with> " + "/storage/"
+ repo.getId() + "/ <actual>" + actual.getDefaultLocalStorageUrl(),
actual.getDefaultLocalStorageUrl().endsWith( "/storage/" + repo.getId() + "/" ) );
+ repo.getId() + "/ <actual>" + actual.getDefaultLocalStorageUrl(), actual
.getDefaultLocalStorageUrl().endsWith( "/storage/" + repo.getId() + "/" ) );
}
// NOTE one of these blocks should be removed
else
{
Assert.assertTrue( "Unexpected defaultLocalStorage: <expected to end with> " + "/storage/"
+ repo.getId() + " <actual>" + actual.getDefaultLocalStorageUrl(),
actual.getDefaultLocalStorageUrl().endsWith( "/storage/" + repo.getId() ) );
+ repo.getId() + " <actual>" + actual.getDefaultLocalStorageUrl(), actual
.getDefaultLocalStorageUrl().endsWith( "/storage/" + repo.getId() ) );
}

Assert.assertEquals( expected.getNotFoundCacheTTL(), actual.getNotFoundCacheTTL() );
Expand All @@ -150,8 +150,8 @@ public void validateResourceResponse( RepositoryBaseResource repo, RepositoryBas
}
else
{
Assert.assertEquals( expected.getRemoteStorage().getRemoteStorageUrl(),
actual.getRemoteStorage().getRemoteStorageUrl() );
Assert.assertEquals( expected.getRemoteStorage().getRemoteStorageUrl(), actual.getRemoteStorage()
.getRemoteStorageUrl() );
}

Assert.assertEquals( expected.getRepoPolicy(), actual.getRepoPolicy() );
Expand Down Expand Up @@ -183,13 +183,13 @@ public RepositoryBaseResource getRepository( String repoId )

return resourceResponse.getData();
}

public RepositoryBaseResource updateRepo( RepositoryBaseResource repo )
throws IOException
{
return updateRepo( repo, true );
}

public RepositoryBaseResource updateRepo( RepositoryBaseResource repo, boolean validate )
throws IOException
{
Expand Down Expand Up @@ -337,21 +337,22 @@ private void validateRepoInNexusConfig( RepositoryBaseResource repo )
ContentClass expectedCc =
repositoryTypeRegistry.getRepositoryContentClass( cRepo.getProviderRole(), cRepo.getProviderHint() );
Assert.assertNotNull( "Unknown repo type='" + cRepo.getProviderRole() + cRepo.getProviderHint() + "'!",
expectedCc );
expectedCc );
Assert.assertEquals( expected.getFormat(), expectedCc.getId() );

Assert.assertEquals( expected.getNotFoundCacheTTL(), cRepo.getNotFoundCacheTTL() );

if ( expected.getOverrideLocalStorageUrl() == null )
{
Assert.assertNull( "Expected CRepo localstorage url not be set, because it is the default.",
cRepo.getLocalStorage().getUrl() );
Assert.assertNull( "Expected CRepo localstorage url not be set, because it is the default.", cRepo
.getLocalStorage().getUrl() );
}
else
{
String actualLocalStorage =
cRepo.getLocalStorage().getUrl().endsWith( "/" ) ? cRepo.getLocalStorage().getUrl()
: cRepo.getLocalStorage().getUrl() + "/";
cRepo.getLocalStorage().getUrl().endsWith( "/" ) ? cRepo.getLocalStorage().getUrl() : cRepo
.getLocalStorage().getUrl()
+ "/";
String overridLocalStorage =
expected.getOverrideLocalStorageUrl().endsWith( "/" ) ? expected.getOverrideLocalStorageUrl()
: expected.getOverrideLocalStorageUrl() + "/";
Expand All @@ -364,8 +365,8 @@ private void validateRepoInNexusConfig( RepositoryBaseResource repo )
}
else
{
Assert.assertEquals( expected.getRemoteStorage().getRemoteStorageUrl(),
cRepo.getRemoteStorage().getUrl() );
Assert.assertEquals( expected.getRemoteStorage().getRemoteStorageUrl(), cRepo.getRemoteStorage()
.getUrl() );
}

// check maven repo props (for not just check everything that is a Repository
Expand Down Expand Up @@ -423,8 +424,21 @@ public static void updateIncrementalIndexes( String... repositories )
public RepositoryStatusResource getStatus( String repoId )
throws IOException
{
return getStatus( repoId, false );
}

public RepositoryStatusResource getStatus( String repoId, boolean force )
throws IOException
{

String uri = SERVICE_PART + "/" + repoId + "/status";

if ( force )
{
uri = uri + "?forceCheck=true";
}

Response response = RequestFacade.sendMessage( SERVICE_PART + "/" + repoId + "/status", Method.GET );
Response response = RequestFacade.sendMessage( uri, Method.GET );
Status status = response.getStatus();
Assert.assertTrue( "Fail to getStatus for '" + repoId + "' repository" + status, status.isSuccess() );

Expand Down
Expand Up @@ -2,15 +2,18 @@

import java.io.IOException;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import junit.framework.Assert;

import org.junit.Test;
import org.restlet.data.MediaType;
import org.sonatype.nexus.integrationtests.AbstractEmailServerNexusIT;
import org.sonatype.nexus.proxy.repository.RemoteStatus;
import org.sonatype.nexus.rest.model.GlobalConfigurationResource;
import org.sonatype.nexus.rest.model.RepositoryProxyResource;
import org.sonatype.nexus.rest.model.RepositoryStatusResource;
import org.sonatype.nexus.rest.model.SystemNotificationSettings;
import org.sonatype.nexus.test.utils.RepositoryMessageUtil;
import org.sonatype.nexus.test.utils.SettingsMessageUtil;
Expand All @@ -30,14 +33,11 @@ public void testAutoBlockNotification()
// make central auto-block itself (point it to bad URL)
pointCentralToRemoteUrl( "http://repo1.maven.org/mavenFooBar/not-here/" );

// expect 3 mails: for admin user, for pipi1 and for pipi2. Mail should be about "auto-blocked"
expectMails( 3, "auto-blocked" );

// make central unblock itself (point it to good URL)
pointCentralToRemoteUrl( "http://repo1.maven.org/maven2/" );

// expect 3 mails: for admin user, for pipi1 and for pipi2. Mail should be about "unblocked"
expectMails( 3, "unblocked" );
// we have 3 recipients set
checkMails( 3 );
}

// --
Expand All @@ -47,7 +47,7 @@ protected void prepare()
{
// set up repo message util
this.repoMessageUtil =
new RepositoryMessageUtil( this.getJsonXStream(), MediaType.APPLICATION_JSON, getRepositoryTypeRegistry() );
new RepositoryMessageUtil( getXMLXStream(), MediaType.APPLICATION_XML, getRepositoryTypeRegistry() );

// CONFIG CHANGES (using Nexus factory-defaults!)
// set up SMTP to use our mailServer
Expand Down Expand Up @@ -95,7 +95,7 @@ protected void prepare()
}

protected void pointCentralToRemoteUrl( String remoteUrl )
throws IOException
throws IOException, InterruptedException
{
// make a proxy server to block (do it by taking central, and breaking it's remoteURL)
RepositoryProxyResource central = (RepositoryProxyResource) repoMessageUtil.getRepository( "central" );
Expand All @@ -104,20 +104,55 @@ protected void pointCentralToRemoteUrl( String remoteUrl )
central.getRemoteStorage().setRemoteStorageUrl( remoteUrl );

repoMessageUtil.updateRepo( central );

// to "ping it" (and not wait for thread to check remote availability)
RepositoryStatusResource res = repoMessageUtil.getStatus( "central", true );

while ( RemoteStatus.UNKNOWN.name().equals( res.getRemoteStatus() ) )
{
res = repoMessageUtil.getStatus( "central", false );

Thread.sleep( 1000 );
}
}

protected void expectMails( int count, String... contentToCheckFor )
throws InterruptedException
protected void checkMails( int recipientCount )
throws InterruptedException, MessagingException
{
server.waitForIncomingEmail( 10000, count );
int expectedMailCount = recipientCount * 2;

// expect total 2*count mails: once for auto-block, once for unblock, for admin user, for pipi1 and for pipi2.
// Mail
// should be about "unblocked"
server.waitForIncomingEmail( 10000, expectedMailCount );

MimeMessage[] msgs = server.getReceivedMessages();

Assert.assertNotNull( "Messages array should not be null!", msgs );

Assert.assertEquals( "We expect " + count + " mails!", count, msgs.length );
Assert.assertEquals( "We expect " + expectedMailCount + " mails, since we have " + recipientCount
+ " recipients!", expectedMailCount, msgs.length );

// TODO: implement simple string search for contentToCheckFor in mail bodies
}
int blockedMails = 0;

int unblockedMails = 0;

for ( int i = 0; i < expectedMailCount; i++ )
{
MimeMessage msg = msgs[i];

if ( msg.getSubject().toLowerCase().contains( "auto-blocked" ) )
{
blockedMails++;
}
else if ( msg.getSubject().toLowerCase().contains( "unblocked" ) )
{
unblockedMails++;
}
}

Assert.assertEquals( "We should have equally " + recipientCount
+ " for auto-blocked and unblocked mails! We have auto-blocked and unblocked!", blockedMails
+ unblockedMails, expectedMailCount );
}
}

0 comments on commit a36296f

Please sign in to comment.