From d3f56e231eae8ec312a1057da23cca5a943506a7 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 11 Feb 2015 22:43:25 +1100 Subject: [PATCH] fix junit --- .../DownloadArtifactFromQueryTest.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java index cedd46a24..341d8388e 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java @@ -23,6 +23,7 @@ import org.apache.archiva.rest.api.services.ManagedRepositoriesService; import org.apache.archiva.rest.api.services.RepositoriesService; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.apache.commons.io.FileUtils; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; @@ -30,9 +31,11 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import javax.ws.rs.RedirectionException; import javax.ws.rs.core.Response; import java.io.File; import java.io.IOException; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -121,7 +124,7 @@ public class DownloadArtifactFromQueryTest } - @Test + @Test( expected = RedirectionException.class ) public void downloadFixedVersion() throws Exception { @@ -136,10 +139,17 @@ public class DownloadArtifactFromQueryTest Assert.assertEquals( Response.Status.TEMPORARY_REDIRECT.getStatusCode(), response.getStatus() ); - String location = String.class.cast( response.getMetadata().get( "Location" ).get( 0 ) ); + //String location = String.class.cast( response.getMetadata().get( "Location" ).get( 0 ) ); - Assert.assertEquals( "http://localhost:" + port + "/repository/" + id - + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar", location ); + //Assert.assertEquals( "http://localhost:" + port + "/repository/" + id + // + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar", location ); + } + catch ( RedirectionException e ) + { + Assertions.assertThat( e.getLocation().compareTo( new URI( "http://localhost:" + port + "/repository/" + id + + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) ) ).isEqualTo( + 0 ); + throw e; } finally { @@ -149,7 +159,7 @@ public class DownloadArtifactFromQueryTest } - @Test + @Test( expected = RedirectionException.class ) public void downloadLatestVersion() throws Exception { @@ -167,11 +177,17 @@ public class DownloadArtifactFromQueryTest /// http://localhost:57168/repository/1400639145722/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar - Assert.assertEquals( "http://localhost:" + port + "/repository/" + id - + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar", location ); - + //Assert.assertEquals( "http://localhost:" + port + "/repository/" + id + // + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar", location ); } + catch ( RedirectionException e ) + { + Assertions.assertThat( e.getLocation().compareTo( new URI( "http://localhost:" + port + "/repository/" + id + + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) ) ).isEqualTo( + 0 ); + throw e; + } finally { getManagedRepositoriesService().deleteManagedRepository( id, false );