Permalink
Browse files

o [NEXUS-5246] Fix ITs to expect temporary redirection

  • Loading branch information...
1 parent af0c0bf commit ccc75394bc8561acc6a3a52a36875eee18da9c95 @nabcos nabcos committed Sep 14, 2012
@@ -82,6 +82,6 @@ private void assertLinkAvailable( String link )
throws Exception
{
// use sendMessage because this is a non-service-URL (?)
- RequestFacade.sendMessage( new URL( link ), Method.GET, null, ResponseMatchers.respondsWithStatusCode( 301 ) ).release();
+ RequestFacade.sendMessage( new URL( link ), Method.GET, null, ResponseMatchers.respondsWithStatusCode( 307 ) ).release();
}
}
@@ -22,6 +22,7 @@
import static org.sonatype.nexus.test.utils.StatusMatchers.isNotFound;
import java.io.File;
+import java.io.IOException;
import java.net.URL;
import org.apache.maven.index.artifact.Gav;
@@ -76,25 +77,7 @@ public void searchSnapshot()
String serviceURI =
"service/local/artifact/maven/redirect?r=" + REPO_TEST_HARNESS_SNAPSHOT_REPO + "&g=" + gav.getGroupId()
+ "&a=" + gav.getArtifactId() + "&v=" + gav.getVersion();
- Response response = null;
-
- try
- {
- response = RequestFacade.doGetRequest( serviceURI );
- assertThat(
- response,
- allOf( isRedirecting(), respondsWithStatusCode( 301 ), redirectLocation( notNullValue( String.class ) ) ) );
-
- RequestFacade.releaseResponse( response );
-
- response =
- RequestFacade.sendMessage( new URL( response.getLocationRef().toString() ), Method.GET, null,
- isSuccessful() );
- }
- finally
- {
- RequestFacade.releaseResponse( response );
- }
+ assertRedirection( serviceURI );
}
@Test
@@ -105,25 +88,7 @@ public void searchRelease()
"service/local/artifact/maven/redirect?r=" + REPO_TEST_HARNESS_REPO + "&g=" + gav.getGroupId() + "&a="
+ "artifact" + "&v=" + "1.0";
- Response response = null;
- try
- {
- response = RequestFacade.doGetRequest( serviceURI );
- assertThat(
- response,
- allOf( isRedirecting(), respondsWithStatusCode( 301 ), redirectLocation( notNullValue( String.class ) ) ) );
-
- RequestFacade.releaseResponse( response );
-
- // location is full url, so sendMessage directly
- response =
- RequestFacade.sendMessage( new URL( response.getLocationRef().toString() ), Method.GET, null,
- isSuccessful() );
- }
- finally
- {
- RequestFacade.releaseResponse( response );
- }
+ assertRedirection( serviceURI );
}
@Test
@@ -133,25 +98,7 @@ public void searchSnapshotOverAGroup()
String serviceURI =
"service/local/artifact/maven/redirect?r=" + NEXUS_602_GROUP + "&g=" + gav.getGroupId() + "&a="
+ gav.getArtifactId() + "&v=" + gav.getVersion();
- Response response = null;
-
- try
- {
- response = RequestFacade.doGetRequest( serviceURI );
- assertThat(
- response,
- allOf( isRedirecting(), respondsWithStatusCode( 301 ), redirectLocation( notNullValue( String.class ) ) ) );
-
- RequestFacade.releaseResponse( response );
-
- response =
- RequestFacade.sendMessage( new URL( response.getLocationRef().toString() ), Method.GET, null,
- isSuccessful() );
- }
- finally
- {
- RequestFacade.releaseResponse( response );
- }
+ assertRedirection( serviceURI );
}
@Test
@@ -162,25 +109,7 @@ public void searchReleaseOverAGroup()
"service/local/artifact/maven/redirect?r=" + NEXUS_602_GROUP + "&g=" + gav.getGroupId() + "&a="
+ "artifact" + "&v=" + "1.0";
- Response response = null;
- try
- {
- response = RequestFacade.doGetRequest( serviceURI );
- assertThat(
- response,
- allOf( isRedirecting(), respondsWithStatusCode( 301 ), redirectLocation( notNullValue( String.class ) ) ) );
-
- RequestFacade.releaseResponse( response );
-
- // location is full url, so sendMessage directly
- response =
- RequestFacade.sendMessage( new URL( response.getLocationRef().toString() ), Method.GET, null,
- isSuccessful() );
- }
- finally
- {
- RequestFacade.releaseResponse( response );
- }
+ assertRedirection( serviceURI );
}
@Test
@@ -190,25 +119,7 @@ public void searchWildcardLatestOverAGroup()
String serviceURI =
"service/local/artifact/maven/redirect?r=" + NEXUS_602_GROUP + "&g=" + gav.getGroupId() + "&a="
+ gav.getArtifactId() + "&v=LATEST";
- Response response = null;
-
- try
- {
- response = RequestFacade.doGetRequest( serviceURI );
- assertThat(
- response,
- allOf( isRedirecting(), respondsWithStatusCode( 301 ), redirectLocation( notNullValue( String.class ) ) ) );
-
- RequestFacade.releaseResponse( response );
-
- response =
- RequestFacade.sendMessage( new URL( response.getLocationRef().toString() ), Method.GET, null,
- isSuccessful() );
- }
- finally
- {
- RequestFacade.releaseResponse( response );
- }
+ assertRedirection( serviceURI );
}
@Test
@@ -218,36 +129,42 @@ public void searchWildcardReleaseOverAGroup()
String serviceURI =
"service/local/artifact/maven/redirect?r=" + NEXUS_602_GROUP + "&g=" + gav.getGroupId() + "&a="
+ gav.getArtifactId() + "&v=RELEASE";
+ assertRedirection( serviceURI );
+ }
+
+ @Test
+ public void searchInvalidArtifact()
+ throws Exception
+ {
+ String serviceURI =
+ "service/local/artifact/maven/redirect?r=" + REPO_TEST_HARNESS_REPO + "&g=" + "invalidGroupId" + "&a="
+ + "invalidArtifact" + "&v=" + "32.64";
+
+ RequestFacade.doGetForStatus( serviceURI, isNotFound() );
+ }
+
+ private void assertRedirection( final String serviceURI )
+ throws IOException
+ {
Response response = null;
try
{
response = RequestFacade.doGetRequest( serviceURI );
assertThat(
response,
- allOf( isRedirecting(), respondsWithStatusCode( 301 ), redirectLocation( notNullValue( String.class ) ) ) );
+ allOf( isRedirecting(), respondsWithStatusCode( 307 ), redirectLocation( notNullValue( String.class ) ) ) );
RequestFacade.releaseResponse( response );
response =
RequestFacade.sendMessage( new URL( response.getLocationRef().toString() ), Method.GET, null,
- isSuccessful() );
+ isSuccessful() );
}
finally
{
RequestFacade.releaseResponse( response );
}
}
- @Test
- public void searchInvalidArtifact()
- throws Exception
- {
- String serviceURI =
- "service/local/artifact/maven/redirect?r=" + REPO_TEST_HARNESS_REPO + "&g=" + "invalidGroupId" + "&a="
- + "invalidArtifact" + "&v=" + "32.64";
-
- RequestFacade.doGetForStatus( serviceURI, isNotFound() );
- }
-
}
@@ -1020,7 +1020,7 @@ public File downloadSnapshotArtifact( String repository, Gav gav, File parentDir
assertThat(
response,
- allOf( isRedirecting(), respondsWithStatusCode( 301 ), redirectLocation( notNullValue( String.class ) ) ) );
+ allOf( isRedirecting(), respondsWithStatusCode( 307 ), redirectLocation( notNullValue( String.class ) ) ) );
serviceURI = response.getLocationRef().toString();
}

0 comments on commit ccc7539

Please sign in to comment.